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.

ADC question.

Other Parts Discussed in Thread: CC2430

It it said in hal_adc.c file:

  /*
  * 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.
  */

 

What does it mean make sure corresponing P0 I/O pin is enabled?

If i use P0_0 as my only ADC input pin, why do I keep it enable even when conversions are not performed?

  • Hello Shahar,

    It means, basically make sure that you configue the I/O for use with the ADC and that if you will be performing frequent conversions, leave it enabled and configured.  Ie in your ADC configuration in the following register ADCCFG ... this is where you set the enabled I/Os.

    If you will only be doing infrequent conversions, you can disable it and reenable it in between.  The suggest is just for effeciciency of time and code in the case where there is one conversion after another.

    Hope this helps clarify things a little.

    Cheers,

    Yoda

  • Hi, I am also looking at ADC these days.

    I have 2 questions regarding your reply.

    (1) How frequent is considered 'frequent'? for example, if ADC is checked per 50 milliseconds, is this considered frequent?

    I know the formula 'Tconv = (decimation rate + 16) x 0.25 μs.', which means if my decimation rate is 256, Tconv=68us.

    (2) If ADC is not used frequently, disabling it will save quite a lot of power. I used extra channel conversion. I am not sure how to disable ADC every time conversion finishes, or does this happen automatically?

    Thanks in advance.

  • foresightyj said:

    (1) How frequent is considered 'frequent'? for example, if ADC is checked per 50 milliseconds, is this considered frequent?

    I know the formula 'Tconv = (decimation rate + 16) x 0.25 μs.', which means if my decimation rate is 256, Tconv=68us.

    With your frequency of using the ADC, it may make sense for you to turn off the ADC after every conversion to save power.  Really, the cross over point of "frequent" is when the time to execute the instructions to turn off and turn on the ADC between conversions impacts the frequency of conversions.  If you will have the ADC idle longer than the setup + conversion time, then power it down.

     

    foresightyj said:

    (2) If ADC is not used frequently, disabling it will save quite a lot of power. I used extra channel conversion. I am not sure how to disable ADC every time conversion finishes, or does this happen automatically?

    The ADC is not disabled automatically.  Your interrupt service routine taking care of the ADC, or after polling the completion flag, your software would then need to turn off the ADC.

  • Thank you.

    I understand my first question.

    But I am still confused about the second one. For example I used the following code to do ADC

    /* Clear ADC interrupt flag */

    ADCIF = 0;

    ADCCON3 = (HAL_ADC_REF_EXT | HAL_ADC_DEC_512 | HAL_ADC_CHN_ACCEL);

    /* Wait for the conversion to finish */

    while ( !ADCIF );

    ......

    In this case, there is no ISR, but only a check on the interrupt flag. So I can only turn off ADC using software. Does disabling ADC mean changing ADC ports to GPIO ports?

     

    Or if I use ISR, do I still have to disable ADC manually?

  • foresightyj said:

    In this case, there is no ISR, but only a check on the interrupt flag. So I can only turn off ADC using software. Does disabling ADC mean changing ADC ports to GPIO ports?

    Changing the ports to GPIO is independent of the actual ADC configuration.  The Port selection register really "connects" the particular pins to the ADC input channels.
    I may have mispoke about the disabling of the ADC.  If you are referencing the CC2430, the ADC can be configured to start a conversion based on some different triggers.  In three of the four possible triggers, the conversion will stop after the last channel has been converted, which is specified by ADCCON2.SCH bit field.  The trigger selection is in ADCCON1.STSEL.

    foresightyj said:
     

    Or if I use ISR, do I still have to disable ADC manually?

    This will depend on the trigger selected for the ADC.