Quantcast
Channel: MSP low-power microcontrollers
Viewing all articles
Browse latest Browse all 65423

Forum Post: ADC values to change PWM using TA0CCR1 register, not decreasing

$
0
0
I am working on a project where for now I'd like to simulate motor control using pwm. I am reading in analog values from a pot, which acts as a proximity sensor, and based upon those values I either increase of decrease the duty cycle of the pwm (which is reflected in the brightness of an LED). It works when the adc values are increasing, but when decreasing there is no change in the LED. Why is TA0CCR1 able to change when increased but it doesn't seem to change on a decrease? I am using the msp430 launchpad with has the msp430g2553 . My code is posted below: #include int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT /*** GPIO Set-Up ***/ P1DIR |= BIT2; P1SEL |= BIT2; /*** Timer0_A Set-Up ***/ TA0CTL |= TASSEL_2 | MC_1 | ID_3; TA0CCR0 |= 1000; TA0CCTL1 |= OUTMOD_7; TA0CCR1 |= 0; ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled ADC10CTL1 = INCH_0; // input A1 ADC10AE0 |= BIT0; // PA.1 ADC option select for (;;) { ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start __bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit if (ADC10MEM 50 && ADC10MEM 0xFF && ADC10MEM 0x200 && ADC10MEM < 0x2EE) TA0CCR1 |= 1000; } } // ADC10 interrupt service routine #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) { __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR) }

Viewing all articles
Browse latest Browse all 65423

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>