CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

qei 32bit

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hasimi20



Joined: 04 Sep 2010
Posts: 19

View user's profile Send private message

qei 32bit
PostPosted: Sat Aug 18, 2012 8:30 am     Reply with quote

Hi, I have made a working qei program using ccs 4.128 for my 500 pulse/rotation encoder and I am using QEI_MODE_X2_RESET_ON_MATCH. The problem is, the qei is limited to 16bit only, and my project needs 32bit. Is there any c program tips to increase the 16bit counting to 32bit encoder counting? Fyi, at this moment I am using if-else and make32(), but its always miss count.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Aug 18, 2012 3:22 pm     Reply with quote

Have you tried simply counting under/overflow of your 16bit variables?

Mike
hasimi20



Joined: 04 Sep 2010
Posts: 19

View user's profile Send private message

PostPosted: Sun Aug 19, 2012 6:29 am     Reply with quote

counting under/overflow? dont understand, could you please explain??
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Aug 19, 2012 8:50 am     Reply with quote

This is taken from the PIC18F4431 data sheet.
Quote:
If the encoder is traveling in the forward direction,
POSCNT is reset (00h) on the next clock
edge when POSCNT = MAXCNT. An interrupt
event is triggered on the next TCY after the Reset
(see Figure 17-10)
If the encoder is traveling in the reverse
direction and the value of POSCNT reaches
00h, POSCNT is loaded with the contents of the
MAXCNT register on the next clock edge. An
interrupt event is triggered on the next TCY after
the load operation (see Figure 17-10).


The qei variable POSCNT is the 16 LSBs of your 32bits.

When encoder is traveling forwards, an interrupt is generated as POSCNT overflows past MAXCNT. When travelling in reverse, the interrupt happens as POSCNT underflows through zero. I'm suggesting you could use the interrupts to increase/decrease a 16MSB_COUNTER. If you make MAXCNT = 0xFFFF then you should have a 32 bit system.

Mike
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group