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

start and stop the process
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

start and stop the process
PostPosted: Mon Jan 04, 2010 6:51 am     Reply with quote

hi,
i want to start a process at defined time and then stop the process at defined time.I have connected a gps system which gives me exact time.
whenever gps time equal to my defined start time the process begins and whenever gps time is equal to stop time the process stops.Below is the code
Code:

if((hour==hour1)&(min==min1)&(sec==sec1))//start time
  {
   start=1;//my desired function starts.
  }
  if((hour==hour2)&(min==min2)&(sec==sec2))//stop time
  {
   start=0;// my function stops here.
   }

This code is works perfect only when my system is power up before the defined start time.
What i want to do is that whenever i power up the system it compare the gps time with start time,If the gps time is >= start time the process starts and when the gps time == stop time the process stops and will remain in the stop mode untill gps time will equal to start time again.
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Mon Jan 04, 2010 7:05 am     Reply with quote

Easy one. Your conditions are joined by '&'; they should be joined by '&&'.

Also, how often are you checking this? If you don't do it at least once a second, you risk missing the correct time. And if you do check it more frequently, is it OK if the "start" condition occurs more than once?
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

PostPosted: Mon Jan 04, 2010 11:37 pm     Reply with quote

ya I am checking more than once in a second.
Let suppose start time is 07:30:0 and stop time is 10:10:45.
what I want to do is that when gps time is between start and stop time the process remains start and when gps time is greater than stop time the process will be stop.
2nd thing I want to add is that if I ON the system after 07:30:0, let suppose 08:00:00, then the process should follow the same procedure as I describe above.
Is there any idea regarding this.
mbradley



Joined: 11 Jul 2009
Posts: 118
Location: California, USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Jan 05, 2010 12:03 am     Reply with quote

When I program on Linux systems, time is in seconds past the epoch, details aside, convert your time to seconds.

With this example, start will be 1 if the time is anywhere between start and stop.

Code:


timeStamp = (hour * 3600) + (min*60) + sec;

if ( (timeStamp >= startTime) && (timeStamp < stopTime) )
  {
  start = 1;
  }
else
  {
  start = 0;
  }


_________________
Michael Bradley
www.mculabs.com
Open Drivers and Projects
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Tue Jan 05, 2010 8:10 am     Reply with quote

I thought of suggesting something like MRBradley's approach, but I held off because there seemed to be a problem: what happens if the desired interval wraps around past midnight, i.e. starts one day and ends the next day? At least if you use an equality test you don't have that issue. The way around it would be to add a test for the date as well as the time, but that's getting more complicated.
mbradley



Joined: 11 Jul 2009
Posts: 118
Location: California, USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Jan 05, 2010 10:37 am     Reply with quote

John P: Very good point! I didnt even think about it.

If the stop time ends on the following day, it does it a lil bit convoluted, I guess we would need more info.
_________________
Michael Bradley
www.mculabs.com
Open Drivers and Projects
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

PostPosted: Tue Jan 05, 2010 11:03 pm     Reply with quote

mbradley according to your suggestion I tried it but it is not working well.
JohnP I am not getting your point.
mbradley



Joined: 11 Jul 2009
Posts: 118
Location: California, USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Jan 06, 2010 12:13 am     Reply with quote

Roughly, I think the max is 90060, based on 24hr clock, so you will need an int32 to hold the timeStamp.

if you are using 12hr, then you need to add 43200 if the pm flag is set.
_________________
Michael Bradley
www.mculabs.com
Open Drivers and Projects
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

PostPosted: Tue Jan 12, 2010 12:52 am     Reply with quote

mbradley thanks for your help but this technique is not working,
mbradley



Joined: 11 Jul 2009
Posts: 118
Location: California, USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Jan 12, 2010 12:55 am     Reply with quote

would you be able to show me the time variables you have, and what they contain?

such as;

int8 day;
int8 month;
etc...

Also, can you give me a specific start and stop time?
_________________
Michael Bradley
www.mculabs.com
Open Drivers and Projects
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

PostPosted: Tue Jan 12, 2010 2:13 am     Reply with quote

following is the part of my code
Code:

main()
{
   int32 start_time,stop_time;
   int32 current_time;
   unsigned int hour1=0,hour2=0,min1=0,min2=0,sec1=0,sec2=0;
 
  while(1)
  {
   start_time=(hour1*3600)+(min1*60)+sec1;//values are stored in eeprom
   stop_time=(hour2*3600)+(min*60)+sec2;//values are stored in eeprom
   
   current_time=(hour*3600)+(min*60)+sec;//this time is from gps
   if((current_time>=start_time) &&(current_time<=stop_time))
  { 
    start=1;
  }
  else
  {
   start=0;
   pulse_ms=0;
  }
 }
}



I want to start and stop process at the user defined time or the default start time is 7:00:00 and stop time is 17:00:00
mbradley



Joined: 11 Jul 2009
Posts: 118
Location: California, USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Jan 13, 2010 12:44 am     Reply with quote

unless I am missing something, that looks about right.

if I get a chance I will test it out. right now, off to bed...
_________________
Michael Bradley
www.mculabs.com
Open Drivers and Projects
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

PostPosted: Wed Jan 13, 2010 1:14 am     Reply with quote

Ok mbradley thanks.
Any other suggestions from other users.
Ttelmah
Guest







PostPosted: Wed Jan 13, 2010 3:34 am     Reply with quote

Look at the mktime function.
This returns the standard 'unix' time, as an int32. The source code is with the compiler, so it is easy to modify to suit any particular RTC format that you have.
This allows mkbradley's 'original' Lnux solution to work 'as is'.
It really is the 'best' approach.

Best Wishes
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

PostPosted: Wed Jan 13, 2010 5:21 am     Reply with quote

From where i get the mktime function.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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