PLC Programming newbie, basic question.

saintnick

New Member
Hi there, I would like to set up one of two scenarios for my current setup.  
I have GE low voltage lights.  I have a webcontrol board to hook up to TTL SSRs.  The GE lights run off a 24v system, and basically shorting them to one pole activates a latching relay remotely, turning the light on.  Shorting the 24v to the other pole reverses the latching relay.  I will use one relay per pole per light to turn on and off with the SSR.  
 
I want to send a half second command to close the relay and have it open back up immediately 1 half second later to prevent burning out the latching relays.  I did some searching for this and wanted to see if the following would do the trick:
START
SET RAM1 CH
SET OP1 1
DELAY 500
SET OP1 0
END
 
Also, any good PLC tutorials out there?  I did a quick google search that did not turn up much.
 
The other scenario has to do more with automation.  I would like to automate the lights based on sunrise/sunset, and wanted to see if the PLC could reference an external value.  If not, I can use openremote or some other item to scrape sunrise sunset
Thanks for the help in advance!
Nick
 
 
You will need some input test to decide when to SET OP1 1, for example, an external switch connected to IP1 for manual light switch.
PLC program always runs from START to END and all over again. Never stop. If you do not add some test condition to only trigger the lights on, PLC code will keep running over and over.  That could burn out your relay coil.
 
You can use a photo resistor running in series with a fixed value resistor. When photo resistor detected light ray, it will change its value. You then hook up one analog input to the middle point of this photo resistor and fixed resistor.  You will see the value change in that analog input based on light condition.  Then you can add test condition between what value you want to turn the lights on and off.
 
In the end of user guide, there is a whole chapter of examples.  If you could go through those examples, it may help learn how to use PLC programming.
 
Thanks for using WebControl.
 
SaintNick,
 
Do you plan to have manual control over the logic control?  If you want, you can use one TTL input to connect to a manual switch to control that.
From your description, your light switch requires two SSR relay, one for ON and one for OFF.  If that is the case, you can have OP1 for ON and OP2 for OFF.
Once all the wires are wired up, you can manually through web GUI test out.  Go to output screen, click on TTL Output1 ON button, then quickly click on the OFF button. that way you can simulate your 500mS delay. Then click on the TTL Ouput 2 ON then OFF to turn off your GE light.
 
If the above test is okay, then you can start program it into PLC.
The simplest PLC program is
START
END
WebControl's PLC engine will loop from START to END then START again, forever and ever.
To make code reuseable, you can use subroutine. For example, one for light ON and one for light OFF.
 
START
END
 
GELITON:
    SET OP1 1
    DELAY 500
    SET OP1 0
RET
 
GELITOFF:
   SET OP2 1
   DELAY 500
   SET OP2 0
RET
 
Next is to add logic to the main PLC body to control the light.  Say you have a photo resistor and resistor to measure the light condition.  You determine after sunset, the photo resister output is 180 and lower (just a random number, yours can be different), and at day break, the photo resistor output is 200.  You can add logic in PLC code, so that when light condition is above 200, you turn OFF the light and when light condition is below 180, your turn ON the light.  Now the above PLC program will become:
 
START
    TSTLT AIP1 180
     CALLSUB GELITON
     TSTGT AIP1 200
      CALLSUB GELITOFF
END
 
GELITON:
    SET OP1 1
    DELAY 500
    SET OP1 0
RET
 
GELITOFF:
   SET OP2 1
   DELAY 500
   SET OP2 0
RET
 
However, the above logic does not care if the GELITON being called all night, and GELITOFF being called all day.  You will need to add more logic to prevent the light being turned ON or OFF all the time.  To do that, you will need to use VAR or RAM to be your flag preventing being called many times.  Use VAR or RAM is your choice. However, during debug the code, VAR is visible on the web GUI, so that you can see the state of the flags.  You could use VAR during debugging, once it is done, change to RAM.  For simple demonstration, we just use whole VAR for that flag. When I say whole VAR, the 3.02.15 and later firmware has bitwise operator allowing to use one bit instead of whole VAR as one flag.
 
GELITON
 SET VAR2 0
 TSTEQ VAR1 1
 RET
 SET OP11
 DELAY 500
 SET OP10
 SET VAR1 1
RET
 
GELITOFF:
 SET VAR1 0
 TSTEQ VAR2 1
  RET
 SET OP2 1
 DELAY 500
 SET OP2 0
  SET VAR2 1
RET
 
You see flags are interlocked between ON and OFF function. Only after ON being called, OFF logic can work once; same only when OFF being called, ON logic can work once.
Please note I use 180 and 200 as photo resistor output, not using 180 for both, because you want to have a range so taht when light condition fluctuate up and down little bit, your light is not being turned on and off repeatedly.
 
Have fun!
 
CAI support, 
This is great, I really appreciate the suggestions and the support!
Thanks for the info on the examples.  I had the user manual and at your suggestion found the technical manual and will review the examples.
I will test out the circuit this weekend with the relay.  I really like the photoresistor idea, I have a great place I can put the photoresistor that should work well.  Where do I wire the photoresistor in?  One of the analog inputs?
I will post results here.  
 
I would consider the non-delay operator.
 
 
SET OP1[500] 1
 
The number in brackets (500) is how many milliseconds it will hold the set value, then it reverts to the old value.  So, if OP1 is off, and it receives that command, it will set it to on, then 500ms later it turns it back off.  Since it is a non-delay operator, the code keeps running and can turn other lights on and off without delay.
 
It also turns 3 lines of code into 1 line of code.
 
Using DELAY freezes the program.  I'm not a big fan of freezing programs.
 
You are absolutely correct, Dr.Lou.
Delay is blocking delay, if you have nothing else waiting to be handled during DELAY. If you do have other I/O to take care during that period of time, your best way is non-blocking delay. One thing that need to be clear is that non-blocking delay starting its timer from the time that output state change.
 
Back
Top