STM32 || Configure Timer || Timer Prescaler, Counter period, Counter mode

Поділитися
Вставка
  • Опубліковано 4 лют 2025

КОМЕНТАРІ • 11

  • @incxxxx
    @incxxxx 9 місяців тому +1

    Very, very helpful. Thank you. But there is also one thing interesting for me. How connect TIM1 to pin, for example pin PA8. I would like to see signal on oscilloscope.

    • @steppeschool3629
      @steppeschool3629  9 місяців тому

      Thank you for your comment. But what do you mean by connecting the timer to pin? Like generating a PWM signal in a certain pin of the microcontroller?

    • @incxxxx
      @incxxxx 9 місяців тому

      @@steppeschool3629The frequency of the Nucleo MCU is 80MHz. How to see the signal of such frequency on the oscilloscope?

    • @incxxxx
      @incxxxx 9 місяців тому

      @@steppeschool3629 Just to see the output signal on pin PA1 of TIM2 having prescalar 72-1, ARR 65535, so I should see on the pin about 15kHz, but I see nothing. Do I have to make pwm on this pin or something more? Clock is ok 72MHz, Input Capture direct mode I have on Channel2 then I see pin PA1 is activated (green) on Pinout view - TIM2_CH2. So what more I shoud do???

    • @steppeschool3629
      @steppeschool3629  9 місяців тому

      Check this article on my website:
      www.steppeschool.com/pages/blog/stm32-pwm-stm32cubemx
      Hope this helps for you

  • @incxxxx
    @incxxxx 9 місяців тому +1

    In other words - the same what you obtain in SWV window (same kind of saw) I would like to see on the oscilloscope. What more I should do ?

    • @steppeschool3629
      @steppeschool3629  9 місяців тому

      You can use the Master clock Output (MCO) pin to generate a clock signal. Check this link below for more detailed information:
      community.st.com/t5/missing-articles/how-can-i-output-a-clock-signal-to-the-stm32-s-mco-pin/td-p/49583
      Another solution is to generate a PWM signal:
      www.steppeschool.com/pages/blog/stm32-pwm-stm32cubemx
      For sawtooth signal generation, you can use Digital-to-analog Converter (DAC)

  • @darylmkhacani6631
    @darylmkhacani6631 Рік тому

    Am I right to think that for the center-aligned the frequency of the timer is half that one of the up/down counting

    • @steppeschool3629
      @steppeschool3629  Рік тому

      The frequency of the timer depends only on the prescaler. So, the counting mode should not affect the clock frequency.

  • @bennguyen1313
    @bennguyen1313 2 роки тому

    Is there a way to configure a Timer to automatically count transitions on an input?
    The reference-manual suggests a Timer can be set to slave-mode controller, with an external clock input.. External Clock Mode 1 (TIMx_SMCR__SMS , TIMX_ETR). Each timer has dedicated trigger input pins (CH1, CH2), but you can select the transition edge of interest via TIMx_SMCR__TS = TI1F_ED / TI1FP1.
    Unfortunately, couldn't get this to count my relatively-slow transitions.
    Based on a Digilent post ("Quadrature encoder signals reading online with scripts and events"), I read someone use CH3 instead of the dedicated CH1,CH2. Apparently modules that don't have a pin assigned in the GPIP are fixed at 0. So in the GPIO AF matrix you can leave CH1 and CH2 unconnected, then setup CH3 ( TIMx_CR2__TI1S) to do a CH1-CH2-CH3 XOR. This should effectively redirect CH3 into CH1 in order to use CH1 as ingot to the slave-mode controller (input to TIM is CH1 TIMx_CCMR1 = CC1S (01)).
    However, would love to see any example, using any input, that shows the hardware counting edges!

    • @steppeschool3629
      @steppeschool3629  2 роки тому

      Hi Ben, If you have low frequency transitions, you can just use external interrupts to count them.
      If you have high frequency transitions and it is required exact timing, for example when reading encoders, and computing the frequency and duty cycle of an input PWM signal, using timers will be more feasible than using external interrupts. I hope in the near future I will show how to do that. Please do not forget to subscribe not to miss it 😀