This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

piezo buzzer has to generate sound until event occurs

i successfully generated sound using pwm and piezo buzzer

while(/*while event occurs*/)
{
	for (uint8_t i = 0; i < 50; ++i)
	{
		value = (i < 20) ? (i * 5) : (100 - (i - 20) * 5);
		/* Set the duty cycle - keep trying until PWM is ready... */
		while (app_pwm_channel_duty_set(&PWM1, 0, value) == 
	}
}

how to turn off the sound, if i given any flag it is not coming out of the while .

Parents
  • It looks like your event has a lower priority than the while loop.

    If this is the case, you have an architecture problem. You could use the quick and dirty fix of moving this loop to a lower priority, but I would recommend some extra changes.

    My suggestion would be to set up the buzzer on a timed event with low priority. You can turn on this timed event where you see fit, and turn it off in the event you are waiting for.

    Again, the priority of your event should be higher than that of your timer.

  • I expect this is due to both the timer having too high of a priority and the for loop being a rather long callback in the timer. This might be causing a timeout in the BLE stack.

    First check the priority of your timed event, and try setting it to 5 or lower. Second, try removing the for loop from your code too, and instead increment the value in each timer event.

    P.s. this might be justified as a second question.

Reply
  • I expect this is due to both the timer having too high of a priority and the for loop being a rather long callback in the timer. This might be causing a timeout in the BLE stack.

    First check the priority of your timed event, and try setting it to 5 or lower. Second, try removing the for loop from your code too, and instead increment the value in each timer event.

    P.s. this might be justified as a second question.

Children
No Data
Related