Adc

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.

Detailed Description

Sample A/D converter driver.

See adc.h for source code.

Note:
Stm32w108xx ADC driver support is preliminary and essentailly untested - please do not attempt to use this ADC driver on this platform.
Except for the Stm32w108xx, the StZNet stack does use these functions.

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.

Note:
This code does not allow access to the continuous reading mode of the ADC, which some clients may require.

Many functions in this file return an StStatus value. See error-def.h for definitions of all StStatus return values.


Enumeration Type Documentation

anonymous enum
Enumerator:
ADC_USER_LQI 

LQI User ID.

ADC_USER_APP 

Application User ID.

ADC_USER_APP2 

Application User ID.

Definition at line 39 of file adc.h.

anonymous enum
Enumerator:
ADC_REF_AREF 

AREF pin reference.

ADC_REF_AVCC 

AVCC pin reference.

ADC_REF_INT 

Internal reference.

Definition at line 57 of file adc.h.

anonymous enum
Enumerator:
ADC_CONVERSION_TIME_US_32 

Rate 32 us, 5 effective bits in ADC_DATA[15:11].

ADC_CONVERSION_TIME_US_64 

Rate 64 us, 6 effective bits in ADC_DATA[15:10].

ADC_CONVERSION_TIME_US_128 

Rate 128 us, 7 effective bits in ADC_DATA[15:9].

ADC_CONVERSION_TIME_US_256 

Rate 256 us, 8 effective bits in ADC_DATA[15:8].

ADC_CONVERSION_TIME_US_512 

Rate 512 us, 9 effective bits in ADC_DATA[15:7].

ADC_CONVERSION_TIME_US_1024 

Rate 1024 us, 10 effective bits in ADC_DATA[15:6].

ADC_CONVERSION_TIME_US_2048 

Rate 2048 us, 11 effective bits in ADC_DATA[15:5].

ADC_CONVERSION_TIME_US_4096 

Rate 4096 us, 12 effective bits in ADC_DATA[15:4].

Definition at line 69 of file adc.h.


Function Documentation

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.

Parameters:
id An ADC user.
Returns:
One of the following:
  • ST_ADC_CONVERSION_DONE if the calibration is complete.
  • ST_ERR_FATAL if the calibration failed.

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.

Parameters:
value An int16u to be converted.
Returns:
Volts as signed fixed point with units 10^-4 Volts.

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.

Parameters:
id An ADC user.
value Pointer to an int16u to be loaded with the new value.
Returns:
One of the following:
  • ST_ADC_CONVERSION_DONE if the conversion is complete.
  • ST_ADC_NO_CONVERSION_PENDING if 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.

Parameters:
id An ADC user.
value Pointer to an int16u to be loaded with the new value.
Returns:
One of the following:
  • ST_ADC_CONVERSION_DONE if the conversion is complete.
  • ST_ADC_CONVERSION_DEFERRED if the conversion is still waiting to start.
  • ST_ADC_CONVERSION_BUSY if the conversion is currently taking place.
  • ST_ADC_NO_CONVERSION_PENDING if 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)

Parameters:
id An ADC user.
reference Voltage reference to use, chosen from enum
channel Microprocessor channel number.
rate rate number (see the ADC rate enum).
Returns:
One of the following:
  • ADC_CONVERSION_DEFERRED if the conversion is still waiting to start.
  • ADC_CONVERSION_BUSY if the conversion is currently taking place.
  • ST_ERR_FATAL if a passed parameter is invalid.

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().


Generated on Mon Apr 11 14:23:57 2011 for Contiki 2.5 by  doxygen 1.6.1