Hi all. I'm currently using a 1024 pulse per revolution optical incremental rotary encoder --- omron brand.
I'm using only 1 encoder channel only...... eg. Channel A. So I'm not using quadrature mode at all.
What I'm noticing (at the moment) is that I'm getting a consistent number of counts (such as 130 counts over a 2 millisecond window) when the arduino attach-interrupt mode (associated with a single encoder channel) is set to 'FALLING'..... which triggers interrupts on each falling edge of the encoder waveform. But getting slightly higher than expected counts when I use the 'CHANGE' mode for the 'attach-interrupt'.
Eg..... my unaveraged raw number of counts is shown in the box below, which were 'serial printed' every 2 seconds, with corresponding converted approximate RPM value. The DC motor I'm driving is in open loop mode..... with PWM level set to max.... ie. PWM level 255.
counts= 131 3837.89 counts= 131 3837.89 counts= 131 3837.89 counts= 131 3837.89 counts= 130 3808.59 counts= 131 3837.89 counts= 132 3867.19 counts= 131 3837.89 counts= 132 3867.19 counts= 131 3837.89 counts= 131 3837.89 counts= 132 3867.19 counts= 132 3867.19 counts= 131 3837.89 counts= 132 3867.19 counts= 131 3837.89 counts= 131 3837.89 counts= 130 3808.59
But when I change the attach-interrupt mode to 'CHANGE' (to trigger on both the RISING and FALLING edge of the single encoder waveform), I assume that the number of counts should be approximately twice the number as before..... such as close to 260 counts (plus or minus a couple of counts).
However, the measured results that I'm getting right is around the 270 region.
The results below are the raw counts (still taken over 2 millisecond windows for each number of counts) .... serial printed every 2 seconds.
counts= 268 3925.78 counts= 272 3984.37 counts= 270 3955.08 counts= 270 3955.08 counts= 270 3955.08 counts= 272 3984.37 counts= 268 3925.78 counts= 266 3896.48 counts= 272 3984.37 counts= 272 3984.37 counts= 270 3955.08 counts= 270 3955.08 counts= 270 3955.08 counts= 271 3969.73 counts= 276 4042.97 counts= 270 3955.08 counts= 266 3896.48 counts= 266 3896.48 counts= 268 3925.78 counts= 270 3955.08 counts= 272 3984.37 counts= 270 3955.08
So, for the attach-interrupt mode set to "CHANGE" , I'm seeing counts of around 270, instead of an assumed (or expected) 260.
I'm seeing no issues with inconsistent or abrupt counting errors for raw counts. But thought I'd ask somebody here to see if I can understand what I'm measuring....such as the reason behind the number of counts not scaling up (doubling) from 130 counts to 260 counts when I alter the interrupt mode from 'FALLING' to 'CHANGE'. Instead....the measured number of counts in the 'CHANGE' mode is around 270.
While I already mentioned that I'm using Channel A only. I also get the same trend if I use Channel B only.
For Channel A, I'm using digital pin '3' for the 'attach-interrupt' on the MEGA 2560. Every 'number of counts' reading (done during 2 millisecond window) always starts at zero count. So my counting routine always waits for the next occurring waveform edge before commencing to measure a set of counts (over a 2 millisec duration).
The 'bandwidth' of this encoder (as the give in their data specifications is 100 kHz).
Thanks for any advice and/or recommendations in advance.