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.

  • It is possible to have more than one timer, but I wouldn't recommend setting up and tearing down a timer within another timer.

    You should be able to just change your interval and increment the PWM setting on each call of the timer event.

    Finally, you could stop the timer when the max value is configured, and set it back to the starting one.

Reply Children
No Data
Related