For quick and easy adjustments, I included a Bourns PEC12R incremental encoder in my design.
I've never used this product before, but now that I have, I'll say this: it is the single most retarded incremental encoder I have ever had the displeasure of using.
The part has 24 mechanical detents throughout the 360° turn of the shaft. The detents are pretty solid -- it is nearly impossible to leave the shaft out of alignment with a detent. This is a good thing.
Here's where it gets crazy: if you properly decode the quadrature output, you get 4 counts per detent! Why not one? It's not like you can use the 4 counts -- the shaft doesn't stop mid-detent (unless you really, really try).
So, you've got to interpret: 4 quadrature counts == 1 real count. Maybe I am missing something, but it seems pretty stupid to have 24 positions representing 96 counts.
I will allow this as an explanation: I suppose if you are not interest in direction, one could just use a single A or B output to produce 24 rising (or falling) edges per revolution. But why use an encoder, then?
For fun, here's my port B IOC interrupt code to drive the encoder:
I've never used this product before, but now that I have, I'll say this: it is the single most retarded incremental encoder I have ever had the displeasure of using.
The part has 24 mechanical detents throughout the 360° turn of the shaft. The detents are pretty solid -- it is nearly impossible to leave the shaft out of alignment with a detent. This is a good thing.
Here's where it gets crazy: if you properly decode the quadrature output, you get 4 counts per detent! Why not one? It's not like you can use the 4 counts -- the shaft doesn't stop mid-detent (unless you really, really try).
So, you've got to interpret: 4 quadrature counts == 1 real count. Maybe I am missing something, but it seems pretty stupid to have 24 positions representing 96 counts.
I will allow this as an explanation: I suppose if you are not interest in direction, one could just use a single A or B output to produce 24 rising (or falling) edges per revolution. But why use an encoder, then?
For fun, here's my port B IOC interrupt code to drive the encoder:
Code:
;*****************************************
;** ENCINT -- Encoder Interrupt routine **
;*****************************************
encint swapf portb,w ;capture new encoder value (bits 4:5 -> 0:1)
andlw b'00000011' ;mask encoder inputs
bcf intcon,rbif ;clear interrupt
rlncf _enclst,f ;shift old values
rlncf _enclst,f
iorwf _enclst,w ;merge in new
andlw b'1111' ;modulo 16
movwf _enclst ;save as new last
cjump _enclst
bra eina ;no action
bra eidec ;decrement
bra eiinc ;increment
bra eina ;no action
bra eiinc ;increment
bra eina ;no action
bra eina ;no action
bra eidec ;decrement
bra eidec ;decrement
bra eina ;no action
bra eina ;no action
bra eiinc ;increment
bra eina ;no action
bra eiinc ;increment
bra eidec ;decrement
bra eina ;no action
eidec decf _encinc,f ;decrement encoder counts
bra eiupd ;and indicate update
eiinc incf _encinc,f ;increment encoder counts
eiupd bsf _encrdy ;indicate new encoder data ready
eina goto intdone ;and get out
