zx-128a1 Dev Board QDEC Implementation
Posted: 01 December 2010, 1:03 AM
Hello,
I am looking for some support on implementing the QDEC on the ZX-128a1 Dev Board. I have an optical encoder connected to A.0 and A.1. After following the instructions in the Atmel XMEGA manual, I have an interesting repeatable error.
I am able to get counts in both directions when I rotate the wheel but there are times when the count increases rapidly without any motion. Using the scope, the signals going in are nice and square. However, I found that if the wheel stops spinning on a count where both A and B are high I get this repeatable rapid incrementing when the wheel is stopped.
Any advice you have would be most appreciated
Thanks,
Daniel
I am looking for some support on implementing the QDEC on the ZX-128a1 Dev Board. I have an optical encoder connected to A.0 and A.1. After following the instructions in the Atmel XMEGA manual, I have an interesting repeatable error.
I am able to get counts in both directions when I rotate the wheel but there are times when the count increases rapidly without any motion. Using the scope, the signals going in are nice and square. However, I found that if the wheel stops spinning on a count where both A and B are high I get this repeatable rapid incrementing when the wheel is stopped.
Any advice you have would be most appreciated
Thanks,
Daniel
Code: Select all
sub InitEventModule()
'~ For a full QDEC setup the following is required:
'~ •I/O port pins - quadrature signal input
'~ •The Event System - quadrature decoding
'~ •A Timer/Counter - up, down and optional index count
'~ The following procedure should be used for QDEC setup:
'~ •Choose two successive pins on a port as QDEC phase inputs.
'~ •Set pin direction for QDPH0 and QDPH90 as input.
'Pin A.0 and A.1 are input by default
'~ •Set pin configuration for QDPH0 and QDPH90 to low level sense.
SetBits Register.PORTA_PIN0CTRL, &B0000_0111, &B0000_0011
SetBits Register.PORTA_PIN1CTRL, &B0000_0111, &B0000_0011
'~ •Select QDPH0 pin as multiplexer input for an event channel, 0.
SetBits Register.EVSYS_CH0MUX, &B1111_1111, &B0101_0000
'~ •Enable quadrature decoding and digital filtering in the Event Channel.
SetBits Register.EVSYS_CH0CTRL, &B0000_1111, &B0000_1001
'~ •Optional:
'~ a.Setup QDEC index (QINDX).
'~ b.Select a third pin for QINDX input.
'~ c.Set pin direction for QINDX as input.
'~ d.Set pin configuration for QINDX to sense both edges.
'~ e.Select QINDX as multiplexer input for Event Channel n+1
'~ f.Set the Quadrature Index Enable bit in Event Channel n+1.
'~ g.Select the Index Recognition mode for Event Channel n+1.
' Don't have an index
'~ •Set quadrature decoding as event action for a Timer/Counter.
SetBits Register.TCC0_CTRLD, &B1110_0000, &B0110_0000
'~ •Select Event Channel 0 as event source the Timer/Counter.
SetBits Register.TCC0_CTRLD, &B0000_1111, &B0000_1000
'~ •Set the period register of the Timer/Counter to ('line count' * 4 - 1). (The line count of the
'~ quadrature encoder).
Register.TCC0_PER = LineCount*4-1
'~ •Enable the Timer/Counter by setting CLKSEL to a CLKSEL_DIV1.
SetBits Register.TCC0_CTRLA, &B0000_1111, &B0000_0001
'~ The angle of a quadrature encoder attached to QDPH0, QDPH90 (and QINDX) can now be read
'~ directly from the Timer/Counter Count register. If the Count register is different from BOTTOM
'~ when the index is recognized, the Timer/Counter error flag is set. Similarly the error flag is set if
'~ the position counter passes BOTTOM without the recognition of the index.
end Sub