1 post / 0 new
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all,


I'm using the XMEGA QDEC with a rotary encoder fitted to a DC motor. The encoder is a 500 CPR unit so I've set my corresponding timer .PER register to 1999 as I'm using the index signal.

I'm using the timer's error interrupt to sense for possible faults (the end application is an industrial machine, and using PID to drive the axis means that if an encoder fails the axis could end up being driven at full speed and crashing, if I can sense when an encoder has failed I can stop this).

So far everything's working fine, which is great, however I'm experiencing some unexpected behavior and I'm curious if anyone knows why...


Essentially, upon power up, the .CNT reg of my timer will be at 0, however this may not align with the index signal, so I would expect the first time the motor is moved to hit the error interrupt when the index hits and the .CNT reg is not at 0. However using a variable as a counter I'm seeing the error interrupt being fired 3 times before it settles? Given that the interrupt is fired if the index signal hits before the .CNT reg resets to 0, and vise versa, I would expect the interrupt to be hit once if the encoder's counting up, and twice if the encoder's counting down, however it's being hit 3 times every time regardless of direction. Whilst I can simply wait for the interrupt to be hit 3 times before actually regarding it as an error and this would be fine, I'm curious as to why, does anyone on here know or experience the same thing? I'm driving the motor at less than 60 rpm so it's not a speed issue.


PS I can post code if needed but it's pretty standard with what others have done and posted on here before me.