Practice Coding Example

jthornton

Member
Join Date
Jul 2002
Location
Poplar Bluff, MO
Posts
295
I read in one message where someone was looking for a place to get practice in writing ladder. Why not here? I also read somewhere here about a traffic light example so why not start with that. Some of the more experianced people when they have time can give us advice on our coding solutions and or give us more examples to practice on.

This is a simple starter. Maybe next we can add some cross walk pushbuttons to the Flow Chart...

traffic01.jpg


I'll be a coding this and uploading what I get later...

Thanks
John
 
Yeah, I'm weakening a bit... but I ain't giving away any secrets...

The Traffic Light problem has been the bane of many a novice programmer. The purpose of the exercise is to get the novice to think in terms of details. Also, to think in terms of cause and effect.

Some might think that it is easy to describe a process. It can be easy. But, of course, it really depends on the complexity of the process.

Where a lot of new programmers get in trouble is thinking that they are very familiar with a particular process and that it should be pretty easy to describe.

Try describing how to tie your shoes!

That is a very familiar process to all of us, and yet, without using pictures or actually showing the steps, it is virtually impossible to describe.

In order to describe something, anything, attention must be paid to the details. In PLC Programming, the details are everything!

Now, if anyone was asked to describe the inner-workings of a computer, most would be over-whelmed at the suggestion that such a thing could be done! Jeez! There are so many different parts!

As in any effort in describing something, the first step is too break the system or process down into it's basic parts. You continue breaking those parts into their basic parts. At some point, you get to a level where you start to see commonality in the basic parts.

The first step in breaking a computer system down produces a split between Power Devices and Logical Devices. Software comes later.

The Power Devices are identified from the wall-plug, to the Power Supply, to the various places where Power is used.

The Logical Devices are identified first as major components; Mother-board, particular cards in the slots, hard-drive, floppy-drive, CD... etc.

Then each of those major components are broken down even further. Eventually, you start to see that there is a great deal of commonality between these Logical Devices. These are the basic building blocks. In order to provide an accurate description of how the devices work, you need to know how the basic building blocks work.

Those are the details.

I am in no way suggesting that this is an easy thing to do. In fact, I am suggesting the opposite; it is hard to do! Paying attention to details can be mind-boggling. And yet, you gotta do it! The Devil and all other denizens of the deep are in the details!

With that in mind, what, exactly, occurs when a traffic light is operating? A very handy tool to use, in this case, is a Timing Diagram.

3d7a2bba1efe619a.gif



In the case of a common Traffic Light the pattern simply repeats in a time-oriented fashion.

As shown above, the N-S lights follow a particular pattern. The E-W lights follow a similar pattern but are synchronized with the N-S lights in such a way that you don't have both lights showing GREEN at the same time.

In this example, you can see that there is a particular ratio between the RED, YELLOW and GREEN. If we use YELLOW as the basic time unit, you can see that the ratio of RED-to-YELLOW is 3:1 and the ratio of GREEN-to-YELLOW is 2:1.

GO-STOPPING-STOPPED
The ratio is NOT fixed. That is, you can establish any ratios you want as long as they don't cause conflict.

In a normal light, the ratios would actually be much larger so that the light would be GREEN for a much longer time in one direction (and therefore, RED for a much longer time in the other direction) than YELLOW in either direction.

The ratio of GO-time would be close to the ratio of STOPPED-time, but both would be much larger than STOPPING-time.

Without even considering the specific value of the time-unit, you can see that each segment in the Timing Diagram always produces the same effect. If each light responds according to the particular segment, then the desired result is produced.

So, the task is... how to develop the "segments".

I can Name-that-Tune in one Timer and one Counter.

I hope I didn't give away too much without at least teaching something.
 
Excellent work both, but a few points to consider. It appears the flowchart and timing diagram are for two different exercises. One with overlap, the other without. Frankly I'd say the flowchart was like the final exam on timers while the timing diagram was the mid-term. Myself, I always start students off with just 1 set of lights and progress from there.

Most courses concentrate on one instruction type at time during the introductory stages rather than allowing students to bounce all over the place trying any instruction but learning none. The traffic lab is typically used for introducing students to timers. As an into to timers, counters and comparison instructions are off limits, and the students are asked to employ cascaded timers to accomplish the job. Ideally the lab will start off with just 1 set of lights operated from 3 cascaded timers. 2 sets of lights using 4 timers comes next. Finally the overlap exercise where 6 timers works out well. By the time they have done all this, they should have a pretty good grasp on timers, and are now ready for an intro to counters.

Using timers only is not the simplest or best way of accomplishing the traffic light problem. But the purpose here is to have students learn about timers. Later when they know counters and comparison instructions they can try the traffic exercise all over again.

Terry's description of how to tackle a program could quite readily be applied to creating a lesson plan. Define the goal, then methodically work through the steps to accomplish it.
 
Last edited:
Bill said...

Most courses concentrate on one instruction type at time during the introductory stages rather than allowing students to bounce all over the place trying any instruction but learning none.

I can certainly appreciate that students need to be introduced to the various tools and how they work. However, way too often, that is all they get!

They get a tool and an exercise for that particular tool; even if the exercise could be done by better means.

I believe that there would be a better caliber of student if more effort was put into teaching students how to analyze a particular process and THEN, already knowing which tools are available, teach them how to choose the proper tool for the given task.

I think that approach would provide a more rounded PLC Education.

As Steve is fond of saying...
If the only tool you know is a hammer, sooner or later, everything begins to look like a nail!
 
Terry said...

I can certainly appreciate that students need to be introduced to the various tools and how they work. However, way too often, that is all they get!

Maybe expectations are set a little too high? There is only so much material that can be packed into a 40 hour introductory PLC course. Take a look at the table of contents from Phil's book. Correlate the topics into lessons with defined objectives and measurable outcomes. Put some hours to these, and you'll then see how much time you have left over for those topics you deem lacking.


They get a tool and an exercise for that particular tool; even if the exercise could be done by better means.

If the objective is to learn about the specific tool, then this approach makes perfect sense! Having a student carve out a canoe with an axe is likely good practice with using the tool. Not necessarily the best selection of tool.


I believe that there would be a better caliber of student if more effort was put into teaching students how to analyze a particular process and THEN, already knowing which tools are available, teach them how to choose the proper tool for the given task.

Yes, but you won't get this all done in 40 hours! It's not so much a matter of effort, as it is a matter of time and dollars. Contrary to popular belief, colleges aren't non-profit organizations, and many are continually searching for new courses to run that will contribute to their bottom line. Introductory PLC courses sell well, and good ones fulfill your stated pre-requisite of "already knowing which tools are available". What you are really asking for is a new course. A course that I'd suggest shouldn't be limited to just PLCs. Broaden the scope to "Programming for Industrial Processes 101" and you might draw enough students (dollars) to make it fly. I think you'd be natural for getting something like this together, and a lot of colleges would love to have you run with it.


As Steve is fond of saying...
If the only tool you know is a hammer, sooner or later, everything begins to look like a nail!


No argument here! You should ideally know all the tools. Once that's done, selecting the appropriate tool for the task is usually quite obvious.
 
Last edited:
Bill said in an earlier post...
It appears the flowchart and timing diagram are for two different exercises. One with overlap, the other without.

Terry said in an earlier post...
GO-STOPPING-STOPPED
The ratio is NOT fixed. That is, you can establish any ratios you want as long as they don't cause conflict.


Terry says...
The design I showed includes the over-lap. Varying the ratios allows the lights to operate over a range of conditions - from no over-lap to total over-lap. It's a general solution.

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Terry said...
I can certainly appreciate that students need to be introduced to the various tools and how they work. However, way too often, that is all they get!

Bill said...
Maybe expectations are set a little too high? There is only so much material that can be packed into a 40 hour introductory PLC course. Take a look at the table of contents from Phil's book. Correlate the topics into lessons with defined objectives and measurable outcomes. Put some hours to these, and you'll then see how much time you have left over for those topics you deem lacking.

Terry says...
Of course, you are right (Gain vs. Bandwidth). So much to do... so little time.

Before I went to college (for EE), I worked as a licensed Electrician (still have my license) and worked with PLC's. Developing programs was an exercise in trying to figure out which tools would produce the desired effect - what I now call, HACKING.

When I went to college, I quickly saw the folly of my ways. There was one idea that kept resounding in my mind; these techniques that I've learned in the first two years of college are not beyond the grasp of everyday programmers! The techniques are basic, common sense kinda things. I recognized that the difference was in the approach.

One of my earlier classes, "Digital Design" used a book called "An Engineering Approach to Digital Design".

Now, pay attention... this is the crux of the issue...

The class and book was based on the idea... "Don't worry about tools, whatever tools you need will be available to you."

The focus of the book was to develop a "logical strategy" for producing the required results. Ultimately, it was the "strategy" that identified the functions (the tools) that were needed.

You would then seek out the tools you needed and implement them. If you didn't know how to use them, you learned. If they didn't exist, you made them - WE ARE TOOL MAKERS! This is basis for the idea that, "If you know how to program one PLC, you know how to program them all." It's not so much the tools that we carry from PLC to PLC as much as the "logical strategies"!

Sometimes, being aware of the tools that are available, or having preferred tools, places a bias on the solution. In one way, the bias might not be unacceptable. It tends to allow you to build as you need with the tools you know.

But then, that exposes the other edge of the double-edged sword. By using, or allowing, the bias, the need to learn new tools (possibly, more effective tools) is reduced. These new tools might be tools that already exist (PID?) or they might be tools of your own design (Roll-Yer-Own PID?). In either case, the bias dampens the need to learn; you end up with two or three different kinds of hammers and things still look like nails.

Damn! This seems to have gone on a bit... hasn't it?

It just seems to me that, knowing every tool in your tool-box does not make you a Craftsman. You can be the best "Timer" programmer in the world... that doesn't make you worth a damn when it comes to system control - which is what this is all about!

At the same time, I recognize that you can't be a Craftsman unless you DO know every tool!

chicken-egg-chicken-egg... yeah, ya gotta start somewhere. Now, where's that nail?



XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Bill said...
Broaden the scope to "Programming for Industrial Processes 101" and you might draw enough students (dollars) to make it fly. I think you'd be natural for getting something like this together, and a lot of colleges would love to have you run with it.

Maybe... but do you really think there is a college out there that has room for me, all my keepers AND my big F'in head?
 
Terry said:
Maybe... but do you really think there is a college out there that has room for me, all my keepers AND my big F'in head?

Yeah!...in actual fact most colleges like to see students succeed, and I'm sure yours would. Don't kill anybody, make them a buck, and they'd learn to love you. Even I'd sign up if I could get there.
 
Hmmmm... Tastes better then Crow.

Bill,

Phil can verify that I've been considering this for quite a while (a couple of years, anyway) in the form of a book. I've also kicked around the idea of doing a design-class in the style of normal PLC vendor classes. In thinking of the syllabus, I ran into the timing issues you brought up.

I hadn't considered the idea of doing them through a college. That's a whole-lot-a-food for thought! THANKS!!
 
As in...

E-W GREEN (N-S RED)
then use ground loop-sensor to count 5 cars going E-W

-then-

N-S GREEN (E-W RED)
then use ground loop-sensor to count 5 cars going N-S

Is that what you mean?

There are some mighty lonely intersections in some parts of the country.

I've seen intersections where, aside from a single building (usually a closed-for-the-night 1-pump gas station... Flying-A, I think) the main feature of the intersection was the mindless Stop/Go Light. You could actually hear the relays.

If you stood in the middle of the intersection you could see from horizon to horizon, in all directions, and not see a car. If you happen to come up on the RED, you might be waiting a long time for the GREEN!

Now, be careful... you might not want to drive through that RED LIGHT. They just might have thought to install one of those Automatic Picture Takers for Red Light Violations. You should probably wait for the GREEN.
 
Okay the ground loop sensor has been brought up. How does it work?

The reason for asking is I work odd hours and usually run across redlights at 4 am , not a big deal in a car but on a motorcycle I've waited over 15 minutes for a car to come along and trip the sensor. Or I get tired and run the red light.

How can I trip the sensor on a motorcycle???
I was once told to put the front wheel where the corner of the sensor is but that doesn't seem to work.

Thanks
Drewcrew6
 
I hope everyone caught on to my error... When I did a step table I doscovered that I had left it out.

[

N-S N-S N-S E-W E-W E-W
Red Yellow Green Red Yellow Green
Step 0 On Off Off On Off Off
Step 1 On Off Off Off Off On
Step 2 On Off Off Off On Off
Step 3 On Off Off On Off Off
Step 4 Off Off On On Off Off
Step 5 Off On Off On Off Off
Step 6 On Off Off On Off Off



traffic02.jpg
 
When it comes to PLC's /Engineering/Industrial Process there are many that can do, many that can teach but once in a while (rare occasions) you run into that TEACHER/DOER person...that would be you Terry. I would like to see a course that you had established either in a college or video. You have a good grasp overall on HOW TO and ways to EXPLAIN HOW TO for a variety of applications pertaining to industrial processes.

My real reason for thinking you will (not would because I think you will do this at some point) be GREAT at this is you are actually sincere about all this. You like the work, you like the writing, you like information that SHOWS details in simplest form and above all you would take it personal if your "students" couldnt understand or grasp the concepts and apply them (assuming they arent lazy).
 
Loop sensors

I live in Minnesota and the government just passed a law that a motorcycle is allowed to run a red light if it has been sitting at a red for to long (sensor not picking up the bike). What is to long?? I ride motorcycle and if I need to run a red because of this, I still make sure there are no cops or cars around.

Craig
 

Similar Topics

I'm working in a steel rolling mill at the moment and while digging my way through some existing programs in a 416 cpu I've come across a load of...
Replies
10
Views
2,896
Compactlogix controller, program has 28 conveyors that use TON's to start the conveyors. The TT sounds a warning horn during start and the DN...
Replies
10
Views
486
Out of interest, I'd like some thoughts on what would be considered best practice with regards to a 2-position turntable control scheme (see...
Replies
17
Views
1,138
I'm looking for some starter kits but there aren't so many on the market, so I'm thinking about buying individual components for my needs. I just...
Replies
15
Views
2,455
I'm building a S7-300 rack to work on my Siemens Classic Step 7 programming skills. I've worked now and then with Siemens hardware, usually...
Replies
19
Views
6,507
Back
Top Bottom