# Arduino project -



## Jan (Oct 5, 2009)

Doesn't sound to complicated. If it is not very much more, and you're not in a hurry, maybe I can help. I know a bit about arduino's. But no hiring, just for the fun of it.


----------



## DJBecker (Nov 3, 2010)

What's the input pulse width and rate? Does it need a noise filter?
What are your physical size constraints? What hardware are you planning to use?
What type of servo output do you need? Standard R/C-type PWM?

The Arduino environment doesn't provide great support for tachometer input, but it's pretty easy to handle if you go directly to C.

When we were using a AVR Mega as the base for our motor controller, I implemented a tachometer using a timer running at 62.5KHz and a capture input. It was a little annoying to figure out and test, but the final code is small and simple.

The Arduino environment is great for outputting servo-style PWM, so that part might be trivial.


----------



## Qer (May 7, 2008)

Jan said:


> Doesn't sound to complicated.


As long as you have a clean, noise free signal. Yep.

Hint: Signals aren't noise free in an EV.


----------



## DJBecker (Nov 3, 2010)

Qer said:


> As long as you have a clean, noise free signal. Yep.
> 
> Hint: Signals aren't noise free in an EV.


I should have been more specific.
There is electrical noise, and there is input bounce.

We initially tried to use a simple circuit for the tachometer input. We counted on the AVR input pin Schmitt trigger to clean up the slow signal transition of a phototransistor connected to a pull-up resistor. Ha! Laughably bad. We eventually ended up with a optointerrupter board with a HOA6970 that has a totem pole (driven both high and low) output.

The second issue is "bounce". Even with a output driver, an optointerrupter might still put out a few false pulses as it turns on and off. This can really bite you if you try to implement a tachometer with interrupts rather than an input capture pin. Most microcontrollers with input capture pins have sampling input filters to handle this in hardware. The STM32, for instance, has six or seven bits of input filter options. It takes some experimentation to get the best setup for the application.

Here are my notes for the AVR:
* On the Mega 1280 board we have only ICP4 (JP2-49) and ICP5 (JP2-48)
* connected, so we are limited to using these timers.
*
* We enable the ICR noise filter, which requires four cycles at the new
* level before triggering the capture.


----------



## DIYguy (Sep 18, 2008)

Jan said:


> Doesn't sound to complicated. If it is not very much more, and you're not in a hurry, maybe I can help. I know a bit about arduino's. But no hiring, just for the fun of it.


Thanks Jan, that's very nice of you. Lets let this develop a bit first and see where it goes.


----------



## DIYguy (Sep 18, 2008)

Thanks to all other replies. I'll explain a bit tomorrow. Have to go to the great Canadian pastime now. (Hockey lol).

Basically, I know what I don't know, and I don't know controls. 

I do need to assemble a specification before project start. . . and a discussion on the topic should help with that.


----------



## DIYguy (Sep 18, 2008)

Ok, a bit of background. The goal is to have the brush gear in my 13" DC series wound motor advanced according to motor RPM. Perhaps the best algorithm should be based on more than just rpm. . . however, I'm not convinced at this time.

The only person doing something similar as this with an EV is (or maybe was) Denis Burube. Denis used a "small servo" of some sort for racing only, to move his brush timing from zero to 12 degrees over the course of his 1/4 mile. I think it was a "timed event only". . . meaning, the servo was told to "go" and a rate of speed was determined that worked for his elapsed time. Now that Smoke Screen is running an inter-poled motor, this is likely passé. It worked for the track, but not something for the street. I would like to take this idea and advance it somewhat so that the brush timing is controlled based on rpm. It's quite possible that this feature will not be used all the time so, lets call it selectable at this point.

My build (or mods) is unlike most in that it is not going to be purpose built for racing only. When racing is the only purpose, MANY issues are different as we all know. Creature comforts as well as many of the design criteria that enables longevity. Example would be a short range (capacity), 300 cycle high performance lipo battery for racing versus one that gives good performance as well as range and longevity. (this is a topic for another thread). Please don't drag this thread off in directions on the merit of my intentions - we can establish up front that I am crazy or whatever. Bottom line is, I want performance. But I also want to drive it. Daily. Not a handful of times at the track only. . and I want it to last. 

This is a direct drive application, well, a GV unit will be used for overdrive, but no conventional transmission. Maximizing torque in this case has a lot of value. It has been established that one negative of brush advance is loss of torque to the tune of approximately 2 percent per degree. 20 plus percent of torque is a lot to give up if you want to achieve fast acceleration times. In most applications this is of little consequence as the "lost" torque can be recovered through gearing.

OK, so what I chose is actually a Stepper Motor controlled linear actuator. It's an Ultra Motion unit and it comes with a motor drive called a 3540i. Here is the spec/manual. http://www.omega.com/manuals/manualpdf/3540i_manual.pdf
The linear actuator looks like this, http://www.ultramotion.com/products/digit.php 
I think it's called the "digit".

The drive runs on 12 - 42 VDC. As I understand it, a program can be written with Applied Motion software (free download) called Si Programmer (manual here: http://www.applied-motion.com/sites/default/files/Si_Programmer_Software_Manual.pdf 
and loaded to memory that will run the stepper motor based on inputs and programmed code. I think even I could write a program that would work with this code. 
My idea is to take the tacho-generator (inductive prox signal I use to feed Shiva) and either directly, or tach drive output from Shiva to drive the extension of the linear actuator. In other words, higher rpm. .. further extension. The problem is, the 3540i can only use a pulse train for speed determination, not position. I think I need a micro controller to interpret the pulse frequency and talk to the 3540i.

OK, beat me up.


----------



## Jan (Oct 5, 2009)

DIYguy said:


> The problem is, the 3540i can only use a pulse train for speed determination, not position.


Checking If I understand this correctly: The 3540i is controlled by a standard stepper motor. So, you can move it forward and backward and at a desired speed. In other words: if you know it's current position, you can move it to a desired position. And the problem is how to know the current position?

And yes, you're crazy. Now that's out of the air.

If I understand correctly you need some sensor, proximity sensor, or switch, or whatever. Every time the computer starts up it first must move the stepper to that switchpoint to callibrate its position.

Correct?


----------



## DIYguy (Sep 18, 2008)

Jan said:


> Checking If I understand this correctly: The 3540i is controlled by a standard stepper motor. So, you can move it forward and backward and at a desired speed. In other words: if you know it's current position, you can move it to a desired position. And the problem is how to know the current position?
> 
> And yes, you're crazy. Now that's out of the air.
> 
> ...


Yes, the 3540i is the drive (controller) that drives the standard stepper motor. Ya, moving it to positions at various speed is within it's capability. 
The problem, is to get it to move to a position based on pulse frequency. For example; the motor is spinning at 2500 rpm and somehow I determine that it should have 5 degrees of advance, . . . it needs to be at a position along it's stroke that positions the brushes at 5 degrees. Motor speeds up, linear actuator extends further. . motor slows, timing moves back towards zero. 
I think it will need at least one switch to determine it's current or home position. Some units come with a built in switch. 
I'm heading to the post office cause I think they tried to deliver this thing yesterday. . . .?? I'll know more then.


----------



## Jan (Oct 5, 2009)

DIYguy said:


> The problem, is to get it to move to a position based on pulse frequency. For example; the motor is spinning at 2500 rpm and somehow I determine that it should have 5 degrees of advance


I don't see that as a problem. The advantage of a stepper motor is that you know exactly where your are, once you know where you are. Just count the steps. But you first have to know where you are with a switch. Build in would be perfect.

Of course you need to callibrate it. In the sence you must know how many degree's a certain position is in the real world. But once you've callibrated that you can programm the arduino that it move to the exact position you want it.

I believe (I have to look it up) that an arduino is capable of reading a pulse signal. So, if you connect it to a pulsed rpm signal, (Maybe with an optocoupler) it all is just a matter of writing an algorithm that computes the correct position that belongs to a certain rpm.

The software isn't very complecated. The hardware is another story. From my point of view.


----------



## DIYguy (Sep 18, 2008)

zsnemeth said:


> In this case, I'd use something simple, mechanic thingy, like on the old diesel engines.
> A centrifugal type "Flying weight", which did regulate the max rpm of the engine. Sorry, don't know the correct term.


Yes, thanks. I thought about this for a while . . and I think it's possible, but rather restrictive. The nice thing about a programmable function is well, u can program it. Tweak it, change the conditions. . . fine tune it. . . turn it on/off. etc.


----------



## DIYguy (Sep 18, 2008)

Here are some pics. . ( it was sitting in the post office. no note on the door and nothing in my mail box indicating I had a package... :roll eyes: )


----------



## Jan (Oct 5, 2009)

Jan said:


> I believe (I have to look it up) that an arduino is capable of reading a pulse signal.


Yep it is. 

http://arduino.cc/en/Reference/pulseIn

Not sure if the rpm pulse is to fast or not. But in that case you could read it as a voltage. By putting some resistors, capacitors and/or inductors between the signal and the analog pin. But that's hardware.


----------



## Yabert (Feb 7, 2010)

DIYguy said:


> This is a direct drive application, well, a GV unit will be used for overdrive, but no conventional transmission. Maximizing torque in this case has a lot of value. It has been established that one negative of brush advance is loss of torque to the tune of approximately 2 percent per degree. 20 plus percent of torque is a lot to give up if you want to achieve fast acceleration times. In most applications this is of little consequence as the "lost" torque can be recovered through gearing.


 
Ummmm!.. you have a 13'' motor and a 3000A controller.... Have you really need 20% more torque??..

Like you know, I start a thread few years ago about brush advance and my conclusion was: I don't need to risk to blew my motor with a barely safe and costly systems of brush advance.

If I was at your place, I would start by calculated the real gain of 20% more torque for a fraction of second.
Without any calcul, I simply guess than it will give you only fraction of second advantage over the 1/4 miles.

Change brush grade and spring pressure when you go to the drag track seem a better and safer idea for me. Better commutation = more voltage capability = more power!

But you can try automatic brush advance... I Will watch with great interest..


----------



## DIYguy (Sep 18, 2008)

Jan said:


> Yep it is.
> 
> http://arduino.cc/en/Reference/pulseIn
> 
> Not sure if the rpm pulse is to fast or not. But in that case you could read it as a voltage. By putting some resistors, capacitors and/or inductors between the signal and the analog pin. But that's hardware.


Ya, that's why I thought it may be a good choice? If there is a better way, I'm all ears. 
As for frequency.. . . I will likely make another one like my 9" motor has and it is 2 pulse/rev. The REALLY NICE thing about the Evnetics controllers is their ability to put out different pulse/rev options to drive your OEM tach. I did a bunch of research before doing my last one figuring that it was looking for 2/rev only find out it was off by 1/3. 2 minutes later, I was outputting 3 pulses/rev and my tach has worked great ever since. 

At 2/rev, even 5,500 rpm is only 11,000 ppm, what is that less than 200/sec. seems "slow" in electrical terms, no?


----------



## DIYguy (Sep 18, 2008)

Yabert said:


> Ummmm!.. you have a 13'' motor and a 3000A controller.... Have you really need 20% more torque??..


we already established that Im crazy. I didn't say I need it. Want and need are different things. 



Yabert said:


> Like you know, I start a thread few years ago about brush advance and my conclusion was: I don't need to risk to blew my motor with a barely safe and costly systems of brush advance.


Yes, I recall it well. I should go back and read it though. It's always been in the back of my mind. I was looking into even before that .. but never did anything about it. I remember a picture of an adjustable ring that Jim Husted had on his site..... going way back. MAjor always talks me out of it... lol



Yabert said:


> If I was at your place, I would start by calculated the real gain of 20% more torque for a fraction of second.
> Without any calcul, I simply guess than it will give you only fraction of second advantage over the 1/4 miles.


one way to find out.....  It's probably longer than you think tho since this advance happens though most of the rpm range, albeit to a lessening degree. Also, with the GV shift, it may make some difference in the second gear. . .? I dunno..



Yabert said:


> Change brush grade and spring pressure when you go to the drag track seem a better and safer idea for me. Better commutation = more voltage capability = more power!
> 
> But you can try automatic brush advance... I Will watch with great interest..


I agree. I think I started the first thread on Helwig Split brushes . . ?? and I think it's an important point. It's not "either" though... it's "both".


----------



## Jan (Oct 5, 2009)

DIYguy said:


> At 2/rev, even 5,500 rpm is only 11,000 ppm, what is that less than 200/sec. seems "slow" in electrical terms, no?


"Works on pulses from 10 microseconds to 3 minutes in length."

Ahm, if my head works correctly 10 microseconds is only 100 pules per second. That's not ok.

If you really need that extra 100, you must convert the pulse signal to an analog voltage, like I said. I think there are enough members here that can tell you exactly how.


----------



## DIYguy (Sep 18, 2008)

Yabert said:


> Like you know, I start a thread few years ago about brush advance and my conclusion was: I don't need to risk to blew my motor with a barely safe and costly systems of brush advance.


I made an adjustable ring. . similar as your design pic, . . last year. I have a second CE housing with brush gear etc to play with. I made a ring of Delrin for the brush ring . . as a bearing surface. (delrin is slippery and takes high temp), I slotted the ring mount holes and bought some socket head shoulder screws. I will go find the pics.....


----------



## Jan (Oct 5, 2009)

DIYguy said:


> we already established that Im crazy. I didn't say I need it. Want and need are different things.


EV is all about 'want'.


----------



## DIYguy (Sep 18, 2008)

Here we go. U can't see the Delrin mount ring . . but it's underneath. The set still needs an lever attached and some details with washers etc under the screws. . . but u get the idea... This slot gives 12 degrees.


----------



## DIYguy (Sep 18, 2008)

Jan said:


> "Works on pulses from 10 microseconds to 3 minutes in length."
> 
> Ahm, if my head works correctly 10 microseconds is only 100 pules per second. That's not ok.
> 
> If you really need that extra 100, you must convert the pulse signal to an analog voltage, like I said. I think there are enough members here that can tell you exactly how.


Hang on. . isn't micro 10 x 6? so, wouldn't 10 microseconds mean 100,000/sec??


----------



## Jan (Oct 5, 2009)

DIYguy said:


> Hang on. . isn't micro 10 x 6? so, wouldn't 10 microseconds mean 100,000/sec??


Yeah. My head was thinking in milliseconds. Stupid head. Don't know why I keep it around.


----------



## DIYguy (Sep 18, 2008)

Jan said:


> Yeah. My head was thinking in milliseconds. Stupid head. Don't know why I keep it around.


LMAO... zeros are a challenge... 
I need to make one of these cables.... 

and download the software to my laptop PC and see if I can make it go..


----------



## Jan (Oct 5, 2009)

What are you going to do with that controller board? Is that thing able to read a pulse signal, and is that the 'arduino'? If not how are you going to communicate with that thing?

My first impression was to control the stepper motor directly from the arduino, with just a darlington transistor or something similar in between.


----------



## DIYguy (Sep 18, 2008)

Jan said:


> What are you going to do with that controller board? Is that thing able to read a pulse signal, and is that the 'arduino'? If not how are you going to communicate with that thing?
> 
> My first impression was to control the stepper motor directly from the arduino, with just a darlington transistor or something similar in between.


Jan, lol, u gotta look at the links I put... lol 
This board is the 3540i controller/driver for the stepper motor. U can write a complete program and load it into memory and this thing will run the cylinder based on I/O. It can do ALMOST everything I need except interpret pulses into a position. So, I need the Arduino to read pulses. 
In the basic form, lets say at x pulses, the Arduino sends a signal to the 3540i. This signal when seen by the program in the 3540i means, move to position y. With a string of these at different levels. . . it could work. Perhaps there is a more sophisticated way. . . but u get the idea.


----------



## Jan (Oct 5, 2009)

DIYguy said:


> but u get the idea.


Yep, I get the idea. A stepper motor is relatively simple to operate, so I didn't expect a seperate control board. It must be prety powerful then.


----------



## DIYguy (Sep 18, 2008)

Jan said:


> Yep, I get the idea. A stepper motor is relatively simple to operate, so I didn't expect a separate control board. It must be prety powerful then.


Yes, take a look at the programming software for it. It's pretty simple and made for the non-prammers. . . like me. 
Here's a shot of the program selector icons.

Hmmm, tried inserting pic... it showed up on preview, but not on post. Anyways check out the manual. . around page 10.

http://www.applied-motion.com/sites/default/files/Si_Programmer_Software_Manual.pdf


----------



## DJBecker (Nov 3, 2010)

Jan said:


> Yep it is.
> 
> http://arduino.cc/en/Reference/pulseIn
> 
> Not sure if the rpm pulse is to fast or not. But in that case you could read it as a voltage. By putting some resistors, capacitors and/or inductors between the signal and the analog pin. But that's hardware.


This does software pulse timing, and will not work well. You really want to use an input capture pin.

Edit: the implementation of this is even more primitive than I had imagined. It doesn't use a time reference at all. It just polls in a software timing loop, and then does an estimate of the time assuming each loop takes 10 clock cycles. That's a pretty rough estimate, and it will likely change with minor compiler updates. The Arduino environment is fun, but you really can't count on it for any serious controller.


----------



## Roy Von Rogers (Mar 21, 2009)

Just an idea, but why could one not use a motor shunt that gives 50/75 millivolt change in voltage, as a reference when to change brush position.

Roy


----------



## DIYguy (Sep 18, 2008)

Maybe I should look for a different stepper motor drive. One that's more functionally powerful . . and can accept a pulse train and analog signals?? Then it's one device.... ??
That's a question.......


----------



## DJBecker (Nov 3, 2010)

DIYguy said:


> Maybe I should look for a different stepper motor drive. One that's more functionally powerful . . and can accept a pulse train and analog signals?? Then it's one device.... ??
> That's a question.......


You must have already paid quite a bit for that CNC-oriented linear actuator and controller...

How much power do you need to turn the brush assembly? A high-power R/C servo might work, and would be trivial to interface. That simplifies the software to a tachometer input (I'll share the AVR code for that), mapping table and PWM servo output (written a zillion times on the AVR).


----------



## gaminde (Sep 18, 2011)

1. Use a hall effect sensor no noise on output
2. some motors have these on the back end or / and can be adapted
3. I think this site sells speed sensors look them up they fit GE and advanced motors


----------



## DIYguy (Sep 18, 2008)

DJBecker said:


> You must have already paid quite a bit for that CNC-oriented linear actuator and controller...


Actually no. I know it's worth a lot new... but I picked up both for $100. I knew I could, at the very least, make it work for the track even with what I have already.



DJBecker said:


> How much power do you need to turn the brush assembly? A high-power R/C servo might work, and would be trivial to interface. That simplifies the software to a tachometer input (I'll share the AVR code for that), mapping table and PWM servo output (written a zillion times on the AVR).


I'll check the current in the morning. . it's probably only 4 or 5 amps I would think. Thank you.


----------



## DIYguy (Sep 18, 2008)

Roy Von Rogers said:


> Just an idea, but why could one not use a motor shunt that gives 50/75 millivolt change in voltage, as a reference when to change brush position.
> 
> Roy


Ya maybe, not sure yet. Thanks for the suggestion Roy . . we'll see.


----------



## DIYguy (Sep 18, 2008)

gaminde said:


> 1. Use a hall effect sensor no noise on output
> 2. some motors have these on the back end or / and can be adapted
> 3. I think this site sells speed sensors look them up they fit GE and advanced motors


you mean that the hall effect is better than the inductive proximity for noise? Ya, I could do that if needed. I think I need to mount one or two magnets for a hall effect, right? Thanks.


----------



## DJBecker (Nov 3, 2010)

DIYguy said:


> you mean that the hall effect is better than the inductive proximity for noise? Ya, I could do that if needed. I think I need to mount one or two magnets for a hall effect, right? Thanks.


A Hall Effect sensor isn't a panacea for noise. In fact they are very delicate devices. In a high electric field and magnetic field environment like a PWM controlled motor, the noise will cause jitter, and perhaps false triggers. They are especially susceptible to a tangential RF electric field.

A common configuration is mounting a magnet behind the sensor, and sensing the changing field from teeth or notches in the moving iron or steel part. That's often better than mounting a magnet on the moving part.


----------



## Jan (Oct 5, 2009)

DIYguy said:


> Maybe I should look for a different stepper motor drive. One that's more functionally powerful . . and can accept a pulse train and analog signals?? Then it's one device.... ??
> That's a question.......


What went wrong then? DJBecker might be right about the accuracy of the pulse reading. But what makes you think it's not accurate enough for your project? There are lots and lots of arduinos out there measuring and controlling stuff.


----------



## DIYguy (Sep 18, 2008)

Jan said:


> What went wrong then? DJBecker might be right about the accuracy of the pulse reading. But what makes you think it's not accurate enough for your project? There are lots and lots of arduinos out there measuring and controlling stuff.


Hi Jan. I've come to no conclusions at this point. It's all about fleshing out the ideas. Let see where it leads. There are people from so many different backgrounds here . . I don't assume to know the best way to do this. I know it can be done though.


----------



## TigerNut (Dec 18, 2009)

Jan said:


> What went wrong then? DJBecker might be right about the accuracy of the pulse reading. But what makes you think it's not accurate enough for your project? There are lots and lots of arduinos out there measuring and controlling stuff.


Without checking all the various arduino builds, I would still guess that there is as much variability in the quality of hardware/software around those projects as there is here in the quality of EV component installation.

To do proper timing with a microcontroller you need some kind of stable timing reference. Best (for this environment) would be a temperature compensated crystal oscillator (TCXO); next-best is a 32.768kHz watch crystal, which many microcontrollers can use directly as a timebase; and way below that is an RC (resistor-capacitor) oscillator. Then, as DJBecker says, the incoming pulses need to drive the MCU's hardware event-capture system so that software execution doesn't affect the timing of that data. It's not complicated, but it's a step up from what many of the quick-start building block solutions give you, and that's why a lot of stuff sorta-kinda works, and only some other solutions work well all the time.

For a noise-insensitive sensor (if a variable-reluctance toothed wheel isn't going to cut it), you could mount a wheel with holes on the CE shaft and an optical transceiver on the motor case. You'd still have to shield the wiring and make sure you use a suitable pull-up/pull-down resistor to avoid stray noise.

If the comm end of the motor is significantly more noisy (electrically) than the drive end, then could you put the sensor arrangement on the drive coupler?


----------



## Jan (Oct 5, 2009)

DIYguy said:


> Hi Jan. I've come to no conclusions at this point. It's all about fleshing out the ideas. Let see where it leads. There are people from so many different backgrounds here . . I don't assume to know the best way to do this. I know it can be done though.


Another idea is that controller you already have: What microprocessor is on it, maybe it's completely reprogrammable, and hardware capable to read a pulsed signal or a voltage itself.

In my opinion is this project not completely comparable with a manned mission to the moon or an open hart surgery. It doesn't have to be super accurate. And with the right program you can filter out some noice or impossible readings.


----------



## DIYguy (Sep 18, 2008)

DJBecker said:


> How much power do you need to turn the brush assembly?


The drive puts out from 0.2 to 3.5 amps/phase with a 147 watt max rating.


----------



## DIYguy (Sep 18, 2008)

Jan said:


> Another idea is that controller you already have: What microprocessor is on it, maybe it's completely reprogrammable, and hardware capable to read a pulsed signal or a voltage itself.
> 
> In my opinion is this project not completely comparable with a manned mission to the moon or an open hart surgery. It doesn't have to be super accurate. And with the right program you can filter out some noice or impossible readings.


Ya, perhaps its true, I'm not sure. 

The processor is a PIC18F452.

I need something that I can basically plug and play. The programming of the drive I have is straight forward, I can do that. . but I can't develop something without a big investment in time that I don't have because I would have to learn a lot, destroy some stuff etc... lol . It's not my bag. 

I'm sure I can live with a set advancement of the brush timing and the ability to switch on the brush control device even if for a flat out run only. Sure would be nice to develop something like this though. Mounting a small camera to watch the brushes while developing the most suitable advance/rpm or voltage would be a kewl endeavor.


----------



## Jan (Oct 5, 2009)

DIYguy said:


> The processor is a PIC18F452.


Hmmm... It is capable of something. But on second thoughts, this isn't the way I would go. Way to complicated for me.

My first impression of what you planned, is still what I would do. Ditch the controller, and replace it with an arduino. A stepper motor is very simple to control. You only have to exite the wires one by one, or one by two by one, in the correct order for forward motion and backward motion. Every exitation is one step. Just count the steps to get to the right position. 

You need 4 or 6 transistors, depending on the number of poles, to be able to give the right amount of amps. Small steppers, like in my case, can be controlled directly from the arduino pins, but heavy ones, like yours, must be controlled trhoug a transistor bank. Transistors that can handle the higher amp and/or voltage. They are probably mounted on this controller board you already have.


----------



## DIYguy (Sep 18, 2008)

Jan said:


> Hmmm... It is capable of something. But on second thoughts, this isn't the way I would go. Way to complicated for me.
> 
> My first impression of what you planned, is still what I would do. Ditch the controller, and replace it with an arduino. A stepper motor is very simple to control. You only have to exite the wires one by one, or one by two by one, in the correct order for forward motion and backward motion. Every exitation is one step. Just count the steps to get to the right position.
> 
> You need 4 or 6 transistors, depending on the number of poles, to be able to give the right amount of amps. Small steppers, like in my case, can be controlled directly from the arduino pins, but heavy ones, like yours, must be controlled trhoug a transistor bank. Transistors that can handle the higher amp and/or voltage. They are probably mounted on this controller board you already have.


I know you thought I wanted to control the stepper directly with the Arduino. . . but in my little brain, I have a complete and proven system that works now. (I think) All I really need is something to interpret pulse frequency and send a signal to it.


----------



## bjfreeman (Dec 7, 2011)

Ii quickly scan the SI manual.
I may be way off base, but it sounds like what you need is a variable devider, that is between the Pickup coil and the input plug of the Si controller.
This can be done with standard chips, hardware wise.

If you want to use a Arduino uno, then you would build a shield board that had signal conditioning and feed the interrupt of the Arduino. The code would count the interrupts then activated an out pin.
you can enhance the code to use a timer that can reset the count every so often.
you could then use a pot to give you manual input as to when the final put is done.

There are Eagle files at sparkfun.com as well as PCB libraries that support the Uno.
if it is a one time thing I suggest the Uno.
if it might become a production I suggest the hardware solution for cost.
be glad to flesh this out here and provide the eagle files either way.
also I will double check my understanding of the controller in the morning.


----------



## bjfreeman (Dec 7, 2011)

DIYguy said:


> Maybe I should look for a different stepper motor drive. One that's more functionally powerful . . and can accept a pulse train and analog signals?? Then it's one device.... ??
> That's a question.......


there is lots of Arduino code and shields that cover all your requirements. The code is open source so you can glue routines together to do what you want. Most all of the hardware (shields) have Schematics and PCB in Eagle files.
You can cut and paste schematics and Eagle will gernate the basic PCB and do basic routing. the last 10% take 99% of the time.
you looking at up to a man week to produce the PCB's
If you use SMB then plan to pot the board.
the beauty of the Uno is you can prototype using add on boards (shields). then you can make finished single board and remove all the ginger bread you don't need.
you can even put a can bus interface on it.
you mention a camera, you can run that through the board and add data to the video.


----------



## DIYguy (Sep 18, 2008)

bjfreeman said:


> Ii quickly scan the SI manual.
> I may be way off base, but it sounds like what you need is a variable devider, that is between the Pickup coil and the input plug of the Si controller.
> This can be done with standard chips, hardware wise.


Hmmm. Do you mean a frequency divider, or a voltage divider? The stepper drive takes only discrete inputs.



bjfreeman said:


> If you want to use a Arduino uno, then you would build a shield board that had signal conditioning and feed the interrupt of the Arduino. The code would count the interrupts then activated an out pin.
> you can enhance the code to use a timer that can reset the count every so often.
> you could then use a pot to give you manual input as to when the final put is done.
> 
> ...


I only want to use what will work. I don't really care what it is. It's just not in my current skills list . .  
I think I may have over-simplified this. . . I thought it was a pretty straight fwd requirement. . . one that others could build from. 
I'm not interested to produce or sell anything. Just for my own use and to share info to others who may have a need/desire.

Thanks for checkin it out.


----------



## bjfreeman (Dec 7, 2011)

DIYguy said:


> Hmmm. Do you mean a frequency divider, or a voltage divider? The stepper drive takes only discrete inputs.
> 
> 
> 
> ...


I like simple which is why I suggested the variable frequency dividers to provide position data to the input connector. Don't need to get into the controller.
based on the manual the input connector feeds position into the controller. So you want to take the variable frequency from a speed source, change the pulses that will give pulse to the controller input connectors to move the steeper motor.
these are all discrete components.


----------



## DIYguy (Sep 18, 2008)

bjfreeman said:


> So you want to take the variable frequency from a speed source, change the pulses that will give pulse to the controller input connectors to move the steeper motor.


yup, that's what I need .



bjfreeman said:


> these are all discrete components.


I meant the signals...


----------



## TigerNut (Dec 18, 2009)

Hey... 
IF your stepper controller will accept an analog control signal then you can make a simple and fairly robust frequency to voltage converter. It doesn't require programming, and it inherently has a decent amount of noise tolerance.
I'm assuming, first of all, that you can use an optical pickup from a slotted or holed wheel on the open end of the motor, as suggested by DJBecker. This would then give a constant-angle pulse, n times per revolution, corresponding to the number of holes in the wheel. The important thing here is that the hole diameter should be proportional to the radius it's located on, so that the on-time of the pickup is small (let's say no more than 5%) relative to the rotational period.
Then you use the output of the pickup circuit to trigger a 555 in monostable-retriggerable mode, to give a constant-width output pulse.
The output duty cycle is now proportional to RPM; you will need to make sure that the output pulse width is small enough to keep the duty cycle below 100% at all RPM of interest, but the pulse width needs to be wider than the input pulse width (which is why the optical pickup holes or slots shouldn't be too large).
Then you can filter the 555's output using an RC filter, and you'll get a reasonably good approximation of motor RPM as an analog voltage. The actual voltage can be scaled using a resistive divider or by changing the pulse width output; the number of pulses per revolution can be changed by drilling or filling holes on your optical disc.

Because the 555 won't re-trigger while its output is still active, you don't have to worry about optical noise on the trailing edge of the hole. You will have to observe all the usual good-design practices, but this eliminates a large class of issues related to doing realtime software.


----------



## DIYguy (Sep 18, 2008)

TigerNut said:


> Hey...
> IF your stepper controller will accept an analog control signal then you can make a simple and fairly robust frequency to voltage converter. It doesn't require programming, and it inherently has a decent amount of noise tolerance.
> I'm assuming, first of all, that you can use an optical pickup from a slotted or holed wheel on the open end of the motor, as suggested by DJBecker. This would then give a constant-angle pulse, n times per revolution, corresponding to the number of holes in the wheel. The important thing here is that the hole diameter should be proportional to the radius it's located on, so that the on-time of the pickup is small (let's say no more than 5%) relative to the rotational period.
> Then you use the output of the pickup circuit to trigger a 555 in monostable-retriggerable mode, to give a constant-width output pulse.
> ...


I like the approach. . . that is to eliminate real time software in the mix. Unfortunately, my drive only accepts digital inputs.  . . by the look of it.


----------



## mmark666 (Feb 21, 2009)

As previously mentioned, I would also advise against using an Arduino for a project like this because of the missing hardware counter / input capture support. Instead a STM32VL Discovery board (see http://www.mouser.com/stm32discovery/ for example) would easily fit the bill.

It looks like your controller has four input pins: if you could program your controller in a way that it would move the stepper motor to a predefined position depending on the state of the input pins, then the STM32 only had to measure the motor rpm and output four bits depending on the current speed. Four bits will give you 16 different position, so if you want to move the brushes over 20 degree, the resolution would be 1.25 degree, which should be more than sufficient.

I am happy to help you writing a short program for the STM32 which would do this...


----------



## DIYguy (Sep 18, 2008)

mmark666 said:


> As previously mentioned, I would also advise against using an Arduino for a project like this because of the missing hardware counter / input capture support. Instead a STM32VL Discovery board (see http://www.mouser.com/stm32discovery/ for example) would easily fit the bill.
> 
> It looks like your controller has four input pins: if you could program your controller in a way that it would move the stepper motor to a predefined position depending on the state of the input pins, then the STM32 only had to measure the motor rpm and output four bits depending on the current speed. Four bits will give you 16 different position, so if you want to move the brushes over 20 degree, the resolution would be 1.25 degree, which should be more than sufficient.
> 
> I am happy to help you writing a short program for the STM32 which would do this...


Now this looks really interesting. Yes, 4 inputs plus 2 for over travel and something else I can't recall. I only need 12 degrees. So, this micro differs in what ways from the Arduino? (electronics for dummies) Thanks.


----------



## bjfreeman (Dec 7, 2011)

DIYguy said:


> yup, that's what I need .
> 
> I meant the signals...


the output feeds into the connector defined on page 68 of the manual.
then you use the controller to program what to do with that information.


----------



## mmark666 (Feb 21, 2009)

DIYguy said:


> Now this looks really interesting. Yes, 4 inputs plus 2 for over travel and something else I can't recall. I only need 12 degrees. So, this micro differs in what ways from the Arduino? (electronics for dummies) Thanks.


the STM32 (even the value line, which is used on the VL Discovery board) is a more advanced uC than the one used on the Arduino boards. It has more advanced hardware peripherals integrated on chip. And did I mention that the ST is giving boards away for very little money: $10 for the STM32VL Discovery, $16 for the much more advanced STM32F4Discovery. 

Don't get me wrong, the Arduino boards and development environment is very nice for someone who gets into uC programming. But for something where you want real time performance, a more powerful uC comes in handy... And if you use ChibiOS (see www.chibios.org) for the STM32, the programming is not so much more complicated, at least IMHO.


----------



## TigerNut (Dec 18, 2009)

DIYguy said:


> Now this looks really interesting. Yes, 4 inputs plus 2 for over travel and something else I can't recall. I only need 12 degrees. So, this micro differs in what ways from the Arduino? (electronics for dummies) Thanks.


Did you get your Digit with the optional linear potentiometer output? If you did you can build a feedback loop using the tach circuit I described, and the 'jog CW/jog CCW' inputs on the controller.


----------



## DJBecker (Nov 3, 2010)

mmark666 said:


> As previously mentioned, I would also advise against using an Arduino for a project like this because of the missing hardware counter / input capture support.


Arduino hardware (an "AVR") does have input capture pins. I referred to them above...



mmark666 said:


> Instead a STM32VL Discovery board (see http://www.mouser.com/stm32discovery/ for example) would easily fit the bill.


The STM32 has much more sophisticated hardware. It can use any timer pin as a capture input, and use the capture signal to reset the timer so the software doesn't have to do a subtraction. It can even use a DMA channel to write the captured value to memory without software intervention. But the Discovery boards aren't especially convenient to prototype with.

Here is the STM32 timer setup to implement a timer capture tach. We track in quarter-RPM units since we report OBD2 info over CAN bus.

void setup_tach(void)
{
tach_redline_qrpm = 0; /* Redline in QRPM */
tach_target_qrpm = 0; /* Target speed in QRPM */

/* Setup timer 2 for elapsed time capture.
* It captures the count, interrupts and starts counting from zero
* with each event. */
TIM2_CR1 = 0x00; /* Turn off timer */
TIM2_CR2 = 0x00;
TIM2_SMCR = 0x0064; /* Use 0x0064 to reset on Filtered input 2. */
TIM2_DIER = 0x0005; /* Enable capture 2, update Intr. */
TIM2_SR = 0;
TIM2_CCMR1 = 0xF132; /* Channel 1+2 configured for capture on In2 */
TIM2_CCMR2 = 0x0000; /* Channel 4 and 3 unused. */
TIM2_CCER = 0x0011; /* Enable channel 1+2 in non-inverted mode. */
/* Use /12 for 2MHz, /384 for 62.5KHz from 24MHz PCLK1 */
TIM2_PSC = (PCLK1/TIM_FREQ)-1;
TIM2_ARR = 0xFFFF; /* Maximum period clock */

TIM2_DCR = 0; /* DMA read off. */
TIM2_CR1 = 0x05; /* Turn on */

INTR_SETENA(TIM2_Intr);
return;
}


/* All timer interrupts arrive on a single interrupt line.
* The timer overflows about 30Hz or 1Hz (w/ 62.5KHz).
* We extend the counter in software so that we can track very slow
* speeds, but there isn't a need to track below about 15 RPM.
*/
ISR(TIM2)
{
uint16_t status = TIM2_SR;
if (status & 0x0001) {
tach_QRPM = 0;
tach_period_overflow = 1;
stats.tach_timebase_interrupts++;
}
if (status & 0x0004) {
tach_last_period = TIM2_CCR2;
if ( ! tach_period_overflow)
tach_QRPM = 60L*4L*TIM_FREQ / tach_last_period;
else
tach_QRPM = 9999*4;
tach_period_overflow = 0;
stats.tach_interrupts++;
}
TIM2_SR = 0x04; /* Clear other events. */
return;
}


----------



## DIYguy (Sep 18, 2008)

TigerNut said:


> Did you get your Digit with the optional linear potentiometer output? If you did you can build a feedback loop using the tach circuit I described, and the 'jog CW/jog CCW' inputs on the controller.



Sorry, had to travel to attend a funeral. Unexpected and tragic.
Anyways, no, unfortunately mine didn't come with the linear potentiometer.


----------



## DIYguy (Sep 18, 2008)

DJBecker said:


> Arduino hardware (an "AVR") does have input capture pins. I referred to them above...
> 
> The STM32 has much more sophisticated hardware. It can use any timer pin as a capture input, and use the capture signal to reset the timer so the software doesn't have to do a subtraction. It can even use a DMA channel to write the captured value to memory without software intervention. But the Discovery boards aren't especially convenient to prototype with.
> 
> Here is the STM32 timer setup to implement a timer capture tach. We track in quarter-RPM units since we report OBD2 info over CAN bus.


What do you think about using the STM vs the Arduino for this application then? Just the development/prototyping issues?


----------



## bjfreeman (Dec 7, 2011)

DIYguy said:


> What do you think about using the STM vs the Arduino for this application then? Just the development/prototyping issues?


the Arduino is an 8bit so math takes more cycle to accomplish.
My 56F803 is 16 bit 80mhz so the math is easier.
The STM32 is even better on math, but is overkill for this simple program.
You have a ,mini Arduino that you can use after using the uno as developement.

As far which is best, for this simple project the ease of prototyping and having a finished product is the driving spec.
otherwise for this project all will work.


----------



## bjfreeman (Dec 7, 2011)

as a sidenote the Arduino Integrated Development Enviorment (IDE) is in java and can be used to incorporate other AVR, Like then 56F803 I use or the STM32.
I use Arduino in my gaming peripherals and in monitoring Class A and B CANbus.
I use 56F803 for Class C Canbus functions, I believe the Arduino can be used for same,. just I have not actually done it.
I am sure that with the same work the STM32 could be added to the Arduino IDE.


----------



## DJBecker (Nov 3, 2010)

DIYguy said:


> What do you think about using the STM vs the Arduino for this application then? Just the development/prototyping issues?


The STM32 is far more capable, but this is a simple workload.
It should be largely driven by the interface considerations.

The Arduino hardware has quite a bit going for it. It has 5V I/O, the ADC is slow but quiet, it's very well understood by many people, and you get an known-working C toolchain by installing the Arduino system.

It took us less than 30 minutes to get our first Arduino program running and decide that the environment was too limiting. In under an hour we had a C program that flashed LEDs. A surprising number of devices worked with the first draft of code.

In contrast it took weeks, including writing a whole bunch of support code, to get a toolchain for the then-new STM32VL-Discovery. It's easier to use the STM32 than it was a year ago, but you still won't find the same quality of pre-built open source tools.


----------



## DJBecker (Nov 3, 2010)

bjfreeman said:


> as a sidenote the Arduino Integrated Development Enviorment (IDE) is in java...


That would be Eclipse. Many IDEs are based on Eclipse. Despite using the same IDE infrastructure, the runtime environments are very different.

Maple is a Arduino-mostly-compatible system on the STM32. But just like Arduino on the AVR, you wouldn't write serious code in it. It doesn't give you access to the hardware capabilities.


----------



## bjfreeman (Dec 7, 2011)

DJBecker said:


> That would be Eclipse. Many IDEs are based on Eclipse. Despite using the same IDE infrastructure, the runtime environments are very different.


Actually no. it is ant driven project and does not need Eclipse.
it can also be compiled in Eclipse but does not use any Eclipse libraries.
I have over 500 Eclipse projects over the years. Most do not depend on the eclipse libraries.


> Maple is a Arduino-mostly-compatible system on the STM32. But just like Arduino on the AVR, you wouldn't write serious code in it. It doesn't give you access to the hardware capabilities.


I did a quick scan of maple on google. it seem it is not open source like the Arduino IDE source code.
Not sure what your comment about serious code, relates to IDE's in general since they are tools and it takes a good programmer to produce good code.
Arduino IDE has independent libraries that support down to the hardware as source code.


----------



## bjfreeman (Dec 7, 2011)

btw thanks for the reference to maple and stm32 have added to my list of AVR'S for future projects.


----------



## bjfreeman (Dec 7, 2011)

I just uploaded The Maple eagle files, in to 6.0
got this message
EAGLE update report Date: 3/9/2012 11:38:59 AM
File: C:/projects/eaglepcb/maple-r5/maple-r5.brd
Update from version 5.4
Polygon rank in packages is now obsolete, and package polygons
in signal layers are now part of the signal an enclosed pad or
smd is connected to.
Please check whether the following parts still behave as expected:
IC1, PSON10-V2, okie


----------



## DJBecker (Nov 3, 2010)

bjfreeman said:


> Actually no. it is ant driven project and does not need Eclipse.
> it can also be compiled in Eclipse but does not use any Eclipse libraries.


What part of what I what I said was wrong?

The common Arduino IDE is Eclipse.



bjfreeman said:


> I have over 500 Eclipse projects over the years. Most do not depend on the eclipse libraries.


There is no reason that the IDE's libraries would end up in the final application.



bjfreeman said:


> I did a quick scan of maple on google. it seem it is not open source like the Arduino IDE source code.


I trust that you have corrected your mistaken impression.


----------



## bjfreeman (Dec 7, 2011)

DJBecker said:


> What part of what I what I said was wrong?
> 
> The common Arduino IDE is Eclipse.


The Eclipse IDE compiles the Arduino IDE application. once you start Arduino.exe it is self supporting and has no need of the Eclipse Libraries or environment.



> There is no reason that the IDE's libraries would end up in the final application.


if you are specifying the Eclipse IDE, that is what I said above.
there must be jar files included in the Compiled application or a path to lib, other wise it will not run.
if you move the folder(arduino-1.0) that has Arduino.exe out of Eclipse into a separate folder, like /arduino, it will run. the Jars in the lib folder support the Arduino IDE. There are no eclipse jars in the lib folder so the Arduino IDE , once compiled is not supported by the Eclipse Environment.


----------



## mmark666 (Feb 21, 2009)

DJBecker said:


> The STM32 is far more capable, but this is a simple workload.
> It should be largely driven by the interface considerations.
> 
> The Arduino hardware has quite a bit going for it. It has 5V I/O, the ADC is slow but quiet, it's very well understood by many people, and you get an known-working C toolchain by installing the Arduino system.
> ...


As I said earlier, the Arduino environment is very nice for beginners. But the hardware is quite limited compared to a STM32 (even one from the value line...) And despite the somewhat steeper learning curve, if you use something like a current Atollic TrueStudio or Keil MDK on a Windows PC, both support the STM32 discovery boards nicely and you should be able to get your first program running within an hour or so, not weeks.

If you already have an Arduino and already know who to program it, please -- by all means -- go ahead and use it. The problem is simple enough... Still I think the problem could be solved as easy if not easier with an STM32, and the STM32 is even cheaper...


----------



## DIYguy (Sep 18, 2008)

OK, this is curious. If you look at the pic of the drive back on post #13, now look close at the bottom/middle and u'll see that it has an Analog input! The manual for the drive and the pics of the drive in the manual show/mention nothing about this. Need to do some more research. hmmmmmm


----------



## bjfreeman (Dec 7, 2011)

this is rough out comparator. it will take analog or digtial. Not sure the resistive value are accurate. if you want to pursue this then I will breadboard it, once I get the speed input specks. then provide the eagle files,
I put the large 5 volt regulator so you could power the controller board.

can be used for motion conversion between different units. The 25,400 step/rev setting is provided as a means of converting motion from metric to english. (There are 25.4 mm in an inch.) Other settings provide step angles that are decimal degrees (36,000 steps/rev makes the motor take 0.01° steps.) Some settings are used with lead screws. When the drive is set to 2000 steps/rev and used with a 5 pitch lead screw, you get .0001 inches/step.
*The microstep resolution of the 3540i is set by the Si Programmer™ software*


----------



## DJBecker (Nov 3, 2010)

mmark666 said:


> As I said earlier, the Arduino environment is very nice for beginners. But the hardware is quite limited compared to a STM32 (even one from the value line...) And despite the somewhat steeper learning curve, if you use something like a current Atollic TrueStudio or Keil MDK on a Windows PC, both support the STM32 discovery boards nicely and you should be able to get your first program running within an hour or so, not weeks.


You might be able to follow a step-by-step example in an hour, but it takes far longer than that to write a new program for the STM32.

There is quite a bit to learn to set up the clock tree and the implications of the choices. Needing to enable clocks to individual peripherals before using them is different than many other microcontrollers. (Later AVRs have clock gating, but clocks default to enabled rather than off so you can pretty much skip learning about it until you are optimising for power.) Taking a short-cut by just enabling all clocks bites you later as some peripheral outputs conflict.

All of this complexity is there because the STM32 is a more sophisticated, capable controller. It's not pointless. But it means there is much more to learn than with a simpler controller, especially an Arduino where people have worked hard to make it easy to set up and pretty much every hardware feature has been written about by someone.


----------



## bjfreeman (Dec 7, 2011)

for the si programing manual


> Encoder Feedback: 3540i with Encoder Option Board
> Most step motor applications run “open loop,” where a motor position is commanded and the controller
> assumes that the motor obeyed. If the system is designed with a reasonable amount of torque
> margin, and nothing blocks the motor’s path, this works perfectly.
> ...


So the way I see it we provide the encoder function feeding to the controller board.
the speed data is translated to encoder positioning.
or
per the hardware manual 
use the speed data converted to 
connector
• input 1,2,3,4
• jog cw
• jog ccw
• cw limit
• ccw limit


----------



## bjfreeman (Dec 7, 2011)

mmark666 said:


> If you already have an Arduino and already know who to program it, please -- by all means -- go ahead and use it. The problem is simple enough... Still I think the problem could be solved as easy if not easier with an STM32, and the STM32 is even cheaper...


The way I see it, is use what will fit the project and the person that takes on the task is comfortable with.
so why not have each present a solution hardware and software to this problem. Each using what they feel comfortable with. Hardware meaning a schematic from speed input to stepper output.

Then who ever reads this thread can pick which they would like to try.


----------



## TigerNut (Dec 18, 2009)

I should know better than to wade back into this...

Designing embedded systems hardware and firmware for sensor applications is my day job. Instead of adding another entry into your-MCU-is-not-as-good-as-mine, I borrowed a page from Forest L. Mims, III (remember him? If you don't, I'm guessing Wikipedia ought to have a page on him) and did it discretely using now little-used linear and MSI logic.

Note that this is not a complete schematic. I'd add protection for the power supply, a proper 5V regulator, and decoupling caps as required on the power rails at the ICs. And yeah, all the passives need values  .


----------



## TigerNut (Dec 18, 2009)

TigerNut said:


> Note that this is not a complete schematic. I'd add protection for the power supply, a proper 5V regulator, and decoupling caps as required on the power rails at the ICs. And yeah, all the passives need values  .


*Correction:* I mislabeled the LIMIT- connection. It should instead go to whichever 'JOG' input causes the brushes to go to their 'home' position. You will need to also wire in the limit switch on at least that side, to prevent the thing from over-driving itself.


----------



## bjfreeman (Dec 7, 2011)

TigerNut said:


> I should know better than to wade back into this...
> 
> Designing embedded systems hardware and firmware for sensor applications is my day job. Instead of adding another entry into your-MCU-is-not-as-good-as-mine, I borrowed a page from Forest L. Mims, III (remember him? If you don't, I'm guessing Wikipedia ought to have a page on him) and did it discretely using now little-used linear and MSI logic.
> 
> Note that this is not a complete schematic. I'd add protection for the power supply, a proper 5V regulator, and decoupling caps as required on the power rails at the ICs. And yeah, all the passives need values  .


good start. I don't think the circuit between the sensor and 555 will take care of spurious spikes one gets in a EV.


----------



## TigerNut (Dec 18, 2009)

bjfreeman said:


> good start. I don't think the circuit between the sensor and 555 will take care of spurious spikes one gets in a EV.


That may be true to some extent, and additional lowpass filtering may be required. However, at least 50% of that problem would be dependent on how carefully the sensor wiring is done. Bonus marks for using Toslink (http://www.tripplite.com/shared/product-pages/en/A10202M.pdf) or similar fiber or lightpipe to remote-sense the optical path and thereby getting the electronics away from the motor altogether.

I'd like to see what kind of noise (amplitude and spectrum) was generated by a given sensor combination before trying to work out a filtering solution for it. I've previously built a crank-triggered distributorless ignition system for a 9000 RPM Toyota 4AG application, using an optical disc mounted on the crank with twin sensors and coils, and had no issues whatsoever with EMI from the one coil affecting the other sensor, even though they were each being driven to 10A primary current.


----------



## DIYguy (Sep 18, 2008)

Thanks guys, keep it coming. There are no wrong answers. . . depends on user I think.
I powered up my 3540i and did some playing around. It worked, but I noticed that it stalled easily in the extend direction. I felt some vibration also. So, I took it apart. One motor bearing is shot. I will pick up two new ones and get this thing back together. At least now I know why it was on flea-bay for $100.

I also made a programming cable and downloaded the software, but was unable to establish communication. Says my com port is not available. ??? This is on my Dell laptop. Another problem to figure out. 

With the micro options, I can get maybe 17 positions. (home plus 4 inputs). What can I get with the embedded circuits shown?

Cheers


----------



## DIYguy (Sep 18, 2008)

DIYguy said:


> With the micro options, I can get maybe 17 positions. (home plus 4 inputs). What can I get with the embedded circuits shown?
> 
> Cheers


Actually, I would do this in the Stepper Drive code. Just figured that out.


----------



## TigerNut (Dec 18, 2009)

DIYguy said:


> Thanks guys, keep it coming. There are no wrong answers. . . depends on user I think.
> I powered up my 3540i and did some playing around. It worked, but I noticed that it stalled easily in the extend direction. I felt some vibration also. So, I took it apart. One motor bearing is shot. I will pick up two new ones and get this thing back together. At least now I know why it was on flea-bay for $100.
> 
> I also made a programming cable and downloaded the software, but was unable to establish communication. Says my com port is not available. ??? This is on my Dell laptop. Another problem to figure out.
> ...


The circuit I posted would give you 10, based on the 10 outputs from the bar-dot display driver. With some extra work it would be possible to gang multiple drivers and then do a full 4-bit encoder, but you would have to decide whether that level of resolution is necessary in the face of the extra complexity. I'm guessing that you'd probably get at least 80% of the benefit that you're looking for from having four brush positions; the rest is specmanship...


----------



## bjfreeman (Dec 7, 2011)

TigerNut said:


> T Bonus marks for using Toslink (http://www.tripplite.com/shared/product-pages/en/A10202M.pdf) or similar fiber or lightpipe to remote-sense the optical path and thereby getting the electronics away from the motor altogether.


Had not thought of fiber optics. Good Idea. Bit more expensive, yet.
friend of mine built a computer built on optics, no electronics.


----------



## bjfreeman (Dec 7, 2011)

DIYguy said:


> At least now I know why it was on flea-bay for $100.


yup if seems to good to be true, it probably is.
but your like me just tear into it and fix it, is still cheaper.
you can probably get the bearing at a bearing specific business. we have two here.



> I also made a programming cable and downloaded the software, but was unable to establish communication. Says my com port is not available. ??? This is on my Dell laptop. Another problem to figure out.


do you have RS232 or usb on laptop. The dongle they provided I did not see a wiring diagram for.



> With the micro options, I can get maybe 17 positions. (home plus 4 inputs). What can I get with the embedded circuits shown?
> 
> Cheers


If I understand you, those 16 potions are determined by how many steps you program. That should be more than enough to cover your application.


----------



## DIYguy (Sep 18, 2008)

TigerNut said:


> The circuit I posted would give you 10, based on the 10 outputs from the bar-dot display driver. With some extra work it would be possible to gang multiple drivers and then do a full 4-bit encoder, but you would have to decide whether that level of resolution is necessary in the face of the extra complexity. I'm guessing that you'd probably get at least 80% of the benefit that you're looking for from having four brush positions; the rest is specmanship...


Ya, as long as I get 4 inputs to the drive I could program the drive to the rest.

Pos1 = home (switch)
Pos2 = Input1
Pos3 = Input1,2
Pos4 = Input 2
Pos5 = Input1,3
Pos6 = Input1,2,3
Pos7 = 1,3
Pos8 = 2,3
Pos9 = 3

etc. . . etc. that should give me 17 or I could add another limit at other end for 18.
I could also turn on a few outputs to know that I am at home and full on, as a minimum.


----------



## DIYguy (Sep 18, 2008)

bjfreeman said:


> yup if seems to good to be true, it probably is.
> but your like me just tear into it and fix it, is still cheaper.
> you can probably get the bearing at a bearing specific business. we have two here.


Ya, I already went. $7 each. They had no stock. I ordered 2, they'll be there by 8:00 am.




bjfreeman said:


> do you have RS232 or usb on laptop. The dongle they provided I did not see a wiring diagram for.


I posted it earlier, on I think page 3....  edit. . .ya, post # 25



bjfreeman said:


> If I understand you, those 16 potions are determined by how many steps you program. That should be more than enough to cover your application.


ya, as above post.


----------



## bjfreeman (Dec 7, 2011)

DIYguy said:


> Ya, I already went. $7 each. They had no stock. I ordered 2, they'll be there by 8:00 am.






> I posted it earlier, on I think page 3....  edit. . .ya, post # 25


thanks missed that the first time around.


> ya, as above post.


Sorry I was not clear enough.
since you can program how many steps through the programmer, each position will be so many steps.
therefore 16 positions should give enough resolution by setting the number of steps for each position.


----------



## bjfreeman (Dec 7, 2011)

How many pulses make a revolution of the motor?
how many pulses resolution are you aiming for?
I use a KMI15 hall effect sensor on a gear tooth.


----------



## DIYguy (Sep 18, 2008)

DIYguy said:


> OK, this is curious. If you look at the pic of the drive back on post #13, now look close at the bottom/middle and u'll see that it has an Analog input! The manual for the drive and the pics of the drive in the manual show/mention nothing about this. Need to do some more research. hmmmmmm


OK, I looked into this A/I terminal/option. It appears that you can run the drive from a PC through a serial connection and programmed in a language called SCL. Here is the manual http://www.applied-motion.com/sites/default/files/920-0010B_SCL_manual.pdf
Page 18 describes some analog program features/options. 

It looks like this would work for position except using this mode, you can't load the program to memory. U need the PC connection to operate. 

Or maybe running the SCL program on the STM32 or Arduino is an option?? 

(U know, sometimes it's good to have someone who doesn't know what they are talking about to ask "dumb" questions . . . lol, and stimulate some outside of the box thinking.)


----------



## DIYguy (Sep 18, 2008)

Can someone help me understand the pros and cons of the micro controller vs the embedded circuit options?

I like the flexibility of the micro, but perhaps the embedded solution is more robust/reliable?

Also, how easy would it be to modify the signal points with the embedded option? I expect that I will have some fine tuning requirements once this is running. I could look at the brushes with a small light and camera under different loads/rpm etc. to see how they behave and adjust as required.


----------



## DIYguy (Sep 18, 2008)

bjfreeman said:


> How many pulses make a revolution of the motor?
> how many pulses resolution are you aiming for?
> I use a KMI15 hall effect sensor on a gear tooth.


I haven't made it yet. I should hope that my design selection will help to drive the best choice for the tacho-generator. 

The last one I made used a simple industrial inductive proximity switch. I made a collar with two screws to give two pulses/rev. I fed this signal to my Soliton1 controller and it was happy. I outputted 3 pulses/rev from the 
Soliton to drive my OEM dash tachometer. It has worked great for a couple years now. 

I have a few more proxies laying around. . . but don't know if I'll need to make one with less chance for electrical noise or????


----------



## TigerNut (Dec 18, 2009)

DIYguy said:


> I haven't made it yet. I should hope that my design selection will help to drive the best choice for the tacho-generator.
> 
> The last one I made used a simple industrial inductive proximity switch. I made a collar with two screws to give two pulses/rev. I fed this signal to my Soliton1 controller and it was happy. I outputted 3 pulses/rev from the
> Soliton to drive my OEM dash tachometer. It has worked great for a couple years now.
> ...


So long as this gives reasonably clean pulses then it would drive the 555's input without much of a problem. The 555 thresholds at 2/3 of its supply voltage. For extra garbage immunity you can pre-condition the input with a Schmitt trigger or a comparator with hysteresis - you can build that from an opamp. This would help the microcontroller as well.

Regarding which one is better - that's really up to you. The discrete circuit is straightforward enough that you could prototype it on some perfboard (in a metal box for EMI protection) and you can debug it with an oscilloscope and some test LEDs on the dot/bar driver outputs. But, as you say, configuring it requires component substitutions (or potentiometers that you can tweak), where configuring the microcontroller would require parameter changes in the software and then reprogramming the micro. It all depends on where your comfort zone is.

As has been noted, potentiometers can, in the long term, become noisy. If you went with pots, then I'd use them to figure out the circuit setpoints and then substitute appropriate fixed resistors once things were dialed in.


----------



## bjfreeman (Dec 7, 2011)

from the KM115 specs
FUNCTIONAL DESCRIPTION
The KMI15 sensor is sensitive to the motion of ferrous
gear wheels or reference marks. The functional principle is
shown in Fig.3. Due to the effect of flux bending, the
different directions of magnetic field lines in the
magnetoresistive sensor element will cause an electrical
signal. Because of the chosen sensor orientation and the
direction of ferrite magnetization, the KMI15/1 is sensitive
to movement in the ‘y’ direction in front of the sensor only
(see Fig.2).
The magnetoresistive sensor element signal is amplified,
temperature compensated and passed to a Schmitt trigger
in the conditioning integrated circuit (Figs 4 and 5).
The digital output signal level (see Fig.6) is independent of
the sensing distance within the measuring range (Fig.14).
A (2-wire) output current enables safe transfer of the
sensor signal to the detecting circuit (see Fig.7).
The integrated circuit housing is separated from the
sensor element housing to optimize the sensor behaviour
at high temperature.

and all that for under $4.00

This is current driven device which reduces electrical noise.
the circuit I gave you earlier is the signal condition for the input to digital circuits.
the only thing is a counter circuit to give you the four inputs for a given frequency.
my preference is a PROM to provide the bits necessary. this give you a few bits for extras.


----------



## DIYguy (Sep 18, 2008)

I was just thinking about the need to make adjustments in the circuit and it dawned on me that as long as I have 4 or 5 inputs at an equal spread, say, every 1000 or 1500 rpm, I can do the rest in the drive programming. If I need to make an adjustment, I just change the position that equals a specific input criteria. 

The other thing that came to mind is that perhaps I could use the output tach signal from the Soliton to feed this thing (the pulse signal board or micro). Would that be a cleaner output? I have to feed the controller an pulse count for rpm control anyways so, I can output 2, 4, 6, or 8 (IIRC) per rev from the Shiva.


----------



## bjfreeman (Dec 7, 2011)

Now if you want to make the pickup and Can Bus class B or C device, then the pickup would feed a Arduino mini from the speed sensor that provides the canbus data.

then you can use multiple devices to read off this, like your positioning and your tack.

the you would use the Arduino in the circuit for Canbus and providing the data to the positioning controller board. 

you then use an Arduino to provide the Tachometer read out like most cars do today.

of course I prefer my 56F803 since it is an $8 chip and had Canbus built in
just another thought


----------



## bjfreeman (Dec 7, 2011)

DIYguy said:


> I was just thinking about the need to make adjustments in the circuit and it dawned on me that as long as I have 4 or 5 inputs at an equal spread, say, every 1000 or 1500 rpm, I can do the rest in the drive programming. If I need to make an adjustment, I just change the position that equals a specific input criteria.
> 
> The other thing that came to mind is that perhaps I could use the output tach signal from the Soliton to feed this thing. Would that be a cleaner output? I have to feed the controller an pulse count for rpm control anyways so, I can output 2, 4, 6, or 8 (IIRC) per rev from the Shiva.


sounds like a plan.
what is the format from the soliton


----------



## DIYguy (Sep 18, 2008)

bjfreeman said:


> from the KM115 specs
> FUNCTIONAL DESCRIPTION
> The KMI15 sensor is sensitive to the motion of ferrous
> gear wheels or reference marks. The functional principle is
> ...


That's cheap enough for sure. 

I already have one of these... http://www.balluff-china.com/PDF/en/datenblaetter/BES%20M08MH1-PSC30B-S04G.pdf

and one of these... http://files.pepperl-fuchs.com/selector_files/navi/productInfo/edb/087762_eng.pdf

and if I need one that is reflective, I have one of these, P/N SME312DVQD
http://www.triadautomation.com/media/pdf/60335.pdf

I would use one of these if I could get away with it. The Banner mini beam is pretty kewl. I wouldn't buy one, but since I have it.

I found a couple more... I have a Turk # 4669460 lke this; http://www.turck-usa.com/illustrations/B1007_D19.pdf

and one or two of the Cycle Analyst hall effect ones with the little neodymium magnet.


----------



## TigerNut (Dec 18, 2009)

DIYguy said:


> I was just thinking about the need to make adjustments in the circuit and it dawned on me that as long as I have 4 or 5 inputs at an equal spread, say, every 1000 or 1500 rpm, I can do the rest in the drive programming. If I need to make an adjustment, I just change the position that equals a specific input criteria.
> 
> The other thing that came to mind is that perhaps I could use the output tach signal from the Soliton to feed this thing (the pulse signal board or micro). Would that be a cleaner output? I have to feed the controller an pulse count for rpm control anyways so, I can output 2, 4, 6, or 8 (IIRC) per rev from the Shiva.


The Shiva has three programmable outputs. If it knows the motor speed then can you have it turn those outputs on and off at set speeds?... that would give you up to eight positions (if you used all three). No need for an additional middleman.


----------



## bjfreeman (Dec 7, 2011)

DIYguy said:


> That's cheap enough for sure.
> 
> I already have one of these... http://www.balluff-china.com/PDF/en/datenblaetter/BES M08MH1-PSC30B-S04G.pdf
> 
> ...


I am getting the hang of this.
the Shiva does not provide speed info it requires a user installed sensor the then connects to the shiva. per page 8
http://evnetics.com/downloads/Soliton1_Manual_1v1_rev1.pdf

so the pickoff circuit from the speed sensor gives a RS 485 or RS422 for connecting the the circuit that counts the pulses and creates the output to the controller.


----------



## DIYguy (Sep 18, 2008)

TigerNut said:


> The Shiva has three programmable outputs. If it knows the motor speed then can you have it turn those outputs on and off at set speeds?... that would give you up to eight positions (if you used all three). No need for an additional middleman.


Yes! It's a good idea. I'm just worried about needing outputs. I currently use one for my tach (which I could likely avoid if I made a 3 pulse/rev tacho-generator) and another for the fluid pump (perhaps I would leave on all the time with Shiva??) I was going to use the third for an "idiot light" on the dash. Qer and Jeff have already made some offers to me regarding this, which is very kewl of them. We are thinking about controlling the GV overdrive also. . . but I think I will use the GV standard unit for this.... I dunno. Be nice if it had a couple more outputs.


----------



## bjfreeman (Dec 7, 2011)

DIYguy said:


> Can someone help me understand the pros and cons of the micro controller vs the embedded circuit options?
> 
> I like the flexibility of the micro, but perhaps the embedded solution is more robust/reliable?
> 
> Also, how easy would it be to modify the signal points with the embedded option? I expect that I will have some fine tuning requirements once this is running. I could look at the brushes with a small light and camera under different loads/rpm etc. to see how they behave and adjust as required.


Note: Embedded includes Micros, the other is Discrete components, like IC and resistors
the main difference is the style of prototyping.
Discrete you breadboard using wire-wrap, Ic connectors, terminals for things like resistors or capacitors.

Now If you have bucks, you can use Eagle (free for boards under 4X4 in) and get a batch of three boards made($5-20 per sq in), then if you have to add a component you have kludge it on.

for Discrete you spend more time and money, if you use proto PCB's if you don't have the engineering back ground.
Depending on the complexity, the cost of a discrete is less than micro for production. With discrete you can buid more complex function for a bunch of chips. This is only good if you have a single source for the complex discrete. and example is RS 232 hardware interface. you can buy one chip or you use a handful of cheaper chips that are more common so you design is not compromised by lead times from a sole source.


Micros, you still have the above for inputs and outputs, like signal conditioning. however the processing of the information is in source code.
Most pins on the AVRs are multifunction so have to be defined and fuses burn, by code, to set it up the way you want to use it. if you define the pin wrong you have to use a new processor chip.
there is the learning curve of each AVR, to determine which is best for now, and future needs. The advantage is you can change the processing of signals easier than the discrete way.
from a production point of view you have to program each micro chip before you send the board out. this is labor intensive.

thats all I can think of off the top of my head


----------



## bjfreeman (Dec 7, 2011)

I was thinking of your method of using screw as marks for the sensor.
it takes only a #10 1/4in brass screw to throw the balance of the armature out. I spent a lot of time balancing armature, by drilling out part of the iron core to know.
The imbalance will eventually flatten bearing, causing brushes to wear uneven, eventually fill the commutator segments with brush material that adds to flash over and or shorts.


----------



## bjfreeman (Dec 7, 2011)

DIYguy said:


> I expect that I will have some fine tuning requirements once this is running. I could look at the brushes with a small light and camera under different loads/rpm etc. to see how they behave and adjust as required.


as you mentioned, you only need to get the speed signal in digital form and set what speed gives the four inputs of the controller board for the project. from the sounds of it Quer can program one of the Motor controller terminals for a digital speed signal. so the project shrinks down to a circuit that converts the digital speed signal to four bits that feed into the position controller board.
once you have the 4 inputs then you can program the number of steps each position will represent then define the position by the 4 inputs.
if you go discrete with a Eprom as the outputs for the 4 inputs of the position controller board then you can change the bits of the Eprom to find tune.
if you go micro then you can modify the table in source code.


----------



## DIYguy (Sep 18, 2008)

bjfreeman said:


> as you mentioned, you only need to get the speed signal in digital form and set what speed gives the four inputs of the controller board for the project. from the sounds of it Quer can program one of the Motor controller terminals for a digital speed signal. so the project shrinks down to a circuit that converts the digital speed signal to four bits that feed into the position controller board.
> once you have the 4 inputs then you can program the number of steps each position will represent then define the position by the 4 inputs.
> if you go discrete with a Eprom as the outputs for the 4 inputs of the position controller board then you can change the bits of the Eprom to find tune.
> if you go micro then you can modify the table in source code.


Yup, I'd say that pretty much sums it up.

As for the tach - I bought a collar with one threaded hole and a set screw. I drilled and tapped same hole 90 degrees. Got 2 SS SHCS, cut them to the same length. Checked/tweaked with digital calipers. It has worked great for the last few years and many miles. No vibration at all.

The 13" motor is gonna be a bit different cause it doesn't have a tail shaft. The CE of the armature has a threaded hole though, so I will drill a hole in the center of the end bell large enough to bolt a spacer to the the armature shaft. The bearing is sealed so, it won't be any different than the DE. From this I will fab something up. If I'm a bit resourceful, perhaps I can do it all inside the end bell and use a cap over the hole.


----------



## bjfreeman (Dec 7, 2011)

DIYguy said:


> Yup, I'd say that pretty much sums it up.


The circuit I choose is discrete.
it has a crystal controlled digital one second strobe.
it converts he speed pulse to a one of 2 million combination for a 8 bit out put from the eprom.
the strobe latches the count every second.
there is an comparator that determines if the count is more or less than the last count.
so you can program the ccw and cw as well.
I linked to a external picture so as i complete it you can follow.
then I will give alink to the eagle files.
http://roadwarrior.free-man.com/hev/ditialtyfreqency_1.png


----------



## mmark666 (Feb 21, 2009)

FYP:

here is the source code for an STM32 using ChibiOS to more or less do what you want. You can compile it with Atollic TrueStudio. If you want, I can send you a zip file containing the full project. Works nicely on a STM32VL Discovery board... Input a 0-5V (not more!) square wave for corresponding the RPM (or a multiple of it) into pin PB6, the 4 output pins are PC0-PC3 (3.3V, max current is around 20mA)

And yes, it took me more than an hour (mainly because the current stable branch of ChibiOS does not have a call back for ICU overflow). You can save a few lines of code if you directly configure the STM32 peripherals via the corresponding registers, but I think using the HAL is a little bit easier for beginners... 

And yes again, using a full blown RTOS for this is total overkill, but it makes things easier to understand for someone getting started with uC programming and it is easy to extend.

Enjoy


```
// Automatic Brush Control (abc)
// needs a current (after 2012-03-10) trunk ChibiOS (for the icuOverflowCB)

#include "ch.h"
#include "hal.h"

#define MAX_RPM (6000*2) // adjust this to max_motor_rpm * encoder_pulses_per_revolution

icucnt_t period = 65535, // max uint16_t
    last_period = 65535; // max uint16_t


static void icuPeriodCB(ICUDriver *icup) {
    period = (icuGetPeriod(icup) + last_period*15)/16; // low pass filter
    last_period = period;
    palClearPad(GPIOC, 8); // LED4 off
}


static void icuOverflowCB(ICUDriver *icup) {
    (void) icup; // suppress argument not used warning
    period = (65535 + last_period*15)/16; // low pass filter
    last_period = period;
    palSetPad(GPIOC, 8); // LED4 on
}


static ICUConfig icucfg = {
    ICU_INPUT_ACTIVE_HIGH,
    100000,                        // ICU clock frequency => overflow after 65535/100000 s = 0.66 s
    0,                            // width call back
    icuPeriodCB,                // period call back
    icuOverflowCB,                // overflow call back
    ICU_CHANNEL_1,                // use Ch1
};


uint32_t getRpm(void) {
    uint32_t rpm = icucfg.frequency * 60 / period;
    if (rpm < MAX_RPM)
        return rpm;
    else
        return MAX_RPM;
}


int main(void) {
    uint32_t outVal;

    halInit();
    chSysInit();

    palSetGroupMode(GPIOC, PAL_PORT_BIT(0) | PAL_PORT_BIT(1) | PAL_PORT_BIT(2) | PAL_PORT_BIT(3) |
            PAL_PORT_BIT(8) | PAL_PORT_BIT(9), 0,
            PAL_MODE_OUTPUT_PUSHPULL);

    palSetPad(GPIOC, 9); // LED3 on: blinks indicating program running
    palClearPad(GPIOC, 8); // LED4 off: LED4 indicates overflow

    icuStart(&ICUD4, &icucfg); // use TIM4-CH1 (PB6) as ICU
    icuEnable(&ICUD4);

    // main loop
    while (TRUE) {
        outVal = getRpm() * 16 / MAX_RPM; // scales 0 - (MAX_RPM-1) to 0 - 15
        if (outVal > 15)
            outVal = 15;
        palWriteGroup(GPIOC, 15, 0, outVal); // write outVal to PC0-PC3
        chThdSleepMilliseconds(100);
        palTogglePad(GPIOC, 9); // toggle LED4
    }
}
```


----------



## bjfreeman (Dec 7, 2011)

mmark666 said:


> FYP:
> 
> here is the source code for an STM32 using ChibiOS to more or less do what you want. You can compile it with Atollic TrueStudio. If you want, I can send you a zip file containing the full project. Works nicely on a STM32VL Discovery board... Input a 0-5V (not more!) square wave for corresponding the RPM (or a multiple of it) into pin PB6, the 4 output pins are PC0-PC3 (3.3V, max current is around 20mA)
> 
> ...


Now just need the pcb to hook up the real world.


----------



## TigerNut (Dec 18, 2009)

bjfreeman said:


> The circuit I choose is discrete.
> it has a crystal controlled digital one second strobe.
> it converts he speed pulse to a one of 2 million combination for a 8 bit out put from the eprom.
> the strobe latches the count every second.
> ...


Doing an update every second is too slow - especially considering this is a race application. What you should do with that kind of arrangement is use the PROM as a divider; you get the 10MHz clock to drive the counter, and the RPM pulse events latch the output and reset the clock. Then the latched output is used to address the PROM.

Side note: mmark666's project will run on the discovery board, so his hardware is already done...


----------



## bjfreeman (Dec 7, 2011)

TigerNut said:


> Doing an update every second is too slow - especially considering this is a race application.


so what shouild the sample rate be. Mind you we have a servo that has a screw actuator. I don't think it can travel full length in one sec, let alone 1/4 travel, using the controller that was specified. 


> What you should do with that kind of arrangement is use the PROM as a divider;


what is the problem with the devices I am using? 


> you get the 10MHz clock to drive the counter, and the RPM pulse events latch the output and reset the clock. Then the latched output is used to address the PROM.


I see a problem with using the pulse you trying to measure as a strobe. the idea is to sample the rate and give an output for that rate. As I mentioned above the slowest part of the circuit determines the sample rate. 
if we needed faster sampling rate I can see you point.


> Side note: mmark666's project will run on the discovery board, so his hardware is already done...


 the proof of the pudding is when it is hooked up and functioning.


----------



## TigerNut (Dec 18, 2009)

bjfreeman said:


> so what shouild the sample rate be. Mind you we have a servo that has a screw actuator. I don't think it can travel full length in one sec, let alone 1/4 travel, using the controller that was specified.


Well, the use case that I see as being most difficult for this system is where the driver does a burnout on the start line of a drag strip. The motor is essentially stationary, then spun up as fast as it will accelerate, to spin the tires and heat/clean them. If you have a one-second delay on measuring the motor speed, in addition to whatever delay is imposed by the actuator's speed, then the burnout will be over before the brushes get moved to the position they should have been in, while the burnout was going on.
Even just accelerating from the start line will be tough. When drag racers have zero-to-60 times in the 4 or 5 second range (or faster) your control system can't be taking a second to figure out how fast the motor is turning. So the maximum response time for the measurement system that is acceptable, I think, is in the 50 millisecond range. Whether or not the actuator is fast enough is a different issue, but the measurement system should not be part of that problem.


bjfreeman said:


> what is the problem with the devices I am using?


At least, that those 4040 timers that you're trying to drive from a 10 MHz clock, are only spec'ed to go to 3.5 MHz when they're powered from 5V.
http://www.ti.com/lit/ds/symlink/cd4020b.pdf

Even if you were to speed up the measurement rate to 20, 50, or 100 Hz, there is no need to be using a source clock at 10 MHz, but if you are going to do that, then you have to use an appropriate logic family.

It's not clear how your 4094's are going to work in this circuit. What are you shifting in? 

I don't know if it's still true, but it used to be (25 years ago) that 4000 series CMOS was way more static sensitive than equivalent TTL logic familes; their only good points were that you could power them from a higher and/or variable supply voltage, and they used less current. Neither of those points is important in this application, and being robust against handling mishaps is nice. I'd use LS-TTL or AS-TTL logic in this application.


bjfreeman said:


> I see a problem with using the pulse you trying to measure as a strobe. the idea is to sample the rate and give an output for that rate. As I mentioned above the slowest part of the circuit determines the sample rate.
> if we needed faster sampling rate I can see you point.


Using the PROM lookup you built in you can build the system three ways: 


You can have fixed time windows so that it counts motor revolutions for a fixed time period. This imposes a fixed time delay on the system response, which may be too long for certain transient situations.
You can have the counter driven from the high speed clock and latched by the motor revolution input; this has a response that speeds up as the motor speeds up. The biggest problem with this is that if the motor speed gets high enough then the counter clock has to be really fast to give good resolution to the measurement.
You can run the motor revolution input through a divider and use that to latch the high speed counter's output; this gives you an average rotation rate measurement over a certain number of motor revolutions.
For any of these three you can easily work out the appropriate PROM output for a given counter input.


bjfreeman said:


> the proof of the pudding is when it is hooked up and functioning.


You're proposing a build-off and everyone goes to DIYguy's garage to test on his motor?


----------



## DIYguy (Sep 18, 2008)

It's pretty awesome to see ppl spending time on this. Thank you. I hope others get something out of it also.

The max speed on the digit actuators is 15"/sec. I haven't designed the lever system yet but I doubt that I will use more than about 2 inches.

Anyone wanting to check out my garage is more than welcome. A ride in "Mader" (long story) is also possible.


----------



## bjfreeman (Dec 7, 2011)

TigerNut said:


> Well, the use case that I see as being most difficult for this system is where the driver does a burnout on the start line of a drag strip. The motor is essentially stationary, then spun up as fast as it will accelerate, to spin the tires and heat/clean them. If you have a one-second delay on measuring the motor speed, in addition to whatever delay is imposed by the actuator's speed, then the burnout will be over before the brushes get moved to the position they should have been in, while the burnout was going on.
> Even just accelerating from the start line will be tough. When drag racers have zero-to-60 times in the 4 or 5 second range (or faster) your control system can't be taking a second to figure out how fast the motor is turning. So the maximum response time for the measurement system that is acceptable, I think, is in the 50 millisecond range. Whether or not the actuator is fast enough is a different issue, but the measurement system should not be part of that problem.


I am sure it is evident I don't know Electric Drag racing or how Dc Motors are used in this environment. and quite Frankly I probably will not put any effort into learning.
So I am out of my league. Now if you Talk about 250KW-500KW 3 phase AC motors in HEV (motor coaches), that is my experience.
for this application it has gone beyond my experience so I bow out.


> You're proposing a build-off and everyone goes to DIYguy's garage to test on his motor?


No, I have built many Micros in the Fishing boat industry.
they are nortorious for electrolysis, Floating Grounds, RF on every conducting surfaces. 
Based on that and the board, I think you have missed some things and probably will find out once you hook it up.
however I don't have time to debate this.


----------



## TigerNut (Dec 18, 2009)

bjfreeman said:


> Based on that and the board, I think you have missed some things and probably will find out once you hook it up.
> however I don't have time to debate this.


You must be a fun guy at company design reviews. I see some good ideas in what you're doing but, like a lot of ideas, the initial implementation might have some potential issues that are easily fixed if you can get past the notion that others might be able to improve on your thinking.


DIYguy said:


> Yes! It's a good idea. I'm just worried about needing outputs. I currently use one for my tach (which I could likely avoid if I made a 3 pulse/rev tacho-generator) and another for the fluid pump (perhaps I would leave on all the time with Shiva??) I was going to use the third for an "idiot light" on the dash. Qer and Jeff have already made some offers to me regarding this, which is very kewl of them. We are thinking about controlling the GV overdrive also. . . but I think I will use the GV standard unit for this.... I dunno. Be nice if it had a couple more outputs.


If you make a 3 pulse/rev tacho-generator then it would be an ideal signal source for this project... if it's good enough to drive your dash tachometer without glitches, then it should be good enough for a brush controller.

The use of 3/rev pulses is interesting because of the way some numbers work out. Since 6000 RPM corresponds to 100 Hz, you can see that you would have 300 pulses per second at that rate... 256 pulses per second correspond to 5120 RPM, which I think will still be higher than what you're likely to run that motor at, right?

If we allow a measurement window of 1/16 of a second, then at a speed of 5120 RPM, the tachogenerator will generate 16 pulses. At speeds below that, it will generate a number of pulses (0 to 15) that is proportional to the RPM, within that 1/16 second window. Since numbers from 0 to 15 can be encoded within four bits, you can use a 4-bit counter that is latched at the end of each 1/16 second window to drive the four inputs on the stepper motor controller. The 1/16 second time reference can be generated from a 32.768kHz crystal or oscillator chip, which is readily available.

This idea is pretty similar to BJ's except that it avoids the use of a PROM (which is a hassle unless you have programming tools readily at hand), and it operates at lower speeds so that the circuit layout is less critical. It still requires a well conditioned tachogenerator input (this, to me, is the biggest unknown), and the outputs need to be buffered so they can drive the stepper motor board. The last two requirements are also valid for the STM32 board solution... 

The scope of this circuit, in terms of complexity and tolerance for layout parasitics, is such that it should be able to be prototyped on some perfboard as long as it's mounted in a well shielded box. If you want to pursue this I can draw up a proper schematic... I'd happily welcome any ideas on signal conditioning the tachogenerator output.


----------



## DIYguy (Sep 18, 2008)

TigerNut said:


> You must be a fun guy at company design reviews. I see some good ideas in what you're doing but, like a lot of ideas, the initial implementation might have some potential issues that are easily fixed if you can get past the notion that others might be able to improve on your thinking.
> 
> If you make a 3 pulse/rev tacho-generator then it would be an ideal signal source for this project... if it's good enough to drive your dash tachometer without glitches, then it should be good enough for a brush controller.
> 
> ...


I was thinking to feed the Shiva with my standard 2 pulses/turn and then have it (Shiva) output a "cleaned up" 3 pulses per turn. I can use this signal for my OEM tach as well as this proposed circuit. 
I think it's good to offer what you can to the thread regardless if I use it or not. .. . as this will hopefully be around for some time and good threads are all about helping the general readership, me thinks. Please do.


----------



## bjfreeman (Dec 7, 2011)

TigerNut said:


> You must be a fun guy at company design reviews. I see some good ideas in what you're doing but, like a lot of ideas, the initial implementation might have some potential issues that are easily fixed if you can get past the notion that others might be able to improve on your thinking.


I took some time to decide if I wanted to invest time in this topic.
if you noticed in the thread I attempted to get a clarification of the project. This is also a Design review process. I would have appreciated your valuable input at that point, so a clear requirement could be set before I used my valuable time to help.
I feel this is more a competition about who is better. That is not what I want to be involved in. My whole view was to help someone with what I knew, because it gives me pleasure to do that at times.
Not sure how many design reviews you have been involved in, but the ones I managed had a outline for the review, with submission of Ideas from the team for everyone to view, before the actual Review meeting.
And your right I was not a fun guy but one that got results.


----------



## TigerNut (Dec 18, 2009)

bjfreeman said:


> I took some time to decide if I wanted to invest time in this topic.
> if you noticed in the thread I attempted to get a clarification of the project. This is also a Design review process. I would have appreciated your valuable input at that point, so a clear requirement could be set before I used my valuable time to help.
> I feel this is more a competition about who is better. That is not what I want to be involved in. My whole view was to help someone with what I knew, because it gives me pleasure to do that at times.
> Not sure how many design reviews you have been involved in, but the ones I managed had a outline for the review, with submission of Ideas from the team for everyone to view, before the actual Review meeting.
> And your right I was not a fun guy but one that got results.


You never stated "Hey, I know squat about drag racing - fill me in, how fast does this thing have to respond?". On re-reading your posts I can see where you're looking for certain pieces of information, but your questions are not direct enough to get the info you were apparently looking for. The Internet does not convey nuances well - as we all know.

This is not about 'who is better', and it never was. But when you make vague assertions like


> Based on that and the board, I think you have missed some things and probably will find out once you hook it up.


then the way it comes across is like you said "I know something you don't but I'm not going to tell you". And it's a short hop from that, to "I know something you don't so I think I'm better than you". 

When you asked "what's wrong with my components?" and I gave a response with some (to me) valid reasons, then that's not me saying "I caught ya!", it's me saying "tell me why you think these parts are legitimately the right choice in this application", and when you give an informative response, everyone learns.

I will post my latest circuit idea when I get a chance to draft it up. And, if there are questions or criticism over that circuit, then I expect to hear about it, from whoever feels they need to ask or to make a point. That's how collaborative efforts get done.


----------



## DIYguy (Sep 18, 2008)

Well, I was able to get my little test set up working. I mentioned earlier that I could seem to communicate with the control board. . as my serial port was "busy" or something. I finally disabled it, then re-enabled it and it started to work again. I'm sure there is another way.... but hey, it worked for me. I wrote a little program and watched it run several times. It's pretty straight fwd. I also had some correspondence with Ultra Motion as I was wondering about their published speeds. Turns out, you need a different ball screw for the higher speeds. I don't think speed should be too much of an issue though. . as there is plenty of torque and I haven't designed the crank arm yet. 

I would love to hear some thoughts on advance vs rpm and if any other parameters should be included. I thought about current for a while and kind of discounted that in my little brain. Voltage and/or rpm seem to be the main parameters I think. Also, I'm wondering if the majority of the advance is really not needed until further into the rpm curve. I know Dennis Burube uses a "timed function" and I think maybe this is not the best. If you study many of the graphs available you see that motor voltage is relatively low for several seconds while current is maxed. I read about someone else who did brush advance only at the point where he switched from series to parallel. . . and since this was implemented, no more zorches... 
We know higher voltage necessitates brush advance. . . so, it kind of implies that it's mostly needed at higher rpm. At what point and by how much is the quandary.


----------



## bjfreeman (Dec 7, 2011)

mmark666 said:


> FYP:
> 
> here is the source code for an STM32 using ChibiOS to more or less do what you want. You can compile it with Atollic TrueStudio. If you want, I can send you a zip file containing the full project. Works nicely on a STM32VL Discovery board...


based on this and other post about this chip. I have ordered and reviewing the Discovery, Maple, and OLIMEXINO-STM32
I found the last one to be the most versatile, however the Maple board is runnng @ 72Mhz compared to the other two at 8Mhz.
I believe you can use the MAPLE ide for all of them.
I am having to write a cross compiler for ADA to the STM32 C .


----------



## DJBecker (Nov 3, 2010)

bjfreeman said:


> based on this and other post about this chip. I have ordered and reviewing the Discovery, Maple, and OLIMEXINO-STM32
> I found the last one to be the most versatile, however the Maple board is runnng @ 72Mhz compared to the other two at 8Mhz.
> I believe you can use the MAPLE ide for all of them.
> I am having to write a cross compiler for ADA to the STM32 C .


You are comparing two different clocks. The 72MHz is the core clock, which comes from multiplying the 8MHz 'high speed' clock. Some cores can support up to 168MHz.

The STM32, like most ARM chips, has clock gating and a clock tree. That means it has multiple clock sources, and a structure to multiply (with PLLs), distribute and divide the clocks to the peripheral devices.

A typical scheme is using a 8MHz crystal, multiplying to 72MHz, then distributing 12MHz to the ADC, 24MHz to the primary USART, 12MHz to Timer1, and disabling the clock (0 MHz) to devices that are unused. STMicro has a new tool to help with this, but it doesn't remove the need to understand the requirements and implications of the choices.

The chip has a 8 MHz internal oscillator (16MHz for the 'F4) that's OK for simple applications, but you need the accuracy and stability of a crystal for CAN or Ethernet. It's best to select an external crystal to match the internal clock to speed switching between sources, and simplify fall-back if the crystal fails.

The chip also has a low-speed internal oscillator ("LSI") and provisions for a 32KHz time-keeping crystal ("LSE"), and a third independent oscillator for the watchdog.

I assume the Ada cross-compile is humor...


----------



## bjfreeman (Dec 7, 2011)

DJBecker said:


> You are comparing two different clocks. The 72MHz is the core clock, which comes from multiplying the 8MHz 'high speed' clock. Some cores can support up to 168MHz.


I am not sure what you define as cores, but maple r6 and OLIMEXINO-STM32 both have the same chip.
I was talking about the crystals on the boards. the OLIMEXINO-STM32 also has a RTC crystal.



> I assume the Ada cross-compile is humor...


No Ada and Pascal are my passions.


----------



## DJBecker (Nov 3, 2010)

bjfreeman said:


> I am not sure what you define as cores, but maple r6 and OLIMEXINO-STM32 both have the same chip.
> I was talking about the crystals on the boards. the OLIMEXINO-STM32 also has a RTC crystal.


It's not my definition. It's common terminology that you need to learn to understand the documentation.

The external crystal is limited to 25MHz. As I said before, it's best to use a 8MHz crystal for general purpose use, and most boards use that approach. The "72MHz" part is the maximum core clock for that specific chip, with some caveats and special configuration needed to actually run that fast (e.g. minimum voltage, wait states, type of memory, etc). 72MHz might be generated by dividing the 8MHz crystal clock by 2, then using the PLL to multiply by 18.

The core is the processor itself. In this case a ARM Cortex-M3, which is provided by ARM as a "pre-synthesized" unit -- a processor core plus mandatory and optional peripherals. The microcontroller is the ARM-provided stuff plus vendor-specific peripherals(*) connected to one of the several buses on the chip. The buses typically have a lower maximum clock rate than the core, and are usually configured to be clocked by a fraction of the core clock using programmable dividers.

(*)The STM32 runs the same instruction set as other Cortex-M3 microcontroller, but has the peripheral devices STMicro designed or licensed. You can see this by how easily code written for the STM8 USART and timers can be moved to the STM32.


----------



## bjfreeman (Dec 7, 2011)

DJBecker said:


> It's not my definition. It's common terminology that you need to learn to understand the documentation.
> 
> The external crystal is limited to 25MHz. As I said before, it's best to use a 8MHz crystal for general purpose use, and most boards use that approach. The "72MHz" part is the maximum core clock for that specific chip, with some caveats and special configuration needed to actually run that fast (e.g. minimum voltage, wait states, type of memory, etc). 72MHz might be generated by dividing the 8MHz crystal clock by 2, then using the PLL to multiply by 18.
> 
> ...


you are addressing the chip design I am addressing the proto board design.
since the boards have the same core, discussion about different cores is irrelevant.


----------



## DJBecker (Nov 3, 2010)

bjfreeman said:


> you are addressing the chip design I am addressing the proto board design.
> since the boards have the same core, discussion about different cores is irrelevant.


You didn't know what "core" meant. I explained it.

All of the boards you listed have a 8MHz crystal. (The VLDiscovery board has a socketed crystal for development using other frequencies, but it ships with a 8MHz crystal installed.)

They all start out at 8MHz using the internal oscillator and the crystal disabled. The PLL is configured for pass-through for minimum start-up time. The peripheral clock dividers are set to a nominal value, usually /1.

With the 'F103 chip, the core is rated to be run at up to 72MHz. (*1)

The maximum 72MHz can be generated by various combinations of crystal frequencies, PLL settings, and dividers. There is nothing magical about 72MHz, it's just one of the clock tree configurations (and the recommended maximum for this chip in a particular voltage range). There is no 72MHz crystal. The Maple board is not faster than the other two. They are all exactly the same.


*1 The original VLDiscovery board had a 32F100 which nominally has a 24MHz rating, but has the same core and PLL structure as the "faster" chips. It functions at the higher speeds. The special edition VLDiscovery has the F103 which is rated at 72MHz maximum.


----------



## bjfreeman (Dec 7, 2011)

DJBecker said:


> You didn't know what "core" meant. I explained it.


No, I wanted clarification since maple site uses
"At the core of every LeafLabs project is a base board"
and I wanted to nail down how you were using it, since there is more than one way to use "core".


> All of the boards you listed have a 8MHz crystal. (The VLDiscovery board has a socketed crystal for development using other frequencies, but it ships with a 8MHz crystal installed.)


I stand corrected. I read 


MCU: _STM32F103RET6_, a 32-bit ARM Cortex M3 microprocessor
Clock Speed: *72 MHz*
but looking at the schematic it calls out an 8Mhz crystal, which you explained.




> They all start out at 8MHz using the internal oscillator and the crystal disabled. The PLL is configured for pass-through for minimum start-up time. The peripheral clock dividers are set to a nominal value, usually /1.
> 
> With the 'F103 chip, the core is rated to be run at up to 72MHz. (*1)
> 
> ...


Now we have gotten through all this I find the OLIMEXINO-STM32_Rev.A.
has more peripheral hardware features on the board while maintaining the Maple shield interface, like


*CAN with driver*allows automotive applications
*micoSD-card* for data logging
Cost $30 compared the Maple Board of $44.


----------



## DJBecker (Nov 3, 2010)

bjfreeman said:


> Now we have gotten through all this I find the OLIMEXINO-STM32_Rev.A.
> has more peripheral hardware features on the board while maintaining the Maple shield interface, like
> 
> 
> ...


It's a very nice board. Had it been available earlier, we would have started with it. The same with the Maple software system.


----------



## bjfreeman (Dec 7, 2011)

DJBecker said:


> It's a very nice board. Had it been available earlier, we would have started with it. The same with the Maple software system.


My last upgrade was from z8000 system to the 56f803 (16 bit 80Mhz clock) by motorola, now Freescale. that was in 1999. I adopted the NewMicro board format of two dual row headers.
So I when I saw the Board with stm32 was open source it meant I could copy paste the parts of the schematic and board to the New Micro format.
This way all my legacy systems can now be upgraded with minimal work.


----------



## mmark666 (Feb 21, 2009)

DIYguy said:


> I was thinking to feed the Shiva with my standard 2 pulses/turn and then have it (Shiva) output a "cleaned up" 3 pulses per turn. I can use this signal for my OEM tach as well as this proposed circuit.
> I think it's good to offer what you can to the thread regardless if I use it or not. .. . as this will hopefully be around for some time and good threads are all about helping the general readership, me thinks. Please do.


I don't know if you lost interest, but just for the sake of completion here is a short video of the ABC (advanced brush controller ) in action:

http://youtu.be/wNExFt2hDaw

The STM32VL board is the one on the bottom. The top is another uC board (with a Luminary Micro LM3S811) which is used as a signal generator. The Luminary outputs a square wave with 0 - 200 Hz as I turn the pot. The STM32 reads the frequency, divides it down and drives the four LEDs. At 200 Hz, all four LEDs are lit. The green LED on the right bottom edge of the STM32 flashes with 5 Hz to show that the board is running. The blue LED on the right top of the STM32 lights up if no pulse was detected for about 0.5 sec, i.e. the frequency is below 2 Hz. You can see the square wave on the scope as well.

The code is exactly the one I posted two weeks ago. The only difference is that I also output the four signals to the pins PA8 - PA11 (as well as PC0 - PC3), because the PA8 - PA11 pins are on the top side and were easier to hook up to the LEDS.

Mark


----------



## DIYguy (Sep 18, 2008)

mmark666 said:


> I don't know if you lost interest, but just for the sake of completion here is a short video of the ABC (advanced brush controller ) in action:
> 
> http://youtu.be/wNExFt2hDaw
> 
> ...


Nice job Mark! I sent you a PM and for some reason, my last PM to you did not work... ??. I've not lost interest, just been busy with other stuff. That said, I tore into my EV yesterday as I have been just waiting for all my pieces before jumping in. I'm still waiting for the reverser/GV unit. . . but had to start.
I managed to make the stepper drive work on my bench with a little program and it's pretty straight fwd. With this STM32, it should allow me to make the system work. I must put some time into the thinking for integrating it into a working system in the car. . . as in power up, run/fault indication (which you seem to have included, nice) in the dash, maybe some default position (advanced) code. . . and I dunno what else yet.


----------



## mmark666 (Feb 21, 2009)

DIYguy said:


> Nice job Mark! I sent you a PM and for some reason, my last PM to you did not work... ??. I've not lost interest, just been busy with other stuff. That said, I tore into my EV yesterday as I have been just waiting for all my pieces before jumping in. I'm still waiting for the reverser/GV unit. . . but had to start.
> I managed to make the stepper drive work on my bench with a little program and it's pretty straight fwd. With this STM32, it should allow me to make the system work. I must put some time into the thinking for integrating it into a working system in the car. . . as in power up, run/fault indication (which you seem to have included, nice) in the dash, maybe some default position (advanced) code. . . and I dunno what else yet.


Sorry, your PM never made it to me...

You would need a 5V source (which is easily done by a 7805 and two caps) and a few resistors to scale the voltage from the Solition output down to 5V. The STM32 inputs are 5V only, so perhaps its a good idea to add a TVS like this one: http://search.digikey.com/us/en/products/SMAJ5.0CA-E3/61/SMAJ5.0CA-E3/61GICT-ND/1091642 to add over voltage protection to the input. I would be surprised if your stepper controller does not have a 5V regulator on board which you could also use for the STM32, since the board only draws a few mA...

I am not sure what you mean by default position? Do you want a way to adjust the bottom end of the range (like instead of going from 0 - 10 degree advancement for 0 - 6000 rpm you want to go from 3 - 10 degree?) or do you want a full manual mode where you could manually select a fixed position/advancement independent from the current rpm?


----------



## DIYguy (Sep 18, 2008)

mmark666 said:


> I am not sure what you mean by default position? Do you want a way to adjust the bottom end of the range (like instead of going from 0 - 10 degree advancement for 0 - 6000 rpm you want to go from 3 - 10 degree?) or do you want a full manual mode where you could manually select a fixed position/advancement independent from the current rpm?


I would like a full manual mode where I can select maximum advance, being 12 or so degrees. This is where the system should "start" and where it should "default" and perhaps where it can be "selected" to be. This is the safe position.


----------



## mmark666 (Feb 21, 2009)

DIYguy said:


> I would like a full manual mode where I can select maximum advance, being 12 or so degrees. This is where the system should "start" and where it should "default" and perhaps where it can be "selected" to be. This is the safe position.


It should be easy to add a toggle switch (to switch between automatic and manual mode) and a pot to dial in a fixed advance in manual mode. Would that work?


----------



## DIYguy (Sep 18, 2008)

mmark666 said:


> It should be easy to add a toggle switch (to switch between automatic and manual mode) and a pot to dial in a fixed advance in manual mode. Would that work?


ya. I think that would work just fine.


----------



## mmark666 (Feb 21, 2009)

DIYguy said:


> ya. I think that would work just fine.


Gary,

I just send the board your way. I implemented the manual override the following way: The pot sets the minimum advance. The measured rpm can only reduce the advance until the value set by the pot is reached. Here is the updated code (which is also programmed into the board):


```
// Automatic Brush Control (abc)
// needs a current (after 2012-03-10) trunk ChibiOS (for the icuOverflowCB)

#include "ch.h"
#include "hal.h"

#define MAX_RPM 6000
#define PULSES_PER_REV 3


#define MAX_POT 3820 // adc reading if pot is turned all the way to the right
#define POT_SAFETY 3900 // if ADC is greater than this value, assume wire is shorted to Vcc

icucnt_t period = 65535, // max uint16_t
    last_period = 65535; // max uint16_t

static void icuPeriodCB(ICUDriver *icup) {
    period = (icuGetPeriod(icup) + last_period*7)/8; // low pass filter
    last_period = period;
    palClearPad(GPIOC, 8); // LED4 off
}

static void icuOverflowCB(ICUDriver *icup) {
    (void) icup; // suppress argument not used warning
    period = (65535 + last_period*7)/8; // low pass filter
    last_period = period;
    palSetPad(GPIOC, 8); // LED4 on
}

static ICUConfig icucfg = {
    ICU_INPUT_ACTIVE_HIGH,
    100000,                       // ICU clock frequency => overflow after 65535/100000 s = 0.66 s
    0,                            // width call back
    icuPeriodCB,                  // period call back
    icuOverflowCB,                // overflow call back
    ICU_CHANNEL_1,                // use Ch1
};

#define ADC_CHANNELS 1            // just one channel
#define ADC_BUF_DEPTH 8           // sample 8 times and average over

static adcsample_t samples[ADC_CHANNELS * ADC_BUF_DEPTH];

static const ADCConversionGroup adcgrpcfg = {
  TRUE,  // circular buffer
  ADC_CHANNELS,
  NULL, //adc call back
  NULL, // adc error call back
  /* HW dependent part.*/
  0,
  0,
  ADC_SMPR1_SMP_AN10(ADC_SAMPLE_41P5),  // set channel 10 (PC0) sample time to 41.5 cycless
  0,
  ADC_SQR1_NUM_CH(ADC_CHANNELS),
  0,
  ADC_SQR3_SQ1_N(ADC_CHANNEL_IN10)      // set sequence 1 to channel 10 (PC0)s
};


uint32_t getRpm(void) {
    uint32_t rpm = icucfg.frequency * 60 / PULSES_PER_REV / period;
    if (rpm < MAX_RPM)
        return rpm;
    else
        return MAX_RPM;
}


int main(void) {
    uint32_t i, outVal, adcVal, adcSum;

    halInit();
    chSysInit();

    palSetGroupMode( GPIOC, PAL_PORT_BIT(8) | PAL_PORT_BIT(9), 0,
            PAL_MODE_OUTPUT_PUSHPULL);
    palSetGroupMode(GPIOA, PAL_PORT_BIT(8) | PAL_PORT_BIT(9) | PAL_PORT_BIT(10) | PAL_PORT_BIT(11), 0,
            PAL_MODE_OUTPUT_PUSHPULL);

    palSetGroupMode(GPIOC, PAL_PORT_BIT(0), 0, PAL_MODE_INPUT_ANALOG);

    palSetPad(GPIOC, 9); // LED3 on: blinks indicating program running
    palClearPad(GPIOC, 8); // LED4 off: LED4 indicates overflow

    icuStart(&ICUD4, &icucfg); // use TIM4-CH1 (PB6) as ICU
    icuEnable(&ICUD4);

    adcStart(&ADCD1, NULL);
    adcStartConversionI(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH);
    chThdSleepMilliseconds(100); // give the adc time to sample...

    // main loop
    while (TRUE) {
        outVal = getRpm() * 16 / MAX_RPM; // scales 0 -- (MAX_RPM-1) to 0 -- 15
        if (outVal > 15)
            outVal = 15;

        adcSum = 0;
        for (i = 0; i < ADC_BUF_DEPTH; ++i)
            adcSum += samples[i];
        adcSum /= ADC_BUF_DEPTH;

        if (adcSum > POT_SAFETY) // wire short protection
            adcSum = 0;

        adcVal = adcSum * 16 / MAX_POT; // scale adc value to 0 - 15
        if (adcVal > 15)
            adcVal = 15;
           adcVal = 15 - adcVal; // invert adcVal 0 -- 15 => 15 -- 0

        if (adcVal > outVal) // take adcVal if bigger
            outVal = adcVal;

        palWriteGroup(GPIOA, 15, 8, outVal); // write outVal to PA8-PC11
        chThdSleepMilliseconds(100);
        palTogglePad(GPIOC, 9); // toggle LED4

    } // while (TRUE)

} // main
```
I can also send you the whole project (including the ChibiOS sources) if you want. 

The wiring diagram is attached. I did not test the operation with the shown voltage divider (R2 & R3) and filter (C3) on the pulse input. The values should be fine if your controller outputs 12V signals. If you observe that the output is unstable, try changing C3 to 20 or even 50 nF. You could also add a 5V Zener/TVS diode parallel to C3 to protect the input from voltage spikes...

Let me know if you have any problems with the board or program.

Mark


----------



## DIYguy (Sep 18, 2008)

mmark666 said:


> Gary,
> 
> I just send the board your way. I implemented the manual override the following way: The pot sets the minimum advance. The measured rpm can only reduce the advance until the value set by the pot is reached. Here is the updated code (which is also programmed into the board):
> 
> ...


Thanks Mark! This is all pretty awesome.  It's great that you u posted it. . . and hopefully someone else will benefit from this as well. (for the general readership, I sent Mark a small "donation" for his time and the board. I'm sure he has much more time in it than what I funded).


----------

