Other Parts Discussed in Thread: MSP430F67641
Hello All,
I am working on ADC10 in msp430f67641 mcu and using 16Mhz clock freq.
I facing the problem:
1> i getting 511 resolution instead of 1024
2> floating point issue.
while execution of code it is block in the mpyf_i.h file.
my code is:
void ADC_init(void)
{
P9SEL |= BIT1 | BIT2 | BIT3; // Enable A3,A4,A5
// ADC initialization
ADC10CTL0 &= ~ADC10ENC;
ADC10CTL0 = ADC10SHT_2 + ADC10ON;
// Single channel, single conversion, SMCLK/MODOSC
ADC10CTL1 |= ADC10SSEL_3 + ADC10SHP + ADC10CONSEQ_0; // SMCLK(8MHz)
// 10bit Result
ADC10CTL2 |= ADC10RES;
}
// INFINITE LOOP CONTINUOUSLY REPEAT THE ADC CONVERSION MECHANISM.
// THIS PROGRAM USES SOFTWARE POLLING METHOD TO CHECK WEATHER ADC CONVERSION IS COMPLETED.
uint32_t ADC_read(int channel)
{
/* ADC10CTL1 INITIALIZATION
* INCH_10 -- CHANNEL10 IS SELECTED -- INTERNAL TEMPERATURE SENSOR
* ADC10DIV_3 -- ADC10 clock divider bits -Clock source divided by 4
******/
if(channel==3)
ADC10MCTL0 = ADC10INCH_3;// + ADC10DIV_2;
else if(channel==4)
ADC10MCTL0 = ADC10INCH_4;// + ADC10DIV_2;
else if(channel==5)
ADC10MCTL0 = ADC10INCH_5;// + ADC10DIV_2;
__delay_cycles(30);
ADC10CTL0 |= ADC10ENC + ADC10SC; // Sampling and conversion start
//__delay_cycles(32000000);
while (ADC10CTL1 & ADC10BUSY); // check for ADC conversion is completed
ADCDATA = ADC10MEM0; // Read ADC value
// Temperature in degrees conversion by using formula ADCDATA = (1024*(Vtemp/Vref))
tempInDeg = ((ADCDATA * 3.3)/1024)*1000;
//return tempInDeg;
return ADCDATA;
}
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
clock_config();
uart_init(BAUDRATE_9600);
// Setup P9.3 for A3, P1.0 output
ADC_init();
uart_string("---------------WELCOME----------------\r\n");
while (1)
{
ADC_Result = ADC_read(CH1);
display(ADC_Result);
__delay_cycles(16000000); // 1 Second Delay
ADC_Result = ADC_read(CH2);
display(ADC_Result);
__delay_cycles(16000000); // 1 Second Delay
ADC_Result = ADC_read(CH3);
display(ADC_Result);
__delay_cycles(16000000); // 1 Second Delay
uart_string("\r\n");
}
}
Any help resolving this issue would be greatly appreciated!
