What is Pulse Width Modulation?
Let's first bring out a concept: Pulse Width Modulation (English: Pulse Width Modulation, abbreviated as PWM), abbreviated as PWM, is a technology that converts analog signals into pulses. Generally, the period of the pulse after conversion is fixed, but the duty cycle of the pulse will change according to the size of the analog signal.
Then everyone will definitely ask, what is duty cycle? In fact, duty cycle refers to the ratio of the effective level to the entire output signal. What role does PWM play in practical applications? Let's take the breathing light as an example to demonstrate the specific usage and practical role of PWM.
Detailed program explanation
First, configure the timer and set it to interrupt once every 100us. At the same time, in the main function, we change the duty cycle of PWM (the value of OUT here) from 0 to 100, and then from 100 to 0. The 50MS delay controls the frequency of the light on and off. You can also use buttons to control the duty cycle of PWM to achieve brightness control.
In the timer interrupt function, we set a count bit, which increases from 0 to 100. When the count bit is greater than the set duty cycle OUT, it outputs a high level (P1=0xFF), and when it is less than the set value OUT, it outputs a low level (P1=0X00). Then the frequency of the PWM wave is 1s/(100us*100)=100Hz, (1s divided by each interrupt time*count).
At this time, the output of the IO port is actually a waveform composed of high and low levels as shown in the figure. One high level plus one low level is one cycle.
Effect display
In actual operation, the LED light gradually becomes brighter and then gradually dims. If you adjust the rate of change, you will have new discoveries. You can give it a try.
The above is the method of using the timer to generate PWM waves. Now many newer microcontrollers have built-in PWM outputs, such as stc12c5a60s2, stm32, etc. The configuration methods are different, but they can all achieve PWM output and control. PWM is a very common tool and has a wide range of applications in lighting and motor control. If you are not satisfied with a simple breathing light, you can also control the motor through a motor driver and use PWM to achieve motor speed regulation. I hope you can master the use of PWM through hands-on practice.
Previous article:How to decarbonize the smart factory
Next article:Learn PWM in a blink
- Popular Resources
- Popular amplifiers
- Red Hat announces definitive agreement to acquire Neural Magic
- 5G network speed is faster than 4G, but the perception is poor! Wu Hequan: 6G standard formulation should focus on user needs
- SEMI report: Global silicon wafer shipments increased by 6% in the third quarter of 2024
- OpenAI calls for a "North American Artificial Intelligence Alliance" to compete with China
- OpenAI is rumored to be launching a new intelligent body that can automatically perform tasks for users
- Arm: Focusing on efficient computing platforms, we work together to build a sustainable future
- AMD to cut 4% of its workforce to gain a stronger position in artificial intelligence chips
- NEC receives new supercomputer orders: Intel CPU + AMD accelerator + Nvidia switch
- RW61X: Wi-Fi 6 tri-band device in a secure i.MX RT MCU
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- MSP430 Program Library---SPI Synchronous Serial Communication
- 15 years of electric racing wind pendulum
- Last night’s “Friends Reunion Special”, youth!
- What is the principle behind adding an op amp to the sensor output to improve resolution and increase current capability?
- Newbie asks for help with Bluenrg lp programming problem
- The meaning of the pins in the chip manual
- Read the good book "Electronic Engineer Self-study Handbook" + Beginner's Guide to Mastery
- Problems with jtag downloader
- [Homemade] OLED full-screen watch, smooth playback of Badapple
- What changes will the high-reliability fully integrated automotive eCall switch bring to the automotive industry?