PLC code to toggle TTL daily

salesguy

Member
Hey folks, I am a long time lurker and users of the Webcontrol, and have been away from my boards and this hobby for a bit while focusing on a new job.  I want to get back into using my webcontrol board for what it's great at doing, things like scheduled TTL changes.  
 
I want to use the board to power-cycle another board, thus simply a 500ms change of state of one TTL output that is connected to a relay.
 
Can someone help me with a simple code example of a once daily or every "x" hours sub to do this?  I'm not great with scheduling and wasn't sure how to check a time variable properly to make sure I don't miss the expected time.  I"m pretty sure this is simple though.

Thanks!
 
What version firmware? I presume it's not "current" if it's been operating for "some time".
 
Code that should run on an older board:
 
 
Code:
 ....
   mul CH 60 ram1
   add CM ram1 ram1     # ram1 now has minute-of-day from 0 at midnight to 1439 at 23:59
   tstne ram1 570   # 9:30am = 9*60 + 30 = 540+30 = 570
   goto nothing     # not 9:30
   tstgt CS 0           # seconds=0?
   goto nothing
   xor op1 1 op1     # toggle output 1
   delay 500
   xor op1 1 op1     # restore to previous state
   delay 600           # make sure we cannot loop again this second
nothing:
   ... rest of your code here
 
Ross' code will work. If you know how many hours you want to cycle the power, you could also compare those hours, then set a flag for that hour done, reset that flag next hour.
DELAY 500 is a good idea, since WebControl PLC just sit there for half second and doing nothing.   Ross' code uses less lines and less VARs.
 
I implemented some code that I can read easily and follows logic I use elsewhere, ie, using flags, etc.  I'm sure there is a more efficient way of doing this, but this worked well:
 
 
TSTEQ CH 1
        CALLSUB RESET
 

TSTNE CH 1
        SET RAM3 0

 
 
RESET:
    TSTEQ RAM3 1
    RET
    SET OP3 0
    delay 250
    SET OP3 1
    SET RAM3 1
    INC VAR8
    RET
 
Another (possibly simpler way) would be using the daily CTS which Ross posted in an earlier example such as this:

       div cts 86400 RAM4
        mul RAM4 86400 RAM4
        sub cts RAM4  var7
 
then just test for var7 = whatever second of the day you want the action to occur (or at various times of the day).
 
Simple!  Happy to get back to my little board, it was getting lonely.
 
Another (possibly simpler way) would be using the daily CTS which Ross posted in an earlier example such as this:

       div cts 86400 RAM4
        mul RAM4 86400 RAM4
        sub cts RAM4  var7
 
then just test for var7 = whatever second of the day you want the action to occur (or at various times of the day).
 
It appears CTS was only introduced in 3.2.10 or 3.2.11, hence my using the code I did as I wasn't sure you had that option.
Just remember that CTS%86400 returns seconds since 0:0:0 UTC which is not the same as 60*CH + CM which is minutes since local midnight.
 
START
TESTEQ CH 1
CALLSUB EACHDAY
TESTEQ CH 2
SET RAM1 0
END

EACHDAY:
TSTEQ RAM1 1
RET
SET OP1[500] 1
SET RAM1 1
RET


 
The above would run once per day turning output 1 on for 500ms at 1am.  I think this is exactly what you wanted (except that you didn't specify the time).
 
It also does not stop or delay the plc code from running at all so you can just keep adding more stuff and it will run more or less without any hicups from the once daily output 1 on for 500ms.
 
Lou Apo said:
START
TESTEQ CH 1
CALLSUB EACHDAY
TESTEQ CH 2
SET RAM1 0
END

EACHDAY:
TSTEQ RAM1 1
RET
SET OP1[500] 1
SET RAM1 1
RET


 
The above would run once per day turning output 1 on for 500ms at 1am.  I think this is exactly what you wanted (except that you didn't specify the time).
 
It also does not stop or delay the plc code from running at all so you can just keep adding more stuff and it will run more or less without any hicups from the once daily output 1 on for 500ms.
 
Not *quite*. 
If op1 is normally on (1), and the desire was to turn it off (0) for 500ms to reboot the other board, this doesn't work:
 
   SET OP1[500] 1
 
That's why I xor'd it, because the original spec was to "toggle" not set or clear :)
 
Man you guys are good!
 
I mispoke the original requirement, what I am doing is resetting a potentially misbehaving arduino board by bringing OP3 LOW, which is connected to the reset pin on the arduino.   
 
Seems like it did the trick last night.  
 
salesguy said:
Man you guys are good!
 
I mispoke the original requirement, what I am doing is resetting a potentially misbehaving arduino board by bringing OP3 LOW, which is connected to the reset pin on the arduino.   
 
Seems like it did the trick last night.  


START
TESTEQ CH 1
CALLSUB EACHDAY
TESTEQ CH 2
SET RAM1 0
END

EACHDAY:
TSTEQ RAM1 1
RET
SET OP3[500] 0
SET RAM1 1
RET

 
So I assumed you figured out, the above would do that.  But you would need to manually turn on output 3 in the first place.  If you found that to be too much work, the following would fix it.
 

START
TESTEQ RAM1 0
CALLSUB STARTUP
TESTEQ CH 1
CALLSUB EACHDAY
TESTEQ CH 2
SET RAM1 1
END

EACHDAY:
TSTEQ RAM1 2
RET
SET OP3[500] 0
SET RAM1 2
RET

STARTUP:
SET OP3 1
SET RAM1 2 EDIT: Might be better to set ram1 to 1 at start up. Your choice whether you want it start the daily power cycle the first 1am or the second 1am.
RET

 
The above has a startup subroutine.  RAM1 will only be 0 when webcontrol first boots.  So the startup subroutine is used to include any states you want to set things in when the unit first powers up.  From there on, RAM1 toggles between 1 and 2 so the subroutine never runs again.
 
You could actually implement a "pulse dialer" for POST phone line using similar logic.  It is probably nothing else to send after dialed the number.  POST line is 50V+, so it must go through relay board.  Maybe have another relay playing recording after finished dialed number?
 
CAI_Support said:
You could actually implement a "pulse dialer" for POST phone line using similar logic.  It is probably nothing else to send after dialed the number.  POST line is 50V+, so it must go through relay board.  Maybe have another relay playing recording after finished dialed number?
 
 
Like 
 
SET OP1 1 [200]
DELAY 400
SET OP1 1 [200]
DELAY 400
SET OP1 1 [200]
 
To "dial" a 3.
 
Say VAR1 is the number to dial, RAM1 is internal register, you could have
 
dial_ph:
tsteq VAR1 0
set VAR1 10
set RAM1 0
dialing:
set op1 1
delay 200
set op1 0
delay 400
inc RAM1
tsteq RAM1 VAR1
RET
goto dialing
 
 
The part of  logic
tsteq VAR1 0
set VAR1 10
is depending on country. In US, zero actually equals to 10 pulses.
 
If play recording or music after dialing, make sure get those 600 Ohm audio transformer having one side connect to the speaker, the other side through relay connect in parallel to the phone line. 
 
During dialing the number, you will need to have load connected to the phone line. Otherwise, phone company side will see ring voltage go up to 48V, then it will consider caller hang up on the phone.  For ATT and most US phone company, the switch expect the load will cause line voltage drop from 48V to 12V or below.  In my past experienment, off hook voltage can be as high as 15V, as low as 9V.  On hook voltage is 48V to 52V.  Ringer voltage is 90V to 120V 20Hz AC.
 
Dialer logic will actually short two phone lines to make that go to zero volt.
 
Back
Top