sean-h
- 19th February 2011, 21:10
Has anyone succesfully got the QEI on the 18F2431 working successfully.
The position counter was easy enough and brilliant for making sure you have the encoder sensor lined up correctly, but struggling with the velocity mode.
Set myself the goal of first just using the INDEX pin of the Encoder wheel, which is on the CAP1 to measure RPM, by reading the time it takes for each revolution. Then when happy with that I wanted to start sampling the time say 64 times per revolution etc etc. And eventually logging the Pulse Width between say every 16 pulses.
But small steps and after jumping back and forth over the 18F2431 data sheet I sort of concluded the following:
I have set
QEI:
Bit7 0=Velocity mode enabled
Bit6 0=No overflow or underflow
Bit5 0 UP/DOWN: Direction of Rotation Status bit
Bits4-2 001=QEI enabled in 2x Update mode; INDX resets the position counter
bits1-0 00=1:1 Velocity Pulse Reduction Ratio
QEICON = %0 0 0 001 00
Then CAP1CON to
CAP1:
Bits 7-4 not used for QEI
Bit 3-0 Special Event trigger mode, every rising edge of cap1
CAP1CON=%0000 1111
And Timer5 to
Timer5:
Bit7 0=Timer Disabled during sleep
Bit6 1=Special Event Trigger Reset is disabled (not used on 2431)
Bit5 0=Continous Count mode
Bit4-3 Timer5 Prescale 00=1:1
Bit2 0=Sync with external clock
Bit1 0=Internal clock source
Bit0 1=Timer 5 enabled
T5CON=%0 1 0 00 0 0 1
I was foolishly thinking I could simply read the VELR values that should get updated every revolution.
Read VELRH and VELRL and joing them to get word value.
But instead of the VELR buffer getting updated each revolution, it is getting updated every pulse.
Any help or code examples appreciatted.
Cheers
Sean.
The position counter was easy enough and brilliant for making sure you have the encoder sensor lined up correctly, but struggling with the velocity mode.
Set myself the goal of first just using the INDEX pin of the Encoder wheel, which is on the CAP1 to measure RPM, by reading the time it takes for each revolution. Then when happy with that I wanted to start sampling the time say 64 times per revolution etc etc. And eventually logging the Pulse Width between say every 16 pulses.
But small steps and after jumping back and forth over the 18F2431 data sheet I sort of concluded the following:
I have set
QEI:
Bit7 0=Velocity mode enabled
Bit6 0=No overflow or underflow
Bit5 0 UP/DOWN: Direction of Rotation Status bit
Bits4-2 001=QEI enabled in 2x Update mode; INDX resets the position counter
bits1-0 00=1:1 Velocity Pulse Reduction Ratio
QEICON = %0 0 0 001 00
Then CAP1CON to
CAP1:
Bits 7-4 not used for QEI
Bit 3-0 Special Event trigger mode, every rising edge of cap1
CAP1CON=%0000 1111
And Timer5 to
Timer5:
Bit7 0=Timer Disabled during sleep
Bit6 1=Special Event Trigger Reset is disabled (not used on 2431)
Bit5 0=Continous Count mode
Bit4-3 Timer5 Prescale 00=1:1
Bit2 0=Sync with external clock
Bit1 0=Internal clock source
Bit0 1=Timer 5 enabled
T5CON=%0 1 0 00 0 0 1
I was foolishly thinking I could simply read the VELR values that should get updated every revolution.
Read VELRH and VELRL and joing them to get word value.
But instead of the VELR buffer getting updated each revolution, it is getting updated every pulse.
Any help or code examples appreciatted.
Cheers
Sean.