Setting OPx on based on time of day

TJF1960

Active Member
Hello,
 
I have been banging my head against the wall trying to figure this out.
 
I want OP8 to turn on for 15 seconds at 3AM, 11AM and 7PM every day (basically every 8 hours).
All RAM is being used and all but 1 VAR is being used as well. Oh, and OP1-7 are being used.
 
Is it possible and if so can you point me in the right direction?
 
Thanks,
Tim
 
I have been banging my head against the wall trying to figure this out.
 
 
I want OP8 to turn on for 15 seconds at 3AM, 11AM and 7PM every day (basically every 8 hours).
All RAM is being used and all but 1 VAR is being used as well. Oh, and OP1-7 are being used.
 
Is it possible and if so can you point me in the right direction?
 
Is the 3am, 11am and 7pm critical, or are you merely choosing convenient times 8hrs apart?
Is the 15 seconds critical?
I can think of some ugly ways to do it, and some more elegant, but your actual requirements will help.
 
Not tested, but pretty sure this (inelegant) code would work using only 1 var, 1 output and nothing else.
 

Code:
    div cts 86400 var8
    mul var8 86400 var8
    sub cts var8 var8     ; var8 now has current second of the day.
 
    tsteq var8 10800    ; if 3:00:00
   set op8 1  ; turn on output
    tsteq var8 10815   ; if 3:00:15
   set op8 0  ; turn off output
    tsteq var8 39600    ; if 11:00:00
   set op8 1  ; turn on output
    tsteq var8 39615   ; if 11:00:15
   set op8 0  ; turn off output
   tsteq var8 68400    ; if 19:00:00
   set op8 1  ; turn on output  
    tsteq var8 68415   ; if 19:00:15
   set op8 0  ; turn off output
 
rossw said:
Is the 3am, 11am and 7pm critical, or are you merely choosing convenient times 8hrs apart?
Is the 15 seconds critical?
I can think of some ugly ways to do it, and some more elegant, but your actual requirements will help.
The times are not critical nor do they have to be 8 hrs apart, infact in thinking about it more if only two on times a day would make it easier that would work. The output on time also is not critical, anything from 5 seconds on would work, I was just trying to keep the on time less than a minute. Again though, if 1 minute on time would be easier to code then that is fine too. 
 
Thanks,
Tim
 
rossw said:
Not tested, but pretty sure this (inelegant) code would work using only 1 var, 1 output and nothing else.
 
 

    div cts 86400 var8
    mul var8 86400 var8
    sub cts var8 var8     ; var8 now has current second of the day.
 
    tsteq var8 10800    ; if 3:00:00
   set op8 1  ; turn on output
    tsteq var8 10815   ; if 3:00:15
   set op8 0  ; turn off output
    tsteq var8 39600    ; if 11:00:00
   set op8 1  ; turn on output
    tsteq var8 39615   ; if 11:00:15
   set op8 0  ; turn off output
   tsteq var8 68400    ; if 19:00:00
   set op8 1  ; turn on output  
    tsteq var8 68415   ; if 19:00:15
   set op8 0  ; turn off output
Thank you for the code! You may not think its elegant but it sure beats by a long shot what i had came up with. And only using 1 variable too! I was having trouble with the timing. I love your approach to breaking the timing down to current seconds of the day.
 
Thanks so very much!
Tim
 
CAI_Support said:
Tim,
 
If  using VAR and RAM to store states, you may consider to use bitwise operators to save VAR and RAM.
Thank you for the suggestion. I am not up to snuff on bitwise operators yet, although I have seen a couple of examples and am still trying to understand their usage. I will keep studying though.
 
Thanks,
Tim
 
Tim, one thing I thought I better mention, because it isn't obvious to those who don't use it all the time - unixtime/CTS works in the UTC timezone.
If your want the times to be 3am local time, remember to calculate it with your local offset.
So for me, at UTC+10, 3am local time is (3-10)= -7.  -7+24 = 17, so I'd have to use 17:00:00 UTC = 61200 seconds.
If you are lets say, UTC-5, then 3am local time is 3+5= 8:00:00 UTC = 28800 seconds.
 
Ross,
 
CTS implemented in the WebControl is Current Total Seconds from Jan. 1st 2000.  In that way, INT32 will have 30 more years to run in the positive side.  That is different from normal computer time.
 
CTS implemented in the WebControl is Current Total Seconds from Jan. 1st 2000.
 
Just to be annoyingly different, huh?
 
*EXACTLY* when on Jan 1st? 0:00:00 ??
And in which timezone?
 
Here's a WC board, synchronised, set in UTC+11 (my timezone)

            It reports  01/28/2013  18:00:26
and the time is actually 18:00:26  on  28/Jan/2013.
 
CTS is 412671782
Unixtime is 1359356670 so yes, different.
However, unixtime%86400 = 25514
CTS % 86400 = 25514
 
So even though the actual EPOC is different, as I'm only using the remainder (modulo 86400) it's the same thing.
            
                       
 
Yes, Ross. The Internet time is always based on UTC, Greenwich mean time internally. Time zone is only for human to see.  What had happened in year 2000 was that a short number to store the date and time in computer would overflow.  All the computers since then use 32 bit number to store the seconds, some even use 64 bit number. We don't have luxury to use 64bit number in WebControl. In addition, users in their PLC will need to manipulate the seconds in INT32, that is VAR and RAM size.
 
However, for 32bit signed number to represent seconds from 1970,1,1, the number will overflow at year 2038, 25 years from now. We want to make sure most user will not have any problem for even longer time, so we internally use 2000,1,1 as start of the time.  That adds 30 years to the overflow time.  Before that, we may change the CTS starts from another time, so that your boards will never have time overflow problem for at least 50 years running.
 
In the 3.02.16c firmware, we added a MOD operator in PLC programming, which allows to do:
MOD  CTS  86400  VAR1
 
In the 3.02.16c firmware, we added a MOD operator in PLC programming, which allows to do:
MOD  CTS  86400  VAR1

 
Yippie!
 
While you're on a run, how about shift-left and shift-right?  Please?! :)
 
Also, when doing a bitwise operation where the bit is not bit-0 (ie, the least significant bit) but where the destination is only a logic device, how about interpreting the result in a suitable context?
 
For example:
 
     orb 128 128 op1
     orb 2 2 op1
 
both set op1 to non-zero values (as displayed on the status screen) yet the output does not turn on.
Identical code
 
    orb 1 1 op1  
 
however works "properly".
 
I can see situations where wanting to andb or orb an input with a register where I am doubtful the results will work either, although I haven't tested.
 
Shift to the left is same as x2, shift to the right is same as /2, am I correct?  For example, number 3 shift to left one digit, that is same as 3 x 2 = 6, the bit pattern moved from bit 0 and 1, to bit 1 and 2.  Reverse that 6 / 2 = 3.
 
bitwise operator only works on that particular bit or all bits, for
orb 2 2 op1,
op1 is at bit 0 location, so the result is correct set to 0.
There will be a test condition to test the Zero bit from last operation, by BZ, BNZ, CZ, CNZ operators.
 
You may suggest another operator for that test examples you proposed, we will for sure consider them.
 
CAI_Support said:
Shift to the left is same as x2, shift to the right is same as /2, am I correct?  For example, number 3 shift to left one digit, that is same as 3 x 2 = 6, the bit pattern moved from bit 0 and 1, to bit 1 and 2.  Reverse that 6 / 2 = 3.
 
bitwise operator only works on that particular bit or all bits, for
orb 2 2 op1,
op1 is at bit 0 location, so the result is correct set to 0.
There will be a test condition to test the Zero bit from last operation, by BZ, BNZ, CZ, CNZ operators.
 
You may suggest another operator for that test examples you proposed, we will for sure consider them.
 
shift left 1 = mul 2, but I want shift left (or right) X bits.
 
  shl 1 var2 ram3    for example, shift 1 left by as many bits as var2 says.
 
If you wanted to make it arguably more useful, make it a rotate rather than a shift.
With shift, if I shift left 8 places, I simply lose the top 8 bits.
With a rotate, I can rotate left 8, then when finished, rotate right 8 and restore the original without needing another register to store it in.
 
Back
Top