Other Parts Discussed in Thread: MSP430G2452
Hi there,
i try to measure dc voltage generated by a capacitance loading circuit with low pass filter. For some reasons the selected ADC channel is always 'high'. That means that the ADC writes 1023 as the result all the time. The strange thing is, that when I use another channel everything works as it should do.
I am using the MSP430G2452 with this code:
#include <msp430G2452.h>
void init_ADC();
void init_clk();
void init_pulse();
void init_system();
int read_ADC();
unsigned int moisture, result, i;
void main(void)
{
init_system(); // init. system
while(1)
{
moisture = 0;
for (i=0; i<100; i++)
{
moisture = moisture + (read_ADC());
}
result = moisture / 100;
};
}
int read_ADC(void)
{
ptr_adc_value = &adc_value;
while(TA0R != 50){}; // trigger ADC
ADC10CTL0 |= ENC + ADC10SC; // start sampling and conversion
while (ADC10CTL1 & ADC10BUSY){}; // wait for conversion completion
*ptr_adc_value = ADC10MEM;
ADC10CTL0 &= ~ENC; //disable ADC
return *ptr_adc_value;
}
void init_system(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1OUT=0x00;
init_clk(); // init. internal clocks
init_pulse(); // init. pulse for cap_meas
init_ADC(); // init. ADC10
}
void init_clk(void)
{
BCSCTL1 = CALBC1_8MHZ; //config internal clocks
DCOCTL = CALDCO_8MHZ;
}
void init_pulse(void)
{
P1DIR |= BIT2; // config P1.2 as TA0.1
P1SEL |= BIT2;
TA0CCR0 = 80-1; // PULSE Period
TA0CCR1 = 40-1;
TACCTL1 = OUTMOD_7;
TA0CTL = TASSEL_2 + MC_1; // SMCLK, up mode
TA0CTL &= ~TAIE;
}
void init_ADC(void)
{
ADC10CTL0 = SREF_1 | ADC10SHT_0 | ADC10ON | REF2_5V | REFON ;
ADC10CTL1 = INCH_3 + ADC10DIV_0 + ADC10SSEL_3;
ADC10AE0 = BIT3;
}
When I switch the ADC input form channel 3 to channel 1, channel 1 is always high.
I wonder if there's something missing in the ADC10 configuration, because I tested my circuit several times and there seems to be no issue with that.