ADC Control#
Sample A/D converter driver.
See adc.h for source code.
Note
The EmberZNet stack does use these functions.
To use the ADC system, include this file and ensure that halInternalInitAdc() is called whenever the microcontroller is started. Call halInternalSleepAdc() to sleep the module and halInternalInitAdc() to wake up the module.
A "user" is a separate thread of execution and usage. That is, internal Ember 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 EmberStatus value. See error-def.h for definitions of all EmberStatus return values.
Sample A/D converter driver.
Note
EM35x ADC driver support is preliminary and may be changed in a future release
Enumerations#
ADC functions employ a user ID to keep different users separate.
ADCReferenceType Enumeration. Note: EM35x only supports one reference type: Internal.
ADCRateType enumeration. These rates are specified in the number of clock cycles That a conversion takes. The actual time taken will depend on the selected ADC clock rate. (Default is 6MHz)
ADC rates for compatibility with EM2xx applications. For EM35x only applications, the ADC_SAMPLE_CLOCKS_nnn definitions should be used instead.
Typedefs#
A type for the channel enumeration.
A type for the reference voltage enumeration.
A type for the sample rate enumeration.
Functions#
Initializes and powers-up the ADC. Should also be called to wake from sleep. The ADC is required for EM250 stack operation so this function must be called from halInit.
Shuts down the voltage reference and ADC system to minimize power consumption in sleep.
Starts an ADC conversion for the user specified by id
.
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
.
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 EMBER_ADC_CONVERSION_DONE, or immediately returns EMBER_ADC_NO_CONVERSION_PENDING.
Calibrates or recalibrates the ADC system.
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).
Calibrates Vref to be 1.2V +/-10mV.
Set ADC clock mode.
Get ADC clock mode.
Measures VDD_PADS in millivolts at the specified sample rate Due to the conversions performed, this function takes slightly under 250us with a variation across successive conversions approximately +/-20mv of the average conversion.
Macros#
Be sure to update NUM_ADC_USERS if additional users are added to the ADCUser list.
Enumeration Documentation#
ADCUser#
ADCUser
ADC functions employ a user ID to keep different users separate.
Avoid many users because each user requires some amount of state storage.
See Also
Enumerator | |
---|---|
ADC_USER_LQI | LQI User ID. |
ADC_USER_APP | Application User ID |
ADC_USER_APP2 | Application User ID |
59
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc.h
@0#
@0
ADCReferenceType Enumeration. Note: EM35x only supports one reference type: Internal.
Enumerator | |
---|---|
PRIORITIZE_BEACONS_BASED_ON_PARENT_CLASSIFICATION | |
PRIORITIZE_BEACONS_BASED_ON_TC_CONNECTVITY | |
TC_CONNECTIVITY | |
LONG_UPTIME | |
BAD_PARENT_CONNECTIVITY | |
EMBER_OUTGOING_MESSAGES | There are messages waiting for transmission. |
EMBER_INCOMING_MESSAGES | One or more incoming messages being processed. |
EMBER_RADIO_IS_ON | The radio is currently powered on. On sleepy devices, the radio is turned off when not in use. On non-sleepy devices (EMBER_COORDINATOR, EMBER_ROUTER, or EMBER_END_DEVICE), the radio is always on. |
EMBER_TRANSPORT_ACTIVE | The transport layer has messages awaiting an ACK. |
EMBER_APS_LAYER_ACTIVE | The ZigBee APS layer has messages awaiting an ACK. |
EMBER_ASSOCIATING | The node is currently trying to associate with a ZigBee PRO network. |
EMBER_ZLL_TOUCH_LINKING | The node is currently touch linking. |
EMBER_NETWORK_TIMEOUT_REQUEST | Network Timeout Request Event. |
EMBER_SEND_ORPHAN_NOTIFICATION | Sending Orphan Notification Event. |
EMBER_MAC_DATA_POLL_SUPER_RETRY | MAC Data Poll Super Retry Event . |
INITIAL | |
SCAN_FOR_TOUCH_LINK | |
SCAN_FOR_DEVICE_INFORMATION | |
SCAN_FOR_IDENTIFY | |
SCAN_FOR_RESET | |
TARGET_NETWORK_FOUND | |
ABORTING_TOUCH_LINK | |
SCAN_COMPLETE | |
TOUCH_LINK_TARGET | |
FORMING_NETWORK | |
RESETTING_TO_FACTORY_NEW | |
ADC_REF_INT | Internal reference. |
TOKEN_COUNT | |
COMM_SERIAL | |
COMM_RADIO |
40
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc-cortexm3.h
@1#
@1
ADCRateType enumeration. These rates are specified in the number of clock cycles That a conversion takes. The actual time taken will depend on the selected ADC clock rate. (Default is 6MHz)
Enumerator | |
---|---|
EMBER_POLL_TIMEOUT_10_SECONDS | |
EMBER_POLL_TIMEOUT_2_MINUTES | |
EMBER_POLL_TIMEOUT_4_MINUTES | |
EMBER_POLL_TIMEOUT_8_MINUTES | |
EMBER_POLL_TIMEOUT_16_MINUTES | |
EMBER_POLL_TIMEOUT_32_MINUTES | |
EMBER_POLL_TIMEOUT_64_MINUTES | |
EMBER_POLL_TIMEOUT_128_MINUTES | |
EMBER_POLL_TIMEOUT_256_MINUTES | |
EMBER_POLL_TIMEOUT_512_MINUTES | |
EMBER_POLL_TIMEOUT_1024_MINUTES | |
EMBER_POLL_TIMEOUT_2048_MINUTES | |
EMBER_POLL_TIMEOUT_4096_MINUTES | |
EMBER_POLL_TIMEOUT_8192_MINUTES | |
EMBER_POLL_TIMEOUT_16384_MINUTES | |
EMBER_RADIO_POWER_MODE_RX_ON | |
EMBER_RADIO_POWER_MODE_OFF | |
ADC_SAMPLE_CLOCKS_32 | Rate 32 cycles, 5 effective bits in ADC_DATA[15:11] |
ADC_SAMPLE_CLOCKS_64 | Rate 64 cycles, 6 effective bits in ADC_DATA[15:10] |
ADC_SAMPLE_CLOCKS_128 | Rate 128 cycles, 7 effective bits in ADC_DATA[15:9] |
ADC_SAMPLE_CLOCKS_256 | Rate 256 cycles, 8 effective bits in ADC_DATA[15:8] |
ADC_SAMPLE_CLOCKS_512 | Rate 512 cycles, 9 effective bits in ADC_DATA[15:7] |
ADC_SAMPLE_CLOCKS_1024 | Rate 1024 cycles, 10 effective bits in ADC_DATA[15:6] |
ADC_SAMPLE_CLOCKS_2048 | Rate 2048 cycles, 11 effective bits in ADC_DATA[15:5] |
ADC_SAMPLE_CLOCKS_4096 | Rate 4096 cycles, 12 effective bits in ADC_DATA[15:4] |
50
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc-cortexm3.h
@2#
@2
ADC rates for compatibility with EM2xx applications. For EM35x only applications, the ADC_SAMPLE_CLOCKS_nnn definitions should be used instead.
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] |
79
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc-cortexm3.h
@3#
@3
Enumerator | |
---|---|
ADC_SOURCE_ADC0_VREF2 | |
ADC_SOURCE_ADC0_GND | |
ADC_SOURCE_ADC1_VREF2 | |
ADC_SOURCE_ADC1_GND | |
ADC_SOURCE_ADC2_VREF2 | |
ADC_SOURCE_ADC2_GND | |
ADC_SOURCE_ADC3_VREF2 | |
ADC_SOURCE_ADC3_GND | |
ADC_SOURCE_ADC4_VREF2 | |
ADC_SOURCE_ADC4_GND | |
ADC_SOURCE_ADC5_VREF2 | |
ADC_SOURCE_ADC5_GND | |
ADC_SOURCE_ADC1_ADC0 | |
ADC_SOURCE_ADC0_ADC1 | |
ADC_SOURCE_ADC3_ADC2 | |
ADC_SOURCE_ADC2_ADC3 | |
ADC_SOURCE_ADC5_ADC4 | |
ADC_SOURCE_GND_VREF2 | |
ADC_SOURCE_VGND | |
ADC_SOURCE_VREF_VREF2 | |
ADC_SOURCE_VREF | |
ADC_SOURCE_VREG2_VREF2 | |
ADC_SOURCE_VDD_GND |
141
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc-cortexm3.h
Typedef Documentation#
ADCChannelType#
typedef uint8_t ADCChannelType
A type for the channel enumeration.
83
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc.h
ADCReferenceType#
typedef uint8_t ADCReferenceType
A type for the reference voltage enumeration.
87
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc.h
ADCRateType#
typedef uint8_t ADCRateType
A type for the sample rate enumeration.
91
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc.h
Function Documentation#
halInternalInitAdc#
void halInternalInitAdc (void )
Initializes and powers-up the ADC. Should also be called to wake from sleep. The ADC is required for EM250 stack operation so this function must be called from halInit.
N/A |
103
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc.h
halInternalSleepAdc#
void halInternalSleepAdc (void )
Shuts down the voltage reference and ADC system to minimize power consumption in sleep.
N/A |
108
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc.h
halStartAdcConversion#
EmberStatus halStartAdcConversion (ADCUser id, ADCReferenceType reference, ADCChannelType channel, ADCRateType rate)
Starts an ADC conversion for the user specified by id
.
N/A | id | An ADC user. |
N/A | reference | Voltage reference to use, chosen from enum ADCReferenceType (fixed at ADC_REF_INT for the EM250). |
N/A | channel | Microprocessor channel number. For EM250 channels, see the EM250 ADC channels enum. For basic, single-ended Atmel channels, see the Atmega single-ended ADC channels enum. For more complex measurements on Atmels (differential and amped channel numbers), see the Atmel datasheet for your micro. |
N/A | rate | EM250 rate number (see the ADC EM250 rate enum). |
@appusage The application must set reference
to the voltage reference desired (see the ADC references enum, fixed at ADC_REF_INT for the em250), 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, fixed at ADC_CONVERSION_TIME_US_256 for the Atmega).
Returns
One of the following:
EMBER_ADC_CONVERSION_DEFERRED if the conversion is still waiting to start.
EMBER_ADC_CONVERSION_BUSY if the conversion is currently taking place.
EMBER_ERR_FATAL if a passed parameter is invalid.
139
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc.h
halRequestAdcData#
EmberStatus halRequestAdcData (ADCUser id, uint16_t * 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
.
N/A | id | An ADC user. |
N/A | value | Pointer to an uint16_t to be loaded with the new value. Take note that the Atmel's ADC only generates 8-bit values which are loaded into the lower 8 bits of |
Returns
One of the following:
EMBER_ADC_CONVERSION_DONE if the conversion is complete.
EMBER_ADC_CONVERSION_DEFERRED if the conversion is still waiting to start.
EMBER_ADC_CONVERSION_BUSY if the conversion is currently taking place.
EMBER_ADC_NO_CONVERSION_PENDING if
id
does not have a pending conversion.
164
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc.h
halReadAdcBlocking#
EmberStatus halReadAdcBlocking (ADCUser id, uint16_t * 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 EMBER_ADC_CONVERSION_DONE, or immediately returns EMBER_ADC_NO_CONVERSION_PENDING.
N/A | id | An ADC user. |
N/A | value | Pointer to an uint16_t to be loaded with the new value. Take note that the Atmel's ADC only generates 8-bit values which are loaded into the lower 8 bits of |
Returns
One of the following:
EMBER_ADC_CONVERSION_DONE if the conversion is complete.
EMBER_ADC_NO_CONVERSION_PENDING if
id
does not have a pending conversion.
183
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc.h
halAdcCalibrate#
EmberStatus halAdcCalibrate (ADCUser id)
Calibrates or recalibrates the ADC system.
N/A | id | An ADC user. |
@appusage Use this function to (re)calibrate as needed. This function is intended for the EM250 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.
Returns
One of the following:
EMBER_ADC_CONVERSION_DONE if the calibration is complete.
EMBER_ERR_FATAL if the calibration failed.
201
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc.h
halConvertValueToVolts#
int32_t halConvertValueToVolts (uint16_t 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).
N/A | value | An uint16_t to be converted. |
@appusage Use this function to get a human useful value.
Returns
Volts as signed fixed point with units 10^-4 Volts.
214
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc.h
emberCalibrateVref#
void emberCalibrateVref (void )
Calibrates Vref to be 1.2V +/-10mV.
N/A |
@appusage 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.
224
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc.h
halAdcSetClock#
void halAdcSetClock (bool slow)
Set ADC clock mode.
N/A | slow | A bool to select slow or normal clock. |
230
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc.h
halAdcGetClock#
bool halAdcGetClock (void )
Get ADC clock mode.
N/A |
Returns
A true if the slow clock is selected.
236
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc.h
halMeasureVdd#
uint16_t halMeasureVdd (ADCRateType rate)
Measures VDD_PADS in millivolts at the specified sample rate Due to the conversions performed, this function takes slightly under 250us with a variation across successive conversions approximately +/-20mv of the average conversion.
N/A | rate |
Returns
A measurement of VDD_PADS in millivolts.
188
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc-cortexm3.h
Macro Definition Documentation#
NUM_ADC_USERS#
#define NUM_ADC_USERSValue:
3U
Be sure to update NUM_ADC_USERS if additional users are added to the ADCUser list.
79
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc.h
ADC_MUXN_BITS#
#define ADC_MUXN_BITSValue:
(4)
106
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc-cortexm3.h
ADC_MUX_ADC0#
#define ADC_MUX_ADC0Value:
0x0
Channel 0 : ADC0 on PB5
110
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc-cortexm3.h
ADC_MUX_ADC1#
#define ADC_MUX_ADC1Value:
0x1
Channel 1 : ADC0 on PB6
113
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc-cortexm3.h
ADC_MUX_ADC2#
#define ADC_MUX_ADC2Value:
0x2
Channel 2 : ADC0 on PB7
116
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc-cortexm3.h
ADC_MUX_ADC3#
#define ADC_MUX_ADC3Value:
0x3
Channel 3 : ADC0 on PC1
119
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc-cortexm3.h
ADC_MUX_ADC4#
#define ADC_MUX_ADC4Value:
0x4
Channel 4 : ADC0 on PA4
122
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc-cortexm3.h
ADC_MUX_ADC5#
#define ADC_MUX_ADC5Value:
0x5
Channel 5 : ADC0 on PA5
125
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc-cortexm3.h
ADC_MUX_GND#
#define ADC_MUX_GNDValue:
0x8
Channel 8 : VSS (0V) - not for high voltage range
128
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc-cortexm3.h
ADC_MUX_VREF2#
#define ADC_MUX_VREF2Value:
0x9
Channel 9 : VREF/2 (0.6V)
131
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc-cortexm3.h
ADC_MUX_VREF#
#define ADC_MUX_VREFValue:
0xA
Channel A : VREF (1.2V)
134
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc-cortexm3.h
ADC_MUX_VREG2#
#define ADC_MUX_VREG2Value:
0xB
Channel B : Regulator/2 (0.9V) - not for high voltage range
137
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/plugin/adc/adc-cortexm3.h