yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
Wheeled Chassis Kit📖
0.Chassis installation course
  • Installation Video-1
  • Installation Video-2
  • Installation Video-3
1.4-channel motor drive module tutorials
Motor introduction and commissioning
  • 1. Motor introduction and usage
  • 2.PC host
IIC communication
  • For Arduino
  • For ESP32
  • For JetsonNANO
  • For MSPM0
  • For PICO2
  • For RDK X5
  • For RPi5
  • For STM32
USART communication
  • For Arduino
  • For ESP32
  • For JetsonNANO
  • For MSPM0
  • For PICO2
  • For RDK X5
  • For RPi5
  • For STM32
2.Kinematic analysis
  • Kinematic Analysis of Two-wheel Drive Vehicles
  • Kinematic Analysis of Four-wheel Drive Vehicles
3.MSPM0 chassis tutorials(MSPM0G3507/MSPM0G3519)
MSPM0 Basic Course
  • 1. Introduction to MSPM0
Development environment construction
  • 01.CCS Theia Development
  • 02.MDK Arm Development
  • 03.UniFlash Downloader
  • 04.DAP-LINK download program
  • 05.Program simulation and debugging
  • 06.Engineering transplantation
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)
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)
MSPM0 Robot Expansion Board Example
  • 1. Introduction to MSPM0 robot expansion board
  • 2. Customize buttons
  • 3. Drive the buzzer
MSPM0 Sensor extension information
  • 01.3-channel tracking
  • 02.4-channel tracking
  • 03.8-channel tracking
  • 04.CCD tracking
  • 05.Electric PTZ control
  • 06.2.4G handle control
  • 07.Servo ultrasonic avoid
  • 08.Bluetooth remote control
  • 09.K210-Automatic Driving
  • 10.K210-Color follow
  • 11.K210-Number recognition
  • 12.K210-Color reaction
  • 13.K210-Road signs
  • 14.K210-Machine code following
  • 15.K210-QR code recognition
  • 16.K230-Visual tracking
  • 17.K230-Color tracking
  • 18.K230-Color response
  • 19.K230-Road sign recognition
  • 20.K230-Machine code tracking
  • 21.K230-QR code recognition action
  • 22.K230-Autonomous avoid
  • 23.K230-License plate tracking
  • 24.K230-Face tracking
  • 25.K230-Gaze direction tracking
  • 26.K230-Palm tracking
  • 27.K230-Target tracking
  • 28.K230-Human body tracking
  • 29.K230-OCR character recognition action
4.STM32 chassis tutorials
  • 01.3-channel tracking
  • 02.4-channel tracking
  • 03.8-channel tracking
  • 04.CCD tracking
  • 05.Electric PTZ control
  • 06.2.4G handle control
  • 07.Servo ultrasonic avoid
  • 08.Bluetooth remote control
  • 09.K210-Automatic Driving
  • 10.K210-Color follow
  • 11.K210-Number recognition
  • 12.K210-Color Reaction
  • 13.K210-Road signs
  • 14.K210-Machine code following
  • 15.K210-QR code recognition
  • 16.K230-Visual tracking
  • 17.K230-Color tracking
  • 18.K230-Color response
  • 19.K230-Road sign recognition
  • 20.K230-Machine code tracking
  • 21.K230-QR code recognition action
  • 22.K230-Autonomous avoid
  • 23.K230-License plate tracking
  • 24.K230-Face tracking
  • 25.K230-Gaze direction tracking
  • 26.K230-Palm tracking
  • 27.K230-Target tracking
  • 28.K230-Human body tracking
  • 29.K230-OCR character recognition action
5.Expand course
  • 1.Autonomous driving car
  • 2.Vehicle-mounted balance ball motion control systemnew
Download
  • Code
  • 3D_Model_File
Download ZIP

Welcome to Wheeled Chassis Kit repository

2. System delay

System Delay

System Delay1. Learning ObjectivesPrinciple of Tick TimerThe role of delay2. Hardware Construction3. Experimental steps1. Open the SYSCONFIG configuration tool2. Tick timer configuration3. Write the program4. Compile4. Program Analysis5. Experimental phenomenon

1. Learning Objectives

  1. Learn the basic use of the pins of the MSPM0G3507 motherboard.
  2. Understand the usage of the tick timer.

Principle of Tick Timer

The tick timer is a commonly used hardware timer used to generate fixed-cycle interrupts or trigger timing operations. Its basic working principle is to count the main clock (MCLK) to achieve precise time intervals.

The SysTick timer is a standard timer built into the Cortex-M0 processor. As a 24-bit down counter, it has an automatic reload function and can mask system interrupts. All controllers based on the M0 core are equipped with a SysTick timer, which makes it easier to port programs between different devices. The SysTick timer is usually used in the operating system to provide the necessary clock beats for task scheduling, play the role of a "heartbeat", and ensure that the system executes tasks on time. Since all M0 core chips contain SysTick timers, the program does not need to reconfigure the timer during porting, and the porting difficulty is lower than that of ordinary timers.

In the system clock configuration, RCU provides the external clock of the Cortex system timer (SysTick) through MCLK. By default, the frequency of MCLK is 32MHz. By setting the SysTick control and status registers, the timer status can be controlled or read. For detailed information about the system clock, please refer to the clock tree section in the user manual.

Clock tree:

image-20241119173600015

Default clock path in the project:

img

The working mode of the SysTick timer is: after setting the initial value and enabling, the count value decreases by 1 every time a system clock cycle passes. When the counter reaches 0, SysTick will automatically reload the initial value and continue counting, and set the internal COUNTFLAG flag to 1, triggering an interrupt (provided that the interrupt is enabled).

The role of delay

The delay function is a function used to introduce artificial delay in the program. Its main function is to suspend the program execution within a specified time period. In simple terms, the role of the delay function is to wait, which actually means waiting for a period of time before executing the next code.

  • Hardware response waiting: Many hardware devices require a certain amount of time to complete operations or stabilize. For example, after sending an initialization command to a display screen, if you start sending display data immediately, display anomalies may occur. Delay can give the hardware enough time to complete initialization and ensure normal operation.
  • Timed task implementation: Delay can help implement operations at fixed time intervals. For example, an automatic door controlled by a microcontroller checks every 5 seconds whether the infrared sensor detects an obstacle. If not detected, the door remains closed; if detected, the door opens and remains for 2 seconds before automatically closing.
  • User interaction optimization: In user interaction scenarios, delay can achieve a better experience. For example, when a button is pressed, the "anti-shake" function is realized through delay to avoid multiple triggers caused by mechanical vibration. In addition, in the switching of the status indicator light, the delay is used to control the frequency of on and off, making the light flashing smoother and easier to observe.

2. Hardware Construction

This course does not require additional hardware equipment, and can directly use the onboard LED lights on the MSPM0G3507 motherboard. In the previous course, we used inaccurate delay. This course uses tick timer to achieve accurate delay.

We set up two LED user lights on the motherboard, and users can DIY their functions. The following takes LED1 as an example.

MSPM0G3507 main control diagram

image-20241118203957884

LED part schematic diagram

image-20241118204017413

3. Experimental steps

1. Open the SYSCONFIG configuration tool

Open the blank project empty in the SDK in KEIL.

image-20241118204605335

Open after selecting, open the empty.syscfg file in the keil interface, when the empty.syscfg file is open, then select to open the SYSCONFIG GUI interface in the Tools bar.

image-20241118204833195

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

image-20241119171733735

2. Tick timer configuration

The tick timer uses MCLK for timing, and MCLK is 32MHz, which means that the time it takes to count once is 1÷32,000,000 = 0.00000003125 S. Assuming that we set the value to be counted to 32000, the time it takes to count 32000 numbers is: 32000 x 0.00000003125 = 0.001 S = 1MS. So if we want to set a 1ms tick timer, we set the count value of the tick timer to 32000.

image-20241119172045173

Parameter Description:

Initialize Period: Initial timer period.

Period (ln McLk Cycles): Set the period count value, here we set it to 32000.

Calculated Period: The time spent counting. The software will automatically calculate this value.

Enable SysTick Interrupt: Whether to enable the tick timer interrupt.

Interrupt Priority: Select the interrupt priority. Here the highest priority interrupt is selected.

Enable SysTick And start Counting: Whether to enable the tick timer and start counting.

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

image-20241119174906393

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 there is no update, we can also copy the file content in SYSCONFIG.

3. Write the program

After configuring the tick timer, we also need to manually write the interrupt service function of the tick timer. Because we have enabled the interrupt of the tick timer, when the count value of the tick timer decreases from the set initial value to 0, an interrupt will be triggered, and the interrupt service function will be automatically executed after the trigger. The interrupt service function name corresponding to each interrupt is usually fixed and cannot be modified at will, otherwise the interrupt service function will not be entered correctly. The specific name of the interrupt service function can be found in the startup_mspm0g350x_uvision.s file of the project, which lists the interrupt service function names corresponding to each interrupt source.

image-20241119175344974

In the empty.c file, write the following code

​x
#include "ti_msp_dl_config.h"
​
volatile unsigned int delay_times = 0;
​
//搭配滴答定时器实现的精确ms延时 Accurate ms delay with tick timer
void delay_ms(unsigned int ms)
{
        delay_times = ms;
        while( delay_times != 0 );
}
​
int main(void)
{
​
    SYSCFG_DL_init();
​
    while (1)
    {
        //LED引脚输出高电平 LED pin outputs high level
        DL_GPIO_setPins(LED1_PORT, LED1_PIN_2_PIN);
        delay_ms(1000);
        //LED引脚输出低电平 LED pin outputs low level
        DL_GPIO_clearPins(LED1_PORT, LED1_PIN_2_PIN);
        delay_ms(1000);
    }
}
​
void SysTick_Handler(void)
{
        if( delay_times != 0 )
        {
                delay_times--;
        }
}

4. Compile

Click the Rebuild icon. The following prompt appears, indicating that the compilation is complete and there are no errors.

image-20241119150803274

image-20241119150902489

4. Program Analysis

  • empty.c
xxxxxxxxxx
volatile unsigned int delay_times = 0;
​
//搭配滴答定时器实现的精确ms延时 Accurate ms delay with tick timer
void delay_ms(unsigned int ms)
{
        delay_times = ms;
        while( delay_times != 0 );
}
​
int main(void)
{
​
    SYSCFG_DL_init();
​
    while (1)
    {
        //LED引脚输出高电平 LED pin outputs high level
        DL_GPIO_setPins(LED1_PORT, LED1_PIN_2_PIN);
        delay_ms(1000);
        //LED引脚输出低电平 LED pin outputs low level
        DL_GPIO_clearPins(LED1_PORT, LED1_PIN_2_PIN);
        delay_ms(1000);
    }
}
​
void SysTick_Handler(void)
{
        if( delay_times != 0 )
        {
                delay_times--;
        }
}

Define a global variable delay_times to record the remaining milliseconds of the delay.

delay_ms(): Implements precise millisecond-level delay.

main(): After initializing the system, call DL_GPIO_setPins to specify the pin output high and low levels to control the on and off of the LED light.

SysTick_Handler(): Decrement delay_times in the interrupt. If delay_times is non-zero, it will be reduced by 1 each time the interrupt occurs. When it is reduced to 0, the delay is completed and the while loop in delay_ms() exits.

5. Experimental phenomenon

After the program is downloaded, you can see that the LED1 light on the MSPM0 development board is on for 1s and off for 1s, repeating the cycle.

Turn on the LED light
Button control

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
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文