Jump to content
bikems

MSP430F5529LP timer interrupt prevents external interrupt

Recommended Posts

Thanks in advance for helping.  New to microcontrollers, not fluent in C so would prefer higher level language like Energia.

Using an MSP430F5529LP to drive a stepper motor, creating a square wave using timer A interrupt handler.  That works fine, but would like an additional input to the MSP to increase/decrease the speed.  In the following code, the external interrupt is detected when the TA0CCR0 assignment is commented out.  With the line included, the external interrupt is not recognized.  Thanks again.

 

 

 

int TESTPIN1 = P1_5;
int state = LOW;

void setup()
{
  // put your setup code here, to run once:
  pinMode(P1_6,OUTPUT); // step motor clock output
  pinMode(GREEN_LED,OUTPUT);
  digitalWrite(GREEN_LED, state);
  pinMode(TESTPIN1, INPUT_PULLUP);

  
  // Configuration word
  // Bits 15-10: Unused
  // Bits 9-8: Clock source select: set to SMCLK (16MHz)
  // Bits 7-6: Input divider: set to 1
  // Bits 5-4: Mode control: Count up to TACCRO and reset
  // Bit 3: Unused
  // Bits 2: TACLR : set to initially clear timer system
  // Bit 1: Enable interrupts from TA0
  // Bit 0: Interrupt (pending) flag : set to zero (initially)
  TA0CTL=0b0000001000010010; 
  TA0CCR0=1200; // Set TACCR0 = 2000 to generate a 1ms timebase @ 16MHz with a divisor of 8
  TA0CCTL0=BIT4; // Enable interrupts when TAR = TACCR0

  attachInterrupt(digitalPinToInterrupt(TESTPIN1), TestISR, CHANGE);

}

void loop()
{
  // put your main code here, to run repeatedly:

}
#pragma vector=TIMER0_A0_VECTOR
__interrupt  void timerA0ISR(void)
{
// Timer A0 Interrupt service routine
  static int msCount=0;// Count milliseconds to allow a 1 second pulse
  static int state=0;  // Remember state for toggling purposes
  msCount++;
  if (msCount >= 18)
  {
    msCount = 0;
    digitalWrite(P1_6,state); // Write stepper output
    state=~state;             // toggle state
  }
}

void TestISR()
{
  state = !state;
 digitalWrite(GREEN_LED, state);

Share this post


Link to post
Share on other sites

Im a little rusty, but i thought you cant service interrupts within interrupts and if an interrupt comes through while running an interrupt it would ignore it. Ill have something tomorrow when i go over my old code.

One thought is step through the code and watch what it does.

Share this post


Link to post
Share on other sites

I didn't realize this was energia.......

and cant answer Energia code questions.

There is something i did notice.

There is no #pragma vector=  for your Pin interrupt. I dont know how this affects energia.

I use in my code something like this to test.

 

// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
  P1OUT ^= BIT0;                            // P1.0 = toggle
  P1IFG &= ~BIT4;                          // P1.4 IFG cleared
}

 

 

 

Share this post


Link to post
Share on other sites
On 11/19/2018 at 4:24 PM, jsolarski said:

Im a little rusty, but i thought you cant service interrupts within interrupts and if an interrupt comes through while running an interrupt it would ignore it.

This is my understanding as well. Placing interrupts inside interrupts is best left to the experts. I am not one of them.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×