Dear Sir.
A timer is defined for 1 hz,
Every 3 minutes or so we drive the buzzer with different pulses ( see code attached )
We are using the PWM to drive a buzzer ( 4khz ) ,
After 2 to 7 hours , the buzzer is not functioning.
Once the pcb is reset , the buzzer start working.
k_timer_init(&my_timer, my_expiry_function, NULL); //Timer - 1 Hz
k_timer_start(&my_timer, K_MSEC(TIEMR_INTERVAL_SEC), K_SECONDS(TIEMR_INTERVAL_SEC)); //Timer - 1 Hz
// Buzzer timer.
k_timer_init(&bz_timer, bz_func, NULL);
k_timer_start(&bz_timer, K_SECONDS(1), K_MSEC(500));
static void work_buzzer_func(struct k_work * work_buzzer)
{
_BZ_SM.bz_state = bz_function(_BZ_SM.bz_state);
}
void my_expiry_function(struct k_timer *timer_id)
{
k_work_submit(&work_top);
}
}
uint8_t bz_function(uint8_t bz_state)
{
static unsigned int led_time = 0;
static unsigned int time = 0;
static unsigned char a = 0;
int times = 700000;
switch(bz_state)
{
case 0 : // BZ_silence.
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
a = 0;
time = 0;
break;
case 1 : // BZ_short_beep.
if(time == 0)
{
pwm_pin_set_usec(pwm_dev,PWM_IO, 240, 120,0);
NRFX_DELAY_US(times);
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
}
if(time == 2)
{
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
bz_state = BZ_silence;
}
time++;
break;
case 2 : // BZ_2_short_beep.
if(time == 0)
{
pwm_pin_set_usec(pwm_dev,PWM_IO, 240, 120,0);
NRFX_DELAY_US(times);
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
}
if(time == 1) // was 2 4 6
{
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
}
if(time == 2)
{
pwm_pin_set_usec(pwm_dev,PWM_IO, 240, 120,0);
NRFX_DELAY_US(times);
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
}
if(time == 3)
{
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
bz_state = BZ_silence;
}
time++;
break;
case 3 : // BZ_long_beep.
if(time == 0)
{
pwm_pin_set_usec(pwm_dev,PWM_IO, 240, 120,0);
NRFX_DELAY_US(times);
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
}
if(time == 10)
{
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
bz_state = BZ_silence;
}
time++;
break;
case 4 : // BZ_siren.
if(time == 0)
{
pwm_pin_set_usec(pwm_dev,PWM_IO, 240, 120,0);
NRFX_DELAY_US(times);
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
}
if(++time == 5)
{
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
bz_state = BZ_silence;
}
break;
case 5 : // BZ_train.
if(time == 0)
{
pwm_pin_set_usec(pwm_dev,PWM_IO, 300, 150,0); // 260, 130,
NRFX_DELAY_US(times);
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
}
if(time == 2)
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
if(++time == 4)
{
time = 0;
}
case 6 : // BZ_charge.
break;
case 7 : // BZ_3_short_beep.
if(time == 0)
{
pwm_pin_set_usec(pwm_dev,PWM_IO, 240, 120,0);
NRFX_DELAY_US(times);
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
}
if(time == 1)
{
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
}
if(time == 2)
{
pwm_pin_set_usec(pwm_dev,PWM_IO, 260, 130,0);
NRFX_DELAY_US(times);
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
}
if(time == 3)
{
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
}
if(time == 4)
{
pwm_pin_set_usec(pwm_dev,PWM_IO, 240, 120,0);
NRFX_DELAY_US(times);
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
}
if(time == 5)
{
pwm_pin_set_usec(pwm_dev,PWM_IO, 0, 0,0);
bz_state = BZ_silence;
}
time++;
break;
}
return bz_state;
}
How can I debug such behavior.
Please Advise.