Jump to content
43oh

How do I use an input to trigger an interrupt to set a output?


Recommended Posts

I have been trying to figure this one out. 

 

I want to run an interrupt upon a trigger from an input, in the interrupt it will cause a pin to go high.  I want to make this function as the interrupt will be reset by another input or by a set time.  This is the code that I have found and attempted to change to work with the MSP430G2553, but I can not get it to work.  What do I need to do to get this to work ? 

 

Thanks!!!!

#include "msp430g2553.h"  
  
void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;     // Stop WDT  
  TA0CCTL0=CCIE;                             // CCR0 interrupt enabled
  TA0CTL = TASSEL_2+MC_1+ID_3;           // SMCLK/8, upmode
  TA0CCR0=10000;                     // 12.5 Hz   
  P1OUT &= 0x00;               // Shut down everything
  P1DIR &= 0x00;               
  P1DIR |= BIT0 + BIT6;            // P1.0 and P1.6 pins output the rest are input 
  P1REN |= BIT3;                   // Enable internal pull-up/down resistors
  P1OUT |= BIT3;                   //Select pull-up mode for P1.3
  P1IE |= BIT3;                       // P1.3 interrupt enabled
  P1IES &= ~BIT3;                     // P1.3 Hi/lo edge
  P1IFG &= ~BIT3;                  // P1.3 IFG cleared
  _BIS_SR(CPUOFF + GIE);          // Enter LPM0 w/ interrupt 
  while(1)                          //Loop forever, we work with interrupts!
  {}
} 
  
// Timer A0 interrupt service routine 
#pragma vector=TIMER0_A0_VECTOR 
__interrupt void Timer_A (void) 
{   
   P1OUT ^= BIT0;                          // Toggle P1.0 
} 
// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{    
   P1OUT ^= BIT6;                      // Toggle P1.6
   P1IFG &= ~BIT3;                     // P1.3 IFG cleared 
}
Link to post
Share on other sites

I want to run an interrupt upon a trigger from an input, in the interrupt it will cause a pin to go high.  I want to make this function as the interrupt will be reset by another input or by a set time.

 

In the description you say you want the pin to go high, but in the code you make the pin change from whatever state it is to the reverse.

(P1OUT ^= BIT6) - rather than make it high (P1OUT |= BIT6), likewise the timer interrupt toggles a (different) pin, rather than turning it off.

 

"If the code and the comments disagree, then both are probably wrong."

--attributed to Norm Schryer

 

What does the program do currently?  (In what way does it not work.)

Link to post
Share on other sites
#include "msp430g2553.h"

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
CCTL0 = CCIE; // CCR0 interrupt enabled
TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK/8, upmode
CCR0 = 10000; // 12.5 Hz
P1OUT &= 0x00; // Shut down everything
P1DIR &= 0x00;
P1DIR |= BIT0 + BIT6; // P1.0 and P1.6 pins output the rest are input
P1REN |= BIT3; // Enable internal pull-up/down resistors
P1OUT |= BIT3; //Select pull-up mode for P1.3
P1IE |= BIT3; // P1.3 interrupt enabled
P1IES |= BIT3; // P1.3 Hi/lo edge
P1IFG &= ~BIT3; // P1.3 IFG cleared
_BIS_SR(CPUOFF + GIE); // Enter LPM0 w/ interrupt
while(1) //Loop forever, we work with interrupts!
{}

}
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{}
// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
P1OUT ^= BIT6; // Toggle P1.6
P1IFG &= ~BIT3; // P1.3 IFG cleared
}

ok I got it to work where I can toggle the output on and off from the input.  Now I just need to debounce the switch where the input signal is there for greater than two seconds and have the interrupt reset after 60 seconds.  !

 

Changing the bitwise to make it high I think will work better also.  I do not want it to toggle back and forth, just go high, reset after time. 

 

Thanks for the help! 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...