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.

[CC2541 ADC (ADCH/ADCL) Registers always showing 0x00 value]

Other Parts Discussed in Thread: CC2541, ASH

Dear TI members,

I am looking for your help regarding my project work. I am working on 14 bit-ADC while using CC2541. I want to show the ADC to convert the BAT_VOL and show it in ADCH/ADCL registers. I am not seeing any value in these registers. I am using following code to read the value in the registers.

/* Read the result */
  reading = (int16) (ADCL);
  reading |= (int16) (ADCH << 8);

I am reading the value using "WATCH" feature in IAR, but I want to see the value in ADCH/ADCL reg.

Please help.

Thanks in Advance.

/Ash

  • you can debug your project and set some breakpoint to see, the watch-window only can display the value of the variable when the debug was paused
  • Dear Sir, I tried that too. I used some breakpoints to see the value of ADCL-ADCH registers, But still this shows 0x00. Plz Suggest.
  • maybe you should run a little experiment , sampling the voltage of the internal Temperature sensor, if the value is right ,then check the configuration of the ADC
  • Thanks for your suggestion. I put the "watch" at [return ((uint16)reading);] and I can see the ADC value correspondingly. But I can not see any changes in the ADCL/ADCH registers. Still it shows 0x00.
  • Do you setup ADC related registers to enable ADC reading? Or you just start to read ADCL/ADCH directly?
  • I set up ADCCON1/2/3 for ADC, not the ADCH/ADCL. How to set ADCH/ADCL registers. Plz suggest. Thanks
  • Why don't you use API in hal_adc.c to do ADC reading?
  • Sir, I used the API in ADC Configuration. Still the same result.
  • Would you show me how you use ADC API ?
  • /* Initialize ADC Service */extern void HalAdcInit ( void );
    /* Read value from a specified ADC Channel */
    extern uint16 HalAdcRead ( uint8 channel, uint8 resolution );
    /* Set the reference voltage for the ADC */
    extern void HalAdcSetReference ( uint8 reference );
    /* Check for minimum Vdd specified */extern bool HalAdcCheckVdd(uint8 vdd);
  • 1. Do you define HAL_ADC
    2. I know these API well but how do you using them in your application?
  • Dear Mr Chen,I am getting back to ADC issue after a bit time span.
    I am using ADC ref as its internal reference and ADC-IN as the point where I set the voltage (1v) (using voltage devider n/w). But I am unable to read any value at ADCH/ADCL.
    Please suggest.Thanks n Regards/Ash
  • Can you show me your code and how you connect to ADC-IN?
  • Dear Mr Chen, Thanks for your prompt reply~ Here It is~
    *********************************************************************************************************************************
    void HalAdcInit (void){#if (HAL_ADC == TRUE) adcRef = HAL_ADC_REF_VDD3;#endif}
    uint16 HalAdcRead (uint8 channel, uint8 resolution){ int16 reading = 0;
    #if (HAL_ADC == TRUE) uint8 i, resbits; uint8 adcChannel = 1;
    if (channel <= HAL_ADC_CHANNEL_5) { 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; }
    /* writing to this register starts the extra conversion */
    ADCCON3 = channel | resbits | adcRef; /* Wait for the conversion to be done */
    while (!(ADCCON1 & HAL_ADC_EOC));
    /* Disable channel after done conversion */
    if (channel <= HAL_ADC_CHANNEL_5) 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);}void HalAdcSetReference ( uint8 reference ){
    #if (HAL_ADC == TRUE) adcRef = reference;#endif}bool HalAdcCheckVdd(uint8 vdd){
    ADCCON3 = 0x0F; while (!(ADCCON1 & 0x80)); return (ADCH > vdd);}
    Regarding ADC-IN, I am using supply as 3V and two resistors of (20k and 10k), while getting the ADC-IN point from the devider whcih goes to P0_5 of CC2541.
    Thanks,/Ash
    ***************************************************************************************************************************************
  • If you want to use external reference, you should connect the reference voltage to AI7 which is P0_7 and use HalAdcSetReference(HAL_ADC_REF_AIN7) to set reference to AI7.
  • Yes I agree. But as people suggested to use Internal ref for good stability and accuracy, so I want to use internal reference only.
    The issue is that ADCH/ADCL are not reading any value. Other registers shows the value like RNDH/RNDL/ADCCON1/ADCCON2/ADCCON3....
    How can I see the values of ADCH/ADCL ?Thanks
  • If you use internal reference, you don't have to connect 1V into any pin. You have to use HalAdcSetReference(HAL_ADC_REF_125V) to set ADC using internal 1.15V reference and use HalAdcRead() to read ADC input.
  • I am usning the Internal reference. The voltage devider point where I want to measure the voltage is actually for Battery_Check, which is connected to P0_5.
    but in any case, the ADCH/ADCL are not showing any value.
    [#define HAL_ADC_REF_125V 0x00 /* Internal Reference (1.25V-CC2430)(1.15V-CC2530) */]
    Please suggest~Thanks.
  • In your application, the ADC reading should be like the followings:
    uint16 adc_reading;
    HalAdcSetReference(HAL_ADC_REF_125V);
    adc_reading=HalAdcRead(HAL_ADC_CHN_AIN5, HAL_ADC_RESOLUTION_14);
  • Dear Mr Chen,I changed that. I tried with....
    HalAdcSetReference(HAL_ADC_REF_125V);
    adc_reading=HalAdcRead(HAL_ADC_CHANNEL_5, HAL_ADC_RESOLUTION_14);
    I used HAL_ADC_CHANNEL_5, which refer to P0_5. What is the use of (HAL_ADC_CHN_AIN5) ? Both are same?
    Also, How can I read ADCH/ADCL ?Please suggest~Thanks /Ash
  • In you case, I suppose adc_reading is always greater or equal to zero. ADCH and ADCL would be
    ADCH= (uint8)((adc_reading&0xFF00)>>8);
    ADCL= (uint8)(adc_reading&0x00FF);
  • Its already set greater or equal to zero. Still I cant see any value to ADCH/ADCL reg during debugging. Also, as I connected the device with supply source, Its showing 100%, but when I connect it with Battery, Its still shows 100% (no change). why so?
    Please help~Thanks n Regards
  • Can you take a picture show me how you connect your HW?
  • I have the same problem. I'm trying to read 0.6V (approx) on P0_1, with 8-bit resolution, using the same API call,  HalAdcRead(). The result returned is always 127. When I trace the function, ADCL and ADCH (SFR BA and BB, respectively) contain 0. Even stranger, when I step through the assembly, after  the instruction which moves ADCL into the accumulator A, A=0xFC although ADCL was 0x00. The the 16-bit value of "reading" is 32764 (0x7FFC).

    Here's a screenshot of the debugger window

  • I cannot explain the debugger behavior, but I can say that the problem I had, of reading junk values from the ADC, is solved. Embarrassingly, this was because I was powering the chip from one of its input pins. I was measuring P0_0 and P0_1. My data sheet assured me that P0_0 would be around 1.0V, and I believed it, and was concentrating on measuring the voltage at P0_1. In fact, P0_0 was close to 4V; at this voltage, all sorts of things go wrong.

  • It is good to know you solve the problem.