PLC Programming is a Journey, not a Destination.
harrybon_98 said:
so given the fact I have four outputs
water pump
heater unit
fill valve
redundant fill valve
and three inputs
low level
normal level
high level
and then
the button turns them on or off as an input to the plc, the plc
So now you are up to (5, 7, ?) inputs?
If you have trouble programming, this is one of the FOUR reasons why:
#1. YOU HAVE TO KNOW WHERE YOU ARE STARTING FROM.
I suggest that before you start writing code, you come up with a more complete I/O list. The list will grow and change as you do the second task.
But that's OK. You've got to start somewhere.
#2. YOU HAVE TO KNOW WHERE YOU ARE GOING TO.
You need a careful, detailed sequence of operations. As you develop this sequence, you'll be realizing that you may have gaps in the I/O, (such as what CK pointed out). Fill them in, and then review your sequence again.
Be sure your sequences are detailed enough.
You were trying to write:
STEP 1. ENERGIZE PUMP OUTPUT.
When you needed to write:
PUMP SEQUENCE
STEP 1a. PRESS "START_PUMP" pushbutton sends signal to PLC.
1b. When "START_PUMP signal is recieved by PLC, energize pump output.
1c. Releasing "START_PUMP" pushbutton drops signal from PLC, but Pump remains running.
etc....
This sequence, unlik yours, shows the need for the START_PUMP PB. As you watch the process, you start asking questions like: "What makes the Pump Stop?" Ah!, I need a STOP_PUMP PB.
Some things to think about:
I have a set of tanks that have a heater unit...
Is that ONE heater to be shared by the SET (how many?) tanks. If so, what are the rules of sharing. If one tank's rules call for the heater to be OFF, and another one wants it ON, who wins.
Is High Level the only thing that turns off the heater, or do you need some sort of temperature sensor to prevent the PLC from boiling away the liquid? Or is that the job of the low level sensor?
Once you have your I/O list and a good sequence, you're ready to START your journey.
#3. YOU HAVE TO KNOW HOW TO GET THERE.
There are no shortcuts. You start by understanding how logic is scanned (especially how what you do on one scan will affect the next), and knowing your instruction set. For beginners, -| |-, -|/|-, -( )-, Timers and Counters are enough (certainly enough for your application.
Then you start with the outputs. Just draw them out in space like this:
PUMP
. . . . . . . . . . . .---( )
FILL_VALVE
. . . . . . . . . . . .---( )
`
Then look at your sequence.
When does the pump come on? -
When the START_PB is pressed
When does the FILL_VALVE open? -
Only while the pump is running and then only the LOW level is reached.
So you add those out in space:
START_PB PUMP
----| |-----+ . . . . . . . . .---( )
PUMP LOW FILL_VALVE
-----| |----+-----|?|---- . . . . . .---( )
`
The -|?|- is there because I don't know if you plan to use the NO or NC contact from the Low Level switch. Does a signal (voltage on the input wire) mean that the tank is low, or that the tank is OK. When you know the answer, change the -|?|- to -| |- or -|/|-, whichever is appropriate.
The line in the sequence: "When the PB is released, the pump keeps running" means that we need to "latch" or "seal" (epending on your age and where you went to school) the pump, like so:
START_PB PUMP
----| |-----+ . . . . . . . . .---( )
|
PUMP |
-----| |----+
`
Similarly, the FILL_VALVE stays open even after the tank has been filled past the low level.
The PMP stops when the STOP_PB is pressed. The FILL_VALVE stops at Mid level.
Adding those in yeilds the complete rung:
START_PB STOP_PB PUMP
----| |-----+------|/|-----------------------------( )
|
PUMP |
-----| |----+
PUMP LOW MID FILL_VALVE
----| |-----+------|?|-----+-----|?|---------------( )
| |
| FILL_VALVE |
+-------| |----+
`
I'm intentially leaving the heater and redundant valve for you to program.
#4. YOU HAVE TO EXPECT DETOURS.
With the completed code, you start asking yourself "What-If" question?
"I know what's supposed to happen when the valve sticks OPEN. What if the valve sticks CLOSED?"
How will I know? Is staying at LOW for more than XX time good enough, or should I have a limit switch on the valve so the PLC can compare what's happening to what it thinks SHOULD be happening?
"What if the valve sticks OPEN (or CLOSED). Shouldn't the PLC tell somebody?"
If so, how. Lights? Noise? How will those be turned off once the problem is fixed?
"What if BOTH the valve stick OPEN?!?"
Should I shut down the Pump? Sound the Alarm? And how will I know? HI_LEVEL staying ON for too long?
This "map" is just a start. If you are serious about learning PLCs, get
PHIL'S BOOK.
Step-by-step. Plain English. It will not just teach you about PLCs, but might even show you how to
think in the methodical manner required, not just for PLCs, but programming in general.