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

problems using delay_ms with #int_RDA

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



Joined: 16 Feb 2004
Posts: 10
Location: Kelowna B.C

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

problems using delay_ms with #int_RDA
PostPosted: Mon Feb 16, 2004 6:08 pm     Reply with quote

im having some strange problems with using #int_RDA while using a Delay_ms(1000); in my main loop. when ever the delay is executed the interrupt is never fired on buffer full, Im allways getting overflow errors.

Its like interrupts are being disabled in the Delay_ms function. Anyone have any experience or data on this?.

in looking at the actual code developed by the compiler it looks like the Delay_ms function is not working as documented in the manual.

the manual states:
Function: This function will create code to perform a delay of the
specified length. Time is specified in milliseconds. This function works by executing a precise number of instructions to cause the requested delay. It does not use any timers. If interrupts are enabled the time spent in an interrupt routine is not counted toward the time. The delay time may be longer than requested if an interrupt is serviced during the delay. The time spent in the ISR does not count toward the delay time.

in my case, my isr is very small so it does not signifiantly affect the timing, as well as i dont need precision timing, im just looking for an approximate delay. However, the code generated for delay_ms(500) is as
follows:



Code:
....................    delay_ms(500); 
044A:  MOVLW  02
044B:  MOVWF  65
044C:  CLRF   28
044D:  BTFSC  0B.7
044E:  BSF    28.7
044F:  BCF    0B.7  <<----interrupts are being globally disabled.. not good
0450:  MOVLW  FA
0451:  BSF    03.5
0452:  MOVWF  2E
0453:  BCF    03.5
0454:  CALL   08B
0455:  BTFSC  28.7
0456:  BSF    0B.7
0457:  DECFSZ 65,F
0458:  GOTO   44C


has anyone else had to deal with this? any suggestions?
neil



Joined: 08 Sep 2003
Posts: 128

View user's profile Send private message

not much help but...
PostPosted: Tue Feb 17, 2004 5:44 am     Reply with quote

Hi, I think Ttelmah explained this one before on one of my posts a while back. Search for posts by 'neil' and look for replies by 'ttelmah' within them.
I avoid using 'delay_ms' functions totally when interrupts are used. They are so wasteful of code. The processor is tied up in the delay for the duration, and I don't trust the reliability of interrupts while using them.
I create a known timebase from a timer interrupt and use a prescale variable to divide that time down into variable lengths, then set a bit variable when the time is reached.

Regards,
Neil.
Vector Research



Joined: 16 Feb 2004
Posts: 10
Location: Kelowna B.C

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

re:not much help but...
PostPosted: Tue Feb 17, 2004 11:43 pm     Reply with quote

I searched for that thread but it looks like the sands of time has eaten it up..
That means that this has been a known problem for over a year. I cant believe this, they let an error like this go unchecked in the compiler/manual for more than a year! Evil or Very Mad This is a perfect example of what is wrong with CCS's whole corporate mentality. Yes compiler/documentation bugs happen, but for there to be nothing done about it really burns me. I wasted a week of my time, and had to buy a ICD to find this problem..

They wont see me purchase support anytime soon. and to think ive been using CCS since their first release back in 94 or 95. I need to go put my fist through a wall or something.. Im really ticked off..


If you have any copies of Ttelmah's posts on this subject, a repost would be greatly appreciated.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 18, 2004 1:41 am     Reply with quote

Various posts which discuss this issue:

http://www.ccsinfo.com/forum/viewtopic.php?t=17661&highlight=delayms+interrupts

http://www.ccsinfo.com/forum/viewtopic.php?t=14228&highlight=delayms+interrupts

http://www.ccsinfo.com/forum/viewtopic.php?t=14426&highlight=delayms+interrupts

http://www.ccsinfo.com/forum/viewtopic.php?t=2074&highlight=delayms+interrupts
Guest








Ouch!
PostPosted: Wed Feb 18, 2004 4:20 am     Reply with quote

Razz Oh the joys of software! It can be the most rewarding job, and the next day the most frustrating! I wouldn't be too harsh on CCS though, the disabling of interrupts in a delay (as mentioned in one of the links above) is there for a good reason - to prevent a sort of 'circular call' within a function.

As I said earlier, use hardware timers with 'postscale' variables to get your desired delay lengths for all but the simplest of programs. All you need in the timer ISR is a 'variable--;' or ++ and do a test for a certain value, then set a flag. This approach keeps your code running smoothly, never tying up the processor in a delay loop. If your main loop runs quickly, checking for event flags and jumping off to do something only when required, you code will start to look like a multitasking system!

Enough rambling! Shocked
Regards,
Neil.
Darren Rook



Joined: 06 Sep 2003
Posts: 287
Location: Milwaukee, WI

View user's profile Send private message Send e-mail

PostPosted: Wed Feb 18, 2004 8:51 am     Reply with quote

When you saw this warning generated by the compiler:

"Interrupts disabled to prevent re-entrancy: @delay_ms"

Didn't you think that maybe it was important?


Last edited by Darren Rook on Wed Feb 18, 2004 12:50 pm; edited 2 times in total
Darren Rook



Joined: 06 Sep 2003
Posts: 287
Location: Milwaukee, WI

View user's profile Send private message Send e-mail

PostPosted: Wed Feb 18, 2004 9:06 am     Reply with quote

I have posted a work-around on the FAQ:

http://www.ccsinfo.com/faq/?50
Laurent Chouinard



Joined: 12 Sep 2003
Posts: 43

View user's profile Send private message

PostPosted: Tue Jun 29, 2004 11:11 am     Reply with quote

Thank you very much for that faq entry! It certainly did save my day. I didn't know that we could create several entities of the #use delay code generator, it's good to know!

It took me quite a while though to pinpoint exactly where I was having a re-entrant function that was forcing the compiler to disable interrupts. I see you made reference to this error message:

"Interrupts disabled to prevent re-entrancy: @delay_ms"

I never saw that message. I've checked the .lst file and the others. Furthermore, the .err file says "no errors". Where should I be watching for that compiler message then? Seeing that would have probably saved me a couple of hours, but i'm already happy to have found the problem itself...
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