need help with programing plc webcontrol

Sayed

Member
hello,
any one can help me with program plc timer,
to turn on op1 for 2 hour and turn it off for 2 hour and so, for incubator turner,
 
If you only need to turn it on for two hours and turn it off for two hours, you can do this:

start
set op1 1
delay 7200000
set op1 0
delay 7200000
end

This will turn op1 on and off endlessly. DELAY is a blocking delay, unit is 1/1000 second, max 32bit number.
 
The above works fine if that is the only function the cai board is performing. If you want cai to do other functions more than once every 2 hours it won't work since the program basically "hangs" during the delay.

You could use the CAI clock function to keep the cai program interface free to do other stuff.

Please note, I haven't tested this and I did it kind of quick.

It starts with a test to see if cai has just been turned on. In that case ram1 will be 0. It set ram2 to the current hour and sets ram1 to 1 so that subroutine never gets run again.

Then it test to see if the current hour equals ram2. If yes, it toggles the output and increases ram2 by 2 hours. Then two hours later it runs the toggle subroutine again and turns it off. It resets the clock when it gets above 23 hours.

This program will turn the output on for somewhere between 1 and 2 hours when you first turn cai on. After that, it will do 2 hours on, 2 hours off with the change occuring at the top of the hour.
START
TESTEQ RAM1 0
CALLSUB STRTUP
TESTEQ RAM2 CH
CALLSUB TOGGLE
TESTGT RAM2 23
SUB RAM2 24 RAM2
END

TOGGLE:
TESTEQ OP1 0
GOTO ON
SET OP1 0
ADD RAM2 2 RAM2
RET

ON:
SET OP1 1
ADD RAM2 2 RAM2
RET

STRTUP:
SET RAM1 1
SET RAM2 CH
RET

 
hello,
thanks very much,
not work,
The above works fine if that is the only function the cai board is performing. If you want cai to do other functions more than once every 2 hours it won't work since the program basically "hangs" during the delay.

You could use the CAI clock function to keep the cai program interface free to do other stuff.

Please note, I haven't tested this and I did it kind of quick.

It starts with a test to see if cai has just been turned on. In that case ram1 will be 0. It set ram2 to the current hour and sets ram1 to 1 so that subroutine never gets run again.

Then it test to see if the current hour equals ram2. If yes, it toggles the output and increases ram2 by 2 hours. Then two hours later it runs the toggle subroutine again and turns it off. It resets the clock when it gets above 23 hours.

This program will turn the output on for somewhere between 1 and 2 hours when you first turn cai on. After that, it will do 2 hours on, 2 hours off with the change occuring at the top of the hour.
START
TESTEQ RAM1 0
CALLSUB STRTUP
TESTEQ RAM2 CH
CALLSUB TOGGLE
TESTGT RAM2 23
SUB RAM2 24 RAM2
END

TOGGLE:
TESTEQ OP1 0
GOTO ON
SET OP1 0
ADD RAM2 2 RAM2
RET

ON:
SET OP1 1
ADD RAM2 2 RAM2
RET

STRTUP:
SET RAM1 1
SET RAM2 CH
RET

 
i need the timer work from 0 to 2 am, 4 to 6am, 8 to 10 am, 12pm to 2pm, 4pm to 6pm then from 8 to 10pm,
 
Now try it. I have a hard time typing tsteq instead of testeq.

START
TSTEQ RAM1 0
CALLSUB STRTUP
TSTEQ RAM2 CH
CALLSUB TOGGLE
TSTGT RAM2 23
SUB RAM2 24 RAM2
END

TOGGLE:
TSTEQ OP1 0
GOTO ON
SET OP1 0
ADD RAM2 2 RAM2
RET

ON:
SET OP1 1
ADD RAM2 2 RAM2
RET

STRTUP:
SET RAM1 1
SET RAM2 CH
RET
 
i need the timer work from 0 to 2 am, 4 to 6am, 8 to 10 am, 12pm to 2pm, 4pm to 6pm then from 8 to 10pm,

The above program will do that if you drop the "strtup" subroutine and are patient enough to wait for midnight at which point it will start on that schedule.
 
it work now, but if i turn it off then on it stop op1 then if i turn it off then on again it set op1 on
 
it work now, but if i turn it off then on it stop op1 then if i turn it off then on again it set op1 on

Did you hit the "save states" button? When the unit power cycles, it will start back up with the output on/off status as they were the last time you hit the "save state" button. Whenever you power cycle, it will toggle the value from whatever it set in the "save states" condition to the other. If you turn all the outputs off, then hit "save states", it should always turn the output on when you power cycle.
 
I was bored last night and re-wrote the program. The difference here is that it starts counting the two hours the minute you turn it on. So, if you turn it on at 2:33, then it will immediately turn the output on upon power up, and at 4:33 it will turn it off, then at 6:33 it goes back on, 8:33 off, and so on.

START
TESTEQ RAM1 0
CALLSUB STRTUP
TSTEQ RAM2 CM
CALLSUB HRCNT
TSTNE RAM2 CM
SET RAM3 0
END

TOGGLE:
TSTEQ OP1 0
GOTO ON
SET OP1 0
RET

ON:
SET OP1 1
RET

HRCNT:
TSTEQ RAM3 1
RET
INC RAM1
TSTEQ RAM1 3
CALLSUB TOGGLE:
SET RAM3 1
RET

STRTUP:
SET RAM1 2
SET RAM2 CM
RET

Also, you could make this run every 3 hours by changing "TSTEQ RAM1 3" in HRCNT subroutine to a 4 (or 5 for every 4 hours, or 6 for every 5 hours, etc). For it to immediately turn the output "on" upon power up, under "STRTUP:" have it set ram1 to one less than the you set the "TSTEQ RAM1 X" line for.
 
Back
Top