This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

problem in ADC

Other Parts Discussed in Thread: CC2530, Z-STACK

hi .. 

i am interfacing CC2530 with chipcap2 sensor and i configured the adc as 14bit but the problem is now when i change the program to ADC8 bit it s printing random numbers .. any suggestions ????

  • - Try with a known DC voltage as input first.

    - Please post your ADC code

  • #include "ioCC2530.h"
    #include "initUART_Timer.h"
    #include "stdio.h"


    INT16 AvgTemp;

    void initTempSensor(void){
    DISABLE_ALL_INTERRUPTS();
    InitClock();
    *((BYTE __xdata*) 0x624B) = 0x01;
    *((BYTE __xdata*) 0x61BD) = 0x01;
    }

    INT16 getTemperature(void){
    UINT8 i;
    UINT16 AdcValue;
    UINT16 value;
    UINT8 value1;
    AdcValue = 0;
    for( i = 0; i < 4; i++ )
    {
    ADC_SINGLE_CONVERSION(HAL_ADC_REF_AVDD | ADC_14_BIT | HAL_ADC_CHN_AIN0); // ʹÓÃ1.25VÄÚ²¿µçѹ£¬12λ·Ö±æÂÊ£¬ADԴΪ£ºÎ¶ȴ«¸ÐÆ÷
    ADC_SAMPLE_SINGLE(); //¿ªÆôµ¥Í¨µÀADC
    while(!ADC_SAMPLE_READY()); //µÈ´ýADת»»Íê³É
    value = ADCL >> 2; //ADCL¼Ä´æÆ÷µÍ2λÎÞЧ
    value |= (((UINT16)ADCH) << 6);
    AdcValue = value; //AdcValue±»¸³ÖµÎª4´ÎADÖµÖ®ºÍ
    }
    value = AdcValue>>2;
    value1=((value>>4)*0.68);
    return value1; //¸ù¾ÝADÖµ£¬¼ÆËã³öʵ¼ÊµÄζÈ
    }
    /****************************************************************
    Ö÷º¯Êý
    ****************************************************************/
    void main(void)
    {
    char i;
    char TempValue[10];

    InitUART0(); //³õʼ»¯´®¿Ú
    initTempSensor(); //³õʼ»¯ADC
    while(1)
    {
    AvgTemp = 0;
    for(i = 0 ; i < 64 ; i++)
    {
    AvgTemp = getTemperature();
    if(AvgTemp < 0)
    {
    AvgTemp=10000;
    }
    // AvgTemp >>= 1; //ÿ´ÎÀÛ¼Óºó³ý2.
    }

    sprintf(TempValue, (char *)"%dRH ", (INT16)AvgTemp);
    UartTX_Send_String(TempValue,6);
    Delay(50000);
    }
    }

    this is the code for 14bit adc i need it to work for 8bit adc

  • You can use those APIs in hal_adc.c of Z-Stack.

  • actually i am not using zigbee to transmit any data .. jst connected a sensor to a coordinator node and getting that data n hyperterminal via uart

  • Even you don't use Zigbee to transmit, you still can include hal_adc.h and hal_adc.c to use those APIs.

  • thanks sir !!! will try it