CH32V003F4P6 Tutorial - Part 3 - Basic Timer and PWM Summary
0:00 Introduction: The video covers timers and PWM functionality on the CH32V003F4P6 microcontroller.
0:45 Basic Timer Operation: Timers count up or down based on the system clock (48MHz in this case). The period is the inverse of the clock frequency (1/48MHz ≈ 20.83ns).
1:33 Timer Registers:
CNT (Counter): Stores the current count value.
ARR (Auto Reload Register): Defines the maximum count value before the timer resets to zero. It also determines the PWM period.
CCR (Capture Compare Register): Controls the PWM duty cycle, specifying when the PWM signal changes state.
5:08 PWM Frequency and Duty Cycle Formulas:
Frequency:Fsystem / ((Prescaler + 1) * (ARR + 1))
Duty Cycle:(CCR / (ARR + 1)) * 100%
7:57 Code Implementation: The video demonstrates timer and PWM configuration using MounRiver Studio.
9:26 Timer Initialization Function: A function TIM1_PWM_Init is created to initialize the timer with prescaler, auto-reload, and capture-compare values.
10:28 Enabling Clocks and GPIO: The code enables peripheral clocks for GPIO and Timer 1, then configures a GPIO pin (PA2) as an alternate function for PWM output.
13:19 Timer Configuration: The timer's time base and output compare modes are configured.
16:14 PWM Mode and Output: The output compare mode is set to PWM1, the output state is enabled, and the initial PWM output is set to high.
20:08 Setting PWM Frequency and Duty Cycle: An example shows setting a 1kHz PWM frequency with a 200ms period and 50% duty cycle by calculating the appropriate prescaler, ARR, and CCR values.
22:57 Dynamic PWM Control via USART: Code is added to receive prescaler, ARR, and CCR values from the serial port, allowing for real-time PWM adjustment.
34:18 Timer-Based Delay without Blocking: The video shows how to use a timer to create delays without using the blocking delay() function.
37:00 Calculating Timer Ticks for Delay: The timer is configured with a 9600 prescaler, giving a 200µs tick period. To achieve a 1-second delay, the timer is set to count up to 5000 (1 second / 200µs).
38:20 Timer Polling Function: A TIM1_Delay_Poll function checks if the timer count has reached the desired value, and then performs an action (toggling an LED in the example).
47:00 Conclusion: The video summarizes the basic timer and PWM concepts, provides links to additional resources, and encourages viewers to subscribe and support the channel.