CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

software usart and delay

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
lewiseley



Joined: 30 Oct 2003
Posts: 24
Location: skegness

View user's profile Send private message Visit poster's website

software usart and delay
PostPosted: Wed Aug 30, 2006 1:36 pm     Reply with quote

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.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed Aug 30, 2006 1:41 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 30, 2006 2:06 pm     Reply with quote

Quote:

anyone know how to get around this.

http://www.ccsinfo.com/forum/viewtopic.php?t=27345
grasspuddle



Joined: 15 Jun 2006
Posts: 66

View user's profile Send private message

PostPosted: Wed Aug 30, 2006 2:15 pm     Reply with quote

nice post pcm Wink

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 30, 2006 2:22 pm     Reply with quote

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.
grasspuddle



Joined: 15 Jun 2006
Posts: 66

View user's profile Send private message

PostPosted: Thu Aug 31, 2006 5:57 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group