-1

Quick question. How do I set an interrupt for 10 seconds and a minute with this specific interrupt? I have tried using the counter below but it does not work. As this program stands, it interrupts 1 second. I would usually go to the professor in times like these, however, he is in Japan.... .... ....

#include <msp430.h>

#define RedLED BIT0
#define GreenLED BIT6

#define RedLEDToggle (P1OUT ^= RedLED)
#define GreenLEDToggle (P1OUT ^= GreenLED)



unsigned int i = 0;

void main(void)
{

WDTCTL = WDTPW|WDTHOLD;


 P1DIR = RedLED|GreenLED;
 P1OUT = RedLED|GreenLED;

 TACTL = TASSEL_2|ID_3|MC_3|TAIE;

 TACCR0 = 62500;



 _enable_interrupts();

 LPM1;
}

#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer_A(void){

if (int i == 10)
{
    switch(TAIV)
         {
          case 0x02: break;
          case 0x04: break;
          case 0x0A: RedLEDToggle|GreenLEDToggle;;
          break;
         }
}
else
{
i++;
}
}
CL.
  • 173,858
  • 17
  • 217
  • 259
TheJr
  • 51
  • 7
  • You are using #define constants to initial registers without telling us what those #define constants are so the help I can provide to the exact problem is limited. Is it only interrupting once and never again? Is it continuous at every 1 second? Do you want 1 interrupt at some common time base and then count up until your higher time? – engineer14 Jul 18 '16 at 05:32
  • Perhaps a long shot, but doesn't TI have a dedicated forum to ask (programming) related questions on their microcontrollers? I don't think there are many dedicated embedded programmers here with the exact knowledge of the MSP430 controller. – Daan Timmer Jul 18 '16 at 06:32
  • I will answer this one as well, as the other question has been put on hold. You may want to delete one (or both) and start again with a single question. – kfx Jul 18 '16 at 13:56
  • @DaanTimmer there are 200+ followers on the msp430 tag and from those surely there are quite a few active users. – kfx Jul 18 '16 at 14:00

1 Answers1

1

To achieve 10 second interrupt interval, you need to apply input divider to the timer. It is not possible to achieve 1 minute without peripheral support (but you can implement that with a software counter).

The problem is that msp430 microcontrollers have 16-bit registers, not capable of holding numerical values larger than 65535. Using low-frequency oscillator running at 32768 Hz (as is typical - you don't provide any details about the hardware clock sources of your system, if they have a different frequency, please mention that) the register overflows once every 2 seconds unless an input divider is applied. The maximum value of input divider on MSP430x2xxx family MCUs is 8, so it's not possible to set a hardware timer more than 8 * 2 = 16 seconds in the future. Refer to MSP430x2xxx family user's guide for further details.

This code calls the interrupt once 10 seconds:

#include <msp430.h>

#define RedLED BIT0
#define GreenLED BIT6

#define RedLEDToggle (P1OUT ^= RedLED)
#define GreenLEDToggle (P1OUT ^= GreenLED)

// 10 seconds, assuming 32768 Hz ACLK source and divider 8
#define TIMER_PERIOD (10u * (32768 / 8))

void main(void)
{
    WDTCTL = WDTPW | WDTHOLD;

    P1DIR = RedLED | GreenLED;
    P1OUT = RedLED | GreenLED;

    // reset timer A config (not strictly needed)
    TACTL = TACLR;

    // ACLK as clock source, divider 8, continuous mode, interrupt enabled
    TACTL = TASSEL_1 | ID_3 | MC_2 | TAIE;

    // set the period
    TACCR1 = TIMER_PERIOD;

    // enable capture/compare interrupts for CCR1
    TACCTL1 = CCIE;

    _enable_interrupts();

    LPM1;
}

#pragma vector=TIMER0_A1_VECTOR

__interrupt void Timer_A(void)
{
    switch (TAIV) {
    case TA0IV_TACCR1:
        // CCR1 interrupt
        RedLEDToggle;
        GreenLEDToggle;
        // set the time of the next interrupt
        TACCR1 += TIMER_PERIOD;
        break;
    }
}
kfx
  • 8,136
  • 3
  • 28
  • 52