Joined: 05 Sep 2007 Posts: 46 Location: Londrina - Brazil
Delays and Interrupts: a little problem...
Posted: Wed Jun 03, 2009 11:15 am
Hello Fellows...
One of the biggest problems when using delays and interrupts is that the compiler must disable interrupts while calling the delay function. (to prevent re-entrancy).
Some applications must use lots of delays to accomplish its tasks (like make some bit-bang communications timing just fine).
I wonder what programming techniques do you use to make less use of delays (when a delay is needed) that makes possible calling delays, and using interrupts at the same time.
Or, just some technique to make a precise delay time, not using delay_us, delay_ms or delay_cycles.
Thanks! _________________ Give a man a fish and you'll feed him for a day. Teach a man to fish, and you'll feed him for a lifetime.
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Wed Jun 03, 2009 11:35 am
Quote:
One of the biggest problems when using delays and interrupts is that the
compiler must disable interrupts while calling the delay function. (to
prevent re-entrancy).
Create a timer0 interrupt handler. Every software timer will count down to zero. If a counter reaches zero it will stop.:
Code:
//-----------------------------------------------------------------------------
// Timer0 interrupt, triggers every 100 miliseconds.
// Used for multiple software based timers.
//-----------------------------------------------------------------------------
#int_timer0
void timer0_isr()
{
set_timer0(MS_100); // fire again in 100 ms
// Many software count down timers...
if (MyTimer1) MyTimer1--;
if (MyTimer2) MyTimer2--;
if (MyTimer3) MyTimer3--;
}
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum