From a542f0dc264a38ff131b6090b773502877fde4eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Wed, 17 May 2017 18:32:55 +0200 Subject: [PATCH] set buyyer to 4khz to be louder --- main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 6a6465f..a8e08c0 100644 --- a/main.c +++ b/main.c @@ -576,9 +576,9 @@ void main(void) rcc_periph_clock_enable(RCC_TIM(BUZZER_TIMER)); // enable clock for timer peripheral timer_reset(TIM(BUZZER_TIMER)); // reset timer state timer_set_mode(TIM(BUZZER_TIMER), TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); // set timer mode, use undivided timer clock, edge alignment (simple count), and count up - timer_set_prescaler(TIM(BUZZER_TIMER), 0); // no prescaler to keep most precise timer (72MHz/2^16=1099<2kHz) - timer_set_period(TIM(BUZZER_TIMER), rcc_ahb_frequency/2000-1); // set the PWM frequency to 2kHz for piezo-buzzer - timer_set_oc_value(TIM(BUZZER_TIMER), TIM_OC1, rcc_ahb_frequency/2000/2-1); // duty cycle to 50% (also applies to TIM_OC1N) + timer_set_prescaler(TIM(BUZZER_TIMER), 0); // no prescaler to keep most precise timer (72MHz/2^16=1099<4kHz) + timer_set_period(TIM(BUZZER_TIMER), rcc_ahb_frequency/4000-1); // set the PWM frequency to 4kHz for piezo-buzzer + timer_set_oc_value(TIM(BUZZER_TIMER), TIM_OC1, rcc_ahb_frequency/4000/2-1); // duty cycle to 50% (also applies to TIM_OC1N) // no preload is used, although the reference manual says to enable it timer_set_oc_mode(TIM(BUZZER_TIMER), TIM_OC1, TIM_OCM_PWM1); // set timer to generate PWM (also applies to TIM_OC1N) timer_enable_oc_output(TIM(BUZZER_TIMER), TIM_OC1); // enable output to generate PWM