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

Delay

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



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Tue Mar 30, 2004 2:29 am     Reply with quote

The delay_ms() function accepts a two-byte parameter (0-65535).
If your delay is not accurate, make sure the oscillator speed is correct in the #use delay statement. And also remember, the amount of delay may be longer than what you expect, depending on the number of interrupts happening and their duration. The interrupt durations will add to the delay.
random_person
Guest







PostPosted: Tue Mar 30, 2004 2:31 am     Reply with quote

The CCSC.hlp reference says delay_ms can take a parameter up to 65535...any long int in other words.

so that would imply that the max (uninterrupted) delay you could get would be 65.535 seconds. This is assuming that you've used the "#use delay (clock=xxxx)" directive to reflect your actual clock speed.

I would theorize that if you used the "#use delay" to refer to a higher clock frequency than you are actually using that the resulting delay may actually be longer. Also, the delay_ms() is "delayed" by ISR's...so that may also explain why you perceive the delay to be longer than specified.
Ttelmah
Guest







Re: Thank u
PostPosted: Tue Mar 30, 2004 8:11 am     Reply with quote

hakam wrote:
Thank u for your replay

what i can do to get 1min. or 15min. delay in easy way
Laughing

I'd really say the 'easy way', is just to use a 'down counter' in a timer interrupt.
If you set up (say) Timer2, to interrupt at 2mSec intervals, then code something like:
Code:

static int16 clock;
#INT_TIMER2
void timertick(void) {
   static int16 tick;
   if (tick) --tick;
   else {
       tick=500;
       if (clock) --clock;
   }
}


Then in the main code, you can just set 'clock' to the number of seconds delay you want, and code with:

Code:

clock=delay_required_in_seconds;
while (clock) ;


The 'nice thing' about this is that the speed is not affected by other interrupts, and provided you work out the maths right on the counters, the times will be accurate. The timings will also be 'synchronous', in that if you set the clock to a new value when it reaches zero, the next 'timeout' will be at the number of seconds from the last timeout, rather than from when it is set (assuming the set is done within one second). If you are using a 'tick' interrupt for other things, the same interrupt can serve multiple purposes (my own tick interrupts typically handle a down counter lke this, a LCD output, and keyboard scanning...).

Best Wishes
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