Sensor API

The Sensor API encompasses the needed software to read both the Analog-to-Digital Converter (ADC) and the physical device which it represents. The advantage this approach is that most programming to be done with a user's system can be done in natural engineering units rather than abstract volts or HEX numbers. However, there are instances where a lower level treatment of these devices are required. In these cases, this API provides the ability to directly access the ADC's.

Example Use

In the following example, an 8 channel card is initialized. Each ADC is connected to a sensor which outputs an analog voltage. Finally, the channel #0 sensor is read in the physical unit.
/* initialize actuators */
int numDacChannels, i;
numDacChannels = 8;
setNumAdcs (8);
for (i = 0; i < numAdcChannels; i++)
{
/* 12-bit, 10V max, bipolar, offset device */
initAdc (i, 1, 0, 12, 10.0);
/* sensor with a 0.0-5.0 units input (e.g. pressure in psi) and +/-2.0 Volts output */
initSensor (i, 0.0, -2.0, 5.0, 2.0);
}
/* Get the sensor value, in sensor physical units, on channel #0*/
getSensor (0);

Method Index

o getAdcNumBits()
o initSensor()
o initAdc()
o isAdcBipolar()
o isAdcTwosComplement()
o getSensor()
o setSensorMaximum()
o setSensorMinimum()
o getAdc()
o setAdcBipolar()
o getAdcHex()
o setAdcNumBits()
o setAdcReference()
o setAdcTwosComplement()
o setNumAdcs()
o updateAll()
o updateAdc()
o updateTotal()

Methods

ogetAdcNumBits
unsigned int getAdcNumBits (unsigned int channel);
Get the number of bits of resolution for a channel.
Parameters
channel : channel number
Returns
Resolution of the ADC channel in bits.
ogetNumAdcs
unsigned int getNumAdcs ()
Get the number of channels of ADCs.
Returns
Number of the ADC channels.
oinitSensor
void initSensor (unsigned int channel, float adcMin, float
sensorMin,  float adcMax, float sensorMax)
Initializes a sensor attached to a given ADC channel. The initialization includes setting both the maximum and minimum points which, with the basic ADC configuration, are used to establish the relationship between the physical units and the HEX value produced by the ADC (see getSensor).
Parameters
channel: channel number of the ADC to set.
adcMin: minimum voltage for the ADC output.
sensorMin: minimum physical value which corresponds to the minimum ADC voltage.
adcMax: maximum voltage for the ADC output.
sensorMax: maximum physical value which corresponds to the maximum ADC voltage.
oinitAdc< HEIGHT=12 WIDTH=12>initAdc
void initAdc (unsigned int channel, int isBipolar,
 int isTwosComplement, unsigned int numBits,
 float referenceVal)
Initializes an ADC channel with the device attributes.
Parameters
channel: channel number of the ADC to set.
isBipolar: set to 1 if ADC is bipolar or 0 if unipolar.
isTwosComplement: set to 1 if two's complement is used or 0 if offset representation is used for ADC numbers.
numBits: resolution of ADC (number of bits).
referenceVal: reference voltage of the ADC. Note, different devices have different rules for relating their reference to their range. This API uses the convention that the maximum voltage is one bit less than the reference voltage.
oisAdcBipolar
unsigned int isAdcBipolar (unsigned int channel);
oisAdcTwosComplement
unsigned int isAdcTwosComplement (unsigned int channel);
ogetSensor
float getSensor">getSensor 
float getSensor (unsigned int channel);
Gets the value of the sensor connected to an ADC channel in physical units. If the value exceeds the limits established, the limit is used instead.
Parameters
channel: channel number of the associated ADC
osetSensorMaximum
void setSensorMaximum (unsigned int channel, float adcValue,
 float sensorValue);
Sets the maximum physical level and the associated ADC voltage output for a given channel.
Parameters
channel: channel number of the ADC to set
adcValue: maximum voltage for the ADC to output (see getSensor)
sensorValue: maximum physical value which corresponds to the maximum ADC voltage.
osetSensorMinimum
void setSensorMinimum (unsigned int channel, float adcValue,
 float SensorValue);
Sets the minimum physical level and the associated ADC voltage output for a given channel.
Parameters
channel: channel number of the ADC to set
adcValue: minimum voltage for the DAC to command (see getSensor)
actuatorValue: minimum physical value which corresponds to the minimum DAC voltage.
ogetAdc
float getAdc (unsigned int channel);
Gets the ADC voltage value for a given channel.
Parameters
channel: channel number of the ADC to get
Returns
voltage value as a floating point number.

osetAdcBipolar
vetAdcBipolar 
void setAdcBipolar (unsigned int channel, int isBipolar);
ogetAdcHex
void getAdcHex (unsigned int channel);
ogetAdcNumBits
void getAdcNumBits (unsigned int channel);
osetAdcNumBits
void setAdcNumBits (unsigned int channel, unsigned int numBits);
osetAdcReference
void setDacReference (unsigned int noChannels, float value);
osetAdcTwosComplement
void setAdcTwosComplement (unsigned int channel,
 int isTwosComplement);
osetNumAdcs
 void setNumAdcs (unsigned int noChannels);
oupdateAll "updateAll">updateAll
void updateAll();

oupdateAdc
void updateAdc (unsigned int channel);

oupdateTotal
unsigned int updateTotal (unsigned int channel);


Last modified: Mon Feb 1odified: Mon Feb 15 00:02:37 Eastern Standard Time 1999 L>