View previous topic :: View next topic |
Author |
Message |
lewiseley
Joined: 30 Oct 2003 Posts: 24 Location: skegness
|
software usart and delay |
Posted: Wed Aug 30, 2006 1:36 pm |
|
|
i am hoping someone can help with this.
i use a software usart to receive data, have tied rcv pin to int1 pin, and i am receiving data ok, my isr for int1 uses fgetc and pushes to a circular que.
i also have a timed routine that goes of every second to do a search of a dallas one wire bus.
the dallas stuff heavily relies on #delay.
problem seems to be that because i use fgetc in my isr, the compiler warns that it disables interupts during delay to prevent re-entrancy.
this disabling of the interupts is causing me to miss characters on my rs232 routine. the dallas routines are not very fast as i do an awfull lot of dallas bus traffick.
anyone know how to get around this.
using 18f2680 8mhz clock, pll switched on so 32mhz.
rs232 is at 19200.
have timer 2 overflowing every 1ms for other stuff.
cant use hw usart as is already used. |
|
![](templates/subSilver/images/spacer.gif) |
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed Aug 30, 2006 1:41 pm |
|
|
Use one of your timers for all of your delays. You can have multiple flags set in the same timer routine. Just calculate how often you need the ISR to be entered and then increment different variables that will set a bit. Then look at that bit somewhere else in your code. I've done this quite a bit. I hate using delay() as it hogs the processor time while it could be doing something else usefull.
Ronald |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
grasspuddle
Joined: 15 Jun 2006 Posts: 66
|
|
Posted: Wed Aug 30, 2006 2:15 pm |
|
|
nice post pcm
nowadays i definately try to avoid any #delay calls like the plague and only use them in my main function
definately look into having your interrupt calls set a flag or a value which you process in your main function with a case statement or if statements
(and use the delays there with no worries) as there will be less 'strange' bugs occurring
of course if you feel thats impossible then definately look into pcm's post or use a timer |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 30, 2006 2:22 pm |
|
|
I wasn't really commenting on program design. I was just giving him
the technical info to resolve his particular problem. In my own programs
I normally avoid putting delay statements inside isr's. |
|
![](templates/subSilver/images/spacer.gif) |
grasspuddle
Joined: 15 Jun 2006 Posts: 66
|
|
Posted: Thu Aug 31, 2006 5:57 am |
|
|
was just reinforcing your suggestion of avoiding delays as that advice from you really helped me out when I was in the same situation
cheers |
|
![](templates/subSilver/images/spacer.gif) |
|