Programming a PLC

Tylar1697

Member
Join Date
Apr 2024
Location
Pennsylvania
Posts
3
Hi, I am trying to set up a plc. I've never done any programming with ladder logic previously. I'm trying to set up a a program to turn a device on 1 every 2 input signals or to restart the loop if a certain time has passed. Any advice or help would be appreciated thanks!
 
first of all, you mention loop, I'm not sure you are aware that a PLC runs the logic in a loop in other words it starts from the first rung of logic & goes through each rung in order then loops back to the start this happens pretty fast for example a typical loop time is about 10-20ms (called the scan time).
There are other things that happen like I/O update, communications etc. these can happen either during the program scan or at the end/beginning of the scan, so in most cases your ladder is being scanned all the time, your description of operation is not clear (well in PLC terms), perhaps elaborate.
For example:
if one input is on but other is off no output (does not turn a device on).
If both inputs are on turn on the device (turn a device on)
Or
Is it needs two presses on one input to turn it on ?.
does it turn the output off after the time delay ?
Then allows the cycle to start again ?.
 
I want it to turn on if input count equals 2
Reset input count if x amount time has passed between inputs.

Not sure what the time has to be yet as I need to adjust as I turn hook it up.

Basically plc will get an input signal and turn a pump on to disperse chemicals in a car wash. I don't need it on for every car as brushes get too saturated so that's where I need the counter. However if it gets 1 input signal at the end of the day. I don't want it to skip the first car the next day and have the brushes dry same if it's a rainy day and there's 15min-several hours between cars. That's where I would like the timer to reset the counter.
 
Here's a quick ladder in Omron's Sysmac software which shows the basic program structure I (as a fairly new programmer) would start with -

If in_1 is a button, it will increment a counter every time you press it. The Up function makes sure there is only 1 increment per button press no matter how long the input is held on.
The second rung sets Output_ON when the counter reaches 2. The S in the output means it sets it on until it is turned off.
The 3rd rung resets the counter to zero when it reaches a value of 2, OR when the timeout value is reached.

I don't have the logic for the timeout in here - would require using an accumulation timer triggered when the button is pressed the first time -- I haven't used that function so would have to think a bit more.

This also doesn't have any logic to turn the output off - depends on your situation.

1714407497113.png
 
Hello, I am new to Ladder programming and have a good understanding of Boolean logic. I have an Automation Direct CLICK C0-00DD2-D which has 5 inputs (X1 - X5) and 5 outputs (Y1 - Y5). The trainer connected to the PLC has 5 input switches; X1, X2, X5 are toggle, X3, X4 are momentary PB. The 5 LED outputs are Y1-Blue, Y2-Green, Y3-Amber, Y4-Red, Y5-White.

I am trying to operate the switches in a specific sequence (X1, X2, X5, X3, X4 (hold X4 for 5 seconds and release), X3, X5, X2, X1 and IF the switches are operated in the correct order the Y2 - Green LED remains lit. If the switches are operated in an incorrect order the Y4-Red LED lights and the system resets to try again. I've set up an initial AND sequence but the output function is lighting different LEDs depending on which switch is currently being set or pressed and not just the Green LED.

I've attached an animated GIF showing what the sequence simulates doing. Any help or suggestions to get me moving in the right direction are greatly appreciated.
R/
Jim
 

Attachments

  • PLC Wafer Load.gif
    PLC Wafer Load.gif
    281.5 KB · Views: 16
First of all, I suggest you create your own thread rather than tag onto an existing one.
according to your attachment this is a sequence of some type of automated loader or what ever, forget the switches it is not really what the process is doing, it's ok to use a correct sequence of inputs to turn lights on/off but not the way to simulate a proper sequence.
Rather than use actual inputs use internal bits for simulating the inputs, before simulation programs were bundled with programming software many engineers would create a block of code to map the real inputs to internal bits but not call the block, so the internal bits did the control by writing some temporary logic to turn them on/off at the correct time, those bits are used in the actual code to run the plant.
For example:
comments or symbols could be X0 "Push_Cyl_Back_PX" but the mapped bit would be M0 "Push_Cyl_Back_PX_M" (M denoting the mapped bit
Then in the block (that you do not call while simulating) you map the real Inputs to the internal memory bits like
AND X0 OUT M0
& so on.
Then you write another block of code that simulates the inputs like this
AND Y0 "Push_Cyl_Fwd_sol" OUT T0 2s //So when Cylinder forward output is energised after a time
Then AND T0 SET M1 "Push_Cyl_Fwd_Px_M" // SET the mapped input bit.
Then in reverse when the Cyl goes back reset the mapped fwd bit & after another time Set the back bit.
When testing is done disable or remove the simulation code & enable or download the map code.
This way you can simulate what the real machine will do.
It makes sense the time taken to map & write simulation code is probably the same as the time taken in trying to simulate the process by flicking the switches (how many times will you get it wrong it's not real process where simulation is although timing is just an estimate of the real process, indeed I have done simulations where we change the timers to either speed up or slow down the operations so that is easier to see where there may be errors or speed it up so as to get through the operation of a sequence quicker to test it works.
If I get some time I will come up with some simple code to demonstrate what I mean, by the way, if you download the Do more & C more software they have simulators & are pretty similar to the click so you don't even need a plc & I do believe the C more HMI has simulation that will connect with the Do more program for simulation purposes.
 
This is a sequence. There are specific transitions ([all are 0] => [X1 only is 1] => [X1 and X2 only are 1] => etc.). Also I note that the sequence is symmetric (after the last button is held for 4s, the sequence reverses until all are 0).

A simple approach would be to have the buttons represent bits (summed powers of 2) in an integer, and you could model the valid combinations and the valid transitions. For example, X1, X2, X5, X3, and X4 could drive bits 1, 2, 3, 4, and 5 (values 2, 4, 8, 16, 32), and the 4s expiry of X4 being held could drive bit 0 (value 1).

So if no buttons are held, all integer bits are 0, and the integer value is 0. If X1 is held, then bit 1 value would be 1, so the integer value would be 1 (2#000010 binary = 2 decimal).

So valid values and their transitions are
  • 0, transition from 3 (2#000011 i.e. X1=bit 1 only, plus expiry=bit0)
  • 2 (X1 only = bit 1 = 2), transition from 0
  • 6 (X1 and X2 only = bits 1 and 2 = 2 + 4), transition from 2
  • 14 (X1, X2, X5 only = bits 1 and 2 and 3 = 2 + 4 + 8), transition from 6
  • 30 (X1, X2, X5, X3 only - bits 1 and 2 and 3 and 4 = 2 + 4 + 8 + 16), transition from 14
  • 62 (all pressed/on = bits 1-5 = 2 + 4 + 8 + 16 + 32), transition from 30
    • This starts a 4s timer
  • 63 (all pressed/on + 4s expiry timer = bits 0-5 = 1 + 2 + 4 + 8 + 16 + 32), transition from 62
    • Timer expiry seals itself in as long as transitions are valid (Y2 on - green LED) and X1 value is 1
  • 31 (X1, X2, X5, X3 + 4s expiry timer = bits 0-4 = 1 + 2 + 4 + 8 + 16), transition from 63
  • etc
The program will have three sections, each evaluated once per scan cycle:
  1. build a new integer value from the states of the inputs on the current scan cycle
  2. compare that new integer value to the saved integer value saved from the last scan cycle
    1. if the integer values are the same at this point, then do nothing
      1. i.e. the new and saved integers' values will be the same
    2. if the integer values are different, then check if the [saved => new] transition is valid
      1. if the transition is valid, then assign the new integer's value to to the saved integer value
      2. if the transition is not valid, then do nothing i.e. leave the new and saved integers' value different
  3. compare the new and saved integers' value again
    1. if they are the same, then
      1. either this scan cycle was the same as the last cycle,
      2. or this scan cycle executed a valid transition from from the last scan cycle
      3. so turn on Y2 (green LED), turn off Y4 (red LED)
    2. if they are not the same, then
      1. turn on Y4, turn off Y2
How to recover from an invalid set of inputs or an invalid transition is another matter; maybe all of the above are only executed as long as Y2 (green LED) is on, and when Y4 is on it waits for the inputs to all be 0 and a user reset to be pressed.

I suspect something like the Step patter (cf. here) will be useful.

Caveats
  • This is a notional approach based on the minimal description of the original post (which should be repeated in a new thread).
  • Code to follow the transitions and keep the green LED on would be fairly straightforward and take around a dozen or two rungs,
    • although some of those rungs will be complex with several branches.
  • I don't know your process and/or how to safely would recover the process from a bad input combination or invalid transition.
  • I am certainly and completely and absolutely ignorant of any safety issues.
 
@ Jim Here is an idea where this is a sort of part of your diagram done in Mitsubishi FBD/LAD but easily translated into any other.
This shows how by disabling (Not calling the mapped inputs) but calling a program for simulation it mimics the real Inputs once tested you just need to remove the call to the simulation & enable the input mapping
 

Attachments

  • Trial.pdf
    97.2 KB · Views: 2
@Jim Thompson:

Just to be clear, the entire purpose of the PLC program is to verify that the inputs are activated and deactivated in a particular sequence, is that correct?

So the only outputs of the program are either the green LED (Y2) or the red LED (Y4), is that correct?

Also, from the animated GIF, it looks like the sequence is
  • initial state all inputs are 0
    • robot arm (X1) is retracted
    • slit valve (X2) is closed
    • water lift (X3) and pedestal (X4) are in lowered positions
    • process T1 (X5) is off
  • X1 transitions from 0 to 1 (slit valve opens)
  • X2 transitions from 0 to 1 (robot arm with part extends through slit valve)
  • X3 transitions from 0 to 1 (water lift raises part off of robot arm)
  • X2 transitions from 1 to 0 (robot arm without part retracts back through slit valve)
  • X1 transitions from 1 to 0 (slit valve closes)
  • X4 transitions from 0 to 1 (pedestal raises part off of water lift)
  • X5 transitions from 0 to 1 (process T1 starts, doing summat to part)
  • X5 transitions from 1 to 0 (process T1 completes)
  • X4 transitions from 1 to 0 (pedestal lowers part on to water lift)
  • X1 transitions from 0 to 1 (slit valve opens)
  • X2 transitions from 0 to 1 (robot arm without part extends through slit valve)
  • X3 transitions from 1 to 0 (water lift lower part on to robot arm)
  • X2 transitions from 1 to 0 (robot arm with part retracts through slit valve)
  • X1 transitions from 1 to 0 (slit valve closes)
  • system is at initial state again
Is that correct?
 

Similar Topics

Hello colleagues, Some time ago I started my adventure with programming. With your help and the courses, things are starting to come together...
Replies
13
Views
776
Dear All, I need a sample PLC program to count the output pulse of a mass flow meter so that a specific amount of mass (for example 100gm)can be...
Replies
2
Views
183
Hi Please I have zeilo smart relay #SR2A201BD but I don't have it's programming cable. Can I use any general usb/rs232 converter? Or need...
Replies
3
Views
190
Hi, Does anyone have thoughts or know of, can point in the right direction any published materials with a plumbing centric point of you explaining...
Replies
1
Views
194
@ All: what is your best guess on a potential range in increase in efficiency in % (i.e. saved programming hours, greater output, etc.) when...
Replies
5
Views
400
Back
Top Bottom