Posts: 60
Joined: Nov. 10, 2006
From: IL, USA / Taichung, Taiwan
Status: offline
Hello, I noticed that QEI (quadrature encoder interface) only works when I configure the pins as analog inputs (ANSEL bits are 0). Is this correct? It seems like the encoder should be a digital device. Any ideas? Thanks, Mike
The ANSEL reg. bits should be 0: digital inputs and tris shold be inputs (1)ofcourse...
The quadrate encoder is a digital device (it's not a tachometer!!!), with two lines A,B channel.(plus one index - 1 pulse/full revolution) The two line signals are 90° out of phase, so the PIC can encode the signal to up/down counts.
Posts: 60
Joined: Nov. 10, 2006
From: IL, USA / Taichung, Taiwan
Status: offline
Thanks for the replies. According to the ADC section of the datasheet, ANSEL=1 is analog and 0 is digital, as you pointed out. However, they provide the following code at the PORTA section:
CLRF PORTA ; Initialize PORTA by ; clearing output ; data latches CLRF LATA ; Alternate method ; to clear output ; data latches MOVLW 0x3F ; Configure A/D MOVWF ANSEL0 ; for digital inputs MOVLW 0xCF ; Value used to ; initialize data ; direction MOVWF TRISA ; Set RA<3:0> as inputs ; RA<5:4> as outputs
0x3F is 00111111 in binary, right? It looks to me like they're writing 0x3F to the ANSEL0 register. Correct me if I'm wrong; I'm just getting started with PICs. If it makes any difference, I am using the C18 compiler. Thanks, Mike
REGISTER 20-6: ANSEL0: ANALOG SELECT REGISTER 0(1)
R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1
ANS7(2) ANS6(2) ANS5(2) ANS4 ANS3 ANS2 ANS1 ANS0
bit 7 bit 0
bit 7-0 ANS<7:0>: Analog Input Function Select bits
Correspond to pins AN<7:0>
1 = Analog Input
0 = Digital I/O
This code is wrong. Let's try it and make a pin stimulus if your pin is configured to input (trisa,x=1), and it's digital you will notice the change on porta, if it's analog, the port reg. will not change.