Tinkering TI MSP430F5529

WDTA as an Interval TimerWDTA as an Interval TimerWDTA as an Interval Timer

As mentioned before, WDTA can be used like an ordinary interval timer if watchdog function is not needed. This is strictly a secondary property of WDTA and there are some limitations of it. Still I would thank TI for this dexterity because sometimes in big projects people tend to run out of timers.

Code Example

#include "driverlib.h"

void GPIO_init(void);
void WDTA_init(void);

#pragma vector = WDT_VECTOR
__interrupt void WDT_A_ISR (void)
{
    GPIO_toggleOutputOnPin( GPIO_PORT_P1,
                            GPIO_PIN0);

    GPIO_toggleOutputOnPin( GPIO_PORT_P4,
                            GPIO_PIN7);
}

void main(void)
{
    WDT_A_hold(WDT_A_BASE);

    GPIO_init();
    WDTA_init();

    while(1)
    {
    };
}

void GPIO_init(void)
{
    GPIO_setAsOutputPin(GPIO_PORT_P1,
                        GPIO_PIN0);

    GPIO_setDriveStrength(GPIO_PORT_P1,
                          GPIO_PIN0,
                          GPIO_FULL_OUTPUT_DRIVE_STRENGTH);

    GPIO_setAsOutputPin(GPIO_PORT_P4,
                        GPIO_PIN7);

    GPIO_setDriveStrength(GPIO_PORT_P4,
                          GPIO_PIN7,
                          GPIO_FULL_OUTPUT_DRIVE_STRENGTH);

    GPIO_setOutputHighOnPin(GPIO_PORT_P1,
                            GPIO_PIN0);

    GPIO_setOutputLowOnPin(GPIO_PORT_P4,
                           GPIO_PIN7);
}

void WDTA_init(void)
{
    WDT_A_initIntervalTimer(WDT_A_BASE,
                            WDT_A_CLOCKSOURCE_SMCLK,
                            WDT_A_CLOCKDIVIDER_512K);

    SFR_clearInterrupt(SFR_WATCHDOG_INTERVAL_TIMER_INTERRUPT);

    SFR_enableInterrupt(SFR_WATCHDOG_INTERVAL_TIMER_INTERRUPT);

    WDT_A_start(WDT_A_BASE);

    __enable_interrupt();
}

Hardware Setup


Explanation

The demo here is a simple LED toggler. On-board LEDs are used. UCS clock settings are untouched and so all clocks are in their defaults. Firstly, WDTA is stopped to prevent a software reset.

WDT_A_hold(WDT_A_BASE);

Configuration of WDTA in interval mode is nothing different from WDTA in watchdog mode. We have to specify WDTA clock source and its divider. Here the clock source is SMCLK and the divider is 512000. Since we are using default clock setting, SMCLK is running at about 1 MHz speed. Thus, dividing this speed with 512000 results in approximately 500 ms interval. We cannot access WDTA counter and so we will have to use interrupt method when using WDTA in interval mode. Thus, at every 500 ms an interrupt is triggered.

void WDTA_init(void)
{
    WDT_A_initIntervalTimer(WDT_A_BASE, WDT_A_CLOCKSOURCE_SMCLK, WDT_A_CLOCKDIVIDER_512K);

    SFR_clearInterrupt(SFR_WATCHDOG_INTERVAL_TIMER_INTERRUPT);

    SFR_enableInterrupt(SFR_WATCHDOG_INTERVAL_TIMER_INTERRUPT);

    WDT_A_start(WDT_A_BASE);

    __enable_interrupt();
}

Inside the interrupt, on-board LED states are toggled.

#pragma vector = WDT_VECTOR
__interrupt void WDT_A_ISR (void)
{
    GPIO_toggleOutputOnPin( GPIO_PORT_P1, GPIO_PIN0);

    GPIO_toggleOutputOnPin( GPIO_PORT_P4, GPIO_PIN7);
}

There is nothing done in the main loop and so it is empty.

Demo

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

Related Posts

12 comments

Leave a Reply to Shawon Shahryiar Cancel reply

Your email address will not be published. Required fields are marked *