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.

ADC10 Only Giving Half the Expected Range

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!

  • Hi,

    Are you actually trying to measure some external voltage on the ADC pins, or the temp sensor? I'm only asking because there were some comments in the code referring to the temp sensor.

    I have a few questions to try to help figure out what the root cause of your issue might be:

    1. What voltage are you applying at A3/A4/A5 when you are doing the measurement, and what Vcc do you use?
    2. Is 511 what you are seeing as the raw ADC result directly viewing ADC10MEM0 in the register view, or what you are seeing in the ADCDATA variable?
    3. How is the ADCDATA variable defined - could it maybe be declared as an 8-bit variable so the 10-bit value from ADC10MEM0 is getting truncated?
    4. Try commenting out the line with tempInDeg = to avoid the floating point calculation since it doesn't look like you are actually using this variable anyway.

    Regards,
    Katie

  • Hi chintan,

    How is this going? Do you have any update so we can try to help you, or were you able resolve the issue already on your own?

    Regards,
    Katie

**Attention** This is a public forum