Check my basic program?

epdiesel

Supporting Member
Join Date
Sep 2023
Location
Wisconsin
Posts
7
Hello I am new here and new to PLC's, I wrote this program for a class that I am taking and my local tech school. The description is switch 7 will start the sequence and the next witch will turn off the previous light and turn on the light in the rung. Each input is momentary so the output will be latched on. There is one output that needs the output to be switched three times before the output will come on. There is another output that needs the input to be true for five seconds before it comes on. No other switch can start the sequence but 7. My though was using xio for output 7 on each rung to prevent any other switch from triggering the sequence. Let me know if there is any thing that I can change, as well as if there is anything I can do to simplify this basic program. Thanks in advance!
 
Welcome to the forum.

On rung 0000, Light 7 can only be 1 if Light 6 is 0, but on rung 0001, Light 6 can only become 1 if Light 7 is 1.

So Light 7 will come 1 when Switch 7 is initially 1 (pressed). However, when Switch 6 is then 1 (pressed), Light 6 will come on for one scan cycle, but on the next scan cycle Light 6 being 1 will write a 0 to Light 7 on rung 0000, after which Light 7 being 0 will write a 0 to Light 6 on rung 0001.

Once that is fixed, to ensure the sequence is followed, you may need to prevent rung 0000 from writing a 1 to Light 7 if any of the other seven lights are 1.

PLC programming is primarily about time, and the PLC scan cycle is the clock.

Watch this video series to understand the scan cycle and basic relay logic, then look at the Seal-In, Start/Stop Circuit, and Step patterns here to see best practices for what you are trying to do.
 
Updated

Welcome to the forum.

On rung 0000, Light 7 can only be 1 if Light 6 is 0, but on rung 0001, Light 6 can only become 1 if Light 7 is 1.

So Light 7 will come 1 when Switch 7 is initially 1 (pressed). However, when Switch 6 is then 1 (pressed), Light 6 will come on for one scan cycle, but on the next scan cycle Light 6 being 1 will write a 0 to Light 7 on rung 0000, after which Light 7 being 0 will write a 0 to Light 6 on rung 0001.

Once that is fixed, to ensure the sequence is followed, you may need to prevent rung 0000 from writing a 1 to Light 7 if any of the other seven lights are 1.

PLC programming is primarily about time, and the PLC scan cycle is the clock.

Watch this video series to understand the scan cycle and basic relay logic, then look at the Seal-In, Start/Stop Circuit, and Step patterns here to see best practices for what you are trying to do.

Is this the sort of thing that would satisfy both of those conditions you stated? Is there a different/more effective way to do that?
 
Is this the sort of thing that would satisfy both of those conditions you stated? Is there a different/more effective way to do that?

yes, well done, definitely getting there.

why is there an XIC O:0/0 (Light 0 output) in the start branch of the Light 7 rung 0000? Shouldn't that be an XIO and outside the start/seal-in parallel branches like the XIOs for Lights 1 through 6? Or should it even be there at all, because an XIO Light 0, when Light 0 was on, would prevent Switch 7 from triggering the logic on Rung 000 to turn on Light 7?

Rung 0001 seems like the basic pattern for most lights' rungs:
XIO Light(N-1) BST XIC Light(N+1) XIC Switch(N) BND XIC Light(N) BND OTE Light(N)
with the caveat that the Switch(N) is replaced the the timer or counter /DN bit for lights 5 and 3. Most of the others are the same but have the possibly unnecessary XIO Switch 7. Rung 0009 is the same logically, but the ordering of the first three instructions is (N-1)/N/(N+1), which makes it easier to check visually.

why is there an XIC I:0/7 (Switch 7 input) in most, but not all of the Light N branches?

how will the CTU C5:0, which is counting Switch 3 presses be reset? what happens if Switch 3 is pressed three times while Light 5 is lit, and then Switch 4 is pressed? Ask yourself a similar question for Light 5 i.e. what happens if Switch 5 is held down for 5s+ while Light 7 is on, and then Switch 6 is pressed? to answer these questions, use the technique described in @Ron Beaufort's video series i.e. mentally be the PLC and describe how the logic 1s and 0s change over a scan cycle; it is slow and laborious at first, but with practice you will be able to "see" things much more adeptly. how can we stop that (premature /DN bit value of 1) result from happening i.e. how can we prevent Switches 3 and 5 from accumulating counts or time prematurely?

Do you understand why I sent you to the Patterns of Ladder Logic Programming pages at the Contact and Coil website? Which one of those patterns is used for every light here?

What logic operation (see here) is implemented by two or more instructions, or compound instructions, in series? What logic operation is implemented by two or more branches in parallel?
 
Last edited:
Being new to PLC's I think you have doner a good job for a beginner.
Probably not wht you are looking at yet but PLC's have moved on from simple ladder so might be worth looking at thre alternatives i.e. Function block diagram this is akin to digital logic IC's i.e. AND/OR/NOT etc. & even perhaps Structured text as a follow on.
Also boolean logic sequences when complex can be a pain when you want to change or add sequences, another approach is to use States i.e. an integer who's value determines when things need to happen, this has a number of advantages.
1. If you write down the sequence of events & give them a number use that number as the control, suggest use a base of say 10 so you have spare if you need to insert another step.
2. Easy to add or change.
3. Can jump to other step numbers back or forward with ease.
4. if using an HMI then the step seq. number can be used to display text of the current operation i.e. multiple text fields based on a value.
Here are a couple of examples, note that one of these has been done in FBD but providing you understand logic symbols & translate them to ladder contacts it is understandable.
 
yes, well done, definitely getting there.

why is there an XIC O:0/0 (Light 0 output) in the start branch of the Light 7 rung 0000? Shouldn't that be an XIO and outside the start/seal-in parallel branches like the XIOs for Lights 1 through 6? Or should it even be there at all, because an XIO Light 0, when Light 0 was on, would prevent Switch 7 from triggering the logic on Rung 000 to turn on Light 7?

Rung 0001 seems like the basic pattern for most lights' rungs:
XIO Light(N-1) BST XIC Light(N+1) XIC Switch(N) BND XIC Light(N) BND OTE Light(N)
with the caveat that the Switch(N) is replaced the the timer or counter /DN bit for lights 5 and 3. Most of the others are the same but have the possibly unnecessary XIO Switch 7. Rung 0009 is the same logically, but the ordering of the first three instructions is (N-1)/N/(N+1), which makes it easier to check visually.

why is there an XIC I:0/7 (Switch 7 input) in most, but not all of the Light N branches?

how will the CTU C5:0, which is counting Switch 3 presses be reset? what happens if Switch 3 is pressed three times while Light 5 is lit, and then Switch 4 is pressed? Ask yourself a similar question for Light 5 i.e. what happens if Switch 5 is held down for 5s+ while Light 7 is on, and then Switch 6 is pressed? to answer these questions, use the technique described in @Ron Beaufort's video series i.e. mentally be the PLC and describe how the logic 1s and 0s change over a scan cycle; it is slow and laborious at first, but with practice you will be able to "see" things much more adeptly. how can we stop that (premature /DN bit value of 1) result from happening i.e. how can we prevent Switches 3 and 5 from accumulating counts or time prematurely?

Do you understand why I sent you to the Patterns of Ladder Logic Programming pages at the Contact and Coil website? Which one of those patterns is used for every light here?

What logic operation (see here) is implemented by two or more instructions, or compound instructions, in series? What logic operation is implemented by two or more branches in parallel?

Sorry for the late reply! I made some corrections let me know your thoughts, thank you very much so far!:geek:
 
yes, well done, definitely getting there.

why is there an XIC O:0/0 (Light 0 output) in the start branch of the Light 7 rung 0000? Shouldn't that be an XIO and outside the start/seal-in parallel branches like the XIOs for Lights 1 through 6? Or should it even be there at all, because an XIO Light 0, when Light 0 was on, would prevent Switch 7 from triggering the logic on Rung 000 to turn on Light 7?

Rung 0001 seems like the basic pattern for most lights' rungs:
XIO Light(N-1) BST XIC Light(N+1) XIC Switch(N) BND XIC Light(N) BND OTE Light(N)
with the caveat that the Switch(N) is replaced the the timer or counter /DN bit for lights 5 and 3. Most of the others are the same but have the possibly unnecessary XIO Switch 7. Rung 0009 is the same logically, but the ordering of the first three instructions is (N-1)/N/(N+1), which makes it easier to check visually.

why is there an XIC I:0/7 (Switch 7 input) in most, but not all of the Light N branches?

how will the CTU C5:0, which is counting Switch 3 presses be reset? what happens if Switch 3 is pressed three times while Light 5 is lit, and then Switch 4 is pressed? Ask yourself a similar question for Light 5 i.e. what happens if Switch 5 is held down for 5s+ while Light 7 is on, and then Switch 6 is pressed? to answer these questions, use the technique described in @Ron Beaufort's video series i.e. mentally be the PLC and describe how the logic 1s and 0s change over a scan cycle; it is slow and laborious at first, but with practice you will be able to "see" things much more adeptly. how can we stop that (premature /DN bit value of 1) result from happening i.e. how can we prevent Switches 3 and 5 from accumulating counts or time prematurely?

Do you understand why I sent you to the Patterns of Ladder Logic Programming pages at the Contact and Coil website? Which one of those patterns is used for every light here?

What logic operation (see here) is implemented by two or more instructions, or compound instructions, in series? What logic operation is implemented by two or more branches in parallel?

Being new to PLC's I think you have doner a good job for a beginner.
Probably not wht you are looking at yet but PLC's have moved on from simple ladder so might be worth looking at thre alternatives i.e. Function block diagram this is akin to digital logic IC's i.e. AND/OR/NOT etc. & even perhaps Structured text as a follow on.
Also boolean logic sequences when complex can be a pain when you want to change or add sequences, another approach is to use States i.e. an integer who's value determines when things need to happen, this has a number of advantages.
1. If you write down the sequence of events & give them a number use that number as the control, suggest use a base of say 10 so you have spare if you need to insert another step.
2. Easy to add or change.
3. Can jump to other step numbers back or forward with ease.
4. if using an HMI then the step seq. number can be used to display text of the current operation i.e. multiple text fields based on a value.
Here are a couple of examples, note that one of these has been done in FBD but providing you understand logic symbols & translate them to ladder contacts it is understandable.

Yes I believe once I get into studio 5000 and the ControlLogix processors and the Siemens controllers ill get into FBD and structured text, ladder is going well for me though but yes I look forward to learning the other languages for these controllers. Side note I don't believe studio 5000 has FBD as an option and just structured text? Is that true? But as of right now I have to learn the MicroLogix controllers and RsLogix 500 as a (I believe) prerequisite to get into the more advanced classes. Plus at work we still do use some 1000's and 1400's so this knowledge I am gaining will be able to actually be applied at work. My final exam for PLC 1 is coming up next Thursday, then over the winter I am taking a course on HMI's which I am pretty excited for and then in spring I begin PLC 2 getting into the 5000 and ControlLogix processors .
 
Yes I understand your problem regarding FBD but it is an easy transition, after all ladder is just the relay equivelent of digital logic i.e. where you put effective relay contacts in series & parallel FBD is just the graphic equivelent
So in relay contacts it is AND x AND y ANDNOT Z OR A
The FBD is the same i.e. you have an AND Block & A ANDNOT then a OR block.
See attached pic, I do not have RSL500 on this PC so could not show code specific to that platform, however, the one I use mainly is better than most as it comes with all the standard forms i.e. LAD/ST/FBD & it is also able to use a combination as shown. I prefer the one attached as it is not restrictive as to placing the contacts/functions in pre-ordained positions & does not need the implied power rails. The only thing you need to learn regarding FBD is the logic symbols, although UI live in the UK & the symbols for logic blocks are european generally, I cut my teeth on digital logic integrated circuits that were totally American format whereas in europe digital IC blocks use symbols like &/ >| / = etc in square blocks . the American ones use the shape of the symbol to determine it's function.

lad_FBD.png
 
Sorry for the late reply! I made some corrections let me know your thoughts, thank you very much so far!:geek:

There is one typo (Light 6 will never turnstay on), but I think you got it. But you don't need us to tell you, you should be able to test the code on the RSEmulate 500 emulator.

If you have time, see "TL;DR - Things to think about" below.

What I sincerely hope you understand, and what I suspect is the point of the exercise, is that all the lights use essentially the same ladder logic pattern (Start/Stop Circuit), whether the Start condition is the corresponding switch itself or some proxy derived from same (timer or counter).

Well done, and again, welcome to the forum.

TL;DR - Things to think about


  • I like where you put the counter reset; it should operate as you intended.
    • N.B. the reset instruction for the counter, depending when it is triggered, will sometime act as it is designed but not exactly how the coder wants it to act, but that is a topic for a separate post.
  • Very nice catch using the XIC Previous_light instruction on the proxy Start conditions' rungs (0003 timer and 0006 counter), so those proxies do not trigger prematurely
    • But think about this: if those XIC Previous_light condition can prevent the proxy rungs from triggering, is the XIC Previous_light necessary on the actual Start/Stop Circuits runs (0002 and 0005)?
      • It does no harm, and maybe it is worth leaving in for clarity, but is it necessary? I think it is not necessary (else why would I ask), but I could easily be wrong.
  • Are all of the XIO Light_7 instructions necessary?
    • If Switch 7 was supposed to unconditionally turn on Light 7 and reset the system by turning off all the other lights, then it would be necessary, but all of the XIOs on Rung 0000 suggest Switch 7 should only be enabled if
      • EITHER all lights are off,
      • OR only Light 0 is on.
    • So re-read the problem statement, because something in it may necessitate the all of the XIO Light_7 instructions, in which case Rung 0000 might be problematic.
  • Double-check the problem statement; some of the switch inputs and or light outputs might be wired NC i.e. a 1 in the code means inactive input or light off.
  • I might swap the order of Rungs 0002 and 0003, and Rungs 0004 and 0005, so the proxy event (timer or counter expiry) triggers the light on the same scan cycle.
  • Note that Rung 0003, without the XIC Light_6, could be a branch on the output side of Rung 0001 to save an instruction, but it reads better as you wrote it, memory and CPU are cheap, and this is not Code Golf.
  • Similarly, Rung 0006, with out the XIC Light_4, could be a branch on the output side of Rung 0004, but again your code reads better.
  • Other than the typo and the possibly unnecessary XIO Light_7 instructions, there are only two things I might change, and thar is only a preference/style issues.
    1. For Lights 5 through 0, the Start condition branch instructions are ordered [XIC event XIC Previous_light], but for Light 6 the order is reversed (previous light before event), so I would make the Light 6 rung consistent with the other lights' rungs.
    2. This is purely preference: for me, the Start/Stop Circuit pattern is most easily recognized (IMO ;)) when
      1. the ORed Start Condition and Seal-in Condition branches are first i.e. on the left, and
      2. the (not-)Stop condition instructions on right i.e. in the middle just before the Run Output instruction(s).
    3. But again, this is merely my own opinion and preference, as
      • the logical AND of the [Start OR Sealed-In] and [(not-)Stop] section achieves the same result regardless of the order of evaluation.
      • other people, perhaps yourself, more easily recognize the Start/Stop Circuit patter the way you coded it.
Again, well done.
 
N.B. the reset instruction for the counter, depending when it is triggered, will sometime act as it is designed but not exactly how the coder wants it to act, but that is a topic for a separate post.
Untitled.png
Consider the program above, with its current state:

  • the B3:0/0 "pushbutton" not pressed,
    • so the value of the counter enable bit, C5:0/EN is 0, and
  • the counter with preset value of 2, and
  • the current counter accumulator value is 1.
If the B3:0/0 pushbutton is then press and held, on the next scan when that press is detected


  • the counter enable bit value will become 1.
    • because the CTU input rung is True, and
  • the counter accumulator will increment to a value of 2,
    • which matches the counter preset value,
  • which will result in the value of the counter done bit, C5:0/DN, becoming 1,
  • which will in turn trigger the reset of C5:0,
    • which will reset the value of the counter enable bit, C5:0/EN, back to 0,
    • as well as reset the value of the counter accumulator, C5:0.ACC, to 0.
All well and good.

But on the scan cycle after that, if the pushbutton is still pressed, the CTU will detect that pressed condition as a rising edge because the value of C5:0/EN counter enable bit is 0 (from the reset), and the CTU will increment the value of the accumulator from 0 to 1.

So, over two scan cycles, the counter increments the accumulator from 1 to 2 and then from 0 to 1, from a single button press.

This behavior, over two scan cycles with the reset happening during the first, can be confirmed by following the logic in the CTU flow chart here.
 

Similar Topics

Hello I am new here and new to PLC's, I wrote this program for a class that I am taking and my local tech school. The description is switch 7 will...
Replies
0
Views
415
Hello all, I have a Controllogix 1756-L61 with some RIO. There are a couple of 1734-OB4E's that have gone bad. (no output voltage) My boss found...
Replies
10
Views
1,074
I'm trying to save a project as an L5X and I need to uncheck the "Encode Source Protected Content" checkbox, but it's grayed out. How do I get...
Replies
1
Views
944
Hello. I have been working on my first plc project for a while now. I just ordered all the parts that I need and before I did that, I created the...
Replies
10
Views
2,036
I have 2 Absolute Encoders 8192 steps per Rev. (Model TR Electronic CEV65m-11003) These Encoders communicate to the PLC5-60 via Parallel push/pull...
Replies
3
Views
1,518
Back
Top Bottom