Hi, I need measure speed of a DC Motor with built-in encoder hall. Motor:Motor DC Link Board: Arduino MEGA 2560
I am also using an optical sensor to detect the passage through zero degrees.
Re-computing speed on every encoder pulse will be somewhat unsteady and noisy.
Grab an averager library to average the speed over 10 pulses or whatever makes sense.
Alternatively, record the last 10 micros() and use the duration from the one that was 10 steps ago. Throw that one out each time and use that space to record the current one.
If the speed is very variable, count pulses for a specific time. That way when it stops, you don't wait forever for the 10th pulse. There are lots of tutorials online for measuring RPM this way.
MorganS:
Re-computing speed on every encoder pulse will be somewhat unsteady and noisy.
Its the best you can do without too much latency using an encoder, and if its a decent encoder will be usuable. Yes you can smooth the result if you want, but you'll sacrifice latency especially at low speed.
If the speed is very variable, count pulses for a specific time. That way when it stops, you don't wait forever for the 10th pulse. There are lots of tutorials online for measuring RPM this way.
Yes, I second that as a reasonable method for some circumstances, and the latency is at least constant, but its more complex to code.
MorganS:
Re-computing speed on every encoder pulse will be somewhat unsteady and noisy.
Grab an averager library to average the speed over 10 pulses or whatever makes sense.
Alternatively, record the last 10 micros() and use the duration from the one that was 10 steps ago. Throw that one out each time and use that space to record the current one.
If the speed is very variable, count pulses for a specific time. That way when it stops, you don't wait forever for the 10th pulse. There are lots of tutorials online for measuring RPM this way.
What did you find when you searched? Which of the various methods I suggested did you try and which one (that you want to try next) is giving you difficulty?
instead of averaging by collecting N points, you can do leaky integration and update an average, a[t] using a fraction of the input, s [t]. yes, there's a lag at startup if you don't initialize a [0] with the first input, s[1]