STM32 timer--general timer output with dead zone complementary PWM

Publisher:幸福家园Latest update time:2018-06-29 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Function: Use a common timer to output 2 complementary PWMs with adjustable frequency, adjustable duty cycle and adjustable dead zone.

Principle: As shown in the figure below, the counting mode is the center alignment mode


It can be seen that the CH3 high level interval is centered when the counter counts to 4 and extends to both sides.

As for CH4, since its output polarity is opposite, it extends to both sides with 0 as the center.

CCR3 becomes smaller and the duty cycle increases

CCR4 becomes larger, and the duty cycle increases

The sum of CCR3 and CCR4 is ARR

Note that in this mode the counter count period = ARR, which is different from the PWM mode: count period = ARR + 1

Refer to the following figure in the STM32 reference manual:




Therefore, the code and calculation formula are sorted out as follows:

void TIM3_PWMShiftInit(void)  

{  

    float Duty = 0;

    u16 ARR = 0, PSC = 0, CH3Ccr = 0, CH4Ccr = 0, DT = 0;

    u32 Frequency = 0;

 

    TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;  

    GPIO_InitTypeDef GPIO_InitStruct;  

    TIM_OCInitTypeDef TIM_OCInitStruct;

    Frequence = 125000; //Frequency, unit: Hz

    Duty = 0.5; //Duty cycle

    DT = 1000; //Dead time, unit: ns

    //Center alignment mode, only when CNT counts to CCR flips once, the frequency is halved compared to PWM mode, and ARR does not need to be -1

    ARR = 36000000/(PSC+1)/Frequence; //Set to 125KHz

    CH3Ccr = ARR*Duty - DT/2/((PSC+1)*13.89f); //TIM 72M, one cycle is about 13.89ns

    CH4Ccr = ARR - CH3Ccr; //CH4 and CH3 are ARR

 

    /************************TIM3 GPIO configuration************************ *****/  

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);  

      

    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;  

    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;  

    GPIO_InitStruct.GPIO_Speed ​​= GPIO_Speed_50MHz;  

  

    GPIO_Init(GPIOB,&GPIO_InitStruct);    

      

    /**********************Initialize TimBase structure****************************/  

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);

      

    TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;  

    TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_CenterAligned1;  

    TIM_TimeBaseInitStruct.TIM_Period = ARR;         

    TIM_TimeBaseInitStruct.TIM_Prescaler = PSC;       

      

    TIM_TimeBaseInit(TIM3, &TIM_TimeBaseInitStruct);  

    TIM_TimeBaseInit(TIM1, &TIM_TimeBaseInitStruct);  

    /**********************Initialize TIM3 OC structure****************************/  

    TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM2;  

    TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_Low;  

    TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;  

    TIM_OCInitStruct.TIM_Pulse = CH3Ccr;            

    TIM_OC3Init(TIM3,&TIM_OCInitStruct);                                                       

    TIM_OCInitStruct.TIM_Pulse = CH4Ccr;  

    TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_High;

    TIM_OC4Init(TIM3,&TIM_OCInitStruct);  

    TIM_Cmd(TIM3, ENABLE);

}  

The oscilloscope waveform is as follows:




The program sets the frequency to 125K, the duty cycle to 50%, and the dead time to 1000ns. The waveform displayed by the oscilloscope is consistent with this.

Change the frequency to 125K, duty cycle to 25%, dead time to 500ns, and the waveform is as follows:





At 125K, the duration of high level with 25% duty cycle should be 2us, minus the dead zone of 0.5us = 1.5us,

From the figure above, we can see that the high level duration is about 1.5us, which is in line with the program setting.


Reference address:STM32 timer--general timer output with dead zone complementary PWM

Previous article:Advanced Timer 1 of STM32F103 with dead zone complementary output configuration
Next article:STM32F107 advanced timer TIM1 uses complementary PWM output

Recommended ReadingLatest update time:2024-11-22 20:30

Use WinCE's precise timing function to output pwm signals to control the servo
The FL2440 board only has TOUT0 and TOUT1 extended pins, and TOUT0 is multiplexed with GPB0, which is connected to the buzzer. So when TOUT0 is used to output the pwm signal, the buzzer will keep beeping. Because the Wince system uses Timer1 as the system timer, using TOUT1 to output the pwm signal will cause the syst
[Microcontroller]
LED Street Light Single Lamp PWM Dimming Controller LT2206-P User Manual
1. Overview LT2206-P LED street lamp controller is the LED street lamp switch control execution component of the street lamp remote integrated monitoring system. It adopts high-performance power line carrier modulation technology, has 7-level relay function and automatic routing function, as well as commu
[Power Management]
LED Street Light Single Lamp PWM Dimming Controller LT2206-P User Manual
Using MCU + PWM to decode WAV live vocals
This program is an example provided by the 51hei single-chip microcomputer development board . It uses the single-chip microcomputer to decode wav real-person sound music and output it using the PWM method. The p2.2 port of the development board is connected to a buzzer, but the effect of the buzzer is too poor. In use
[Microcontroller]
Simulation of permanent magnet synchronous motor control system—Simulink model of PWM comparator
Functionality of PWM Comparator The three-phase two-level inverter used in this series of articles is still used as the control object. The figure below shows the waveform of the three-phase two-level inverter with sinusoidal wave modulation (SPWM). The input is a three-phase sine wave signal. The tr
[Embedded]
Simulation of permanent magnet synchronous motor control system—Simulink model of PWM comparator
PIC microcontroller CCP pulse (PWM) output
#include pic.h //This program is used to make the CCP1 module generate a PWM waveform with a resolution of 10 bits and a duty cycle of 50%. The frequency is calculated according to PWM_WIDE. Proteus simulation initializes the subroutine through the PWM working mode of //CCP1 (same setting for CCP2) module (why can't
[Microcontroller]
What is Pulse Width Modulation (PWM) or Pulse Frequency Modulation
What is Pulse Width Modulation (PWM) or Pulse Frequency Modulation (PFM) The so-called pulse width modulation method is a method in which the switching frequency remains unchanged during the entire working process, while the switch-on time is changed as required. The so-called pulse frequency modula
[Analog Electronics]
What is Pulse Width Modulation (PWM) or Pulse Frequency Modulation
Multi-output LED driver with patented control technique eliminates audible PWM noise
The ALT80600 LED driver for small size LCD backlighting uses Allegro 's innovative patented Pre-Emptive Boost (PEB) control technology in a small 4x4 package to achieve ultra-high true PWM dimming contrast while eliminating the normally audible noise. ALT80600 Technical advantages The PEB control technology used
[Automotive Electronics]
Multi-output LED driver with patented control technique eliminates audible PWM noise
STC12C5A60S2 MCU PWM Program
Two header files main.c #include REG51.H #include intrins.h #define U8 unsigned char #define U16 unsigned int void DelayMs(U8 ms); void PWM_clock(U8 clock); void PWM_start(U8 module,U8 mode); //////////////////////// Delay subroutine/////////////////////////////// void DelayMs(U8 ms) //ms level delay of stc10f seri
[Microcontroller]
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号