How to build your own ring counter with bits.

Doug Hylton

Member
Join Date
Oct 2007
Location
Milwaukie Oregon
Posts
27
This is an example of how to build your own ring counter with bits. This will work with most all PLC’s. It’s a six station ring counter. Try it you will love it. You can add as many stations to it as you have bits. The nice think about it is its under your control and its not a black box instruction. You can modify it and run it backwards or forwards any order you want.

RingCTR1.jpg



M19 Ring Counter Reset

M20 Ring Counter Shift input

M25 Ring Counter Shift Pulse

M1 Station #1

M2 Station #2

M3 Station #3

M4 Station #4

M5 Station #5

M6 Station #6



The zrst instruction is a Mitsubishi instruction that just turns off all the bits. You can do this with a MCR too.

Doug Hylton
 
Last edited:
How to build your own Shift Register with bits

A “roll your own” Shift register.



This is an example of how to build your own Shift Register with bits. This will work with most all PLC’s. It’s a six station Shift Register. Try it you will love it. You can build it as long as you have bits. The nice think about it is its under your control and its not a black box instruction. You can modify it and run it backwards or forwards any order you want. I love jumps. When you jump logic it acts just like the logic is not there. If a bit is on it stays on if a bit is off it stays off.

ShiftReg.jpg
M19 Shift Register Reset

M20 Shift Register Shift input

M25 Shift Register Shift Pulse

X1 Shift Register Data

M1 Station #1

M2 Station #2

M3 Station #3

M4 Station #4

M5 Station #5

M6 Station #6



The zrst instruction is a Mitsubishi instruction that just turns off all the bits. You can do this with a MCR too.
 
Ratchet Relay

This is an example of a Ratchet Relay. X1 is the input and M10 is the out put. Notice the output rung is enclosed by a jump.

If the output rung was not enclosed by the jump M10 would oscillate as fast as possible and that would be “on” one scan and “off” one scan.

Every time the you get an X1 input the output rung is enabled for one scan and if its on it turns off and if its off it turns on.

RR.jpg


With the Mitsubishi PLC’s the Ratchet Relay is built in with the ALT instruction but many PLC's dont have the ALT instruction. There are many other ways to build a Ratchet Relay. I love one line programming. The best programs can be broken down to simple logic that works. Large networks with many rungs are difficult for me to understand.



Doug Hylton
 
Push button Interface

Lets say you have four push buttons for four machine speeds and you want only one machine speed to be on at any one time.

X1 Speed one button
X2 Speed two button
X3 Speed three button
X4 Speed four button

M1 Speed one output
M2 Speed two output
M3 Speed three output
M3 Speed four output.



BB.jpg



When a button is pushed the logic is scanned once and only the output with the button contact in the rung is turned on all other outputs are turned off. Notice the inverted logic in the PLS rung. The inverted logic allows you to change “or” logic to “and” logic. I like doing this because it keeps my rungs to one line. If you keep all your rungs to one line when you are monitoring the project on line you can see more of what is going on. I love simple logic.

Doug Hylton
 
Somebody likes their jump instruction.

While I'm not one of those programming zealots that says you should never use a jump, I will say that the use of jumps is somewhat atypical in plc programming. Just make sure you document the living death (hows that for an oxymoron) out of those constructs. You will be using something many in the general user population haven't seen before. A few sentences may save you a call at 3AM form a VERY upset tech.

Keith
 
I just recently went to a machine controlled by a mitsi plc.

The program was full of CJ's (conditional jumps)
And they were long jumps and then a jump back then a jump forward.

After a while I realised that this original programmer was not using clever logic - he was trying to keep me and anyone else that might try fault find - out..

And he failed!
 
I have seen 2 FX 'bricks' ( 8in 6out or whatever it is ) in the
last month with this style of programming. One had a STL instruction, and the other had th CJ instruction. I looked them up, and though to myself, in a program of this size, why? I am
unsure of the typical scan times of these units, but is a CJ really
necessary, will it have that much effect on the overall scan time? I am assuming that this is why it was done??

I am not badging mitsi, I actually started on medoc/LSS?Tisoft.
 
Latch logic and subs

This is the typical latch or one bit memory. And it looks like a seal in circuit for a relay. The set bit is M1, the reset bit is M2 and the output is Y0.

MyLatch1.jpg



It should have one-shots on the inputs to help with any overlap interference. If they both come on at the same time there will be an unintended result.

The Set bit and Reset bit instructions differ from the latch in that they are not continually driving the output state.


This latch logic works the same as the standard latch but its all on one line. Again you see inverted logic that moves every thing to one line.

MyLatch.jpg


A good program is a series of lists and one line programming lends to making instruction lists. A program has a main loop that is a list of subroutines and within each subroutine is a list of instructions.

Start main
Call sub 1
Call sub 2
Call sub 3
Cal sub 4
Fend (End main)
Sub 1
List of instructions
Sub 2
List of instructions
Sub 3
List of instructions
Sub 4
List of instructions
end

Some subs are called every scan and some may have calling conditions. A fun thing to do is run a sub for one scan. Put an examine on contact in the call sub rung and a reset in the last rung in the sub. The bit can be set anywhere in the program and the sub gets called it does its thing and resets the calling bit.

During startup and trouble shooing the sub calls can be easily disabled allowing trouble shooting the program one list at a time.

A simple program may just be one list of instructions without subs.

Doug Hylton
 
I have to comment

You talk fun, but is it pratical?

I do not know Mitsi, but can you translate any of that to work with ANY plc?
 
Reply to rsdoran

All of the examples I have posted on here using jumps will work on any PLC possibly with the exception of Modicon PLC’s. Modicon PLC’s used to do a funny scan where they didn’t scan each rung but scanned from the left to the right. I don’t know if they still do that.

I know that AB and GE both have a jump instructions and I have programmed with both of them.

Using jumps is just another tool in your bag that can be used to your advantage. I like programs with lots of simple blocks of code over huge networks that can be sometimes unintelligible.



Doug Hylton
 
Thanks Doug,

Not sure if I will use the Jump's or not but thanks for taking the time for the lessons, I love to learn...

I do have a question... the / in the rung, that reverses the logic?

I have a few Mitsubishs but I dont get a chance to play with them much... I just got v8.55 but have not loaded it
 
Why is this a definiton of a 'Good' program?

IMHO, a 'Good' program, is one that achieves the desired result, and is readable and maintainable.

Doug Hylton said:
A good program is a series of lists and one line programming lends to making instruction lists. A program has a main loop that is a list of subroutines and within each subroutine is a list of instructions.
 
Doug Hylton said:
I love jumps. When you jump logic it acts just like the logic is not there. If a bit is on it stays on if a bit is off it stays off.

I despise jumps.
Leaving bits in multiple states in multiple places is poor programming practice.
If I'm looking through a program, I expect to see why my cylinder output is on, not 6 different places where it is fun to use a series of lists on one line.
One line programming does not make a program any easier to monitor or follow IMO.
 
Personally if I was going to use 4 discrete inputs for speed settings I would use a 4 position maintained switch, just one hole to cut, and then 4 lines to turn on the necessary output or one-shot move a value into a word for analog or comm output.

I do not know enough about Mitsi but for me what you are doing is confusing. I am not sure what you mean by driving the output.

With that reverse logic it looks to me like every other scan its turns on or off, I may be wrong because I do not know how Mitsi works nor the instructions available.
 
Using jumps and seting bits

rsdoran said:
Personally if I was going to use 4 discrete inputs for speed settings I would use a 4 position maintained switch, just one hole to cut, and then 4 lines to turn on the necessary output or one-shot move a value into a word for analog or comm output.

I do not know enough about Mitsi but for me what you are doing is confusing. I am not sure what you mean by driving the output.

With that reverse logic it looks to me like every other scan its turns on or off, I may be wrong because I do not know how Mitsi works nor the instructions available.
The logic with jumps will work with most PLC’s. Using a jump is similar to using a set or reset instruction with a one shot except that a jump sets or resets a list of bits. The jump is normally jumping the list and you scan the list for one scan. During that scan any bit instructed off goes off any bit instructed on goes on and they stay that way until that list of bits is scanned again.

There are only two states for a bit on or off there are not multiple states.

Driving the output state
A regular PLC out instruction will continually drive the output state. If the logic is true the bit will be instructed to turn on every scan of the PLC. If the logic is false the bit will be instructed to turn off every scan.

This is fine for straight relay logic but for more advanced programming set-bit and reset-bit must be used. The set-bit and reset-bit instructions can be used in multiple places in the program. For example you can set up a calculation in a subroutine and call that subroutine any where in the program by just setting a bit with the set bit instruction.

If control of the machine is with an HMI the HMI cannot change the state of bits that are being continually driven in the ladder logic.

What if there is a three position selector switch for “Manual Mode”, “Auto Mode” and “Setup” Mode?

When the machine is initially started you want the machine to be in Manual mode. You do not want the machine to start running instantly in Auto mode when the power is turned on. Typically to be safe the operator should turn on the power and nothing should happen until the operator does something else to start the process running.

If you are using a selector switch you cannot change the switch position in the program. I would use three lighted push buttons. Then when the machine is powered up it will be instructed in the logic to always be in Manual Mode.

The same thing would be true for the speed selection if the machine should always start in slow speed.

If you have multiple control stations around your machine don’t use a selector switch use lighted push buttons. Then when auto mode is selected on one station all stations can be in auto mode.

I love simple code and using jumps is a powerful tool in your tool kit that enables you to write compact code. I have seen a lot of PLC programs written without jumps that had relays operating relays operating relays that were practically unintelligible so you don’t have to use jumps to make the program incomprehensible.



Doug Hylton
 
Last edited:

Similar Topics

M8, I'm planning to build my personal PLC trainer. I would appreciate if you can provide me schematic diagram and set-up. I will be using...
Replies
4
Views
8,205
A couple people have asked me about my PLC Trainer, so I thought I would throw it up on the Web for all to see. Hopefully it inspires those not...
Replies
5
Views
6,570
We are considering dropping our UL membership because most of our customers do not care if we are a 508A shop. However, there may be times when a...
Replies
8
Views
342
I'm looking for some clarification if anyone here is familiar with UL698a panels. Panel is out of zone/class'd area. with thermocouples extending...
Replies
0
Views
112
Hey guys, last week I posted part 1 of a series of OPC UA articles in Node-RED. That article covered some important concepts of OPC UA and how...
Replies
8
Views
3,904
Back
Top Bottom