我是靠谱客的博主 贪玩冰棍,最近开发中收集的这篇文章主要介绍ZigBee_ADC数据位,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

ADC通道( channel)与引脚是一一对应的关系,即每个ADC通道都有固定的与之对应的引脚。
有内部通道和外部通道之分。

模拟传感器:
value = ADCL >> 2 ; //将采集到低6位赋值到7~2中(5-0),ADCH(13-6)
value |= ((uint16) ADCH) << 6 ; //得到整个寄存器的值,最高位是符号位
value <<= 1; //湮没符号位
value >>= 3; //将所得数值送到低八位,准备转
这里写图片描述

//CC253x采集电池电压(内部通道VDD/3):  
#if defined (HAL_MCU_CC2430) || defined (HAL_MCU_CC2530)

  uint16 value;

  /* Clear ADC interrupt flag */
  ADCIF = 0;

  ADCCON3 = (HAL_ADC_REF_125V | HAL_ADC_DEC_128 | HAL_ADC_CHN_VDD3);

  /* Wait for the conversion to finish */
  while ( !ADCIF );

  /* Get the result */
  value = ADCL;
  value |= ((uint16) ADCH) << 8;

  /*
   * value now contains measurement of Vdd/3
   * 0 indicates 0V and 32767 indicates 1.25V
   * voltage = (value*3*1.25)/32767 volts
   * we will multiply by this by 10 to allow units of 0.1 volts
   */

  value = value >> 6;   // divide first by 2^6
  value = (uint16)(value * 37.5);
  value = value >> 9;   // ...and later by 2^9...to prevent overflow during multiplication

  return value;

#endif    // CC2430 or CC2530
//MSP430采集电池电压:
#if defined HAL_MCU_MSP430

  uint16 value;

/*
  There are more than MSP430 board now. Idealy, ADC read should be called
*/
#if defined (HAL_BOARD_F5438)

  value = HalAdcRead (HAL_ADC_CHANNEL_VDD, HAL_ADC_RESOLUTION_14);
  value = value * 50;
  value = value / 4096;                                            //这种做法与CC3200类似            

#else

  ADC12CTL0 = ADC12ON+SHT0_2+REFON;             // Turn on and set up ADC12
  ADC12CTL1 = SHP;                              // Use sampling timer
  ADC12MCTL0 = SREF_1+INCH_11;                  // Vr+=Vref+

  ADC12CTL0 |= ENC | ADC12SC;                   // Start conversion
  while ((ADC12IFG & BIT0)==0);

  value = ADC12MEM0;

  /*
   * value now contains measurement of AVcc/2
   * value is in range 0 to 4095 indicating voltage from 0 to 1.5V
   * voltage = (value*2*1.5)/4095 volts
   * we will multiply by this by 10 to allow units of 0.1 volts
   */

  value = value >> 1;     // value is now in range of 0 to 2048
  value = value * 30;
  value = value >> 11;

#endif

  return ( value );

#endif // MSP430
//AVR采集电池电压:
#if defined HAL_MCU_AVR

  // If platform doesnt support a battery sensor, just return random value

  uint8 value;
  value = 20 + ( osal_rand() & 0x000F );                  //调用函数直接读取寄存器,与51单片机类似        
  return ( value );

#endif  // AVR
//CC253x采集温度(内部通道TEMP):  
#if defined (HAL_MCU_CC2430) || defined (HAL_MCU_CC2530)

  uint16 value;

  /* Clear ADC interrupt flag */
  ADCIF = 0;

  ADCCON3 = (HAL_ADC_REF_125V | HAL_ADC_DEC_512 | HAL_ADC_CHN_TEMP);

  /* Wait for the conversion to finish */
  while ( !ADCIF );

  /* Get the result */
  value = ADCL;
  value |= ((uint16) ADCH) << 8;

  /*
   * value ranges from 0 to 0x8000 indicating 0V and 1.25V         值范围从0到0 x8000表示0 v,1.25 v
   * VOLTAGE_AT_TEMP_ZERO = 0.743 V = 19477
   * TEMP_COEFFICIENT = 0.0024 V/C = 62.9 /C
   * These parameters are typical values and need to be calibrated 这些参数是典型值,需要校准
   * See the datasheet for the appropriate chip for more details   看到合适的芯片的数据表为更多的细节
   * also, the math below may not be very accurate
   */
#if defined (HAL_MCU_CC2430)
  #define VOLTAGE_AT_TEMP_ZERO      19477   // 0.743 V
  #define TEMP_COEFFICIENT          62.9    // 0.0024 V/C
#elif defined (HAL_MCU_CC2530)
    /* Assume ADC = 5158 at 0C and ADC = 15/C */
  #define VOLTAGE_AT_TEMP_ZERO      5158
  #define TEMP_COEFFICIENT          14
#endif

  // limit min temp to 0 C
  if ( value < VOLTAGE_AT_TEMP_ZERO )
    value = VOLTAGE_AT_TEMP_ZERO;

  value = value - VOLTAGE_AT_TEMP_ZERO;

  // limit max temp to 99 C
  if ( value > TEMP_COEFFICIENT * 99 )
    value = TEMP_COEFFICIENT * 99;

  return ( (uint8)(value/TEMP_COEFFICIENT) );

#endif  // CC2430 || CC2530
……

综上所述,ADC数据位与MCU、内部通道、外部通道有关。选择不同的MCU或通道,处理数据位略有不同,但目的都是将采集到的数据从相应的寄存器中提取出来。应用时参考数据手册和官方的例子即可。

最后

以上就是贪玩冰棍为你收集整理的ZigBee_ADC数据位的全部内容,希望文章能够帮你解决ZigBee_ADC数据位所遇到的程序开发问题。

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

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

评论列表共有 0 条评论

立即
投稿
返回
顶部