There are several ways to do this. Using code wheels (or encoder discs) with photoelectric or Hall effect detectors seems to be the easiest way, in a software point of view, but requires mechanical adaptations to include the code wheels. This would affect the design of the bot, and would be too invasive to include in a “hacked toy” (such as a tank rc, this is what I plan to do, the mechanical parts on the tank cannot be modified, and shouldn’t be). Anyway…
Another way to do this is measuring the back-emf feedback. This is well describedÂ here. Basically, voltage coming from the motor, while it’s turned off (not powered), must be measured using ADC. The value is proportional to the speed of the motor. Compared to the voltage applied, it’s possible to know if the motor is turning as expected or not (too fast, or more plausible, too slow). And possibly to adjust the applied voltage to correct the speed.
I found thisÂ nice pageÂ on back-emf using control feedback, with the same parts I use (16F88, L293D). This is what I’m currently trying to implement.Â Master PatrickÂ also helped me a lof, with advices, suggestions and patience…
After several tries, first results are quite interresting. Here’s a series of screenshots from an experiment. There’s one DC motor. Its speed is increased at each step, using PWM. One step consists in activating the motor for 2 seconds, then shutdown the motor for 1 second. When PWM is turned off, an ADC measure is acquired and sent through serial link. This gives…
Lot’s of noise (more on this later), but we can clearly see how the motor is accelerating, step by step. As expected, while the PWM increase step is constant, acceleration is not linear.
Also note, duringÂ the very steps, PWM is not high enough to make the motor rotates. There’s a voltage applied to it, but none generated…
Zooming on a step show interesting things… First, each step looks the same:
- nÂ is the current step,
- AnÂ is the current average being computed
- An-1Â is the average at previous step
- anÂ is the new measure for current step
- kÂ is a coefficient used to balance the average with the new measure.Â 0 < k < 1
During this last experiment, I voluntarily slow down the motor several times. The green line is the sliding average, usingÂ kÂ = 0.98 (the new measure has only 2% weight in the average). More readable, heh ?