help with plc coding....

bbsux

Active Member
I'm going to be using my webcontrol for quite a few things. but they are all going to be similar enough that I should be able to edit the code if you guys can help me get it sorted out.

First I I have a intermittant problem with tree roots in my sewer, so I want to use a water sensor hooked to a digital input to drive a motorized ball valve to shut off my water main and send me an email if it has been triggered.

Then I want to have my washer and dryer notify me when they are done (but they are the older kind with no leds. Just the round mechanical timer BUT it does have 120vac that stays on the entire cycle, that I plan to use to run a 120vac relay to connect to the digital inputs on the webcontrol.) then Send me an e-mail when complete.

Then I would also like to be notified by email if my mail has been delivered. I plan on having a mercury tilt switch on the mailbox door, which will drive the input and send me an e-mail.

I see this plc code but its setup for analog signals how do I set it up for digital and having a bounce in there as well?:

START
TSTLT T1 500
CALLSUB COLD1
TSTGT T1 510
SET RAM1 0
TSTLT T1 550
CALLSUB COLD2
TSTGT T1 560
SET RAM2 0
END

COLD1:
TESTEQ RAM1 1
RET
EMAIL EM1
SET RAM1 1
RET

COLD2:
TESTEQ RAM2 1
RET
EMAIL EM2
SET RAM2 1
RET

thanks
 
digital inputs are either 1 (getting voltage) or 0 (not getting voltage) so you use tsteq 1 or tsteq 0. Wire one leg of your sensor switch to the cai 5v output, and the other to the digital input. When the switch closes, 5v shows up at the input and it registers "1".

Not sure what you mean by "having a bounce in there"
 
Lou,

I think he means "debouncing" the switch noise.

bbsux,

I would recommend to have one function coded at a time, then add next function.
In the code, you are testing some pretty high temperature, what are those for?

For mechinical dryer, when the timer motor stops, the cycle is done. The rotary timer motor normally is 110VAC. Be careful when working on 110VAC wires. You will also need to detect the dryer was started. Same to washer notification: WebControl needs to know you started the machine, and machine indicates it finished the job. You can use another IP to trigger the logic change RAM or VAR value indicating machine started, or manually set VAR to indicate the starting, or you could setup some relay logic only trigger WebControl IP when both conditions meet.
 
I found that code on here and was looking for help to modify it to work with digital inputs. I can see how that could screw up the RAM variables.

Is there a way I could put a resetswitch that would be hooked to a digital input and reset the digital input I want by software? (like just in case it gets stuck on)

As far as the 120vac on the washer/dryer timer, I am planning on hooking a 120vac coiled relay to them both, then connecting the webcontrol's digital input to that. (I suppose I could hook a 120vac to 5vdc supply then run that to the input as well)

I found this code posted by MobileMe but again its setup for analog inputs instead of digital. @ http://cocoontech.com/forums/topic/20778-webcontrol-email/#entry169145

Code:
START
SET RAM1 0
SET RAM2 0

LOOP:
CALLSUB RESETRAMS
DELAY 1000
TSTGT AIP1 390
CALLSUB SEND_EM1
DELAY 1000
TSTGT AIP2 350
CALLSUB SEND_EM2
GOTO LOOP
END

RESETRAMS:
TSTLT AIP1 370
SET RAM1 0
TSTLT AIP2 230
SET RAM2 0
RET

SEND_EM1:
TSTEQ RAM1 0
EMAIL EM1
SET RAM1 1
DELAY 2000
RET

SEND_EM2:
TSTEQ RAM2 0
EMAIL EM2
SET RAM2 1
DELAY 2000
RET

Thanks
 
As far as the 120vac on the washer/dryer timer, I am planning on hooking a 120vac coiled relay to them both, then connecting the webcontrol's digital input to that. (I suppose I could hook a 120vac to 5vdc supply then run that to the input as well)

In case I wasn't clear I meant maybe i could use a small 120vac - 5vdc or 120vac - 3.3vdc power supply and hook that to the output of the timer on the washer/dryer and then hook the power supply to the webcontrol input -- instead of the relay... But somehow the relay seems simpler????
 
I would just use a relay designed for detecting current on the line. When the relay closes, it connects the 5v output from the cai to the 5v input on an input. You could use a digital input or an analog input, it really doesn't matter. For digital, you check for equal to 1, for analog, you check greater than something like 200 (it will be roughly 0 when off and roughly 500 when on).

start

tsteq ip1 1
set ram1 1
tsteq ip1 0
callsub drierend
end

drierend:
tsteq ram1 1
email em1
set ram1 0
ret

The above program works as follows.

You boot cai, ram1 is 0 and ip1 is 0 (drier is off)
drierend subroutine calls every time the program cycles but no email is sent since ram1 is 0
when you turn the drier on, ip1 becomes 1 and sets ram1 to 1 and the subroutine stops calling
when the drier turns off, ip1 becomes 0 and the subroutine calls
the first time the subroutine calls, ram1 will be 1, and it sends the email, then it sets ram1 to 0 so it doesn't send another email until ip1 (the drier) turns on again.
 
Thanks, I was looking over the other code and was totally exasperated on how to change it.

Code:
start
dryer:
tsteq ip1 1
set ram1 1
tsteq ip1 0
callsub dryerend
end
dryerend:
tsteq ram1 1
email em1
set ram1 0
ret
washer:
tsteq ip2 1
set ram2 1
tsteq ip2 0
callsub washend
end
washend:
tsteq ram2 1
email em2
set ram2 0
ret
mailbox:
tsteq ip3 1
set ram3 1
tsteq ip3 0
callsub mailhere
end
mailhere:
tsteq ram3 1
email em3
set ram3 0
ret
 
with this as a starting point... how do I add the following? For my floor drain leak detector (PCB based on a digital input PIC HERE)



-- when it detects the leak I want it to test it for 5 seconds to make sure its not a splash or something, then if its still triggered I need it to activate an output (with a solid state relay on it) to trigger the motorized ball valve I have to shut off my water main (the valve also has limit switches on both sides, should I integrate them into a check?) And also send me a email. Then I want to have a push button or switch I can press to initiate a reverse of the whole thing (except the e-mail).

This is the wiring diagram of my valve its on page 4. mine is 85 - 240 v ac/dc (no control signal)
http://cdn.valworx.com/downloads/datasheets/valworx/56005601.pdf

Code:
start
dryer:
tsteq ip1 1
set ram1 1
tsteq ip1 0
callsub dryerend
end
dryerend:
tsteq ram1 1
email em1
set ram1 0
ret

Thanks again guys!
 
The code you have there has multiple ends.

PLC code only has one start and one end. Subroutines go after the end. If you want to have notes in there (ie your labels like "dryer:", write your programs in MS word and use the notes feature.

I added input 4 as your water sensor with a 500 millisecond hold for value. If it stays true for 5 seconds it will set output 1 on which is where your valve would be attached. After 5 seconds of being 0, it turns the water back on (turns the output off). Of course you need to purchase a ttl relay to attach to output 1.



start
tsteq ip1 1
set ram1 1
tsteq ip1 0
callsub dryerend
tsteq ip2 1
set ram2 1
tsteq ip2 0
callsub washend
tsteq ip3 1
set ram3 1
tsteq ip3 0
callsub mailhere
tsteq ip4[500] 1
set op1 1
tsteq ip4[500] 0
set op1 0
end

dryerend:
tsteq ram1 1
email em1 set ram1 0
ret
washend:
tsteq ram2 1
email em2 set ram2 0
ret
mailhere:
tsteq ram3 1
email em3 set ram3 0
ret​
 
lou can i have it send me an email if the leak sensor (ip4) is tripped?

Yes, just have it call another subroutine similar to the others.



start
tsteq ip1 1
set ram1 1
tsteq ip1 0
callsub dryerend
tsteq ip2 1
set ram2 1
tsteq ip2 0
callsub washend
tsteq ip3 1
set ram3 1
tsteq ip3 0
callsub mailhere
tsteq ip4[500] 1
callsub leak
tsteq ip4[500] 0​
callsub leakrst
end

dryerend:
tsteq ram1 1
email em1​
set ram1 0
ret​

washend:
tsteq ram2 1
email em2​
set ram2 0
ret​

mailhere:
tsteq ram3 1
email em3 set ram3 0
ret

leak:
tsteq ram4 1
ret
set op1 1
email em4
set ram4 1
ret​

leakrst:​
set op1 0​
set ram4 0​
 
Lou, thanks again for your help with this!

Just one more thing. I'd like to use 2 solid state relays on the water shut off valve instead of one regular one (because that code leaves the valve always energized, and stresses the board more by pulling more power to activate the relay).

so can I do this? In leak: have it run op1 it senses the limit switch on the valve trips (which I could hook to an input), and same with leakrst: ?

wiring diagram for valve is linked in post 8 above page 4 in pdf

thanks again.
 
leak:
testeq ram4 1
ret
set op1 1
email em4
testeq op1[20000] 1
set op1 0
set ram4 1
ret

leakrst:
set op2 1
testeq op2[20000] 1
set op2 0
set ram4 0
ret
 
I think what you are doing will work. Though it really isn't a problem to leave an output on continuously. TTL relays use the switching input as a signal only, they have a separate power source that actually moves the relay. TTL relays can be held continuously on indefinitely using all 8 outputs simultaneously without damaging the cai unit. If you are using a solid state relay you will have to look up the current specs.
 
Lou, I've worked these up in case i decide to use analog current sensors instead of the relays of the washer/dryer, but I also did the other set of code too.

Could you check them over?

(the parts between the ---- will obviously not be included in the code, I just edit them in notepad, and this makes it easier to keep track)

Thanks

Code:
------------------------
analog current sensor on washer/dryer
dryer	   =  analog input 1 = aip1 (analog current sensor)
washer	  =  analog input 2 = aip2 (analog current sensor)
mail	    = digital input 1 =  ip1 (Tilt Switch, when box door is closed is high)
leak	    = digital input 2 =  ip2 (Leak Sensor)
leakrst1    = digital input 3 =  ip3 (Actuator Limit Switch)
leakrst2    = digital input 4 =  ip4 (Actuator Limit Switch)
valve close = output	    1 =  op1 (SSR
valve open  = output	    2 =  op2 (SSR)
----------------
start
tstle aip1 50
set ram1 1
tstge aip1 500
callsub dryerend
tstle aip2 50
set ram2 1
tstge aip2 500
callsub washend
tsteq ip1 0
set ram3 1
tsteq ip1 1
callsub mailhere
tsteq ip2[5000] 1
callsub leak
tsteq ip2[5000] 0
callsub leakrst
end
:dryerend
tsteq ram1 1
email em1
set ram1 0
ret
:washend
tsteq ram2 1
email em2
set ram2 0
ret
:mail
tsteq ram3 1
email em3
set ram3 0
ret
:leak
tsteq ram4 1
ret
set op1 1
email em4
tsteq ip3[11000] 1
tsteq ip3[500] 1
set op1 0
set ram4 1
ret
:leakrst
set op2 1
tsteq ip4[11000] 1
tsteq ip4[500] 1
set op2 0
set ram4 0
ret
---------------------------
digital/direct/relay on washer/dryer
dryer	   = digital input 1 = ip1 (direct/digital/relay sensor)
washer	  = digital input 2 = ip2 (direct/digital/relay sensor)
mail	    = digital input 3 = ip3 (Tilt Switch, when box door is closed is high)
leak	    = digital input 4 = ip4 (Leak Sensor)
leakrst1    = digital input 5 = ip5 (Actuator Limit Switch)
leakrst2    = digital input 6 = ip6 (Actuator Limit Switch)
valve close = output	    1 = op1 (SSR
valve open  = output	    2 = op2 (SSR)
--------------------
start
tsteq ip1 1
set ram1 1
tsteq ip1 0
callsub dryerend
tsteq ip2 1
set ram2 1
tsteq ip2 0
callsub washend
tsteq ip3 1
set ram3 1
tsteq ip3 0
callsub mailhere
tsteq ip4[5000] 1
callsub leak
tsteq ip4[5000] 0
callsub leakrst
end
dryerend:
tsteq ram1 1
email em1
set ram1 0
ret
washend:
tsteq ram2 1
email em2
set ram2 0
ret
mailhere:
tsteq ram3 1
email em3
set ram3 0
ret
:leak
tsteq ram4 1
ret
set op1 1
email em4
tsteq ip5[11000] 1
tsteq ip5[500] 1
set op1 0
set ram4 1
ret
:leakrst
set op2 1
tsteq ip6[11000] 1
tsteq ip6[500] 1
set op2 0
set ram4 0
ret
 
Back
Top