- All Articles
Siemens PLC programming training tutorial | Counters
Part 1 | Siemens PLC programming training tutorial on counters.
Repetition helps build retention and is often the difference between education and training. The Siemens PLC programming tutorial - Counters video has a little repetition in it, but more wont hurt. Plus our first PLC programming example video using the Siemens PLC simulator came out a little blurry. So we offer the additional Counter PLC programming example content below to supplement the video. Also below are screen shots that are more clear than video so you can click on them to enlarge and study. We promise when we create the PLC counter programming example part 2 video, we'll do a better production job. J
The video above shows the factory simulation process we’ll use to explorer how the Siemens PLC counter drives the counter display. You will see us switch the Factory simulator to run mode and the counter starts counting pallets. The bottom photo eye on the safety light curtain detects each pallet passing by. You will also learn in the example that the operator can manually reset the counter to zero.
Ok, lets pull back the curtain and see what controls this counter display on the operator control panel. As shown in picture above, in the Siemens simulation software, we have a counter function. You can see the current value of counter number 107 matches the displayed count via the binary integer output from Siemens PLC counter. Shown below, is the Siemens counter number 107, programmed to reset if the operator’s reset pushbutton is pressed OR if the internal 'Counter Done' bit becomes true.
You can click on Siemens PLC programming example above to enlarge.
Tip: Best practice is to first save a copy of the PLC program to be modified as a different name. So if things go south, you can always go back to original PLC program. We renamed the Sort Height Basic program, adding the word "counter" to the end of its original name. The Sort Height Basic is a Siemens PLC program example that comes with the Siemens simulation software bundle.
This is counter number 107. It is counted up (incremented by 1) with a photo eye pallet bit. In other words, a photo eye that detects each pallet released, increments the counter up. The counter output on right labeled "Q" is a place you can put an output bit that indicates the counter is counting. (We are not using it in this example)
A more useful output bit for a counter would be a counter done bit, like in Allen Bradley PLC counter below.
After limit_switch_1 goes from disabled to enabled 10 times, the .DN bit is true and light_1 turns on. If limit_switch_1 continues to go from disabled to enabled, counter_1 continues to increment its count and the .DN bit remains set. When limit_switch_2 is enabled, the RES instruction resets counter_1 (clears the status bits and the .ACC value) and light_1 turns off.
Eventually the the Rockwell counter above could reach 32767 (the decimal equivalent of a 1 in each of the first 15 bits of ACC integer), try to count 1 more and send the PLC processor into a math overflow major fault shutting down the process. That is why PLC programming Best Practices dictate every counter should have a reset and a failsafe rung to act incase the operator never hits the counter reset button.
Siemens PLC doesn’t have that Done bit, so as you seen in the video, we create another rung (Network) below the counter rung (Network) in the Siemens PLC simulator, that had a comparative statement to create our own counter done bit. It is pictured below so you can see it more clearly. We used a Compare function for Greater Than or Equal To (>+) to create the Siemens counter done bit. Another programming best practice, never use an = instruction unless specifically needed, using >= or <= as it builds greater reliability into your programming and process.
Siemens has the ability to put a preset in the counter, but you have to put a rung/branch with an extra bit to fire the (S)et input of the counter. And it is a bit (pun intended) confusing. It may be more preferred to use a compare statement to generate a done bit and use the done bit to reset the counter or some other event to automatically reset the counter before it reaches its limit. Be it 999 or 32727 accumulated (ACC or CV). Additionally you can have the operator’s push button also resetting the counter.
Bookmark this page as there will be a link "Siemens PLC programming examples - Counters 2" here soon, that will go into counters even more deeply. Even show application of Siemens (S) (PV) combo rung programming example. You wouldn't think so much could be learned from such a simple PLC instructions as a counter. But as you probably noticed by now, we are using the simple instruction to teach you about other PLC programming aspects and instructions too.
Other PLC programming examples.
If you would like to see more PLC programming examples likes this, please share this page with others.
Update: We had a few re-share this webpage with others, so we just added another Siemens PLC programming example pdf #2. (keep sharing this webpage with others and we'll create more!)
The popularity will inspire us to create even more! Thanks
New! 11 PAC/PLC Programming Examples in Structured Text programming language.