set buyyer to 4khz to be louder

This commit is contained in:
King Kévin 2017-05-17 18:32:55 +02:00
parent 159d969e3e
commit a542f0dc26
1 changed files with 3 additions and 3 deletions

6
main.c
View File

@ -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