Hello,
I'm playing beep sound using pwm1 (timer1).
The onSound() starts beep sound.
The disableBuzzer() terminates pwm1.
The handler_buzzer() selects continuous sound playback or pwm1 termination.
- Abnormal condition with log message
-
The "buzzer stop" does not occur and the watchdog reset(2 sec) occurs intermittently.
-
Even if "buzzer stop" is output, there is no buzzer sound and watchdog reset (2 sec) occurs intermittently.
I am wondering if there is a problem with the code. I use nrf51822/SDK 12.1.0. I need help.
thanks.
void onSound(uint8_t Num)
{
NRF_LOG_PRINTF("buzzer start\r\n");
// offSound();
BUZZER_USE;
if(Num != BEEP_DOOR_ALARM)
doorAlarmBeepCnt = 0; // door open alarm beep cancel
beepOrder = 0;
beepCnt = beepCntInfo[Num];
soundNum = Num;
makeSound(beepLevel[soundNum][beepOrder]);
controlLed(ledInfo[soundNum][beepOrder]);
timerBuzzer(START, beepTime[soundNum][beepOrder]);
}
void disableBuzzer(void)
{
ret_code_t err_code;
timerBuzzer(STOP, NULL);
app_pwm_disable(&PWM_BUZZER);
// err_code = app_pwm_end(&PWM_BUZZER);
// APP_ERROR_CHECK(err_code);
nrf_gpio_pin_clear(BUZZER_PIN);
nrf_gpio_cfg_output(BUZZER_PIN);
BUZZER_NO_USE;
NRF_LOG_PRINTF("buzzer stop\r\n");
}
void makeSound(uint16_t level)
{
ret_code_t err_code;
err_code = app_pwm_uninit(&PWM_BUZZER);
// APP_ERROR_CHECK(err_code);
// app_pwm_disable(&PWM_BUZZER);
app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(level, BUZZER_PIN);
pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;
err_code = app_pwm_init(&PWM_BUZZER, &pwm1_cfg, NULL); // callback_pwmBuz);
APP_ERROR_CHECK(err_code);
app_pwm_enable(&PWM_BUZZER);
// sound level check
#if !TEST_SOUND_OFF
if(fireStatus)
while(app_pwm_channel_duty_set(&PWM_BUZZER, 0, SOUND_MAX) == NRF_ERROR_BUSY);
else if(batteryStatusSave <= BATTERY_LOW)
while(app_pwm_channel_duty_set(&PWM_BUZZER, 0, SOUND_MIN) == NRF_ERROR_BUSY);
else if(soundLevelTemp == 0)
while(app_pwm_channel_duty_set(&PWM_BUZZER, 0, soundLevelInfo[lockInfo.soundLevel]) == NRF_ERROR_BUSY);
else
while(app_pwm_channel_duty_set(&PWM_BUZZER, 0, soundLevelTemp) == NRF_ERROR_BUSY);
#else
while(app_pwm_channel_duty_set(&PWM_BUZZER, 0, SOUND_OFF) == NRF_ERROR_BUSY);
#endif
}
void handler_buzzer(void * p_context)
{
UNUSED_PARAMETER(p_context);
beepOrder++;
beepCnt--;
if(beepCnt)
{
timerBuzzer(START, beepTime[soundNum][beepOrder]);
makeSound(beepLevel[soundNum][beepOrder]);
controlLed(ledInfo[soundNum][beepOrder]);
}
else
{
disableBuzzer();
soundLevelTemp = 0;
}
}