cancel
Showing results for 
Search instead for 
Did you mean: 

Setting Prescaler and Period for Buzzer

hazin
Associate III

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Peter BENSCH
ST Employee

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

In order 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.

View solution in original post

4 REPLIES 4
Peter BENSCH
ST Employee

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

In order 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.
TDK
Guru

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

If you feel a post has answered your question, please click "Accept as Solution".

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

Peter BENSCH
ST Employee

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

In order 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.