1. Introduction of ADC
The ADC supports up to 14-bit analog-to-digital conversions with up to 12 digits of significant digits. It includes an analog multiplexer with up to 8 individually configurable channels and a reference voltage generator. The conversion results are written to the memory via DMA. It also has several operating modes.
The main features of the ADC are as follows:
Optional decimation rate, which also sets the resolution (7 to 12 bits)
8 independent input channels to accept single-ended or differential signals
Reference voltage selectable as internal single-ended, external single-ended, external differential, or AVDD5
Generate Interrupt Request
DMA trigger at end of conversion
Temperature sensor input
Battery measurement function
2. ADC operation
This section describes the general installation and operation of the ADC, and describes the ADC control of the CPU access and the use of the status register.
2.1. ADC Input
The signals on the Port 0 pins can be used as ADC inputs. In the following, these port pins is referred to as the ain0–ain7 pins. The input pins ain0–ain7 is connected to the ADC.
The inputs can be configured as single-ended or differential inputs. In the case of differential input selection, the differential input includes input to Ain0-1, ain2-3, ain4-5, and ain6-7. The voltage cannot be negative or greater than VDD. The difference between these input pairs is that they use different modes for conversion.
In addition to the input pin ain0-ain7, the on -chip temperature sensor output can optionally be used as an input to the ADC for temperature measurement. For this register TR0.ADCTM and Atest.atestctrl must be described in section 2.10 and register respectively as described in the settings.
You can also enter a voltage corresponding to the AVDD5/3 as an ADC input . This input allows for functions such as the need to implement a battery monitor in the application. Note In this case the reference voltage cannot be dependent on the supply voltage, such as the AVDD5 voltage cannot be used as a reference voltage.
The single-ended voltage input AIN0 to AIN7 is indicated by the channel number 0 to 7 . Channel numbers 8 through 11 represent differential inputs, consisting of ain0–ain1, ain2–ain3, Ain4–ain5, and ain6–ain7. The channel numbers 12 through 15 represent the G-N D (12) temperature sensor (14), and the AVDD5/3 (15). These values are used in the Adccon2.sch and Adccon3.sch domains.
2.2. ADC conversion sequence (temporarily difficult to understand)
The ADC performs a series of transformations and moves the results to memory (via DMA) without any CPU intervention.
The conversion sequence can be affected by the apcfg Register, and the eight-bit analog inputs come from the I/O pins without having to be programmed into analog inputs. If a channel should normally be part of a sequence, but the corresponding analog input is disabled in apcfg, then the channel will be skipped. When using differential input, two pins in a differential pair must be set to the analog input pin in the APCFG register.
The ADCCON2. SCH (used to define the conversion sequence) register bits is used to define a ADC conversion sequence from the ADC inputs.
If ADCCON2. SCH is set to a value less than 8, the conversion sequence contains a conversion from each channel from 0 up to and includ ing the channel number programmed in Adccon2.sch.(when the register value is set to less than 8 o'clock, the conversion sequence is defined as a value from channel 0 to SCH, including the value)
When ADCCON2. SCH is set to a value between 8 and, the sequence consists of differential inputs, starting at Channel 8 and ending at The programmed channel. (between 8~12, for powder input, channel from 8 to defined value)
For ADCCON2. SCH greater than or equal to a, the sequence consists of the selected channel only. (if greater than 12, define which is which)
Ps:the Channel define in the last of 2.1
2.3, single ADC Conversion (individual ADC conversion, 2.2 is to set an ADC sequence for conversion)
In addition to this sequence of conversions, the ADC can is programmed to perform a single conversion from any channel (ADC can be configured to perform a single-channel conversion from any channel). Such A conversion is triggered by writing to the ADCCON3 register. (conditions for conversion start) The conversion starts immediately unless a conversion sequence is already ongoing, in which case the A-conversion is Performed as soon as, sequence is finished.
2.4. ADC Operating Modes
This section describes: Operating modes and initialization of conversions.
The ADC has three control registers: ADCCON1, ADCCON2, and ADCCON3. These registers is used to configure the ADC and to report status.
- ADCCON1. The EOC bit is a status bit that is set to high when a transition is finished, and is cleared when the ADCH is read.
- ADCCON1. The ST bit is used to start a conversion sequence. When this bit is set to high level, ADCCON1. Stsel is 11, and a sequence is started when no conversion is currently running. When the sequence conversion is complete, the bit is automatically cleared.
- ADCCON1. The Stsel bit selects which event will start a new conversion sequence. This option can be selected for the external pin P2.0 rising edge or external pin event, before the end event of the sequence, the channel 0 comparison event of the timer 1, or the Adccon1.st is 1.
- The ADCCON2 register controls how the conversion sequence is performed.
- ADCCON2. The sref is used to select the reference voltage. The reference voltage can only be modified when no conversion is running.
- ADCCON2. The SDIV bit selects the decimation rate (and therefore also sets the resolution and time required to complete a conversion, or sample rate). The decimation rate can only be modified when no conversion is running.
- The last channel of the conversion sequence is selected by the Adccon2.sch bit, as described above.
- The ADCCON3 register controls the channel number, reference voltage, and decimation rate for a single conversion. A single conversion occurs immediately after the register ADCCON3 is written, or immediately after the end of the sequence if a conversion sequence is in progress. The encoding and ADCCON2 of this register bit are exactly the same.
2.5. ADC Conversion Results
The number conversion results are expressed in 2 complement form. For a single-ended configuration, the result is always positive. This is because the result is the difference between the input signal and the ground, and it is always a positive symbol number (Vconv=vinp-vinn, where vinn=0v). The maximum value is reached when the input amplitude equals the selected voltage reference Vref.
For differential configurations, the difference between the two pin pairs is converted, which can be a negative symbol number. For a 12-bit MSB with a numeric conversion result of 512, the numeric conversion result is 2047 when the analog input Vconv equals Vref. When the analog input equals
When-vref, the number conversion result is-2048.
When ADCCON1.EOC is set to 1 o'clock, the numeric conversion results are available and the results are placed in ADCH and ADCL. Note that the conversion results always reside in the MSB segment of the ADCH and ADCL register combinations.
When the Adccon2.sch bits are read, they indicate which channel the conversion is on. The results in ADCL and ADCH generally apply to previous transformations. If the conversion sequence has ended, ADCCON2. The value of SCH is greater than the last channel number, but if the channel number that was last written to Adccon2.sch is 12 or greater, the same value will be read back.
2.6. ADC Reference Voltage
The positive reference voltage of the analog-to-digital conversion can be selected as an internally generated voltage, the AVDD5 pin, for the external voltage of the AIN7 input pin, or the differential voltage for the ain6-ain7 input pin.
The accuracy of the conversion results depends on the stability of the reference voltage and the noise properties. The desired voltage bias causes the ADC gain error to be proportional to the desired voltage and the actual voltage ratio. The noise of the reference voltage must be less than the quantization noise of the ADC to ensure that the specified Snr is reached.
2.7. ADC Conversion Time
The ADC can only run on a xosc, and the user cannot divide the system clock. The frequency of 4 MHz sampled by the actual ADC is generated by a fixed internal partition. The time required to perform a conversion depends on the selected decimation rate. In general, the conversion time is given by the following formula:
Tconv = (decimation rate + +) x 0.25μs.
2.8. ADC Interrupt
When a single conversion triggered by the write ADCCON3 is complete, the ADC generates an interrupt. When a sequence conversion is completed, no interrupt is generated.
2.9, ADC DMA trigger (and ADC interrupt a kind of complementary feeling ~)
For each sequence conversion, the ADC generates a DMA trigger. When a single conversion is completed, no DMA triggers are generated.
There is one DMA trigger for each of the eight channels defined by the first eight possible settings for ADCCON2. SCH. When a new sample is ready to be converted in the channel, the DMA trigger is active. The DMA triggers is named ADC_CHSD in following Table, where S was single-ended channel and D is differential channel.
In addition, one DMA trigger, Adc_chall, was active when new data was ready from any of the channels in the ADC conversion s Equence.
3. Engineering Analysis
From the following main function can be seen, the entire process is first initialized serial transceiver (this and the previous section introduced the same serial transceiver, please refer to the previous section); then initialize the ADC to select the output of the on-chip temperature sensor as the input of the ADC for temperature measurement In the while cycle is continuously read 64 times the temperature data and averaging (the code to find the average method is a bit strange), finally through the serial port will be collected on-chip temperature sensor data output.
1 voidMainvoid) 2 { 3 Chari;4 floatavgtemp; 5 Charstrtemp[6];6 7Inituart ();//Initialize the serial port8Initsensor ();//Initializing the ADC9 Ten while(1) One { AAvgtemp =gettemperature (); - - for(i=0; i< the; i++) the { -Avgtemp + =gettemperature (); -Avgtemp = avgtemp/2;//after each accumulation, save 2 - } + -memset (strtemp,0,6); +sprintf (strtemp,"%.02f", avgtemp);//Convert floating-point numbers to strings AUartsendstring (strtemp,5);//send computer to display the chip temperature via serial port atDelayms ( +);//Delay - } -}
where initsensor () is the initialization of the ADC:
Line 3rd #define DISABLE_ALL_INTERRUPTS () (IEN0 = IEN1 = IEN2 = 0x00) is to turn off all interrupts;
The 4th behavior sets the system main clock to 32M, the previous section of the main function of the first work;
1 voidInitsensor (void)2 { 3Disable_all_interrupts ();//turn off all interrupts4Initclock ();//set the system master clock to 32M5tr0=0x01;//set as a connection temperature sensor to SOC_ADC6atest=0x01;//Enable temperature Sensing7}
Line 5th Tr0=1 Connect to SOC_ADC for setting the temperature sensor:
Line 6th atest=1 for the Enable temperature sensor:
Where the gettemperature () function is used to obtain the value of the TEMP sensor ad:
1 /****************************************************************************2 * Name: Gettemperature ()3 * Function: Get the TEMP sensor AD value4 * Entry parameters: None5 * Export parameter: Returns the actual temperature value by calculation6 ****************************************************************************/7 floatGettemperature (void)8 { 9 UINTvalue;Ten OneADCCON3 = (0x3e);//Select 1.25V for reference voltage, 14-bit resolution, sample on-chip temperature sensor AADCCON1 |=0x30;//Select the ADC's start mode to manual -ADCCON1 |=0x40;//Start AD Conversion - while(! (ADCCON1 &0x80));//wait for AD conversion to complete theValue = ADCL >>4;//ADCL Register low 2 bit invalid, because he only 12 bit valid, ADCL register low 4 bit invalid. There's a lot of code on the network that's right two-bit, that's wrong. -Value |= ((UINT) ADCH) <<4); - - return(value-1367.5)/4.5-5;//according to the AD value, calculate the actual temperature, chip manual error, temperature coefficient should be 4.5/℃ + //for temperature correction, subtract 5 ℃ (different chips are corrected according to the specific situation) -}
Wherein the ADCCON3 is set to 0x3e, that is, the selection of an inline reference voltage, 512 sampling rate (12 digits of significant digits), on-chip temperature sensor single channel sampling!
where ADCCON1 |= 0x30 is the start select. Selects the event that starts a new conversion sequence (ADC start mode is manual)
where ADCCON1 |= 0x40 is the start a conversion sequence if ADCCON1. Stsel = one and no sequence is running (start ADC conversion)
where while (! ( ADCCON1 & 0x80)) wait for one conversion to complete
Line 15th, 16: The value of the 12-bit valid data that obtains the ADC sample is saved in value
value = ADCL >> 4; ADCL Register low 2 bit invalid, because he only 12 bit valid, ADCL register low 4 bit invalid. A lot of code on the network here is the right shift two bit, that is not the value |= ((UINT) ADCH) << 4);
But the value is only the ADC value, not the temperature value, need to convert, the code 18, 19 lines is to complete the conversion: (As for how to calculate I guess there should be a formula corresponding!) )
return (value-1367.5)/4.5-5; According to the AD value, calculate the actual temperature, the chip manual error, the temperature coefficient should be 4.5/℃19 //temperature correction, here minus 5 ℃ (different chip according to the specific situation correction)
4. Experimental phenomena
The program is burned into the CC2530, using USB to connect the development Board and PC, you can use the Serial assistant to observe the temperature data from ZigBee, when touching the chip by hand, the temperature will change significantly:
ZigBee Series Articles:
[ZigBee] 1, ZigBee introduction
[ZigBee] 2, ZigBee development environment construction
[ZigBee] 3, ZigBee basic experiment--gpio Output control experiment-control LED light off
[ZigBee] 4, ZigBee basic experiment--interrupt
[ZigBee] 5, ZigBee basic Experiment--graphics and code detailed timer 1 (16-bit timer) (long text)
[ZigBee] 6, ZigBee basic Experiment--timer 3 and Timer 4 (8-bit timer)
[ZigBee] 7, ZigBee analysis of the UART (only serial transmission)
[ZigBee] 8, ZigBee of the UART analysis • Two (serial transceiver)
PS: If you feel good, click a praise, let more people benefit ~
@beautifulzzzz 2016-07-16 continue~
e-mail:[email protected]
Sina:http://weibo.com/beautifulzzzz?is_all=1
[ZigBee] 9, ZigBee AD Analysis--ad collection CC2530 temperature serial display