1. What is PWM
What is PWM? Professionally speaking, it is pulse width modulation. In layman's terms, it is the continuous output of high and low levels. For example, the microcontroller outputs a high level for 40ms, then a low level for 60ms, and then continuously and periodically outputs high and low levels alternately. This is a typical PWM wave. The high level output time of 40ms is the legendary pulse width, and 40ms+60ms=100ms is the PWM cycle. Assuming that we set the cycle to 100ms, we can increase or decrease the high level time according to our needs. For example, the high level output time is increased to 80ms, then the low level time becomes 20ms. It is also possible to reduce the high level output time to 20ms, then the low level time becomes 80ms. This is pulse width modulation, and what is adjusted is the high level time. The proportion of time occupied by the high level (pulse width) in the cycle is called the duty cycle. Expressed in mathematical formulas, the high level time/cycle time = duty cycle.
2. PWM implementation method
How do we make the microcontroller output PWM waves? There are two ways: one is to use I/O output directly, and the other is to use the module.
2.1 Using I/O port to output PWM
If your microcontroller does not have a PWM output function module, you can write a program to output PWM waves yourself. Because PWM is not just high and low levels. An I/O plus a timer is easy to do for any microcontroller.
2.2 Using the module to output PWM
PIC microcontrollers have a PWM output module. Using the module to output PWM is actually simpler, more convenient and more accurate than using I/O to output PWM.
3. The role of PWM
What can PWM be used for? The more typical application of PWM is LED dimming and motor speed control. How does PWM dim and control? It is easy to understand. Take LED dimming as an example. If the LED is powered on all the time, the LED is the brightest. If the LED is not powered off, the LED is not bright. If the LED is powered on and off repeatedly in a very short period of time, the LED will appear bright, but at a low brightness.
If the LED is bright when the microcontroller outputs high level, then the longer the high level output time in the PWM wave, the brighter the LED will be, and vice versa.
Previous article:PIC microcontroller achieves x ms/1s accurate delay
Next article:PIC microcontroller watchdog
Recommended ReadingLatest update time:2024-11-15 13:45
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
- Intelligent Control Technology of Permanent Magnet Synchronous Motor (Written by Wang Jun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
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
- Why software-defined vehicles transform cars from tools into living spaces
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Optimizing EMC and Efficiency in High Power DC/DC Converters Part 1
- Common Problems in RF Circuit Design
- Telink Microelectronics Matter Development Guide (I): The Past and Present of Matter
- F280049C CAN_ex3 Issue
- [Factory Visit Live Replay] Arrived at the destination - TE Qingdao Factory
- Useful tutorial | How to quickly splice PCB data at unconventional angles?
- Class AB Audio Amplifier
- Max30102 heart rate blood oxygen sensor measures heart rate problem 2
- Xunwei IMX6 development board non-device tree source code compilation environment construction (I)
- Execution process before keil main