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

10 second delay & 3 hours delay

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



Joined: 22 Dec 2003
Posts: 82

View user's profile Send private message

10 second delay & 3 hours delay
PostPosted: Mon Mar 15, 2004 8:41 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 15, 2004 8:57 am     Reply with quote

What kind of accuracy do you need?
edi



Joined: 22 Dec 2003
Posts: 82

View user's profile Send private message

PostPosted: Mon Mar 15, 2004 10:02 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 15, 2004 10:15 am     Reply with quote

What chip are you using? What timers are not already used? What is the xtal freq?
edi



Joined: 22 Dec 2003
Posts: 82

View user's profile Send private message

PostPosted: Mon Mar 15, 2004 1:44 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 15, 2004 2:47 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 16, 2004 2:28 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 16, 2004 9:09 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 16, 2004 1:10 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 16, 2004 3:19 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 16, 2004 11:38 pm     Reply with quote

ok, I'll try.
Edi
wedilo



Joined: 16 Sep 2003
Posts: 71
Location: Moers, Germany

View user's profile Send private message

PostPosted: Wed Mar 17, 2004 1:26 am     Reply with quote

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 Embarassed

73 Sven
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