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 CCS Technical Support

Delay in hours

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







Delay in hours
PostPosted: Thu Mar 20, 2008 11:59 am     Reply with quote

Hello all

I want to ask do you have some ideas to realize 1, 2, or 3 hours delay ?
I use CCS C compiler and pic16f88.

Is it possible to do cycle which calls many times delay function. Example:
i = 0 ;
while (i<34534534){
delay(); //( the ms version of the function )
i++;
}
And is this the best choice ?

10x all
esa



Joined: 31 Jan 2008
Posts: 19

View user's profile Send private message

PostPosted: Thu Mar 20, 2008 12:46 pm     Reply with quote

You can use a interrupt using timer0 or timer1.
Configure to call this timer each 100ms
In this timer increment a variable : centms++
if centms==10 then sec++
if sec==60 the minut++
etc...etc....
In the main program, create a test on minute to make what you want.
You can find a lot of code about this to make
Hope this will help you.
Regards
Eric
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Mar 20, 2008 12:47 pm     Reply with quote

Would the PIC have to do ANYTHING during the delay? Your method would work. Delay_ms(60000) will delay for one minute. looping 60 times would delay an hour. But the PIC would be TOTALLY occupied during the delay.

I would rather set a timer to count some long period I would call a "tick". Then I would have the PIC either poll or use interrupts to count ticks, and roll ticks into minutes and hours. That way each tick the PIC can check inputs to see if the delay should be aborted for some other function.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Johnsecada
Guest







plese, tell me your opinion for my idea
PostPosted: Thu Mar 20, 2008 2:27 pm     Reply with quote

10x for the ideas

my core of my idea is that :

Code:
int count;

int second () {
Delay_ms(1000) ; // delay one second
return 1 ;
}

void main(void){
count = 0;  // the count of seconds that are passed
while(1){
   read_from_ports(); // function that read  from ports

   if (count > 20 &&  count < 30) { // the time space between the 20s and // the 30 s
   take_desision1();
   }

   if (count > 40 &&  count < 70   ) {
// the time space between the 40s and  the 70 s
   take_desision2();
   }

   count = count + second(); // delay one second and +1 to count (  second returns 1  ) 
 }
}

I want to read each second the input information and to take a decision but the decision must depend by the count of seconds that had been past.

Please tell me your opinion about my idea
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: plese, tell me your opinion for my idea
PostPosted: Thu Mar 20, 2008 3:41 pm     Reply with quote

Johnsecada wrote:
10x for the ideas

my core of my idea is that :

Code:
int count;

int second () {
Delay_ms(1000) ; // delay one second
return 1 ;
}

void main(void){
count = 0;  // the count of seconds that are passed
while(1){
   read_from_ports(); // function that read  from ports

   if (count > 20 &&  count < 30) { // the time space between the 20s and // the 30 s
   take_desision1();
   }

   if (count > 40 &&  count < 70   ) {
// the time space between the 40s and  the 70 s
   take_desision2();
   }

   count = count + second(); // delay one second and +1 to count (  second returns 1  ) 
 }
}

I want to read each second the input information and to take a decision but the decision must depend by the count of seconds that had been past.

Please tell me your opinion about my idea


You do not need to use delays to count time. There is a better way. Everything else follows in a better way.
http://www.ccsinfo.com/forum/viewtopic.php?t=26177
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