PWM In fact, the output pulse width is adjustable ( That is duty cycle adjustment ) A square wave signal based on Wavelet Transform , signal frequency The register is automatically reloaded ARR The value of , The duty cycle is determined by the comparison register CCR The value of .
Here's the picture at the bottom PWM Output duty cycle adjustment diagram

* pwm The output frequency is constant , What has changed is that CCR The value in the register , A change in this value will result in pwm Change of duty cycle of output signal . The duty cycle is the ratio of the high level time to the cycle in a cycle .
* pwm Two modes of change
pwm1 and pwm2 The two patterns are similar in usage , The difference is the polarity of the output level .

pwm Mode according to counter CNT restart at , It can be divided into edge alignment mode and center alignment mode .
<>STM32F103 Of PWM calculation
stm32f103 The system clock of is 72MHz 72MHz = 72000KHz 72000KHz/(PSC+1)=100kHz Here I put it PSC Set to 719
100KHz/(arr+1)= frequency Here we are arr Set to 99 that is pwm The wave will be 1khz Frequency of operation
<>stm32f103 Of pwm Duty cycle adjustment code
We set it to pwm by 20% Wavelength of void TIM3_PWM_Init(void) { GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef
TIM_OCInitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); //
Enable GPIOB Clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); // to configure IO pattern
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode =
GPIO_Mode_AF_PP;// Multiplexed push pull multiplexed output GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure); // initialization TIM3 Count mode of , Frequency division value , Reloading value, etc
TIM_TimeBaseStructure.TIM_Period = 99; //ARR TIM_TimeBaseStructure.TIM_Prescaler
= 719; //PSC TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure
.TIM_CounterMode = TIM_CounterMode_Up;// Up count mode TIM_TimeBaseInit(TIM3, &
TIM_TimeBaseStructure); /*TIM3_CH1 The output duty cycle is 20% Of PWM Timing configuration of wave */ TIM_OCInitStructure.
TIM_OCMode= TIM_OCMode_PWM1;// Select timer mode :TIM Pulse width modulation mode 1 TIM_OCInitStructure.
TIM_OutputState=TIM_OutputState_Enable;// Compare output enable TIM_OCInitStructure.TIM_Pulse =
20; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;// Output polarity :TIM High output polarity
TIM_OC1Init(TIM3, &TIM_OCInitStructure); TIM_OC1PreloadConfig(TIM3,
TIM_OCPreload_Enable);// Enable TIM3 stay OC1 Preload register on TIM_Cmd(TIM3, ENABLE);// Enable TIM3 Clock }
That's change pwm The duty cycle only needs to be changed TIM_Pulse The value of ok It's over

©2019-2020 Toolsou All rights reserved,
Huawei 2021 session Hardware Engineer Logical post (FPGA) Super detailed surface !!!Vue-element-admin upgrade ui edition virtual machine VMware Download and install the most detailed tutorial !C++ Move constructor and copy constructor sound of dripping water java Backstage interview pygame Realize full screen mode and adjustable window size mysql Database setting character set configuration modification my.ini file (windows)30 What's the experience of being a junior programmer at the age of 20 C++ Multithreading programming ( Summary of common functions and parameters )python_ cherry tree