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

Need incremental encoder to velocity algorithm

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



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

Need incremental encoder to velocity algorithm
PostPosted: Sat Jan 06, 2007 9:07 am     Reply with quote

I have to drive an external analog servo from a PIC16F877A. The feedback is from a 2-channel optical encoder, and it was easy to write an algorithm for deriving position from that. Unfortunately the servo wants a tachometer input, i.e. an analog voltage representing the speed of the motor, and getting that from the encoder, or from the "position" quantity that's derived from the encoder, isn't so easy. We already use 12-bit DACs with a +/-5V output, so that's the desired output element.

Theoretically I understand how to turn a pulse stream into a velocity quantity: if the rate is fast, count pulses over a fixed time. If it's slow, count time intervals between pulses and take the reciprocal. But it seems like a serious amount of code to write, with bugs along the way guranteed, and I'm sure it's already been done many times over. In particular, changing over from pulses-per-unit-of-time to time-between-pulses looks quite tricky. Can anyone point to a site where I can find at least the basis of this algorithm already done? I'd appreciate any leads.
jma_1



Joined: 08 Feb 2005
Posts: 147
Location: Wisconsin

View user's profile Send private message

PostPosted: Sat Jan 06, 2007 10:25 am     Reply with quote

Greetings John,

I'm sure you have researched the servo which you are using, but I would double check that you need an anolog output as the velocity component. Many of the servos which are a self contained unit and contain their own closed loop control, require a velocity pulse train. Tachometer outputs to guages and other components are using 16 pulses / rev.

If you have to use an analog ouput as a representation of the velocity, make a map and interpolate between the points. For example, set up a ratio of pulses per unit of time (freq) to the DAC value (voltage). This could even be a simple in-line formula.

If your code does not measure period between pulses, compare the incremental pulse count of the encoder with each main() loop interation (fixed time interval gives pulse frequency). From this, you can even determine acceleration. :-) However, the resolution of this may be lousy depending on your system setup.

If you need to change to measuring tick counts (period), there are one or two examples provided by CCS. I do not have the example files on my present computer so I cannot give you the specific file names. There are also previous posting on measuring frequency by using the period between pulses. Please be aware that you must deal with the possibility of a near infinite time between pulses when in a steady state. You can use a 16 bit timer or chain timers together, but ultimately you must catch the timer roll-over to detect long periods (zero frequency).

For curiosity sake, is your encoder output in quadrature? or a single pulse train and a direction output?

Cheers,
JMA
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Sun Jan 07, 2007 3:44 pm     Reply with quote

John,

If you want to do it in a really old-fashioned analog way, you could use a frequency-to-voltage F/V converter. Such as LM2917, for example, but there are tons of them. If you are more of a hardware person (rather than firmware), this method migh well be the quickest path to a working system.

Cheers,
Nick
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