Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Can TimerA ISR Stop Itself?

$
0
0

Bottom line is that I was trying to come up with a way to initiate a 50ms pulse but searching through forums I was surprised that I couldn't find much on doing this. I have a ISR on Port1 with a button/switch connected to it. The WDT debounces this button/switch which also starts TimerA. I thought I could just use the TimerA ISR to stop itself but stepping through the debug code looks like it just ignores this statement.

 

Here's the TimerA ISR I have:

#pragma vector = TIMERA0_VECTOR
__interrupt void CCR0_ISR(void) {
	if (++i == 5) {
		P2OUT ^= BIT7; // Toggle P2.7 every ~50ms
		P1OUT ^= BIT1; // Toggle P1.1 LED for testing
		P1OUT&= ~EN; //Disable DRV8838. OUT1/OUT2 will be low
		// put DRV8838 into sleep. need to connect JP2 tp P2.7
		TACTL |= MC_0; // Stop timer, enabled on next button push
		i=0;
	}
} // CCR0_ISR

and here's the WDT ISR that starts TimerA:

// WDT is used to debounce S1 by delaying the re-enable of the P1IE interrupt
// and to time the length of the press
#pragma vector = WDT_VECTOR
__interrupt void wdt_isr(void)
{

if (Pressed & S1) // Check if switch is pressed
 {
	 if (++PressCount == 40 ) // Long press duration 34*44ms = 1.5s
	 {
		 P1OUT |= BIT1; // Turn on the P1.1 LED to indicate long press
		 P2OUT |= BIT7; // Set P2.7 high for testing
		 P2OUT |= EN; // Enable DRV8838
		 P1OUT &= ~PH; // Set PH low for "FWD". Positive to OUT1, Negative to OUT2
		 TACTL |= MC_1; // Set timer to up mode, begin pulse to DRV8838
	 }
 }
 P1IFG &= ~BIT3; // Clear the button interrupt flag (in case it has been set by bouncing)
 P1IE |= BIT3; // Re-enable interrupt for the button on P1.3
}

Of course I could just use delays but I'm trying to be efficient since this will be a battery operated application. What I'm trying to so is fairly straightforward, a short button press sends a 50ms on P1.2 and a long press sends a 50ms on P2.6


Viewing all articles
Browse latest Browse all 2077

Trending Articles