MG32F10x Standard Peripherals Firmware Library
|
*************** (C) COPYRIGHT 2020 - 2023 megawin Technology *************** * @file TIM/TIM_PWM_Output/readme.txt * @author megawin Application Team * @version V0.1.10 * @date 05-January-2023 * @brief Description of the TIM_PWM_Output example. ****************************************************************************** * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, MEGAWIN SHALL NOT BE HELD LIABLE FOR ANY DIRECT, * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM * THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. ******************************************************************************
This example shows how to configure the TIM peripheral in PWM (Pulse Width Modulation) mode.
The system clock works at 96Mhz and is generated through PLL configuration. The PLL clock source is an external 8Mhz crystal oscillator. The frequency division ratio of APB1 is 1, and the frequency division ratio of APB2 is 1.
The TIM1CLK frequency is set to SystemCoreClock(Hz),The TIM3CLK frequency is set to SystemCoreClock / 2 (Hz), to get TIM1 counter clock at 96 MHz,
the Prescaler is computed as following:
-Prescaler=(TIM1CLK / TIM1 counter clock)- 1
The TIM1is running at 96MHz:TIM1 Frequency = TIM1 counter clock /(ARR + 1)
= 96MHz / 0xFFFF = 1.46KHz
The TIM1->CCR1 register value is equal to 0x7FFF,so the TIM1 Channel 1 generates a PWM signal with a frequency equal to 1.46KHz and a duty cycle equal to 50.0:
TIM1 Channel 1 duty cycle=(TIM1->CCR1 / TIM1->ARR + 1)* 100 = 50.0%
The TIM1->CCR2 register value is equal to 0x3FFF,so the TIM1 Channel 2 generates a PWM signal with a frequency equal to 1.46KHz and a duty cycle equal to 37.5%:
TIM1 Channel2 duty cycle =(TIM1->CCR2 / TIM1->ARR + 1)* 100 = 37.5%
The TIM1->CCR3 register value is equal to 0x1FFF,so the TIM1 Channel 3 generates a PWM signal with a frequency equal to 1.46KHz and a duty cycle equal to 25.0%:
TIM1 Channel3 duty cycle =(TIM1->CCR3 / TIM1->ARR + 1)* 100 = 25.0%
The TIM1->CCR4 register value is equal to 0x0FFF,so the TIM1 Channel 4 generates a PWM signal with a frequency equal to 1.46KHz and a duty cycle equal to 12.5%:
TIM1 Channel4 duty cycle =(TIM1->CCR4 / TIM1->ARR + 1)* 100 = 12.5%
The PWM waveform can be displayed using an oscilloscope.
In order to make the program work, you must do the following :
Run the example