我是靠谱客的博主 跳跃唇膏,最近开发中收集的这篇文章主要介绍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位。看看是那几位:
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;
#endif

  return ((uint16)reading);
}


转载于:https://www.cnblogs.com/-song/archive/2013/03/12/3331821.html

最后

以上就是跳跃唇膏为你收集整理的zigbee cc2530 adc转换的全部内容,希望文章能够帮你解决zigbee cc2530 adc转换所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(42)

评论列表共有 0 条评论

立即
投稿
返回
顶部