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.
I have a Launchpad board with a 20 pin dip installed. MSP420G2452 installed. I am having trouble with the ADC10 peripheral. In my infinite loop I can only read once, the first time around. The second time it gets caught in the wait for busy line. "while( ADC10CTL1 & ADC10BUSY );". Any suggestions would help a lot. Thanks. Paul
Here is my initialization
WDTCTL = WDTPW + WDTHOLD; // WDT off, Stop watchdog timer to prevent time out reset
P1SEL = 0x00; // I/O, not module control
P1OUT = 0x00; // Clear P1
P1DIR |= 0x00; // Set P1.0 to output direction
P1IES = 0x00; // No interrupts on port 1 pins
P1IE = 0x00; // No interrupts on port 1 pins
//Configure ADC
ADC10CTL1 = INCH0 + CONSEQ_0;
ADC10CTL0 = SREF_0 + ADC10SHT_0 + REFON + ADC10ON + ENC ;
ADC10DTC1=0x01; // one conversion
ADC10AE0 |= 0x03; // P1.1,0 ADC10 option select)
My infinite loop code.
for (;;)
{
ADC10CTL1 = INCH0 + CONSEQ_0; // channnel A0 is selected; single channel, single conversion
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
while( ADC10CTL1 & ADC10BUSY ); // wait for conversion to be finished
//ADC10CTL0 &= ~ENC; // ADC10 disable
ADC_Result = Adc_Conv( 0x0401 );
Rt = 9910 * (1023.0 / ADC_Result - 1.0);
logRt = log(Rt);
T = ( 1.0 / (c1 + c2*logRt + c3*logRt*logRt*logRt ) ) - 273.15;
T5 = T4;
T4 = T3;
T3 = T2;
T2 = T1;
T1 = T;
T = (T1 + T2 + T3 + T4 + T5)/5.0;
T = (T * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
int(wholeNum) = T; //wouldn't hurt to cast it to avoid warning
int decimalNum = (int) ((T - wholeNum) * 10000);
itoa(wholeNum, wholeNumStr);
itoa(decimalNum, decNumStr);
//LcmSetCursorPosition(0, 1);
ClearLCD();
PrintStr("T=");
PrintStr(wholeNumStr);
PrintStr(".");
for(i=1;i<4;i++) // clear out digits
{
decNumStr[i] = ' ';
}
PrintStr(decNumStr);
} // infinite loop ends here.
Here is my subroutine.
int Adc_Conv( int channel )
{
ADC10CTL1 = channel;
ADC10CTL0 = SREF_0 + ADC10SHT_0 + REFON + ADC10ON ;
ADC10CTL0 |= ENC + ADC10SC ;
ADC10CTL0 &= ~ENC;
ADC10CTL0 &= ~(REFON + ADC10ON);
return ADC10MEM;
}
I would like to read the port 1.0 pin continuously. With 5 rolling averages for filtering.
My problem is this it works once then the second time around it gets caught in the wait for busy line.
This line.
while( ADC10CTL1 & ADC10BUSY ); // wait for conversion to be finished
Hi Paul,
why don't you use the DTC (data transfer controller)? It will store the desired number of conversion results in RAM and you will get one ADC10 interrupt once all conversions are done. Then you can do your moving average and process the result.
Have a look at my files http://e2e.ti.com:80/members/1702574/files/default.aspx; there is some sample code for LCD access where I used the LCD for simply displaying averaged ADC10 results (using the DTC for data handling).
Rgds
aBUGSworstnightmare
Thanks aBUGSworstnightmare,
Will do, I will check your code and impliment DTC for data handling. Once agin thanks,
Paul
**Attention** This is a public forum