Compare commits

..

No commits in common. "jeopardy" and "main" have entirely different histories.

2 changed files with 15 additions and 26 deletions

View file

@ -8,7 +8,7 @@
#include "buzzer.h"
#define FREQ_BASE 3906250 // round(125 MHz [CPU frequency] * 16 [scaling] / 512 [PWM steps])
#define FREQ_BASE 24414063 // round(125 MHz [CPU frequency] * 100 [scaling] / 512 [PWM steps])
uint m_slice_num;
@ -23,14 +23,14 @@ void buzzer_init(void)
pwm_set_clkdiv_int_frac(m_slice_num, 244, (14 << 4) / 100); // 125 MHz / 244.14 / 512 = 1 kHz
gpio_set_function(BUZZER_PIN, GPIO_FUNC_PWM);
pwm_set_wrap(m_slice_num, 512);
pwm_set_chan_level(m_slice_num, PWM_CHAN_B, 1 * 512 / 100); // 1% duty cycle is sufficient for full voltage swing
pwm_set_chan_level(m_slice_num, PWM_CHAN_B, 1 * 512 / 100);
}
void buzzer_on(uint16_t freq_hz)
{
uint32_t divider_x16 = FREQ_BASE / freq_hz; // = 16 * 125e6 / 512 / freq_hz
uint32_t divider_x100 = FREQ_BASE / freq_hz; // = 100 * 125e6 / 512 / freq_hz
pwm_set_clkdiv_int_frac(m_slice_num, divider_x16 / 16, divider_x16 % 16);
pwm_set_clkdiv_int_frac(m_slice_num, divider_x100 / 100, divider_x100 % 100);
gpio_set_function(BUZZER_PIN, GPIO_FUNC_PWM);
pwm_set_enabled(m_slice_num, true);
}

View file

@ -174,36 +174,33 @@ static void update_countdown_fsm(uint32_t time_ms)
sseg_set_pwm_times(0, 255, 0);
sseg_set_pwm_times(1, 255, 0);
sseg_set_pwm_times(2, 255, 0);
buzzer_on(2963);
break;
case 500:
sseg_set_char(0, '#', false);
buzzer_on(3951);
buzzer_on(1000);
break;
case 1000:
sseg_set_char(1, '|', false);
buzzer_on(2963);
buzzer_on(1414);
break;
case 1500:
sseg_set_char(1, '#', false);
buzzer_on(1976);
buzzer_on(2000);
break;
case 2000:
sseg_set_char(2, '|', false);
buzzer_on(2963);
buzzer_on(2828);
break;
case 2500:
sseg_set_char(2, '#', false);
buzzer_on(3951);
buzzer_on(4000);
break;
case 200:
case 700:
case 1200:
case 1700:
@ -257,9 +254,6 @@ static void update_countdown_fsm(uint32_t time_ms)
if((m_countdown_off_time - time_ms) > 10 * ONE_HOUR) {
m_countdown_off_time = time_ms + 10 * ONE_HOUR;
}
// ensure the buzzer is off after the time was extended
buzzer_off();
}
// beep codes
@ -317,39 +311,34 @@ static void update_countdown_fsm(uint32_t time_ms)
sseg_set_char(0, '#', false);
sseg_set_char(1, '#', false);
sseg_set_char(2, '#', false);
buzzer_on(3951);
break;
case 500:
sseg_set_char(0, '1', false);
break;
case 750:
buzzer_on(3322);
buzzer_on(4000);
break;
case 1000:
sseg_set_char(0, ' ', false);
buzzer_on(2960);
buzzer_on(2828);
break;
case 1500:
sseg_set_char(1, '1', false);
buzzer_on(2637);
buzzer_on(2000);
break;
case 2000:
sseg_set_char(1, ' ', false);
buzzer_on(2489);
buzzer_on(1414);
break;
case 2500:
sseg_set_char(2, '1', false);
buzzer_on(2217);
buzzer_on(1000);
break;
case 200:
case 950:
case 700:
case 1200:
case 1700:
case 2200: