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.

CC2530 ADC problem

Part Number: CC2530
Other Parts Discussed in Thread: TIMAC, Z-STACK

Hi,

I am using a CC2530F128 ADC, and I do not get to read the input (the values is always 0). I have tried using the ADC registers, using TIMAC ADC library and z-stack library and I always get the same result. I also try to read  the temperature sensor and the result is 0. But in all cases, the conversion has been completed because the ADCCON1.EOC is set.

The code for read temperature sensor:

  ADCCON3 = 0x3E;
  while (!(ADCCON1 & 0x80));
  // Use all 14 MSB of adcValue
  ADC_result = ADCL >> 2;
  ADC_result |= ADCH << 6;

The code for read channel 0:

    P0DIR = 0x00;   //todo entradas
    P0SEL = 0xFF;     //todo funcion periferico
    HalAdcSetReference( HAL_ADC_REF_125V );
    ADC_result = HalAdcRead(HAL_ADC_CHN_AIN0, HAL_ADC_RESOLUTION_14);

What it is wrong?

Thanks.

Ruben

  • Part Number: CC2530

    Hi,

    I am using a CC2530F128 ADC, and I do not get to read the input (the values is always 0). I have tried using the ADC registers, using TIMAC ADC library and z-stack library and I always get the same result. I also try to read  the temperature sensor and the result is 0. But in all cases, the conversion has been completed because the ADCCON1.EOC is set.

    The code for read temperature sensor:

      ADCCON3 = 0x3E;
      while (!(ADCCON1 & 0x80));
      // Use all 14 MSB of adcValue
      ADC_result = ADCL >> 2;
      ADC_result |= ADCH << 6;

    The code for read channel 0:

        P0DIR = 0x00;   //todo entradas
        P0SEL = 0xFF;     //todo funcion periferico
        HalAdcSetReference( HAL_ADC_REF_125V );
        ADC_result = HalAdcRead(HAL_ADC_CHN_AIN0, HAL_ADC_RESOLUTION_14);

    What it is wrong?

    Thanks.

    Ruben

  • Hi YiKai,

    I have used the same code that the example:

    HalAdcSetReference( HAL_ADC_REF_125V );
    ADC_result = HalAdcRead(HAL_ADC_CHN_AIN0, HAL_ADC_RESOLUTION_10);

    And ADC_result is always 0. In fact, I can not modify the variable ADC_result. I have defined as uint16 ADC_result = 0xFF; and In the watch window, I can see the value is 0. If I execute for example de code ADC_result = 1; , the value does not change (It is alway 0). Why have that ocurred?

    Thanks.

    Ruben
  • AIN0 is mapped to P0.0. Do you use multimeter to check voltage on it?
  • Make sure you have configured your pin as ADC, INPUT and as PERIPHERAL.

    Below you can find an exemple for an ADC input at pin P0.4.
    The ADC is configured to use the AVDD5 as voltage reference and 7bits ENOB setting

    //ADC
    APCFG = 0x10; //0b00010000; //[0] P0.4 Analog IO
    ADCCON1 = 0x33; //0b00110011; //[7] EOC (read_only) | [6] Start_conversion | [5:4] Start Trigger (ADCCON1.ST) | [3:2] reserved (00) | [1:0] reserved (11)
    ADCCON2 = 0x80; //0b10000000; //[7:6] AVDD5 REF | [5:4] 7bits | [3:0] Channel | (Single Conversion)

    //I/O PINS
    P0SEL = 0x3C; //0b00111100; //[7:0] {1}-Peripheral {0}-GPIO
    P0DIR = 0xEA; //0b11101010; //[7:0] {0}-Input | {1}- Output

    ADCCON2 |= 0x04; //Channel 4

    if(ADCCON1 & 0x80) //Check EOC...
    var = ADCH; //Read any "dummy" remaining value..

    ADCCON1 |= 0x40; //Start Conversion

    while( !(ADCCON1 & 0x80)); Wait for EOC


    uint16 var;
    var = ADCL; //Receive LSB
    var |= ((uint16)ADCH << 8); //Receive MSB.
    var = var >> 8; //Rotate 8 bits because they are dont care when using 7bits

  • I have solved it. The problem was that IAR does not declare the variable in XDATA, and It always reads 0.

    Thanks for you reply.

    Rubén