yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
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

7. PWM Breathing Light

PWM Breathing Light

PWM Breathing Light1. Learning ObjectivesPWM PrinciplePWM Basic Parameters2. Hardware Setup3. Experiment Steps1. Open SYSCONFIG Configuration Tool2. PWM Parameter Configuration3. Write Program4. Compile4. Program Analysis5. Experimental Phenomena

 

1. Learning Objectives

  1. Learn the principle of PWM breathing light.

  2. Output a PWM signal through TIMG6_C0 to control the LED indicator light, making it brighten from dim to bright and then dim from bright to dim, similar to human breathing.

 

PWM Principle

PWM stands for Pulse Width Modulation. It is a very effective technique for digitally controlling analog circuits using microprocessor digital outputs. With its advantages of simple control, flexibility, and good dynamic response, it has become the most widely used control method in power electronics technology. Its application areas include measurement, communication, power control and conversion, motor control, servo control, dimming, switching power supplies, and even some audio amplifiers. Therefore, learning PWM has very important practical significance.

Actually, we can understand it this way: PWM is a method of digitally encoding analog signal levels using high-resolution counters. By using a high-resolution counter, the duty cycle of a square wave is modulated to encode a specific analog signal level. The PWM signal remains digital because at any given moment, the full-scale DC supply is either completely on (ON) or completely off (OFF). The voltage or current source is applied to the analog load through a repetitive pulse sequence of on (ON) or off (OFF). When on, the DC supply is connected to the load; when off, the supply is disconnected. As long as the bandwidth is sufficient, any analog value can be encoded using PWM.

PWM Basic Parameters

PWM is pulse width modulation with two very important parameters: frequency and duty cycle.

  • Frequency: The frequency of PWM is the reciprocal of the entire period, which is the number of times the PWM signal repeats per unit time. It represents how many signal cycles are completed per second. Higher frequency means shorter signal period and more changes.

  • Duty Cycle: Duty cycle refers to the proportion of high level in one cycle. Usually expressed as a percentage. It reflects the "width" of the PWM signal, which is the ratio of the high-level duration to the entire period time. Higher duty cycle means higher average output voltage.

 

2. Hardware Setup

Earlier we introduced that the MSPM0G series has 7 timers in total, which can be divided into 2 types: general-purpose timers (TIMG) and advanced control timers (TIMA). The PWM function is implemented based on the timer. From the user manual, you can learn that MSPM0G3519 has 7 timers. Which timer has PWM functionality needs to be referred to the pin description in the data manual. Each PWM channel corresponds to a pin on the microcontroller. This pin is not uniquely fixed. There may be one or two pins corresponding to the same channel. For example, TIMG_C0 corresponds to PA5 and PA12, meaning both PA5 and PA12 pins can be configured as timer channel 0. When using, you can choose either one for configuration.

image-20241121090906375

image-20241121090948832

This case uses LED1's PB2 pin, configured as timer 6 channel 0, to generate a PWM signal controlling the light on/off.

image-20241121104433286

PWM has two modes. One is edge-aligned PWM, which means the timer uses down-counting mode. The output channel outputs high level when the timer count starts. When the count value equals the output channel's compare value (CC0 and CCP0, CC1 and CCP1 in the figure), the output channel outputs low level. This continues until the timer count reaches 0, completing one cycle of pulse output.

img

The other mode is center-aligned mode, which means the timer uses up/down counting mode. The output channel outputs low level when the timer starts. It toggles the level once when the timer counts up and down to the equal compare value of the output channel.

img

3. Experiment Steps

Achieve breathing light effect through driving PWM signal. By changing the PWM signal's duty cycle, you can adjust the current flowing through the LED, thereby achieving LED brightness gradient. Generally, the human eye does not perceive obvious flickering at refresh rates above 80Hz because the flickering cannot be detected at high frequencies. Larger duty cycle means brighter LED; smaller duty cycle means dimmer LED. Therefore, at a fixed frequency, adjusting the duty cycle controls the LED brightness, thereby achieving the breathing light effect. This case will use the onboard LED light (PB2) to achieve breathing light effect, gradually brightening then gradually dimming.

1. Open SYSCONFIG Configuration Tool

Create a new empty project empty in CCS.

image-20241126182939655

image-20241126183128934

Find and open the empty.syscfg file in the left workspace of CCS.

image-20241127152938881

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

image-20241128114627045

2. PWM Parameter Configuration

Here set channel 0 to 4kHz frequency, 0% duty cycle PWM. Period count value is 1000, compare value is also set to 1000. This way, starting from 1000 and counting down, whenever it encounters 1000, the PWM state toggles once.

image-20241128115936436

Parameter description:

Name: Custom name. Here set to PWM_LED

PWM Profiles: Configure PWM template. Default is fine.

Timer Clock Source: Timer clock source. Select BUSCLK (bus clock), default frequency is 32MHz.

Timer Clock Divider: Timer clock divider. Set to 8 divider.

Calculated Timer Clock Source: Shows the clock frequency after division.

Timer Clock Prescale: Timer prescaler. We configured TIMG6, a 16-bit timer, which supports prescaler. No prescaler set here.

Calculated Clock Freguency (Hz): Shows the frequency after division and prescaling.

PWM Period Count: PWM period count value. Here set to 1000.

Calculated PwM Frequency(Hz): Software automatically calculates PWM frequency, showing 4000.

Start Timer: Whether to start timer. Checked here. Timer PWM output starts on power-up.

PWM Mode: PWM mode. Configured as Edge-aligned Down Counting edge-aligned mode with down-counting mode.

PWM Channel(s): PWM channel. Configured to only enable channel 0.

Enable Channel Complimentary Output: Whether to enable channel complementary output. Not enabled here.

Initial Value: Default output state of PWM channel. Configured as default low level output.

Counter Compare Value: PWM compare value. Set to 1000, meaning PWM duty cycle setting range is 0-999.

Desired Duty cycle (%): PWM duty cycle. Default duty cycle 0 is used here.

Actual Duty cycle (%): Shows the actual duty cycle automatically calculated by software.

Invert Channel: Whether to enable inverted output. Not enabled here.

Channel Update Mode: Channel update mode. Configured as Capture Compare value has immediate effect - update immediately when compare value is reached.

image-20241121154537499

LED1's control pin is PB2. PB2 has timer 6 channel 0, so select TIMG6, PB2/50 here.

image-20241121154851704

We have already assigned PB2 of LED1 to PWM. It cannot be used for GPIO peripheral anymore and needs to be removed. Currently, only one button configuration remains in the GPIO peripheral in the example.

Save the configuration in the .syscfg file using the shortcut key Ctrl+S.

3. Write Program

In the empty.c file, write the following code

​x
#include "ti_msp_dl_config.h"

volatile unsigned int delay_times = 0;

//Precise millisecond delay with tick timer
void delay_ms(unsigned int ms)
{
    delay_times = ms;
    while( delay_times != 0 );
}

int main(void)
{
    int i = 0;

    SYSCFG_DL_init();

    while (1)
    {

        // Breathing light gradually brightens
        for (i = 0; i <= 999; i++)
        {
            // Set LED Brightness
            DL_TimerG_setCaptureCompareValue(PWM_LED_INST,i,GPIO_PWM_LED_C0_IDX);
            delay_ms(1);  // Delay to control the speed of brightness change
        }
        // Breathing light dimming process
        for (i = 999; i > 0; i--)
        {
            // Set LED Brightness
            DL_TimerG_setCaptureCompareValue(PWM_LED_INST,i,GPIO_PWM_LED_C0_IDX);
            delay_ms(1);  // Delay to control the speed of brightness change
        }
    }
}

//Tick timer interrupt service function
void SysTick_Handler(void)
{
    if( delay_times != 0 )
    {
        delay_times--;
    }
}

4. Compile

image-20241127155238783

Compilation was successful. You can now download the program to the development board.

4. Program Analysis

  • empty.c

After initializing the hardware, enter the breathing light loop. Use PWM signal duty cycle to control LED brightness. The breathing light gradually brightens and gradually dims using two for loops, adjusting the PWM duty cycle from 0 to 999 and then from 999 to 0 progressively. delay_ms(1) sets the brightness change interval to 1 millisecond. You can control the breathing light change speed by adjusting the delay function parameter.

5. Experimental Phenomena

After the program is downloaded, you can see the LED light slowly brighten and dim, showing a breathing light effect.

image-20241121155739168

Timer
ADC Acquisition

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