Hello Everyone,
I would like to have a pair of delayed monostable pulses that can be terminated by an input or an interrupt. (One of the monostables will set a status flag for the other one.)
(I am only working with one pulse thus far, eventually I will need two.)
Specifically I want to:
1) drive an LED
2) close a switch (producing an output pulse.)
3) reset the timer
4) turn off the LED
5) start the timer with a delay period
6) open the switch
7) after delay, turn on the LED
Repeat steps 2-6 indefinitely. . I am using the 32,768 crystal as the ACLK clock. ( I would prefer to have step 2 have a fast ~ a few microseconds delayed output pulse.)
So far I have been able to close the switch and reset the timer which are steps 2 and 3. I can start the timer in step 4, and I can turn on the LED in step 5.
What I can not do is turn OFF the LED, in step 4. (i.e. one of Port P2.4, P2.5) I am using the PWM, pulse width modulation approach, with the switch closure as an interrupt in step 2. The timer output is the LED drive.
Any switch closure resets the TAR timer, to zero, which is desired. Whatever state the P2.4 or P2.5 LEDs are in, (on or off) remains frozen in place while the timer begins a new delay cycle.
I have tried several approaches to modifying the registers to effect P2.4, I will detail below. None have worked.
I could try using software to use a manually controllable auxiliary port as the LED driver, say P2.3, or even a hard reset on the NMI input. That would require two separate chips I think.
I have tried setting TA2CTL = MC_0 and TACLR,, and setting TACCR0 and TACCR2 to various values. Also setting TA2CCTL2 = OUTMOD_7 Nothing turns off P2.4, or P2.5.
Should I try to drive port P2.3 using logic like if(P2OUT && BIT4 == 0x10) P2OUT &= ~BIT3; Or should I hard reset the uP with NMI? Any ideas?
Here is my code for the MSP430F5529:
#include <msp430.h> //for MSP430F5529
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= BIT0; // Set P1.0 to output direction
P2REN |= BIT1; // Enable P2.1 internal resistance
P2OUT |= BIT1; // Set P2.1 as pull-Up resistance
P2IES |= BIT1; // P2.1 Hi/Lo edge
P2IFG &= ~BIT1; // P2.1 IFG cleared
P2IE |= BIT1; // P2.1 interrupt enabled
P2DIR |= BIT3+BIT4+BIT5; // P2.3, P2.4and P2.5 output
P2SEL |= BIT4+BIT5; // P2.4 and P2.5 options select
TA2CCR0 = 65535; // PWM full Period (16 seconds)
TA2CCTL1 = OUTMOD_3; // 7=CCR1 reset/set, 3=set/reset
TA2CCR1 = 29000; // CCR1 PWM duty cycle (7 seconds)
TA2CCTL2 = OUTMOD_3; // 7=CCR2 reset/set, 3=set/reset
TA2CCR2 = 21000; // CCR2 PWM duty cycle (5 seconds)
P2OUT != BIT3;
P1OUT |= BIT0;
// 1=ACLK,up mode, div8=16 sec, clear TAR
TA2CTL = TASSEL_1 + MC_1 + ID_3 + TACLR; // Starts the timer
__bis_SR_register(LPM4_bits + GIE); // Enter LPM4 w/interrupt
__no_operation(); // For debugger
}
// Port 2 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=PORT2_VECTOR
__interrupt void Port_2(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(PORT2_VECTOR))) Port_2 (void)
#else
#error Compiler not supported!
#endif
{
P1OUT ^= BIT0;
TA2CTL = TASSEL_1 + MC_1 + ID_3 + TACLR; // 1=ACLK,up mode, div8=16 sec, clear TAR
P2IFG &= ~BIT1; // P1.4 IFG cleared
}
Thank you! -Sandy