yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
MSPM0 Smart Robot Car📖
1.Quick Start Guide
  • 1. Assembly Videos
  • 2. Quick Start Videos
  • 3. Battery charging
  • 4. Notes
2.Introduction to the MSPM0 Car
  • 1.About MSPM0
  • 2.Development board interface description
3.Development environment setup and usage
  • 1.CCS Theia development
  • 2.MDK Arm development
  • 3.Uniflash burning
  • 4.External crystal oscillator configuration
  • 5.Project Migration
4.MSPM0 basic course
  • 1. LED light control (GPIO)
  • 2. Buzzer Control (GPIO)
  • 3. Button Control (EXTI)
  • 4. Serial Port (UART)
  • 5. Voltage Detection (ADC)
  • 6. Temperature Detection (ADC)
  • 7. Independent Watchdog (WWDG)
  • 8. Window Watchdog (WWDG)
  • 9. Timer (TIM)
  • 10. Breathing LED (PWM)
  • 11. I2C Communication (I2C)
  • 12. External Flash (SPI)
  • 13. Internal Flash (Flash)
  • 14. DMA
  • 15. FreeRTOS
5.Sensor basic course
  • 1.Servo control
  • 2.Ultrasonic servo PTZ basic use
  • 3.Motor PID control
  • 4.OLED display photosensitive value
  • 5.Infrared avoid sensor
  • 6.1 Infrared line tracking sensor-8 channel infrared tracking sensor module
  • 6.2 Infrared line tracking sensor-4 channel infrared tracking sensor module
  • 7.Infrared remote control
  • 8.Ultrasonic ranging
  • 9.RGB light drive
  • 10.MPU6050 raw data acquisition
  • 11.MPU6050 data fusion
  • 12.K210 vision recognition module
  • 13.K230 vision recognition module
6.Smart car course
  • 1.1 Car line tracking-8 channel infrared tracking sensor module
  • 1.2 Car line tracking-4 channel infrared tracking sensor module
  • 2.1 Drawing a circle-8 channel infrared tracking sensor module
  • 2.2 Drawing a circle-4 channel infrared tracking sensor module
  • 3.Ultrasonic following
  • 4.Ultrasonic avoid
  • 5.Ultrasonic avoid(Servo PTZ)
  • 6.Infrared sensor avoid
  • 7.Light following
  • 8.Gyroscope calibration straight-line walk
  • 9.Infrared remote control
  • 10.Autonomous driving car
7.Vision application course
  • 1.K210 autonomous driving
  • 2.K210 color tracking
  • 3.K210 handwritten digit action
  • 4.K210 color response
  • 5.K210 road sign indication action
  • 6.K210 following machine code
  • 7.K210 QR code command
  • 8.K230 vision line tracking
  • 9.K230 color tracking
  • 10.K230 machine code tracking
  • 11.K230 QR code command
  • 12.K230 autonomous avoid
  • 13.K230 license plate tracking
  • 14.K230 face tracking
  • 15.K230 gaze direction tracking
  • 16.K230 palm tracking
  • 17.K230 target tracking
  • 18.K230 human body tracking
  • 19.K230 OCR character recognition
8.Extended application course (Sold separately)
  • 1.Voice interaction module communication
  • 2.Voice interaction control
  • 3.K230 road sign indication action(Voice)
  • 4.K230 color response(Voice)
  • 5.K230 gesture control(Voice)
  • 6.K230 rock-paper-scissors(Voice)
  • 7.8-channel grayscale color line tracking
  • 8.Bluetooth remote control
  • 9.K210 Scenario-based autonomous driving
  • 10.K230 Scenario-based autonomous driving
Download
  • Code
  • SCH
  • 3D Model File
  • MSPM0 Data Sheet
  • Voice firmware
  • Hardware interface manual
Download ZIP

Welcome to MSPM0 Smart Robot Car repository

9. Timer (TIM)

Timer

TimerI. Learning ObjectivesII. Timer IntroductionIII. Hardware SetupIV. Experiment StepsV. Experiment Phenomenon

I. Learning Objectives

  1. Learn the basic usage of the MSPM0G3507 development board timer.
  2. Implement timed LED status toggling.

II. Timer Introduction

Timer is a very important peripheral in microcontrollers, used for timing and generating periodic interrupts. The core principle of a timer is to record time through an internal counter. The counter increments by one every 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 LED, reading sensor data, controlling motors, 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 is based on the timer divider being 8-bit). TIMG can select BUSCLK, MFCLK, LFCLK as clock sources, can divide the clock by up to 8, and then passes through an 8-bit prescaler, finally becoming the timer's counting clock.

img

  1. Up or Down Counting Mode

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

  1. Update Event

  An update event is triggered when the counter overflows or underflows and starts a new counting cycle. The update event can trigger DMA requests to update timer operating parameters in time when the next counting cycle starts, which is especially suitable for real-time control.

III. Hardware Setup

The MSPM0G series has a total of 7 timers, 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, followed by general-purpose timers.

img

IV. Experiment Steps

If the project needs to execute specific tasks periodically or repeatedly, timer configuration becomes particularly important. The following will introduce how to set up a timer to trigger an interrupt every 2 seconds and implement LED status toggling in the interrupt service function, thereby achieving the effect of LED on for 2 seconds and off for 2 seconds.

Open the SYSCONFIG configuration tool, open the empty project in the SDK in KEIL or migrate the LED example source code. Here we use the LED source code as an example

First, we open the graphical configuration tool through the sysconfig tool to add timer configuration

image-20251020122832745

Enable timer interrupt

image-20251020122857382

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

image-20241119193346732

Select Yes to All in the pop-up window

image-20241119143728060

Similarly, we also need to confirm whether the ti_msp_dl_config.c and ti_msp_dl_config.h files are updated. Compile directly, and the compilation will automatically update to keil. If not updated, we can also copy the file contents from SYSCONFIG.

After saving the generated files, add the following code

xxxxxxxxxx
#include "ti_msp_dl_config.h"
​
int main(void)
{
    // System configuration initialization
    SYSCFG_DL_init();
​
    /* Enable device TimerG interrupt */
    NVIC_EnableIRQ(TIMER_0_INST_INT_IRQN);
​
    /* Enable sleep on exit */
    DL_SYSCTL_enableSleepOnExit();
​
    /* Set LED initial state to indicate timer counter is enabled */
    DL_GPIO_clearPins(LED_PORT, LED_MCU_PIN);
​
    /* Start TimerG counter */
    DL_TimerG_startCounter(TIMER_0_INST);
​
    // Main loop - wait for interrupt
    while (1) {
        __WFI(); //  Wait for interrupt
    }
}
​
/**
 * @brief Timer interrupt service function
 */
void TIMER_0_INST_IRQHandler(void)
{
    // Check and process timer interrupt
    switch (DL_TimerG_getPendingInterrupt(TIMER_0_INST)) {
        // Zero count interrupt
        case DL_TIMER_IIDX_ZERO:
            // Toggle LED status every 2 seconds
            DL_GPIO_togglePins(LED_PORT, LED_MCU_PIN);
            break;
        
        // Other interrupt cases
        default:
            break;
    }
}

V. Experiment Phenomenon

After flashing the program, the MCU indicator LED (red) is on for two seconds and off for two seconds

Window Watchdog (WWDG)
Breathing LED (PWM)

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/中文