We had a minor ECO to our new board - the buzzer has been replaced with one that doesn't oscillate on its own, so the software has to manage it. I thought I'd re-use the LED control software, but it's not working (can't get the buzzer to sound).
Here's my set-up code:
Code: Select all
#define BUZZER_TIMER (LEDC_TIMER_1)
#define BUZZER_CHANNEL (LEDC_CHANNEL_1)
#define BUZZER_GPIO (5)
#define BUZZER_FREQ (2200)
const ledc_timer_config_t buzzer_timer = {LEDC_HIGH_SPEED_MODE,
{LEDC_TIMER_13_BIT },
BUZZER_TIMER,
BUZZER_FREQ};
const ledc_channel_config_t buzzer_channel = {BUZZER_GPIO,
LEDC_HIGH_SPEED_MODE,
BUZZER_CHANNEL,
LEDC_INTR_DISABLE,
BUZZER_TIMER,
0x1fff};
err = ledc_timer_config(&buzzer_timer);
assert (err == ESP_OK);
ledc_channel_config(&buzzer_channel);
assert (err == ESP_OK);
Code: Select all
void Buzzer::setDuty(uint32_t duty)
{
ESP_ERROR_CHECK(ledc_set_duty(LEDC_HIGH_SPEED_MODE, BUZZER_CHANNEL, duty));
ESP_ERROR_CHECK(ledc_update_duty(LEDC_HIGH_SPEED_MODE, BUZZER_CHANNEL));
}
void Buzzer::buzzer_task()
{
BuzzerQueueEntry entry;
while (1)
{
entry.value = 0; // reset between queue reads.
// look for a change request from our queue. Process if present.
if (xQueueReceive(m_buzzerQueue, &entry, portMAX_DELAY) == pdTRUE)
{
if (entry.value > 0)
{
ESP_LOGI(TAG, "turning buzzer on.");
setDuty(0x3ff);
// turn buzzer on
}
else
{
ESP_LOGI(TAG, "turning buzzer off.");
setDuty(0x0);
// turn buzzer off
}
}
}
}
Thanks...