Sample A/D converter driver. More...
Defines | |
#define | NUM_ADC_USERS 3 |
Be sure to update NUM_ADC_USERS if additional users are added to the ADCUser list. | |
Typedefs | |
typedef int8u | ADCChannelType |
A type for the channel enumeration (such as ADC_SOURCE_ADC0_GND). | |
Enumerations | |
enum | { ADC_USER_LQI = 0, ADC_USER_APP = 1, ADC_USER_APP2 = 2 } |
enum | { ADC_REF_AREF = 0x00, ADC_REF_AVCC = 0x40, ADC_REF_INT = 0xC0 } |
enum | { ADC_CONVERSION_TIME_US_32 = 0x0, ADC_CONVERSION_TIME_US_64 = 0x1, ADC_CONVERSION_TIME_US_128 = 0x2, ADC_CONVERSION_TIME_US_256 = 0x3, ADC_CONVERSION_TIME_US_512 = 0x4, ADC_CONVERSION_TIME_US_1024 = 0x5, ADC_CONVERSION_TIME_US_2048 = 0x6, ADC_CONVERSION_TIME_US_4096 = 0x7 } |
Functions | |
void | halInternalInitAdc (void) |
Initializes and powers-up the ADC. | |
StStatus | halStartAdcConversion (ADCUser id, ADCReferenceType reference, ADCChannelType channel, ADCRateType rate) |
Starts an ADC conversion for the user specified by id . | |
StStatus | halRequestAdcData (ADCUser id, int16u *value) |
Returns the status of a pending conversion previously started by halStartAdcConversion(). | |
StStatus | halReadAdcBlocking (ADCUser id, int16u *value) |
Waits for the user's request to complete and then, if a conversion was done, writes the raw register value of the conversion (the unaltered value taken directly from the ADC's data register) into value and returns ADC_CONVERSION_DONE, or immediately returns ADC_NO_CONVERSION_PENDING. | |
StStatus | halAdcCalibrate (ADCUser id) |
Calibrates or recalibrates the ADC system. | |
int16s | halConvertValueToVolts (int16u value) |
Convert the raw register value (the unaltered value taken directly from the ADC's data register) into a signed fixed point value with units 10^-4 Volts. | |
void | stCalibrateVref (void) |
Calibrates Vref to be 1.2V +/-10mV. |
Sample A/D converter driver.
See adc.h for source code.
To use the ADC system, include this file and ensure that halInternalInitAdc() is called whenever the microcontroller is started.
A "user" is a separate thread of execution and usage. That is, internal St code is one user and clients are a different user. But a client that is calling the ADC in two different functions constitutes only one user, as long as the ADC access is not interleaved.
Many functions in this file return an StStatus value. See error-def.h for definitions of all StStatus return values.
anonymous enum |
anonymous enum |
anonymous enum |
StStatus halAdcCalibrate | ( | ADCUser | id | ) |
Calibrates or recalibrates the ADC system.
Use this function to (re)calibrate as needed. This function is intended for the microcontroller, which requires proper calibration to calculate a human readible value (a value in volts). If the app does not call this function, the first time (and only the first time) the function halConvertValueToVolts() is called, this function is invoked. To maintain accurate volt calculations, the application should call this whenever it expects the temperature of the micro to change.
id | An ADC user. |
Definition at line 235 of file adc.c.
References ADC_CONVERSION_TIME_US_4096, ADC_REF_INT, FALSE, halReadAdcBlocking(), halStartAdcConversion(), and TRUE.
Referenced by halConvertValueToVolts().
int16s halConvertValueToVolts | ( | int16u | value | ) |
Convert the raw register value (the unaltered value taken directly from the ADC's data register) into a signed fixed point value with units 10^-4 Volts.
The returned value will be in the range -12000 to +12000 (-1.2000 volts to +1.2000 volts).
Use this function to get a human useful value.
value | An int16u to be converted. |
Definition at line 300 of file adc.c.
References ADC_USER_LQI, and halAdcCalibrate().
Referenced by temperatureSensor_GetValue().
StStatus halReadAdcBlocking | ( | ADCUser | id, | |
int16u * | value | |||
) |
Waits for the user's request to complete and then, if a conversion was done, writes the raw register value of the conversion (the unaltered value taken directly from the ADC's data register) into value
and returns ADC_CONVERSION_DONE, or immediately returns ADC_NO_CONVERSION_PENDING.
id | An ADC user. | |
value | Pointer to an int16u to be loaded with the new value. |
id
does not have a pending conversion. Definition at line 223 of file adc.c.
References halRequestAdcData().
Referenced by halAdcCalibrate(), and temperatureSensor_GetValue().
StStatus halRequestAdcData | ( | ADCUser | id, | |
int16u * | value | |||
) |
Returns the status of a pending conversion previously started by halStartAdcConversion().
If the conversion is complete, writes the raw register value of the conversion (the unaltered value taken directly from the ADC's data register) into value
.
id | An ADC user. | |
value | Pointer to an int16u to be loaded with the new value. |
id
does not have a pending conversion. Definition at line 189 of file adc.c.
References ATOMIC, BIT, and INTERRUPTS_ARE_OFF.
Referenced by halReadAdcBlocking().
StStatus halStartAdcConversion | ( | ADCUser | id, | |
ADCReferenceType | reference, | |||
ADCChannelType | channel, | |||
ADCRateType | rate | |||
) |
Starts an ADC conversion for the user specified by id
.
The application must set reference
to the voltage reference desired (see the ADC references enum), set channel
to the channel number required (see the ADC channel enum), and set rate
to reflect the number of bits of accuracy desired (see the ADC rates enum)
id | An ADC user. | |
reference | Voltage reference to use, chosen from enum | |
channel | Microprocessor channel number. | |
rate | rate number (see the ADC rate enum). |
Definition at line 158 of file adc.c.
References ADC_REF_INT, ATOMIC, and BIT.
Referenced by halAdcCalibrate(), and temperatureSensor_GetValue().
void stCalibrateVref | ( | void | ) |
Calibrates Vref to be 1.2V +/-10mV.
This function must be called from halInternalInitAdc() before making ADC readings. This function is not intended to be called from any function other than halInternalInitAdc(). This function ensures that the master cell voltage and current bias values are calibrated before calibrating Vref.
Definition at line 44 of file micro-common-internal.c.
References FALSE.
Referenced by halInternalInitAdc().