yahboom
HomeTutorialsProduct
Solution
Blog
Online Store
About Us
EN/中文
Store
MSPM0G3519 Development Board📖
1. Introduction to MSPM0
  • 1. Introduction to MSPM0
2. Development environment construction
  • 1. CCS Theia Development
  • 2. MDK Arm Development
  • 3. UniFlash Downloader
  • 4. DAP-LINK download program
  • 5. Program Simulation and Debugging
  • 6. Engineering transplantation
3. Keil basic case
  • 1. Turn on the LED light
  • 2. System Delay
  • 3. Button Control
  • 4. External Interruption
  • 5. Serial Communication
  • 6. Timer
  • 7. PWM Breathing Light
  • 8. ADC Acquisition
  • 9. DMA Transfer
  • 10. Get MPU6050 data (I2C)
  • 11. LCD Display (SPI)
4. CCS basic case
  • 1. Turn on the LED light
  • 2. System Delay
  • 3. Button Control
  • 4. External Interruption
  • 5. Serial Communication
  • 6. Timer
  • 7. PWM Breathing Light
  • 8. ADC Acquisition
  • 9. DMA Transfer
  • 10. Get MPU6050 data (I2C)
  • 11. LCD Display (SPI)
5. MSPM0 Robot Expansion Board
  • 1. MSPM0 Robot Expansion Board Introduction
  • 2. Custom Buttons
  • 3. Drive Buzzer
6. MSPM0-K230Vision module application
  • 1. K230 Color Recognition
  • 2. K230 Barcode Recognition
  • 3. K230 QR Code Recognition
  • 4. K230 Apriltag Code Recognition
  • 5. K230 DM Code Recognition
  • 6. K230 Face Detection
  • 7. K230 Gaze Direction
  • 8. K230 Face Recognition
  • 9. K230 Human Body Detection
  • 10. K230 Fall Detection
  • 11. K230 Palm Detection
  • 12. K230 Gesture Recognition
  • 13. K230 OCR Character Recognition
  • 14. K230 Object Detection
  • 15. K230 Target Tracking
  • 16. K230 Self-learning Object Recognition
  • 17. K230 License Plate Recognition
7. MSPM0-K210Vision module application
  • 0. K210 Prerequisites For Making A Coprocessor - Must-see
  • 1. MSPM0_K210 Color Recognition
  • 2. MSPM0_K210 Barcode Recognition
  • 3. MSPM0_K210 QR Code Recognition
  • 4. MSPM0_K210 Mechanical Code Recognition
  • 5. MSPM0_K210 Face Detection
  • 6. MSPM0_K210 Facial Feature Detection
  • 7. MSPM0_K210 Mask Detection
  • 8. MSPM0_K210 Face Recognition
  • 9. MSPM0_K210 Object Detection
  • 10. MSPM0_K210 Self-study Classification
  • 11. MSPM0_K210 Handwritten Digit Recognition
8. Expansion case
  • 1. Autonomous Driving Car
  • 2. Vehicle-mounted Balance Ball Motion Control System
Download
  • Code
  • Hardware_Info
  • Software_Tools
Download ZIP

Welcome to MSPM0G3519 Development Board repository

6. Timer

Timer

Timer1. Learning ObjectivesTimerTimer Basic Parameters2. Hardware Setup3. Experiment Steps1. Open SYSCONFIG Configuration Tool2. Timer Parameter Configuration3. Write Program4. Compile4. Program Analysis5. Experimental Phenomena

 

1. Learning Objectives

  1. Learn the basic use of the timer on the MSPM0G3519 motherboard.

  2. Implement timed LED status toggle.

 

Timer

The timer is a very important peripheral in microcontrollers, used for timing and generating timed interrupts. The core principle of a timer is to record time through an internal counter. The counter increments by one for each machine cycle. When the counter reaches a preset value, it triggers an interrupt. The program can execute certain operations in the interrupt service routine, such as toggling an LED, reading sensor data, controlling a motor, etc.

Timer Basic Parameters

  1. Prescaler

The prescaler can divide the timer clock (TIMCLK) frequency by any value between 1 and 256 (1 to 256 based on the timer prescaler being 8-bit). TIMG can select BUSCLK, MFCLK, or LFCLK as the clock source. It can divide the clock by up to 8, then passes through an 8-bit prescaler to become the timer's counting clock.

img

  1. Up or Down Counting Mode

Up counting means the counter continuously counts up from 0 to the auto-reload value. Once the counter counts to the auto-reload value, it resets to 0 and continues counting up, generating an overflow event. Down counting means the counter continuously counts down from the auto-reload value to 0. Once the counter counts to 0, it resets to the auto-reload value and continues counting down, generating an underflow event.

  1. Update Event

An update event is triggered when the counter starts a new counting cycle due to overflow or underflow. Update events can trigger DMA requests to timely update the timer's operating parameters at the start of the next counting cycle, which is especially suitable for real-time control.

 

2. Hardware Setup

The MSPM0G series has 7 timers in total, which can be divided into 2 types: general-purpose timers (TIMG) and advanced control timers (TIMA). Different types of timers have different numbers of features. Generally, advanced timers have the most features, and general-purpose timers have fewer.

img

 

3. Experiment Steps

If a project needs to execute or repeatedly execute specific tasks at regular intervals, timer configuration is particularly important. The following will introduce how to configure the timer to trigger an interrupt every 1 second and implement LED status toggle in the interrupt service function, thereby achieving the effect of LED on for 1 second and off for 1 second.

1. Open SYSCONFIG Configuration Tool

Open the empty project from the SDK in KEIL.

image-20241118204605335

After selecting and opening it, open the empty.syscfg file in the KEIL interface. With the empty.syscfg file open, then open the SYSCONFIG GUI interface from the Tools menu.

image-20241118204833195

In SYSCONFIG, select MCU peripherals on the left, find the TIMER option and click to enter. Click ADD in TIMER to add a timer peripheral.

image-20241120200456599

2. Timer Parameter Configuration

In this case, Timer Clock Source selects BUSCLK-32MHz. Timer Clock Divider configures timer division, selecting divide by 8. Timer Clock Prescaler configures 100 prescaler, resulting in a timer frequency of 40KHz. Desired Timer Period sets the timer period to 1S. Timer Mode sets to periodic down-counting mode. Enable Interrupts enables the 0 overflow interrupt. LED GPIO configuration follows the LED light course.

image-20241120200910786

Click SAVE to save the SYSCONFIG configuration, then close SYSCONFIG and return to KEIL.

image-20241119193346732

Select Yes to All in the popup.

image-20241119143728060

We also need to confirm whether ti_msp_dl_config.c and ti_msp_dl_config.h files are updated. Simply compile, and the compilation will automatically update to KEIL. If not updated, we can also copy the file content from SYSCONFIG.

3. Write Program

In the empty.c file, write the following code

​x
#include "ti_msp_dl_config.h"

int main(void)
{
    SYSCFG_DL_init();
    // Clear the timer interrupt flag
    NVIC_ClearPendingIRQ(TIMER_0_INST_INT_IRQN);
    // Enable timer interrupt
    NVIC_EnableIRQ(TIMER_0_INST_INT_IRQN);

    while (1)
    {

    }
}

// The timer interrupt service function has been configured to a period of 1 second
void TIMER_0_INST_IRQHandler(void)
{
    // If a timer interrupt occurs
    switch( DL_TimerG_getPendingInterrupt(TIMER_0_INST) )
    {
        case DL_TIMER_IIDX_ZERO:// If it is 0 overflow interrupt
            // Flip the LED status
            DL_GPIO_togglePins(LED1_PORT, LED1_PIN_2_PIN);
            break;

        default:// Other timer interrupts
            break;
    }
}

4. Compile

Click the Rebuild icon. The following prompt indicates compilation is complete with no errors.

image-20241119150803274

image-20241119150902489

4. Program Analysis

  • empty.c

xxxxxxxxxx
// The timer interrupt service function has been configured to a period of 1 second
void TIMER_0_INST_IRQHandler(void)
{
    // If a timer interrupt occurs
    switch( DL_TimerG_getPendingInterrupt(TIMER_0_INST) )
    {
        case DL_TIMER_IIDX_ZERO:// If it is 0 overflow interrupt
            // Flip the LED status
            DL_GPIO_togglePins(LED1_PORT, LED1_PIN_2_PIN);
            break;

        default:// Other timer interrupts
            break;
    }
}

This is a timer interrupt service routine used to handle timer overflow interrupts and execute corresponding operations. Whenever the timer overflows, it toggles the status of an LED.

5. Experimental Phenomena

After the program is downloaded, you can see the LED light flashing according to the 1-second period configuration.

Serial Communication
PWM Breathing Light

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文