yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
MSPM0G3507 Development Board📖
1. Introduction to MSPM0
  • 1. Introduction to MSPM0
2. 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
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-K230 Vision Application Module
  • 1.k230 color recognition
  • 2.k230 barcode recognition
  • 3.k230 QR code recognition
  • 4.k230Apriltag code recognition
  • 5.k230DM 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.k230OCR 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.Prerequisites for K210 as a coprocessor
  • 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 casenew
  • 1.Autonomous driving car
  • 2.Vehicle-mounted balance ball motion control system
Download
  • Code
  • Hareware_Info
  • Software_Tools
  • Communication Protocol
Download ZIP

Welcome to MSPM0G3507 Development Board repository

7. PWM breathing light

7.PWM breathing light

PWM breathing light

PWM breathing light1. Learning objectivesPWM principleBasic PWM Parameters2. Hardware Construction3. Experimental steps1. Open the SYSCONFIG configuration tool2. PWM parameter configuration3. Write the program4. Compile4. Program Analysis5. Experimental phenomenon

1. Learning objectives

  1. Learn the principle of PWM breathing light.
  2. Output a PWM signal through TIMG6_C0 to control the LED indicator from dark to bright, and then from bright to dark, similar to human breathing.

PWM principle

PWM is the abbreviation of Pulse Width Modulation, which means pulse width modulation in Chinese. It is a very effective technology that uses the digital output of the microprocessor to control the analog circuit. Its advantages such as simple control, flexibility and good dynamic response make it the most widely used control method in power electronics technology. Its application fields include measurement, communication, power control and conversion, motor control, servo control, dimming, switching power supply, and even some audio amplifiers. Therefore, learning PWM has very important practical significance.

In fact, we can also understand it this way. PWM is a method of digitally encoding the level of analog signals. Through the use of high-resolution counters, the duty cycle of the square wave is modulated to encode the level of a specific analog signal. PWM signals are still digital because at any given moment, the full-scale DC power supply is either fully present (ON) or completely absent (OFF). The voltage or current source is applied to the analog load in a repetitive sequence of pulses that are either on (ON) or off (OFF). On is when the DC power supply is applied to the load, and off is when the power supply is disconnected. As long as the bandwidth is sufficient, any analog value can be encoded using PWM.

Basic PWM Parameters

PWM is pulse width modulation, which has two very important parameters: frequency and duty cycle.

  • Frequency: The frequency of PWM is the inverse of the entire cycle, that is, the number of times the PWM signal is repeated per unit time. It indicates how many signal cycles are completed per second. The frequency determines the rate at which the PWM signal changes. The higher the frequency, the shorter the signal cycle and the more times it changes.
  • Duty Cycle: The duty cycle refers to the proportion of the high level in a cycle. It is usually expressed as a percentage. It reflects the "width" of the PWM signal, that is, the ratio of the duration of the high level part to the total cycle time. The duty cycle determines the average output voltage of the signal. The larger the duty cycle, the higher the average output voltage.

2. Hardware Construction

We introduced earlier that the MSPM0G series has a total of 7 timers, which can be divided into 2 types, general timer (TIMG) and advanced control timer (TIMA). The PWM function is implemented on the basis of the timer. From the user manual, we can know that MSPM0G3507 has 7 timers. Which timer has PWM function needs to refer to the pin description of the data manual. Each PWM channel corresponds to a pin of the microcontroller. This pin is not unique and fixed. One or two pins may correspond to the same channel. For example, TIMG_C0 corresponds to PA5 and PA12, which means that both PA5 and PA12 pins can be configured as channel 0 of the timer. When using it, we can choose any one of them for configuration.

image-20241121090906375

image-20241121090948832

This case uses the PB2 pin of LED1, configured as channel 0 of timer 6, to generate a PWM signal to control the on and off of the light.

image-20241121104433286

There are two modes of PWM. One is edge-aligned PWM, which refers to the down-counting mode used by the timer. The output channel will output a high level when the timer starts counting. When the count value is the same as the comparison value of the output channel (CC0 and CCP0, CC1 and CCP1 in the figure), the output channel will output a low level until the count value of the timer counts to 0, completing a cycle of pulse output.

img

The other mode is center-aligned mode, which refers to the up-down counting mode of the timer. The output channel will output a low level at the start of the timer, and flip the level once when the timer counts up and counts down twice to reach the comparison value of the output channel.

img

3. Experimental steps

By driving the PWM signal to achieve the breathing light effect, by changing the duty cycle of the PWM signal, the current flowing through the LED can be adjusted, thereby achieving a gradual change in the brightness of the LED. Generally speaking, the human eye does not have a noticeable flickering sensation for refresh frequencies above 80Hz, because flickering cannot be detected at higher frequencies. The larger the duty cycle, the brighter the LED; the smaller the duty cycle, the dimmer the LED. Therefore, when the frequency is fixed, the brightness of the LED can be controlled by adjusting the duty cycle, thereby achieving a breathing light effect. In this case, the onboard LED light (PB2) will be used to achieve the breathing light effect, which gradually lights up and then gradually turns off.

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 column.

image-20241118204833195

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-20241121104126259

2. PWM parameter configuration

Here, set channel 0 to 4kHz frequency, 0% duty cycle PWM, cycle count value to 1000, and compare value to 1000. In this way, count down from 1000, and the PWM state will flip every time 1000 is encountered.

image-20241121121649151

Parameter description:

Name: custom name. Here it is set to PWM_LED

PWM Profiles: configure PWM template, select the default one.

Timer Clock Source: the clock source of the timer, select BUSCLK (bus clock), the default frequency is 32MHz.

Timer Clock Divider: Set the timer clock divider to 8 division.

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

Timer Clock Prescale: Timer pre-allocation. We configure TIMG6, a 16-bit timer, which supports pre-division. No pre-division is set here.

Calculated Clock Freguency (Hz): Displays the frequency after division and pre-division.

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

Calculated PwM Frequency(Hz): The software automatically calculates the PWM frequency, which is displayed as 4000.

Start Timer: Whether to start the timer. Check it here to start the timer PWM output on power-on.

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

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

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

Initial Value: The default output state of the PWM channel. Configured as the default low-level output.

Counter Compare Value: The comparison value of PWM. Configured as 1000, that is, the setting range of the PWM duty cycle is 0-999.

Desired Duty cycle (%): The duty cycle of PWM. The default duty cycle of 0 is used here.

Actual Duty cycle (%): Displays the actual duty cy

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