View previous topic :: View next topic |
Author |
Message |
edi
Joined: 22 Dec 2003 Posts: 82
|
10 second delay & 3 hours delay |
Posted: Mon Mar 15, 2004 8:41 am |
|
|
Hi,
1. I want to run my software and after 10 seconds to activate something.
Can someone recommend on a way to get a 10 seconds delay, while the program is still running.
2. What is the best way to achieve 3 hours delay?
Edi |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Mon Mar 15, 2004 8:57 am |
|
|
What kind of accuracy do you need? |
|
|
edi
Joined: 22 Dec 2003 Posts: 82
|
|
Posted: Mon Mar 15, 2004 10:02 am |
|
|
The accuracy is not so important.
For the 10 seconds +-0.5s is ok
For the 3 hours +-10s is ok
thanks,
Edi |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Mon Mar 15, 2004 10:15 am |
|
|
What chip are you using? What timers are not already used? What is the xtal freq? |
|
|
edi
Joined: 22 Dec 2003 Posts: 82
|
|
Posted: Mon Mar 15, 2004 1:44 pm |
|
|
I'm using the 16f819 or 16f877.
Xtal = 20MHz
Timer1 in use.
There is need for WDT.
tnx,
Edi |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Mon Mar 15, 2004 2:47 pm |
|
|
This is how I would handel it.
Try this.
Code: |
int1 Clock_Been_Initialized=0;
Int16 Miliseconds;
Int16 Seconds;
int16 Three_Hour;
int8ten_Seconds;
int1 Second_Tick=0;
int1 ten_second_Tick=0;
int1 three_Hour_Tick=0;
// Global Real Time Clock Information
#int_TIMER2 // Clock interrupt adjusted to occurs ~ 1ms
void TIMER2_isr()
{ Miliseconds++;
if(Miliseconds>999)
{ Miliseconds=0;
Seconds++;
Second_Tick=1;
}
}
/***********************************************************
* Service Hardware Modules *
***********************************************************/
#inline
void Clock_Service(void)
{ if(!Clock_Been_Initialized)
{ setup_timer_2(T2_DIV_BY_4,249,5); // Set 1mS period
enable_interrupts(INT_TIMER2);
Seconds=0;
Clock_Been_Initialized=1;
}
if(Second_Tick)
{ Second_Tick=0;
if(--ten_Seconds==0)
{ ten_Seconds=10;
ten_second_Tick=1;
}
if(--Three_Hour==0)
{ Three_Hour=10800;
three_Hour_Tick=1;
}
}
}
|
|
|
|
wedilo
Joined: 16 Sep 2003 Posts: 71 Location: Moers, Germany
|
|
Posted: Tue Mar 16, 2004 2:28 am |
|
|
Hello Neutone,
I would like to understand the problematic nature of a timer.
In your code I can see, that the isr will be called every millisecond.
Is the performance ok? Is there also enough time for other actions like controlling etc. ?
In my sources I call it every 100ms, but I would like to take your code. It looks reliable. Sorry, but I'm doubtful.
73 Sven |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Tue Mar 16, 2004 9:09 am |
|
|
wedilo wrote: | Hello Neutone,
I would like to understand the problematic nature of a timer.
In your code I can see, that the isr will be called every millisecond.
Is the performance ok? Is there also enough time for other actions like controlling etc. ?
In my sources I call it every 100ms, but I would like to take your code. It looks reliable. Sorry, but I'm doubtful.
73 Sven |
edi specifies Xtal = 20MHz
That means that in 1 mS there are 5000 instruction cycles. Vectoring to an interupt take ~100 insctuction cycles. That means that 2% of total processor time is spent tracking time. It really just depends on your processing requirements. |
|
|
edi
Joined: 22 Dec 2003 Posts: 82
|
|
Posted: Tue Mar 16, 2004 1:10 pm |
|
|
Neutone,
Thanks a lot it's look excellent.
Do you have also a good WDT function that you can post.
Edi. |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Tue Mar 16, 2004 3:19 pm |
|
|
edi wrote: | Neutone,
Thanks a lot it's look excellent.
Do you have also a good WDT function that you can post.
Edi. |
It's really an application specific thing. Maybe just add restart WDT within the clock service routine not the interupt. If something locks up the processor will restart. |
|
|
edi
Joined: 22 Dec 2003 Posts: 82
|
|
Posted: Tue Mar 16, 2004 11:38 pm |
|
|
ok, I'll try.
Edi |
|
|
wedilo
Joined: 16 Sep 2003 Posts: 71 Location: Moers, Germany
|
|
Posted: Wed Mar 17, 2004 1:26 am |
|
|
Hello Neutone,
Neutone wrote: | edi specifies Xtal = 20MHz
That means that in 1 mS there are 5000 instruction cycles. Vectoring to an interupt take ~100 insctuction cycles. That means that 2% of total processor time is spent tracking time. It really just depends on your processing requirements. |
From this point of view it looks clear. Thank you
73 Sven |
|
|
|