Other Parts Discussed in Thread: MSP430F5152
i have a question about how the adc of msp430f5152 works
i have 2 analog input, i want check these 2 input in a order
following is what i do
for(; ;){
a = adc(0); // get value from pin1
b = adc(1); // get value from pin2
if(a<0x1FF){
if(b<0x1FF){
pwm(50);} // duty cycle 50
}
else
pwm(100);
}
int ADC (char channel){
// Configure ADC
ADC10CTL0 |= ADC10SHT_5 + ADC10ON+ADC10MSC;
// ADC10ON, S&H=1024 ADC clks
ADC10CTL1 |= ADC10SHP+ADC10DIV_7+ADC10CONSEQ_2;
// ADCCLK =SMCLK; sampling timer;
//clock divide by 8; single channel, Repeat-single-channel conversion;
ADC10CTL2 |= ADC10RES;
// 10-bit conversion results
ADC10IE |= ADC10IE0;
// Enable ADC conv complete interrupt
ADC10MCTL0 |= ADC10INCH_1;
// A1 ADC input select; Vref=AVCC
ADC10CTL0 |= ADC10ENC + ADC10SC;
// Sampling and conversion start
__bis_SR_register(CPUOFF + GIE);
// LPM0, ADC10_ISR will force exit
ADC10CTL0 &= ~ADC10ENC;
__no_operation();
// For debug only
}
it seems the value of pin1(input1) doesn't matter.
it turns out that if pin2 value< 0x1FF, pwm(50)
if pin2 value>0x1FF, pwm(100)
what did i do wrong? someone could help me out?
if someone could also make the modification, i will appriciate so much
thx