Skip to main content
Graduate
January 9, 2024
Question

PWM Frequency generated

  • January 9, 2024
  • 3 replies
  • 1168 views

Hi,

i am working on STM32F302R8Tx and i would like to have a  490 Hz PWM on Timer15 Channel2, 

attached are my configuration and my code, when i measure it , i become 491,13..Hz. what can I do to get the exact 490Hz? 

Any  Suggestions?? 

thank you!!!

Jess32_0-1704784722767.png

Clockkonfiguration.PNG

Pinout Konfiguration.PNG

 

 

 

 

 

 

    This topic has been closed for replies.

    3 replies

    Super User
    January 9, 2024

    Hi,

    you clock at 64MHz , 

    so -> 64M / 130 = 492,3kHz

    divide by counter (arr) : (1005-1) -> 489,9Hz (closest you can get here)

    ---

    If you set 64M / 131  , arr (997-1) , then 490,02 Hz is possible.

    Super User
    January 9, 2024

    Also, HSI is not a precise primary clock source (see datasheet for HSI specification), so there will always be some error introduced by that fact.

    JW

    Jess32Author
    Graduate
    January 9, 2024

    okay, thank you for your answers!!!!!