PIC microcontroller PWM PWM principle

Publisher:温柔花香Latest update time:2018-05-13 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.


Reference address:PIC microcontroller PWM PWM principle

Previous article:PIC microcontroller achieves x ms/1s accurate delay
Next article:PIC microcontroller watchdog

Recommended ReadingLatest update time:2024-11-15 13:45

Improve PWM accuracy of stm32f103c8t6
I just switched from 51, and I don't want to invest too much money, so I chose the bluePill board from Taobao, which is probably the cheapest (7.6 yuan including shipping). I did some preliminary tests on the clock, timer, interrupt, DMA, etc. I was quite satisfied with the ADC, but I was confused by the DAC (this chi
[Microcontroller]
Improve PWM accuracy of stm32f103c8t6
Application of inverter control circuit based on UC3637 dual PWM controller
  Design Points   Based on the characteristics, circuit composition and basic functions of UC3637, the inverter control circuit can be specifically designed. The following only introduces the design methods of several key circuit units.   Dead time td   The inverter main circuit usually has several basic forms such as
[Power Management]
Application of inverter control circuit based on UC3637 dual PWM controller
AVR MCU Phase Correction PWM Timer 0 Generation Mode Test Program
/*AVR phase correction PWM timer 0 generation mode*/ /*PWM wave generation mechanism is that TCNT0 of timer 0 counts from 0 to 255, and then from 255 to 0 continuously. When TCNT0=OCR0 during the count from 0 to 255, a low level appears on the OC0 pin. */ /*When TCNT0=OCR0 at 255-0, a high level appears on the OC0 pin
[Microcontroller]
STM32 TIM1 F1 four-channel fully remapped PWM configuration
void TIM1_PWM_Init(u16 arr,u16 psc) {   GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure; TIM_OCInitTypeDef  TIM_OCInitStructure;   RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);//    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE , ENABLE);   RCC_APB2PeriphClockCmd(RCC_APB2P
[Microcontroller]
Learning 3 of timer based on stm32f103zet6 (timer generates 4-way PWM)
Timer TIM3 generates four PWM wave outputs. First, let me introduce PWM, which is a very effective technology for controlling analog circuits using the digital output of a microprocessor. To put it simply, it is the control of pulse width. 1. The main function of this program is quite simple: span style="font-size:
[Microcontroller]
51 single chip microcomputer - use PWM to control the speed of DC motor
- What is PWM PWM (Pulse Width Modulation) controls the output voltage by changing the pulse width and controls the output frequency by changing the cycle. (A pulse can be understood as a high or low level change of the IO port) - How does PWM regulate the speed of a DC motor? When using PWM to adjust the speed of
[Microcontroller]
Is it difficult to change LED brightness linearly? PWM duty cycle can help you
Duty cycle is the ratio of power-on time to power-on cycle, and is often used to adjust more precise parameters. A typical application is the adjustment of the brightness of LED lighting equipment. This article will introduce how to ensure that the brightness of the LED changes linearly by adjusting the duty cycle of
[Power Management]
Is it difficult to change LED brightness linearly? PWM duty cycle can help you
Advantages and Disadvantages of PWM LED Dimming Technology Using AC Power Supply
PWM dimming is to connect a MOS switch tube in series with the LED load, and the anode of this string of LEDs is powered by a constant current source. Then a PWM signal is added to the gate of the MOS tube to quickly switch this string of LEDs, thereby achieving dimming. In this article, we will briefly talk about t
[Power Management]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号