I am trying to use a handwheel direct-drive attached to quadrature encoder to replace the stick of an RC radio. (servo library driving into the radio's trainer port). So I spin the wheel fast, it's equivalent to pushing the RC radio stick hard. Spin slow and it's like barely pushing on the stick. In my usage, it's more important to read slow than fast - I can only hand-crank the encoder so fast - let's say 300rpm.
Here's what I've (basically) figured out::
-Quadrature encoder w/ interrupts return a direction and pulse count.
-RC PWM is direction and amount of that direction 0-255 (servo.h)
-I think I need to read the quadrature as "instantaneous" velocity? This can be scaled and output to the servo function.
I am NEW to interrupts and overall a novice, so any help reasoning through this would be VERY appreciated thank you!
The usually don’t do this. They as the name implies return a quadrature signal. This is two signals that are 90 degrees out of phase, so there are four states. These are subject to contact bounce so you need a state machine to determine when a full set of transitions have been received. Only then can you consider they have generated one step. On its own that just tells you it has moved. It tells you nothing about the velocity.
That explains why I've been having trouble figuring out how to make it work.
So I need to poll it over time. I have some 600 pulse/revolution encoders to test this, and ideally I can measure every 10 ms or faster to calculate velocity. If I understand correctly, I need direction * (new pulses)/10ms
No you let each rotary encoder generate an interrupt and let the ISR ( interrupt service routine ) handle the count accumulation.
There are libraries to help you do this.
I use the Encoder.h library by Paul Stoffregen find it in the menu Sketch-> Include Library -> Manage Library.
Then it is up to you to see how many counts you have had in x seconds or the time between a new count and the last count to get the instantaneous speed.
No that is taken care of by the count going up or down.
the standard encoder-library works only reliably wit optical encoders but unreliable with encoders that have mechanical switches.
The library newEncoder uses a different and much more reliable software-technique which is rock-solid even with the most cheapest mechanical-switch encoders.
I guess if your encoder hs 600 pulses per revolution it is an optical one.