Skip to main content
Associate II
November 21, 2023
Solved

Timer Configuration

  • November 21, 2023
  • 4 replies
  • 5662 views

Hi, I got a small problem while configuring timers in NUCLEO-F072RB board. I want to configure one timer for 1ms and another for 1sec, Could you please explain me how to set the prescaler and period(ARR) values of both the timers. My HCLK is 48MHz.

    This topic has been closed for replies.
    Best answer by raisa_razak

    Thank you all for the replies.

    I figured out my problem. Except for the more recent dual core MCUs, most STM32 are limited to running only one thing at a time, so i am trying to use FreeRTOS or similar to have the system switch between tasks as needed.

    4 replies

    STTwo-32
    ST Technical Moderator
    November 21, 2023

    Hello @raisa_razak and welcome to the ST Community :smiling_face_with_smiling_eyes:.

    You will fin here everything you are looking for with détails.

    Best Regards.

    STTwo-32

    To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
    Associate II
    November 21, 2023

    Thankyou for your reply.

    Yeah i tried this one for 1sec interrupt in one timer and it is working but I want to configure the 2nd timer for 1ms interrupt, there it is not working with this calculation.

    STTwo-32
    ST Technical Moderator
    November 21, 2023

    To make it easier, you Can keep the same parameters as for the 1s timer and use PSCms-1=(1/1000)*(PSCs+1)  

    PSCms: prescaler for 1ms.

    PSCs: prescaler for 1s.

    Or do the samething with ARR.

    Best Regards.

    STTwo-32 

    To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
    Tinnagit
    Senior II
    November 21, 2023

    you can read it in page 81 - an4776-generalpurpose-timer-cookbook-for-stm32-microcontrollers-stmicroelectronics.pdf

    t = ((PreScalar+1)*(ARR+1))/Tclk

    but If you have don't use RTC to alarm something, You should use Alarm-A and Alarm-B to trigger every sec and millisec.

    Tinnagit
    Senior II
    November 21, 2023

    you just change ARR from 9 to 9999, it should work correctly.

    Associate II
    November 21, 2023

    Then it is working like a 1sec timer. 

    For my 1sec timer i put prescaler as 4799 and ARR as 9999 as per the calculation and it is working properly. But the problem is with the configuration of 1ms timer.

    Tinnagit
    Senior II
    November 21, 2023

    So you can use same configuration with timer for 1ms and change ARR to 9 and it's trigger every 1ms.

    STTwo-32
    ST Technical Moderator
    November 21, 2023

    Try to adapt this example to your needs. It should work.

    Best Regards.

    STTwo-32 

    To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
    Associate II
    November 23, 2023

    Thank You. 

    Your timer calculations are correct and thanks for sharing the github code.