Microchip Technology
Welcome to www.microchip.com
Search: Click here to Search Microchip.com
Forums Home Register LoginLog Out Inbox Address Book My Subscription Member List Search My Profile FAQ
PIC18F4431 Quadrature Encoder

PIC18F4431 Quadrature Encoder

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [Microcontroller Discussion Group] >> 16-Bit Core (instructions, reset, WDT, specifications...) PIC17Cxx, PIC18Fxxx >> PIC18F4431 Quadrature Encoder Page: [1]
Login
Message << Older Topic   Newer Topic >>
PIC18F4431 Quadrature Encoder - Nov. 10, 2006 3:00:41 PM   
mhwang

 

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
Post #: 1
RE: PIC18F4431 Quadrature Encoder - Nov. 10, 2006 6:27:25 PM   
rmoline

 

Posts: 352
Joined: Dec. 18, 2004
Status: offline
Ooops, read the datasheet again ;-)

ANSEL bits = 1 are analog input
ANSEL bits = 0 are digital I/O

(in reply to mhwang)
Post #: 2
RE: PIC18F4431 Quadrature Encoder - Nov. 11, 2006 3:53:18 AM   
dubble

 

Posts: 208
Joined: Nov. 7, 2006
From: Hungary
Status: offline
Hi!

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.

(in reply to rmoline)
Post #: 3
RE: PIC18F4431 Quadrature Encoder - Nov. 11, 2006 2:30:25 PM   
mhwang

 

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


< Message edited by mhwang -- Nov. 11, 2006 2:45:39 PM >

(in reply to rmoline)
Post #: 4
RE: PIC18F4431 Quadrature Encoder - Nov. 11, 2006 4:01:36 PM   
dubble

 

Posts: 208
Joined: Nov. 7, 2006
From: Hungary
Status: offline
Hi Mhwang!

You have just found a bug, I think, look at that:



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.








(in reply to mhwang)
Post #: 5
RE: PIC18F4431 Quadrature Encoder - Nov. 11, 2006 5:01:39 PM   
rmoline

 

Posts: 352
Joined: Dec. 18, 2004
Status: offline
quote:

Hi Mhwang!

You have just found a bug, I think, look at that:

Indeed, a typo in the datasheet. Strong guess would be that the PORT A code example 10-1 is wrong. But until you test it you won't know.

(in reply to dubble)
Post #: 6
RE: PIC18F4431 Quadrature Encoder - Nov. 12, 2006 3:49:37 AM   
dubble

 

Posts: 208
Joined: Nov. 7, 2006
From: Hungary
Status: offline
Hi!

Rmoline: It looks wrong, I have tested to be sure and it's wrong :(

(in reply to rmoline)
Post #: 7
RE: PIC18F4431 Quadrature Encoder - Nov. 12, 2006 9:53:14 PM   
mhwang

 

Posts: 60
Joined: Nov. 10, 2006
From: IL, USA / Taichung, Taiwan
Status: offline
Thank you everyone for your replies.  I'll email tech support about this.
-Mike

(in reply to dubble)
Post #: 8
Page:   [1]
All Forums >> [Microcontroller Discussion Group] >> 16-Bit Core (instructions, reset, WDT, specifications...) PIC17Cxx, PIC18Fxxx >> PIC18F4431 Quadrature Encoder Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


  Site Index  |  Legal Information  |  microchipDIRECT  |  Samples  |  Technical Support  |  Investor Information  |  Careers at Microchip  |  Contact Us  |  RSS Feeds ©2009 Microchip Technology Inc.  
  Shanghai ICP Recordal No.09049794  
Forum Software © ASPPlayground.NET Advanced Edition 2.5.5 Unicode

0.156