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 support@ccsinfo.com

RTC Alarm, How?

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



Joined: 04 Mar 2010
Posts: 102

View user's profile Send private message

RTC Alarm, How?
PostPosted: Sat Apr 03, 2010 10:41 am     Reply with quote

Can't figure out how to check for time on my alarms.
What I was planning is to change the hr's to minute's, like 8:30 = 8*60+30=510 minute.
Code:

timer0 = 480 // 8:00
timer0_1 = 960 // 16:00
current time 540 //9:00
if current time > 480 and current time < 960
turn on
else
turn it of

It work until I set up the opposite way
Code:

current time 1020 //17:00
timer0 = 960 // 16:00
timer0_1 = 480 // 8:00
if current time > 960 and current time < 480
turn on
else
turn it of

Code:
 
timer0 = 480; timer0_1 = 1345; device0 = 1 ;
timer1 = 1380; timer1_1 = 500; device1 = 9;

Code:

void check_time()
{
   if (ctimer >= timer0 && ctimer <= timer0_1)
   {
       bit_set(aqua_device,device0);
       UpdateBtn(aqua_device);
   }
   else
   {
       bit_clear(aqua_device,device0);
       UpdateBtn(aqua_device);
   }
   if (ctimer >= timer1 && ctimer <= timer1_1)
   {
       bit_set(aqua_device,device1);
       UpdateBtn(aqua_device);
   }
   else
   {
       bit_clear(aqua_device,device1);
       UpdateBtn(aqua_device);
   }
}
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Sat Apr 03, 2010 12:19 pm     Reply with quote

You could have one large integer that would hold your absolute seconds...

int32 absolute_secs; <-- This would work for another 136 years.

So you set this seconds to one fixed date and then you can calculate with that. You could use this also for daily time.... how many seconds passed from midnight.

So if you set alarm for 9:31:20 then the value you would be comparing for would be:

(3600*9)+(31*60)+21 ---> 34341 seconds

Also, it could be simplified and you would be setting alarm only on 00 seconds so you would count only minutes from midnight.....

Here are some thoughts about topic Wink
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Sat Apr 03, 2010 12:57 pm     Reply with quote

In 136 years from now some one will probably have taken this project to Mars. Will it work there? Just joking.
dezso



Joined: 04 Mar 2010
Posts: 102

View user's profile Send private message

PostPosted: Sat Apr 03, 2010 1:54 pm     Reply with quote

This alarms should repeat daily.
I don't worry about the seconds.
In basic I can do this:
Code:
            Select Case hour2min
                    Case 0 To 479         ' 00:00 to 08:00 hr
                    Main_Light = 0
                    Second_Light = 0
                    Moon_Light = 1
                    Sump_light = 1
'                    Print At 1,10, "Moon Light/Sump Light ON"
                    Case 480 To  539     ' 08:00 to 09:00
                    Main_Light = 0
                    Second_Light = 0
                    Moon_Light = 1
                    Sump_light = 0
'                    Print At 1,10, "Sump Light OFF"
                    EndSelect


Is it possible in C to have a range of case ?
dezso



Joined: 04 Mar 2010
Posts: 102

View user's profile Send private message

PostPosted: Sat Apr 03, 2010 1:58 pm     Reply with quote

Hold on, this will fail just like my original version.

Code:

Select Case hour2min
                    Case 1439 To 1         ' 23:59 to 00:01 hr


isn't ?
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Sat Apr 03, 2010 2:32 pm     Reply with quote

Ok, what do you want to do here with this code? Are you programming some sort timed power switch?

You have to set conditions according to 24h. Like this :
Code:
 |00----02----04----06----08----10----12----14----16----18----20----22----|
  ______________________________________________________#############_____
#--> On time, _ --> off time
This would be light turn on from 18 till 22 hours

If your light would need to be on trough the night like this:
Code:
 |00----02----04----06----08----10----12----14----16----18----20----22----|
  ################______________________________________##################
On from 18 till 5 in the morning....

In your code you would just check if the time meets condition and then you switch outputs accordingly.

Code:
if (time_of_day==480) //8:00
{
   Light1(0);
   Light2(1);
   Light3(1);
}

if (time_of_day==600) //10:00
{
   Light1(0);   //If there is no change this is not necessary
   Light2(0);
   Light3(1);   //If there is no change this is not necessary
}


You do not need to write switch (case) sentence, all you need are if terms and this is it Wink
dezso



Joined: 04 Mar 2010
Posts: 102

View user's profile Send private message

PostPosted: Sat Apr 03, 2010 5:30 pm     Reply with quote

Yes I should change the title to "24Hr Timer"
This is to turn on and off various device multiple time a day, currently using 8 old fashion mechanical timer like this one.


Anyway, thanks for the input.

I want the timers to be user selectable, so their value will change.
New approach:
Code:
timer0 = 1345; timer0_1 = 360; device0 = 1 ;


Code:

void check_time()
{
   if (ctimer == timer0)                //Tun on time
       {
       bit_set(aqua_device,device0);
       UpdateBtn(aqua_device);
       }
          if (ctimer == timer0_1)      //Turn off time
               {
               bit_clear(aqua_device,device0);
               UpdateBtn(aqua_device);
               }
}


Is there any way to add some redundancy/safety to be sure the selected device will not turn ON or OFF in the not selected time frame ?


Last edited by dezso on Sat Apr 03, 2010 8:55 pm; edited 1 time in total
dezso



Joined: 04 Mar 2010
Posts: 102

View user's profile Send private message

PostPosted: Sat Apr 03, 2010 5:36 pm     Reply with quote

Super quick question, how can I convert the combined minute's to hr's &
min's ?

///
23:25 = (23*60)+25 = 1380 + 25 = 1405
1405 = 1405/60 = 23.4166666666 = 23 hr and 41 min, Grrrrr
dezso



Joined: 04 Mar 2010
Posts: 102

View user's profile Send private message

PostPosted: Sat Apr 03, 2010 5:45 pm     Reply with quote

Maybe :
Code:

ctimer = 1405;
         for (i =ctimer; i > 61; i -60)
               {
               ++hr;
                }
                min = i;
//on the end hr=23 min=25


will this one would work ?

My compiler no longer works, now just writing code. Sad Very Happy
dezso



Joined: 04 Mar 2010
Posts: 102

View user's profile Send private message

PostPosted: Sat Apr 03, 2010 9:23 pm     Reply with quote

I think this should do the trick !?

Code:

       ctimer = 944 // 15:44
       lidiv=ldiv(ctimer,60);
       //lidiv will contain lidiv.quot=15 and lidiv.rem=44 ?

This way I can scroll through all the timer setting and I can see the actual hr:min instead of the guff 944
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