Other Parts Discussed in Thread: MSP430G2553
Dear all
I am posting an ADC coding here.
#include <msp430g2553.h>
volatile int value=0;
unsigned int sampling;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
InitializeClocks(); // Configure system clocks
ConfigureADC();
__enable_interrupt(); // Enable interrupts.
while(1)
{
ADC10CTL0 &= ~ENC;
while((ADC10CTL1 & ADC10BUSY) == ADC10BUSY);
sampling = 1;
ADC10CTL0 |= ENC + ADC10SC;// Sampling and conversion start
value=ADC10MEM;
ADC10CTL0 &= ~(ADC10IFG | ADC10ON | REFON);
while(sampling>0); // wait until the sampling sequence is complete
__delay_cycles(100);
}
}
void ConfigureADC(void)
{
ADC10CTL0 = SREF_1 + ADC10SHT_0 + REFON + ADC10ON + ADC10IE;
ADC10CTL1 = INCH_4 + ADC10DIV_0 + ADC10SSEL_0 + CONSEQ_0;// channel 5, clock divider 2, ADC10CLK, Conversion sequence mode select single channel single conversion
ADC10AE0 |= BIT4;
ADC10CTL0 &= ~ENC+ADC10SC; // Disable conversion
__delay_cycles(40);
}
void InitializeClocks(void)
{
BCSCTL1 = CALBC1_16MHZ; // Set range
DCOCTL = CALDCO_16MHZ;
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
sampling=0;
__bic_SR_register_on_exit(CPUOFF); // Return to active mode }
__delay_cycles(40);
}
In this if I give 1.3 as Vin. It does not give the expected exact output. integer 887(886.6 is the exact value). Instead of this it gave 868 integer value at ADC10MEM register. Please help in this context to expain the problem with this code. How could I get the exact value?