Page Links
MSP430F5529LP Hardware Library: TIMERA2

Overview

This webpage provides information about the TIMERA2 hardware library created for the MSP430F5529LP Development Board.


Contains


These files are optional. They only need to be included if the TIMERA2 functionality is desired. If they are not included, the TIMERA2 module will remain disabled.

When included, the MSP430F5529LP_TIMERA2.h/c files configure the TIMERA2 timer as an up-counter timer that generates an interrupt once per millisecond. This interrupt is not visible at the application level, but is used to increment a 16-bit and 32-bit tick counter, which are then used to provide various delay and timeout capabilities. The maximum timeout for the 16-bit functions is 65.535 seconds. The maximum timeout for the 32-bit functions is 49.7 days.


Public Definitions

None 

Public Functions

void 
    MSP430F5529LP_TIMERA2_Initialize(
        void); 
                    
 Calling this function initializes the timer A2 timer module as a 1 millisecond interval timer. The timer interrupt is enabled, but global interrupts are not. After all initialization is completed, the application must enable global interrupts using "__enable_interrupt();" to begin operation of the interval timer.  
void 
    delay(
        uint16_t ms); 
                    
 Calling this function pauses execution of the application until the requested timeout has expired. The maximum delay value is 65.535 seconds. Interrupts are not disabled during this delay, however no other application code will execute. 
uint16_t 
    GetTick(
        void); 
                    
 Calling this function returns the current value of the 16-bit tick counter. 
uint16_t 
    Elapsed(
        uint16_t start,
        uint16_t stop); 
                    
 Calling this function returns the difference (stop-start) of two 16-bit tick counter values. 
uint16_t 
    Expired(
        uint16_t duration, 
        uint16_t start,
        uint16_t stop); 
                    
 Calling this function determines whether the difference (stop-start) of two 16-bit tick counter values is greater than or equal to the target duration. If the difference is greater than or equal to the target duration, the function will return 1 (true), and will return 0 (false) otherwise.  
uint32_t 
    millis(
        void); 
                    
 Calling this function returns the number of milliseconds that have elapsed since the program execution started. This value will overflow after 49.7 days. 
uint32_t 
    GetTick32(
        void); 
                    
 Calling this function returns the current value of the 32-bit tick counter. 
uint16_t 
    Elapsed32(
        uint32_t start,
        uint32_t stop); 
                    
 Calling this function returns the difference (stop-start) of two 32-bit tick counter values. 
uint16_t 
    Expired32(
        uint32_t duration,
        uint32_t start,
        uint32_t stop); 
                    
 Calling this function determines whether the difference (stop-start) of two 32-bit tick counter values is greater than or equal to the target duration. If the difference is greater than or equal to the target duration, the function will return 1 (true), and will return 0 (false) otherwise.  

CAUTION: The MSP430 is a 16-bit processor, and 32-bit operations are not atomic! This means that an interrupt can occur in the middle of a 32-bit operation, and the results may be unpredictable. This is particularly dangerous for 32-bit values being updated by an ISR, such as the 32-bit tick counter in this library. The 32-bit functions provided in this library disable interrupts during 32-bit operations to maintain integrity. Although functions like millis(), GetTick32(), and Elapse32() are provided It is highly recommended that the Expired32() function provided be used to determine whether a 32-bit timer has expired, as opposed to performing these operations and comparisons in the application code.

Example Code

The following example code is provided to demonstrate the functionality of this library. All examples are presented as main.c files, which are available on GitHub. In order to build the example projects, follow the instructions here for how to create and configure a new project.

Example Summary Description
Using the TimerA2 blocking delay This example uses the TIMERA2 hardware library to generate a sequence of blocking delays that blink the LEDs. Blocking delays are very simple to use and understand, and can be useful for creating very simple programs quickly. They have a significant drawback however that they prevent the processor from performing other tasks while it waits for the delay to complete.
Requires: Only the MSP430F529LP development board.
Using the TimerA2 non-blocking delay This example uses the TIMERA2 hardware library to generate a state machine using non-blocking delays that blink the LEDs. The use of the non-blocking delays adds a little complexity to the program flow, however it is a very powerful foundation for creating large applications that can process many tasks simultaneously.
Requires: Only the MSP430F529LP development board.