Skip to main content
Explorer
December 4, 2023
Solved

Setting Prescaler and Period for Buzzer

  • December 4, 2023
  • 3 replies
  • 3690 views

For producing 4KHz resonant frequency sound from a buzzer using 32KHz system clock, what should be the Prescaler value and Period(ARR)? Is there any rules for defining these values?

    This topic has been closed for replies.
    Best answer by Peter BENSCH

    You could generate your 4kHz from the 32kHz with prescaler=0 (1 -1) and ARR=7 (8 -1). The product of PRE*ARR must be 8 in your case, although you can also use PRE=1 (2 -1) and ARR=3 (4 -1).

    Does it answer your question?

    Regards
    /Peter

    3 replies

    Technical Moderator
    December 4, 2023

    You could generate your 4kHz from the 32kHz with prescaler=0 (1 -1) and ARR=7 (8 -1). The product of PRE*ARR must be 8 in your case, although you can also use PRE=1 (2 -1) and ARR=3 (4 -1).

    Does it answer your question?

    Regards
    /Peter

    hazinAuthor
    Explorer
    December 4, 2023

    What about a 32MHz system clock and required frequency as 4KHz? Is there any rules in defining the PRE and ARR combination? I know that if the ARR register is 16bits, then the maximum value is 65535. anything else other than that

    Super User
    December 4, 2023

    If you mean a 32768 Hz clock, you won't be able to get 4 kHz exactly, but you can get close (4096 Hz).

    Technical Moderator
    December 4, 2023

    The same procedure applies: you need divide by 8000, so that any factors can be used (in the context of prime factorisation).