View previous topic :: View next topic |
Author |
Message |
Johnsecada Guest
|
Delay in hours |
Posted: Thu Mar 20, 2008 11:59 am |
|
|
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
|
|
Posted: Thu Mar 20, 2008 12:46 pm |
|
|
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
|
|
Posted: Thu Mar 20, 2008 12:47 pm |
|
|
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 |
Posted: Thu Mar 20, 2008 2:27 pm |
|
|
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
|
Re: plese, tell me your opinion for my idea |
Posted: Thu Mar 20, 2008 3:41 pm |
|
|
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 |
|
|
|