|
|
View previous topic :: View next topic |
Author |
Message |
glenjoy
Joined: 18 Oct 2004 Posts: 21
|
Timer Interrupt Loading for PIC and CCS C |
Posted: Wed Apr 13, 2005 10:32 pm |
|
|
I want to create a device that will Turn OFF a device after a preset time, the preset time can be incremented by 30 minutes at the selector, running time selection or ON times selection will be from 30 min. to 9.5 hours with selection increments of 30 min.
Now how can I use the timer to time out the PIC micro after my preset ON time and which timer to use, I do not want to use delay_ms command because while waiting for the time to expire I am displaying the preset time.
Thanks.
PS. If you are quite confused, just tell me. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Apr 14, 2005 6:35 am |
|
|
Pick a timer. It doesn't really matter which one. Take a look (search the forum) at the code that keeps track of time (RTC). You are going to have to setup the timer to count a smaller unit of time, say seconds or even smaller, maybe tenths of seconds.
Here is a snippet that is called every milisecond. It is not my acutal code but a version that I edited in an effort to make it a little clearer:
Code: | void Relay_Timers(void)
{
static uint8_t secs_count = 0; /* Used to count seconds */
static uint8_t tenths_count = 0; /* Used to count tenths of seconds */
uint8_t count;
/* Handle the warn and timeouts. These are in seconds */
tenths_count++;
// 100 miliseconds is a tenth
if (tenths_count >= 100)
{
tenths_count = 0;
secs_count++;
// 10 tenths is a second
if (secs_count >= 10)
{
secs_count = 0;
for (count=0; count < MAX_RELAYS; count++)
{
if (RelayTimers[count].timeout)
{
if (--RelayTimers[count].timeout == 0)
Relay_Activate(count, 0, 0, 0);
else if (RelayTimers[count].timeout == RelayTimers[count].warn)
Relay_Warn(count);
}
}
}
}
} |
|
|
|
|
|
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
|