Encoder API

The Encoder API encompasses the needed software to configure and control the encoders used as position sensors in servo control applications.

Example Use

In the following example, 4 encoder channels are initialized, the range set to map encoder counts to actual position values, and finally, the encoders are read, both directly in position physical uits and also in encoder counts.
float positions[4];
int counts[4];
/* main program for control applications */
main()
{
int ii;
unsigned int numEncChannels = 4;
setNumEncs (numEncChannels);
for (ii=0; ii<numEncChannels; ii++)
{
/* Encoder in channel ii uses quadrature for increasing resolution (4) and is a 24 bit encoder */
initEnc (ii, 4, 24);
}
/* Map encoder pounts to physical units of position. for channel 0, count of 0 represents 0 degrees while a count of 8756 corresponds to 360 degrees. For encoder channel 3, count of 0 corresonds to 0 physical units of position (inches), while a count of 42s of position (inches), while a count of 4224 represents 1.0 inches. */
initPosition (0, 0, 0.0, 8756, 360.0);
initPosition (1, 0, 0.0, 8756, 360.0);
initPosition (2, 0, 0.0, 41984, 3240.0);
initPosition (3, 0, 0.0, 4224, 1.0);
for (ii=0; ii<numEncChannels; ii++)
{
/* the actual encoder counts are stored in the array counts[] */
counts[ii] = getEncoder (ii);
/* the position physical unts are stored in the array positions[] */
positions[ii] = getPosition (ii);
}
}

Method Index

o setNumEncs ()
o getNumEncs()
o initEnc ()
o initPosition ()
o getPosGain ()
o getPosOffset ()
o clearEncoder ()
o setEncoder ()
o getEncoder ()
o setPosition ()
o getPosition ()
o setDifferential al">setDifferential ()
o clearDifferential ()
o setFilterDiv ()

Methods

o setNumEncs
int setNumEncs (unsigned int noChannels);
Parameters
noChanels: Total number of channels
Returns
0: if successful
-1: failure to set chanels, e.g. due to insufficient memory
o getNumEncs
unsigned int getNumEncs ();
Parameters:
Returns:
Total number of encoder channels.
o initEnc
void initEnc (unsigned int channel, unsigned int multiplier, unsigned
int numBits); 
Configures the encoder channel.
Parameters
channel: refers to the channel number
multiplier: refers to the factor by which the encoder resolution is increased. Using quadrature the number is 4.
numbits: refers to the nuture the number is 4.
numbits: refers to the number of bits used for the encoder count.
o initPosition
void initPosition (unsigned int channel, int aCounts, float aPosition,
int bCounts, float bPostion);
Enables the user to specify the mapping between encoder counts and position physical units.
Parameters
channel: Refers to the encoder channel number
aCounts: first count of encoder corresponding to first known position, aPosition
aPosition: first position in physical unts (e.g. degrees, inches) corresponding to first encoder count, aCount
bCounts: second encoder count, corresponding to second position, bPosition
bPosition: second position value in physical unts corresponding to second encoder count.
o getPosGain
float getPosGain (unsigned int channel);
Gives the value of the slope between encoder reading position physical units, based on the mapping provided by the initPosition function.
Parameters
channel: number of encoder channel
Returns
position gain (i.e. the slope) of the linear graph of position physical units vs. encoder counts.
o getPosOffset
float getPosOffset (unsigned int channel);

Gives the position offset of the encoder reading in position physical units, based on the mapping provided through the initPosition function.
Parameters
channel: channel number
Returns
offset value in position physical units.
o clearEncoder
void clearEncoder (unsigned int channel);

Sets the encoder channels to zeros.
Parameters:
channel: channel number
o setEncoder
void setEncoder (unsigned int channel, int value);
Sets the encoder chanel to a specific count.
Parameters
channel: channel number
value: encoder count for the channel.
o getEncoder
int getEncoder (unsigned int channel);
Gives the encoder count.
Parameter
channel: encoder channel number
Returns
encoder count
o setPosition
void setPosition (unsigned int channel, float position)
Sets the encoder value in physical units.
Parameter
channel: channel number
position: value in physical units that tts that the encoder is to be set to
o getPosition
float getPosition (unsigned int channel);
Provides the current encoder reading in position physical units.
Parameter
channel: number of channel
Returns
Current position value in physical units.
o setDiferential
void setDifferential (unsigned int channel);

Sets the encoder to read as a differential encoder. The default assumption is a single-ended encoder.
Parameter
channel: channel number
o clearDifferential
void clearDifferential (unsigned int channel);
Sets the encoder channel back to being a single-ended encoder instead of a differential encoder.
o setFilterDiv
void setFilterDiv (unsigned int channel, unsigned int filterDiv);
Sets the sampling interval for sub-sampling the encoder channel as a multiple of the base clock frequency.
Parameters
channel: chant>
Parameters
channel: channel number
filterDiv: the integer multiple for the base clock frequency


Last modified: Mon Feb 15 00:02:37 Eastern Standard Time 1999