How to achieve variable frequency PWM output for STC microcontroller (with PCA function)? Many friends are still using timers to do variable frequency PWM. Here I will introduce how to use hardware PWM and design PWM under the frequency division base of timer 0.
First, let's look at the CMOD register. Here we mainly focus on CPS0, CPS1, and CPS2. These three bits control the selection of the PCA count pulse source. For the PWM function, it is to select the frequency. First, you can choose 6 fixed frequency divisions. As you can see from the picture, they are 1, 2, 4, 6, 8, and 12 system frequency divisions. We need to make a variable frequency PWM, so we need to select mode 2 and select the overflow of timer 0 as the system frequency division base.
Then, let's see how to calculate and implement frequency division. Here we need the calculation rules in the picture above. Here I give an example to illustrate, for example, the crystal oscillator of our microcontroller uses 12MHZ, and we need to achieve a frequency of 300HZ. What if we get it?
First, if we use the fixed frequency division of CMOD, we can find that no matter it is 1, 2, 4, 8, or 12, the frequency divided is not 300HZ. So here we can see the benefit of using timer 0 as the frequency division base.
We continue to calculate, 12MHZ needs to be converted to 300HZ, then according to the above figure, first we need to determine the PCA clock input frequency, according to the formula 300*256=76800HZ, this value is the PCA clock input frequency we need. Now the question is, how do we convert 12MHZ to 76.8KHZ, 12000KHZ/76.8KHZ=156.25, this 156.25 is the frequency division base, and this frequency division base is set by our timer overflow parameter, which means that when our timer counts 156.25 overflows, the frequency division base can be 156.25, so we set the count start value of timer 0 to 65536-156=65380, corresponding to TH0=0XFF, TL0=0X64.
Well, here is the introduction of how to calculate PWM to achieve any frequency we need under timer 0. If we want to dynamically change the frequency, we can dynamically adjust the counting base of timer 0 through communication (actually adjusting the frequency division base), and the frequency can be changed. In addition, it is explained that the timer 0 here does not need interrupts, and the timer is not used to generate PWM, but as a frequency division base!
Previous article:Use of STM8L15x series DAC
Next article:STC15 MCU 6-channel dedicated PWM
Recommended ReadingLatest update time:2024-11-23 07:48
- Popular Resources
- Popular amplifiers
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- STC32G Series MCU Technical Reference Manual
- Microcontroller Principles and Application Project Tutorial - Based on STC15W4K32S4 Series Microcontroller
- Raspberry Pi Development in Action (2nd Edition) ([UK] Simon Monk)
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Develop a membership card management system
- How to measure the quality of quartz crystal
- TI Learning Points Exchange Gift Headphones
- What are the practical application scenarios of 5G industrial applications?
- Adaptive radio improves spectrum efficiency of wireless connections (reposted)
- Why do voice chips have malfunctions?
- The difference between electronic ABS and mechanical ABS
- consult
- MSP430 timer is set to 1S
- Wi-Fi in 2025: It might be watching your every move