CH32V003F4P6 Tutorial - Part 3 - Basic Timer and PWM

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ม.ค. 2025

ความคิดเห็น • 8

  • @CuriousScientist
    @CuriousScientist  2 หลายเดือนก่อน +1

    *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.
    I used gemini-1.5-pro-exp-0827 on rocketrecap dot com to summarize the transcript.
    Cost (if I didn't use the free tier): $0.03
    Input tokens: 21321
    Output tokens: 713

  • @AbhijithAJ-s2q
    @AbhijithAJ-s2q หลายเดือนก่อน +1

    Any videos/tutorials on usart_interupts?

    • @CuriousScientist
      @CuriousScientist  หลายเดือนก่อน

      It will be part 5. It will be released in about two weeks (Nov 26 to be precise). 😎

    • @CuriousScientist
      @CuriousScientist  หลายเดือนก่อน +1

      The video is published: th-cam.com/video/LcPfUYLC9L4/w-d-xo.html

  • @Architector120
    @Architector120 หลายเดือนก่อน

    Hi, I have a variant of the CH32V003A4M6 MCU, which does not have the PD2 pin exposed on his package... how to reassign timer 1 to alternate pin?

    • @CuriousScientist
      @CuriousScientist  หลายเดือนก่อน

      Hi! Watch the video. It is shown line by line how to assign the timer to a specific pin.

    • @Architector120
      @Architector120 หลายเดือนก่อน

      @@CuriousScientist no you don't!... the code only shows the assignment to a port PD2... and as i understand it, it works because TIM1_CH1 is on PD2 by default!
      and according to the datasheet i need to somehow remap TIM1_CH1 to an available port on my microcontroller via (AFIO_PCFR1) remap register using bits ((7, 6)TIM1_RM)

    • @CuriousScientist
      @CuriousScientist  หลายเดือนก่อน

      Ah, you mean that way. T1CH1 is not available on the SOP16 package as you said. Solution → Use another timer channel, for example, T1CH2 seems to be available on PA1...