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 CCS Technical Support

30f2010 QEI extending count range

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







30f2010 QEI extending count range
PostPosted: Fri Mar 06, 2009 12:36 pm     Reply with quote

I am using a ds30f2010 for the quadrature encoder hardware. The problem is that i can only count up to 65000(whatever it is); When the counter rolls over i would like to increment or decrement another number, multiply it by 65000 and add the current qei_read(). I run an interrupt service routine when the counter rolls over, read the qei count direction from the hardware. If it is 1 then increment my number if 0 then decrement the value.

*The problem is this does not always work? Does anyone have suggestions? Also FYI i do not have an encoder connected i am simulating the signal with switches (this may be the whole problem?).

Thanks
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

PostPosted: Sat Mar 07, 2009 11:13 pm     Reply with quote

The counter will work in the range of 0 to 0xFFFF (65535). The range can be extended by sampling the count frequently, and adding the difference in sampled values between successive samples to a signed int32 variable. This difference may be negative, so signed arithmetic is necessary.

Code:

signed int32 position = 0;
signed int16 new;
signed int16 old = 0;
signed int16 difference;



The following needs to be in a loop. The count has to be sampled faster than half the shortest time it would take for the count to change by the width of the counter. eg. if it takes the qei counter 10 seconds to go from 0 to 65535 at the fastest expected speed in one direction then the count has to be taken faster than every 5 seconds. Sampling faster than needed would be OK.


Code:

new = qei_read();
difference = new - old;
position += difference;
old = new;



Obviously, if the direction of rotation is one way for a long period then even the signed int32 value will also overflow. However, for a situation where there is a finite number of rotations, for example in a machine with a lead screw, this works well.
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