upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Public Member Functions
ADC121C021 Class Reference

API for the ADC121C021 I2C Analog-to-Digital Converter. More...

Detailed Description

UPM module for the ADC121C021 12-bit analog-to-digital converter (ADC). By constantly providing a reference voltage, this sensor helps increase the accuracy of a value collected from an analog sensor.

adc121c021.jpg
// Instantiate an ADC121C021 on I2C bus 0
upm::ADC121C021 *adc = new upm::ADC121C021(ADC121C021_I2C_BUS,
ADC121C021_DEFAULT_I2C_ADDR);
// An analog sensor, such as a Grove light sensor,
// must be attached to the adc
// Prints the value and corresponding voltage every 50 milliseconds
while (shouldRun)
{
uint16_t val = adc->value();
cout << "ADC value: " << val << " Volts = "
<< adc->valueToVolts(val) << endl;
usleep(50000);
}

Public Member Functions

 ADC121C021 (int bus, uint8_t address=ADC121C021_DEFAULT_I2C_ADDR, float vref=ADC121C021_DEFAULT_VREF)
 
 ~ADC121C021 ()
 
mraa_result_t writeByte (uint8_t reg, uint8_t byte)
 
mraa_result_t writeWord (uint8_t reg, uint16_t word)
 
uint8_t readByte (uint8_t reg)
 
uint16_t readWord (uint8_t reg)
 
uint16_t value ()
 
float valueToVolts (uint16_t val)
 
bool getAlertStatus ()
 
bool alertLowTriggered ()
 
bool alertHighTriggered ()
 
void clearAlertStatus ()
 
void enableAlertFlag (bool enable)
 
void enableAlertPin (bool enable)
 
void enableAlertHold (bool enable)
 
void enableAlertPinPolarityHigh (bool enable)
 
void setAutomaticConversion (ADC121C021_CYCLE_TIME_T cycleTime)
 
mraa_result_t setAlertLowLimit (uint16_t limit)
 
mraa_result_t setAlertHighLimit (uint16_t limit)
 
mraa_result_t setHysteresis (uint16_t limit)
 
uint16_t getHighestConversion ()
 
uint16_t getLowestConversion ()
 
mraa_result_t clearHighestConversion ()
 
mraa_result_t clearLowestConversion ()
 

Constructor & Destructor Documentation

ADC121C021 ( int  bus,
uint8_t  address = ADC121C021_DEFAULT_I2C_ADDR,
float  vref = ADC121C021_DEFAULT_VREF 
)

ADC121C021 ADC constructor

Parameters
busI2C bus to use
addressAddress for this sensor; default is 0x55
vrefReference voltage for this sensor; default is 3.0v
~ADC121C021 ( )

ADC121C021 destructor

Member Function Documentation

mraa_result_t writeByte ( uint8_t  reg,
uint8_t  byte 
)

Writes a byte value into the register

Parameters
regRegister location to write into
byteByte to write
Returns
0 (MRAA_SUCCESS) if successful; non-zero otherwise
mraa_result_t writeWord ( uint8_t  reg,
uint16_t  word 
)

Writes a word value into the register

Parameters
regRegister location to write into
wordWord to write
Returns
0 (MRAA_SUCCESS) if successful; non-zero otherwise
uint8_t readByte ( uint8_t  reg)

Reads the byte value from the register

Parameters
regRegister location to read from
Returns
Value in the specified register
uint16_t readWord ( uint8_t  reg)

Reads the word value from the register

Parameters
regRegister location to read from
Returns
Value in the specified register
uint16_t value ( )

Reads the current value of conversion

Returns
Current value of conversion
float valueToVolts ( uint16_t  val)

Converts a supplied value to voltage based on the set vref

Parameters
valValue of conversion (from value())
Returns
Value of conversion in volts
bool getAlertStatus ( )

Reads the current status of the alert flag. If the flag is set, the low or high alert indicators are set as appropriate, and you can access these values with alertLowTriggered() or alertHighTriggered().

Returns
True if the alert flag is set
bool alertLowTriggered ( )
inline

Returns the current value of m_alertLow. You must call getAlertStatus() to update this value.

Returns
Current status of the alert low flag
bool alertHighTriggered ( )
inline

Returns the current value of m_alertHigh. You must call getAlertStatus() to update this value.

Returns
Current status of the alert high flag
void clearAlertStatus ( )

Clears the alert low and alert high flags. This also clears the last stored alert values.

void enableAlertFlag ( bool  enable)

Enables or disables the alert flag functionality. If enabled, when the measured value exceeds the low or high limits configured, the alert flag is set. Use getAlertStatus() to access these values.

Parameters
enableIf true, enables the alert flag; otherwise, disables the alert flag
void enableAlertPin ( bool  enable)

Enables or disables the alert pin functionality.

Parameters
enableIf true, enables the alert pin; otherwise, disables the alert pin
void enableAlertHold ( bool  enable)

Enables or disables the alert hold functionality. When the alert hold is enabled, the alert status remains until manually cleared via clearAlertStatus(). Otherwise, the alert self-clears when the value moves into the defined limits if alerts are enabled via enableAlertFlag().

Parameters
enableIf true, enables the alert hold; otherwise, disables the alert hold
void enableAlertPinPolarityHigh ( bool  enable)

If the alert pin is enabled, defines the active polarity of the pin in an alert condition. Enabling this sets the pin to active high in an alert condition; otherwise, active low is used.

Parameters
enableIf true, the alert pin is active high; otherwise, active low
void setAutomaticConversion ( ADC121C021_CYCLE_TIME_T  cycleTime)

Enables or disables the automatic conversion mode. When enabled, the ADC samples and updates the conversion value independently. It is disabled by default, so conversion is only done by calling value().

Parameters
cycleTimeSets the cycle time for automatic conversion
mraa_result_t setAlertLowLimit ( uint16_t  limit)

Sets the alert low limit. If alerts are enabled and the measured conversion value is lower than the low limit, an alert is triggered.

Parameters
limitAlert low limit
Returns
0 (MRAA_SUCCESS) if successful; non-zero otherwise
mraa_result_t setAlertHighLimit ( uint16_t  limit)

Sets the alert high limit. If alerts are enabled and the measured conversion value is higher than the high limit, an alert is triggered.

Parameters
limitAlert high limit
Returns
0 (MRAA_SUCCESS) if successful; non-zero otherwise
mraa_result_t setHysteresis ( uint16_t  limit)

Sets the hysteresis value. If a high or low alert condition is triggered, the conversion result must move within the high or low limit by more than this value to clear the alert condition. If the alert hold is set, the alert doesn't self-clear regardless of this value.

Parameters
limitHysteresis limit
Returns
0 (MRAA_SUCCESS) if successful; non-zero otherwise
uint16_t getHighestConversion ( )

Returns the highest conversion value recorded so far. This value is only updated by the converter when the automatic conversion mode is enabled.

Returns
Highest conversion value
uint16_t getLowestConversion ( )

Returns the lowest conversion value recorded so far. This value is only updated by the converter when the automatic conversion mode is enabled.

Returns
Lowest conversion value
mraa_result_t clearHighestConversion ( )

Clears the highest conversion value recorded so far.

Returns
0 (MRAA_SUCCESS) if successful; non-zero otherwise
mraa_result_t clearLowestConversion ( )

Clears the lowest conversion value recorded so far.

Returns
0 (MRAA_SUCCESS) if successful; non-zero otherwise

The documentation for this class was generated from the following files: