Jump to content

DarthMessiah15

Members
  • Content Count

    24
  • Joined

  • Last visited


Reputation Activity

  1. Like
    DarthMessiah15 reacted to SugarAddict in Interrupts?   
    #include // DEMO counter unsigned int demoCounter = 0; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1DIR &= ~(BIT3); // 1.3 is button P1SEL &= ~(BIT3); P1OUT |= (BIT3); // Set to high P1REN |= (BIT3); // Resistor enabled P1IE |= (BIT3); // Interrupt enabled P1IES |= (BIT3); // Edge select P1IFG &= ~(BIT3); // Clear interrupt flags P1OUT |= BIT1; // Direction control - left P1OUT &= ~BIT0; // Direction control - right // Both 0 or 1 - dynamic break P1DIR |= BIT0 + BIT1 + BIT2; // Bit 2 is connected to enable and will be used for PWM P1SEL |= BIT2; // P1.2 TA1 option select CCTL0 = CCIE; // CCR0 interrupt enabled CCR0 = 1000; // ~8ms CCTL1 = OUTMOD_3; // CCR1 set/reset CCR1 = 950; // CCR1 duty cycle, slow in the beginning _bis_SR_register(LPM3_bits + GIE); // Enter LPM3 w/ interrupt __no_operation(); // Make sure we have something to sleep on TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK/8, upmode _bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt } // Timer A0 interrupt service routine #pragma vector = TIMERA0_VECTOR __interrupt void Timer_A (void) { // DEMO movement demoCounter++; if(demoCounter == 800) CCR1 = 900; if(demoCounter == 1600) CCR1 = 500; if(demoCounter == 2000) CCR1 = 250; if(demoCounter == 2400) CCR1 = 0; if(demoCounter == 2800) CCR1 = 900; if(demoCounter == 3200) { P1OUT |= BIT0; // switch direction P1OUT &= ~BIT1; } if(demoCounter == 3600) CCR1 = 0; if(demoCounter == 4000) CCR1 = 900; if(demoCounter == 4400) { P1OUT |= BIT1; // switch direction P1OUT &= ~BIT0; } if(demoCounter == 4800) { P1OUT |= BIT0; // switch direction P1OUT &= ~BIT1; } if(demoCounter == 5200) { CCR1 = 500; P1OUT |= BIT1; // switch direction P1OUT &= ~BIT0; demoCounter = 0; } // END DEMO movement } #pragma vector=PORT1_VECTOR __interrupt void P1ISR(void) { if(P1IFG & BIT3) // We interrupted on P1.3 { _bic_SR_register_on_exit(LPM3_bits); P1IFG &= ~BIT3; // clear the button press } }
     
    Like so, I beleive.
  2. Like
    DarthMessiah15 reacted to SugarAddict in Interrupts?   
    Yep, you would do all of your work in the TimerA interrupt.
×
×
  • Create New...