I am using MSP430G2553 to sample the analog input and process it further. When I checked voltage at ADC input pin A0 it was arround 1.4 V even when input was not connected. Then I tried to pull down it externally then it fall to 1.1 V instead of 0 V. I need tristate input of ADC as I am giving input from precision rectifer ,due to this I was not able to detect input level less than 1.4 V. Here is its code.
#include <msp430g2553.h>
int PWM(int a);
int main(void) {
float err = 0,ref = 122, Vadc = 0, Kp = 1, Ki = 0.4, P = 0, I = 0, PImax = 1000, PI = 0;
WDTCTL = WDTPW + WDTHOLD;
ADC10CTL0 = SREF_1 + REFON + REF2_5V + ADC10ON+ MSC;
ADC10CTL1 = CONSEQ_2; //repeated single conversion
ADC10AE0 = INCH_0;
ADC10CTL0 |= ENC + ADC10SC;
Vadc = ADC10MEM;
while(1)
{
Vadc = ADC10MEM;
err = ref - Vadc;
P = Kp * err;
if (PI + Ki * err < PImax)
I = I + Ki * err;
PI = P + I;
if(PI > PImax)
PI = PImax;
PWM(PI);
}
}
int PWM(int a) {
P1DIR |= BIT2;
P1SEL |= BIT2;
TA0CCR0 = 1000; //Set the period in the Timer A0 Capture/Compare 0 register to 1000 us.
TA0CCTL1 = OUTMOD_7;
TA0CCR1 = a; //The period in microseconds that the power is ON. It's half the time, which translates to a 50% duty cycle.
TA0CTL = TASSEL_2 + MC_1; //TASSEL_2 selects SMCLK as the clock source, and MC_1 tells it to count up to the value in TA0CCR0.
return 0;
}