Wixel SDK
|
Go to the source code of this file.
Macros | |
#define | ADC_REFERENCE_INTERNAL 0b10000000 |
#define | ADC_REFERENCE_VDD 0 |
#define | ADC_BITS_7 0b00110000 |
#define | ADC_BITS_9 0b00100000 |
#define | ADC_BITS_10 0b00010000 |
#define | ADC_BITS_12 0 |
Functions | |
uint16 | adcRead (uint8 channel) |
int16 | adcReadDifferential (uint8 channel) |
uint16 | adcReadVddMillivolts () |
void | adcSetMillivoltCalibration (uint16 vddMillivolts) |
int16 | adcConvertToMillivolts (int16 adcResult) |
The adc.lib
library provides functions for using the CC2511's Analog-to-Digital Converter (ADC). The ADC can measure several different things, including voltages on any of the six Port 0 pins, the voltage on the VDD line (the 3V3 pin on the Wixel), and the temperature.
The ADC has 14 channels:
Channel Number | Name | Appropriate Function |
---|---|---|
0 | AIN0 (P0_0) | adcRead() |
1 | AIN1 (P0_1) | adcRead() |
2 | AIN2 (P0_2) | adcRead() |
3 | AIN3 (P0_3) | adcRead() |
4 | AIN4 (P0_4) | adcRead() |
5 | AIN5 (P0_5) | adcRead() |
8 | AIN0 - AIN1 | adcReadDifferential() |
9 | AIN2 - AIN3 | adcReadDifferential() |
10 | AIN4 - AIN5 | adcReadDifferential() |
11 | AIN6 - AIN7 | adcReadDifferential() |
12 | GND | |
13 | Internal 1.25 V Reference | adcRead() |
14 | Temperature Sensor | adcRead() |
15 | VDD/3 |
Most functions in this library require a channel parameter to specify which channel to use. The value of this parameter should be one of the channel numbers in the table above.
You can also use the bitwise OR operator (|) to specify advanced options in the channel parameter:
The CC2511F32 datasheet says that to configure a pin on Port 0 to be used as an analog pin, the corresponding bit in the ADCCFG register must be set to 1. However, we have not found this to be necessary, and this library does not touch ADCCFG.
If you want to follow the datasheet, then you could write to ADCCFG at the beginning of your program with some code like this:
Definition in file adc.h.
#define ADC_BITS_10 0b00010000 |
#define ADC_BITS_12 0 |
#define ADC_BITS_7 0b00110000 |
#define ADC_BITS_9 0b00100000 |
#define ADC_REFERENCE_INTERNAL 0b10000000 |
#define ADC_REFERENCE_VDD 0 |
Converts an ADC result to millivolts.
adcResult | An ADC result between -2048 and 2047 that was measured using VDD as a reference. You can obtain such a measurement by calling adcRead() or adcReadDifferential(). |
By default, this function assumes that your VDD is at 3300 mV. If you expect your VDD to go above or below that, or you want more accurate results, you should use adcSetMillivoltCalibration().
This function only applies to AD conversions where VDD was used as a reference. If you used the internal 1.25 V reference instead, you can convert your result to millivolts by multiplying it by 1250 and then dividing it by 2047.
Definition at line 17 of file millivolts.c.
Reads the voltage on the specified channel.
channel | The number of the channel to measure (0-6 or 13-15). This parameter can also contain advanced options (see above). |
Example:
This function returns an unsigned number so it is not appropriate for differential channels. See adcReadDifferential().
Reads the voltage difference on the specified differential channel.
channel | The number of the differential channel to measure (8-11). This parameter can also contain advanced options (see above). |
Example:
uint16 adcReadVddMillivolts | ( | ) |
Reads the voltage of the VDD (3V3) line using the internal voltage reference and returns the voltage of VDD in units of millivolts (mV).
Definition at line 6 of file millivolts.c.
void adcSetMillivoltCalibration | ( | uint16 | vddMillivolts | ) |
Sets the calibration parameter that is used by adcConvertToMillivolts().
vddMillivolts | The voltage of the VDD line in units of millivolts. |
If your VDD is going to drop below 3.3 V, and you want to measure a voltage in units of millivolts (as opposed to the raw ADC units) you should run the following code regularly:
Definition at line 12 of file millivolts.c.