PWM Output based on two analog inputs

Hi I am having the following problem. I am inputting two voltage signals to change my output waveform however the registers say that the two pins are 7FFF which is my voltage limit even though nothing is applied, why is that? Here is my code:

#include <msp430x20x3.h>

void main(void)

{

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

P1DIR |= 0xFE; // Only P1.0 is an input

SD16AE = SD16AE0; // Disables A0 (P1.0) an digal input alowwing pure analog

SD16CTL = SD16REFON + SD16SSEL0;

SD16CCTL0 |= SD16DF; // set values from 0 - 7FFF

SD16INCTL0 = SD16INCH_0 + SD16GAIN_1;

SD16CCTL0 |= SD16SC ; // START CONVERSION

int a = 0;

a = SD16MEM0;

P1DIR = 0xFD; // Only P1.1 is an input

SD16AE = SD16AE1; // Disables A1 (P1.0) an digal input alowwing pure analog

SD16CTL = SD16REFON + SD16SSEL1;

SD16CCTL0 |= SD16DF; // set values from 0 - 7FFF

SD16INCTL0 = SD16INCH_1 + SD16GAIN_1;

SD16CCTL0 |= SD16SC ; // START CONVERSION

int b = 0;

b = SD16MEM0;

//OutputPWM(a);

BCSCTL1 = 0x80;

BCSCTL2 = 0x04;

P1DIR = 0x04; // P1.2 output

P1SEL = 0x04; // P1.2 TA1/2 options

a = (a / (0x7FFF/9));

CCR0 = a; // PWM Period

CCTL1 = OUTMOD_4; // CCR1 reset/set

int x = CCR0/x;

CCR1 = CCR0/2; // CCR1 PWM duty cycle

TACTL = TASSEL_2 + MC_1; // SMCLK, up mode

_BIS_SR(CPUOFF); // Enter LPM0

}

I detected a few problems in your code.

(1) You are using P1.0 and P1.1 for analog input. I think you should set:

SD16AE=SD16AE0+SD16AE1;

But at first, your code says:

P1DIR|=0xFE; SD16AE=SD16AE0;

This will put a digital output at P1.1 fighting your analog input at P1.1.

Later on, your code says:

P1DIR=0xFD; SD16AE=SD16AE1;

This will put a digital output at P1.0 fighting your analog input at P1.0.

(2) After you set the SD16SC bit, it takes hundreds of clock for the SD16 to do the conversion. But you try to read SD16MEM0 right away. You will get garbage this way. You need to wait for SD16 to finish by polling SD16IFG or set it to interrupt.

(3) Analog input at P1.1 is SD16 channel 4, not channel 1.