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.
_____________________________________Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.
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 ?
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.