zigbee cc2530 adc转换
生活随笔
收集整理的這篇文章主要介紹了
zigbee cc2530 adc转换
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
cc2530的通用datasheet上沒怎么講到adc的一些特性,
http://download.csdn.net/detail/songqqnew/5132088
而是下面這個文檔有較多講解
www.ti.com/lit/ds/symlink/cc2530.pdf
#include "adc.h" void main(void) {while(1)adcSampleSingle (ADC_REF_AVDD,ADC_12_BIT,ADC_AIN0); }
1.源于basic代碼
2.cc2530沒有專門設置分辨率的寄存器,有一個抓取率,設置這個東東就相當于設置了分辨率和adc轉換時間,(套餐,分辨率越高,轉換時間越長)
單個測量時,分辨率最高為12位,達不到14位,
在抓取率是512時可以達到最大分辨率(同時也達到最慢的轉換速率)。
datasheeet上如此介紹
The ADC supports up to 14-bit analog-to-digital conversion with up to 12 bits ENOB (Effective Number OfBits).
最高支持14位ad轉換分辨率,但是有效位是12位??纯词悄菐孜?#xff1a;
ADCH的最高位是符號位,對于單個測量,結果總是正,所以符號位總是0。所以用到bit6--bit0,計7位
ADCL的低2位(bit0,bit1)系統保留,bit2不用,所以用到bit7--bit3,計5位。
所以共12位。
當然其他抓取率時,有效分辨率如下:
00: 64 decimation rate (7 bits ENOB)--ADCH低7位
01: 128 decimation rate (9 bits ENOB)--ADCH低7位+ADCH高2位
10: 256 decimation rate (10 bits ENOB)--ADCH低7位+ADCH高3位
11: 512 decimation rate (12 bits ENOB)--ADCH低7位+ADCL高5位
在分辨率是7位時,如果按照分辨率是12去取結果,是不太準確的。
3.參考電壓
#define ADC_REF_1_25_V ? ? ?0x00 ? ? // Internal 1.25V reference
#define ADC_REF_P0_7 ? ? ? ?0x40 ? ? // External reference on AIN7 pin
#define ADC_REF_AVDD ? ? ? ?0x80 ? ? // AVDD_SOC pin,=3.3v
#define ADC_REF_P0_6_P0_7 ? 0xC0 ? ? // External reference on AIN6-AIN7 differential input
其實如果連符號位和bit2也算上,最高分辨率是14位。
不過不如協議棧的adc轉換函數更加可信:
直接使用即可
#include "hal_adc.h"
uint16 u16cvalu=HalAdcRead(HAL_ADC_CHANNEL_4,HAL_ADC_RESOLUTION_12);
分辨率設置為12位時,從源碼可以看出,可用位是ADCH 8位+ADCH高4位,其中ADCH最高位是符號位,所以有11位的分辨率,0-2047
默認基準電壓3.3V
uint16 HalAdcRead (uint8 channel, uint8 resolution) {int16 reading = 0;#if (HAL_ADC == TRUE)uint8 i, resbits;uint8 adctemp;volatile uint8 tmp;uint8 adcChannel = 1;uint8 reference;/* store the previously set reference voltage selection */reference = ADCCON3 & HAL_ADC_REF_BITS;/** If Analog input channel is AIN0..AIN7, make sure corresponing P0 I/O pin is enabled. The code* does NOT disable the pin at the end of this function. I think it is better to leave the pin* enabled because the results will be more accurate. Because of the inherent capacitance on the* pin, it takes time for the voltage on the pin to charge up to its steady-state level. If* HalAdcRead() has to turn on the pin for every conversion, the results may show a lower voltage* than actuality because the pin did not have time to fully charge.*/if (channel < 8){for (i=0; i < channel; i++){adcChannel <<= 1;}}/* Enable channel */ADCCFG |= adcChannel;/* Convert resolution to decimation rate */switch (resolution){case HAL_ADC_RESOLUTION_8:resbits = HAL_ADC_DEC_064;break;case HAL_ADC_RESOLUTION_10:resbits = HAL_ADC_DEC_128;break;case HAL_ADC_RESOLUTION_12:resbits = HAL_ADC_DEC_256;break;case HAL_ADC_RESOLUTION_14:default:resbits = HAL_ADC_DEC_512;break;}/* read ADCL,ADCH to clear EOC */tmp = ADCL;tmp = ADCH;/* Setup Sample */adctemp = ADCCON3;adctemp &= ~(HAL_ADC_CHN_BITS | HAL_ADC_DEC_BITS | HAL_ADC_REF_BITS);adctemp |= channel | resbits | (reference);/* writing to this register starts the extra conversion */ADCCON3 = adctemp;/* Wait for the conversion to be done */while (!(ADCCON1 & HAL_ADC_EOC));/* Disable channel after done conversion */ADCCFG &= (adcChannel ^ 0xFF);/* Read the result */reading = (int16) (ADCL);reading |= (int16) (ADCH << 8);/* Treat small negative as 0 */if (reading < 0)reading = 0;switch (resolution){case HAL_ADC_RESOLUTION_8:reading >>= 8;break;case HAL_ADC_RESOLUTION_10:reading >>= 6;break;case HAL_ADC_RESOLUTION_12:reading >>= 4;break;case HAL_ADC_RESOLUTION_14:default:reading >>= 2;break;} #else// unused arguments(void) channel;(void) resolution; #endifreturn ((uint16)reading); }
http://download.csdn.net/detail/songqqnew/5132088
而是下面這個文檔有較多講解
www.ti.com/lit/ds/symlink/cc2530.pdf
#include "adc.h" void main(void) {while(1)adcSampleSingle (ADC_REF_AVDD,ADC_12_BIT,ADC_AIN0); }
1.源于basic代碼
2.cc2530沒有專門設置分辨率的寄存器,有一個抓取率,設置這個東東就相當于設置了分辨率和adc轉換時間,(套餐,分辨率越高,轉換時間越長)
單個測量時,分辨率最高為12位,達不到14位,
在抓取率是512時可以達到最大分辨率(同時也達到最慢的轉換速率)。
datasheeet上如此介紹
The ADC supports up to 14-bit analog-to-digital conversion with up to 12 bits ENOB (Effective Number OfBits).
最高支持14位ad轉換分辨率,但是有效位是12位??纯词悄菐孜?#xff1a;
ADCH的最高位是符號位,對于單個測量,結果總是正,所以符號位總是0。所以用到bit6--bit0,計7位
ADCL的低2位(bit0,bit1)系統保留,bit2不用,所以用到bit7--bit3,計5位。
所以共12位。
當然其他抓取率時,有效分辨率如下:
00: 64 decimation rate (7 bits ENOB)--ADCH低7位
01: 128 decimation rate (9 bits ENOB)--ADCH低7位+ADCH高2位
10: 256 decimation rate (10 bits ENOB)--ADCH低7位+ADCH高3位
11: 512 decimation rate (12 bits ENOB)--ADCH低7位+ADCL高5位
在分辨率是7位時,如果按照分辨率是12去取結果,是不太準確的。
3.參考電壓
#define ADC_REF_1_25_V ? ? ?0x00 ? ? // Internal 1.25V reference
#define ADC_REF_P0_7 ? ? ? ?0x40 ? ? // External reference on AIN7 pin
#define ADC_REF_AVDD ? ? ? ?0x80 ? ? // AVDD_SOC pin,=3.3v
#define ADC_REF_P0_6_P0_7 ? 0xC0 ? ? // External reference on AIN6-AIN7 differential input
其實如果連符號位和bit2也算上,最高分辨率是14位。
不過不如協議棧的adc轉換函數更加可信:
直接使用即可
#include "hal_adc.h"
uint16 u16cvalu=HalAdcRead(HAL_ADC_CHANNEL_4,HAL_ADC_RESOLUTION_12);
分辨率設置為12位時,從源碼可以看出,可用位是ADCH 8位+ADCH高4位,其中ADCH最高位是符號位,所以有11位的分辨率,0-2047
默認基準電壓3.3V
uint16 HalAdcRead (uint8 channel, uint8 resolution) {int16 reading = 0;#if (HAL_ADC == TRUE)uint8 i, resbits;uint8 adctemp;volatile uint8 tmp;uint8 adcChannel = 1;uint8 reference;/* store the previously set reference voltage selection */reference = ADCCON3 & HAL_ADC_REF_BITS;/** If Analog input channel is AIN0..AIN7, make sure corresponing P0 I/O pin is enabled. The code* does NOT disable the pin at the end of this function. I think it is better to leave the pin* enabled because the results will be more accurate. Because of the inherent capacitance on the* pin, it takes time for the voltage on the pin to charge up to its steady-state level. If* HalAdcRead() has to turn on the pin for every conversion, the results may show a lower voltage* than actuality because the pin did not have time to fully charge.*/if (channel < 8){for (i=0; i < channel; i++){adcChannel <<= 1;}}/* Enable channel */ADCCFG |= adcChannel;/* Convert resolution to decimation rate */switch (resolution){case HAL_ADC_RESOLUTION_8:resbits = HAL_ADC_DEC_064;break;case HAL_ADC_RESOLUTION_10:resbits = HAL_ADC_DEC_128;break;case HAL_ADC_RESOLUTION_12:resbits = HAL_ADC_DEC_256;break;case HAL_ADC_RESOLUTION_14:default:resbits = HAL_ADC_DEC_512;break;}/* read ADCL,ADCH to clear EOC */tmp = ADCL;tmp = ADCH;/* Setup Sample */adctemp = ADCCON3;adctemp &= ~(HAL_ADC_CHN_BITS | HAL_ADC_DEC_BITS | HAL_ADC_REF_BITS);adctemp |= channel | resbits | (reference);/* writing to this register starts the extra conversion */ADCCON3 = adctemp;/* Wait for the conversion to be done */while (!(ADCCON1 & HAL_ADC_EOC));/* Disable channel after done conversion */ADCCFG &= (adcChannel ^ 0xFF);/* Read the result */reading = (int16) (ADCL);reading |= (int16) (ADCH << 8);/* Treat small negative as 0 */if (reading < 0)reading = 0;switch (resolution){case HAL_ADC_RESOLUTION_8:reading >>= 8;break;case HAL_ADC_RESOLUTION_10:reading >>= 6;break;case HAL_ADC_RESOLUTION_12:reading >>= 4;break;case HAL_ADC_RESOLUTION_14:default:reading >>= 2;break;} #else// unused arguments(void) channel;(void) resolution; #endifreturn ((uint16)reading); }
轉載于:https://www.cnblogs.com/-song/archive/2013/03/12/3331821.html
總結
以上是生活随笔為你收集整理的zigbee cc2530 adc转换的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: js 如何获取class的元素 以及创建
- 下一篇: Android联系人Contacts详解