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.

ADC12 in MSP430f2618

Other Parts Discussed in Thread: CC2520

Hi! all

am currently working with msp430+ cc2520. I configured ADC12 and using it. I have two routiens to read ADC channel 11 and ADC channel 12 respectively. While reading ADC, channel 11 is giving me ADC count as 2021. This is ok but the channel 12 is also giving the same value. What can be the problem ? please reply ...here the code which i am using to read adc

/*ADC channel 11*/

uint16 HalMyAdc11Read ()
{
/* Setup sampling */
ADC12CTL0 = ADC12ON + SHT0_7; //192 cycles
HAL_ADC_11_MEM_CONTROL = SREF_0 | HAL_ADC_11_CHANNEL;

/* Disable conversions */
HAL_ADC_DISABLE_12()
/* Use sampling timer */
ADC12CTL1 = HAL_ADC_11_CONV_STARTADDR | SHP;
/* Enable conversions */
HAL_ADC_ENABLE_12();
/* Start Conversion */
ADC12CTL0 |= ADC12SC;
/* Wait for conversion to be done */
while (!(ADC12IFG & HAL_ADC_11_CH_BV));

/* Get Result */
return (HAL_ADC_11_RESULT);
}

Here is the code for reading ADC 12 channel

/*ADC channel number 12*/

uint16 HalMyAdc12Read ()
{
/* Setup sampling */
ADC12CTL0 = ADC12ON + SHT0_7 ; //192 cycles
HAL_ADC_12_MEM_CONTROL = SREF_0 | HAL_ADC_12_CHANNEL;

/* Disable conversions */
HAL_ADC_DISABLE_12()
/* Use sampling timer */
ADC12CTL1 = HAL_ADC_12_CONV_STARTADDR | SHP;
/* Enable conversions */
HAL_ADC_ENABLE_12();
/* Start Conversion */
ADC12CTL0 |= ADC12SC;
/* Wait for conversion to be done */
while (!(ADC12IFG & HAL_ADC_12_CH_BV));

/* Get Result */
return (HAL_ADC_12_RESULT);
}

Channel 12 shold give a count around 0 but it is not the case here

Please reply

Thanking you

shivraj

  • I wonder why you use all this HAL stuff when it doesn't do anything different than setting the ADC12 registers 1:1.
    It jsut adds a leayer of obfuscation to the code and brings no benefit. Also, you partly configure the ADC12 directly instead of using HAL functions. If teh HAL serves any purpose besides adding possible confusion, not using the HAL for these operations (like setting ADC12SC) may interfere with it and lead to completely unpredictable results.

    Anyway, you configure SHT0_7, but use HAL_ADC_11_MEM_CONTROL for sampling channel 11 (note that ADC12MEM11, and any other ADC12MEM register) can be used to sample any ADC input channel), and for setting the SHT value for ADC12MEM8..15 you'll have to define the SHT with SHT1_x.

  • Thanks! Michael 

    I Checked with SHT using SHT1_7 instead of SHT0_7 but this time also its giving me the same results.

    Whats The problem with this ? 

    Please reply 

    Thanks 

    Shivraj

  • Lookign at the schematics of the ADC12 in the users guide, channel 11 is VCC/2 and channel 12 is floating. It's well possible that a floating pin gives a similar result as VCC/2. Or as the teh last chanel used. I don' tknow.

    And since I don't know what your HAL functions really do, I cannot say what else might be wrong.

**Attention** This is a public forum