Alternating output

mrbob24

Member
Join Date
Jul 2012
Location
Illinois
Posts
17
Hi, i recieved this machine in our plant and it was missing some parts and some code. I am trying to get O:8/5 turn every other time it goes up in Auto. The code is at Rung 114 - 121.
I have tried various things. First i had it turn every time and then i had trun but not stop. Now it won't turn at all. I am using a counter. I was thinking maybe using a SEQ but have never programed one before. I am trying to learn my way through this to avoid paying an outside guy.
thanks
 
Like Eric said... Counter are a clean way, I use them all the time... you can also search flip flop

See this it may help

counter6843873.png
 
I prefer to use the counter method for flip-flopping myself most of the time, but just to offer an alternative, I thought I'd post this old chestnut. This method should work for any brand of PLC. Not as easy for your average maintenance guy to decipher, but it is about as simple for the PLC to execute as any method out there.

Cheers,
Dustin

🍻

Simple Flip-Flop.png
 
Great!! Thanks that was easy to install and it works but now i need away to reset the counter don't I?. I can't reset it when it comes back down because it will always be at one then. Can you use a CTD to reset a CTU? Or could i use a counter to count the pipes coming into the machine, but again i will need to reset that one???? I feel like i am going in circles now.
 
Last edited:
Great!! Thanks that was easy to install and it works but now i need away to reset the counter don't I?. I can't reset it when it comes back down because it will always be at one then. Can you use a CTD to reset a CTU? Or could i use a counter to count the pipes coming into the machine, but again i will need to reset that one???? I feel like i am going in circles now.

No need to reset it, it will just roll over to a negative number and count back up to zero. Then go positive again, an endless cycle.
 
Mickey's right (of course)... but for the sake of understanding the logic, you should be able to reset the counter at 2 and the logic would still just toggle 0.1.0.1.0.1.0.etc....
 
Well it seems that it never resets. i don't kow if it is because i keep re-laoding the program. I now have another probelm is i can't get the turning motor to stop rotating o:8/5. It needs to rotate one time and stop at the input I:1/13 and then go back down. I used a couter and a equ for it but i got something messed up in the code. One day i will master this machine and the art of writing good code.
How do i attach the file to a reply?
 
Last edited:
Latest file

Here is the lastest upload. it appears that the counter is not resetting and the motor will not stop turning 🔨
 
I prefer to use the counter method for flip-flopping myself most of the time, but just to offer an alternative, I thought I'd post this old chestnut. This method should work for any brand of PLC. Not as easy for your average maintenance guy to decipher, but it is about as simple for the PLC to execute as any method out there.

Cheers,
Dustin

🍻

A problem with the code you posted (certainly in A-B PLCs) is that the output will ALWAYS TURN ON, regardless of its previous state, if Auto-Mode is true when the processor restarts, whether that is from a power-cycle, or a change from Program to Run mode.

This is because the processor's pre-scan will turn off all non-retentive outputs, thus resetting the "one-shot" control bit.

The first (proper) scan then triggers the one-shot, and since the pre-scan turned the output off, it will be turned on... always.
 
Here is the lastest upload. it appears that the counter is not resetting and the motor will not stop turning 🔨

Sorry, I am not even going to try to decipher this, as there is no documentation attached to internal data-table addresses.

Trying to understand undocumented code is very difficult, even for an expert.

What I will say is there is no need to reset a counter when you use bit 0 of the accumulator as a toggle bit.

Bit 0 continues to "toggle" ad infinitum, even after the max. count is reached and the overflow bit is set. Just ignore the status bits, and use bit 0 as a toggle.

Advantages of using a counter for toggling is that the count value survives a power-cycle, and program-to-run change. Many of the discrete logic solutions do not restore to the previous state....
 
Sorry kind of a newbie and not sure i understand you correctly. The ACC is going to be 2 for C5:1. Where is the toggle bit? I did not see anything in the help about a toggle bitI need this one to active every other time. And the second counter to active only one time evry time this one is activated.
Thanks for your help and time
 
Where is the toggle bit?

MrBob,

It is the 0 bit of any Counter Accumulator word. For your Counter C5:2 on Rung 121, it would be C5:2.ACC/0. This is an undocumented feature and you will not find it in any Allen Bradley manual that I know about.

For your Rung 119, to use the counter alternating-bit method, use an XIC (Examine If Closed) instruction with address C5:2.ACC/0.

NOTE: I do not think that Rungs 119 to 122 will give you one turn of a motor. As soon as O:8/5 goes ON in Rung 119, the counter will count to 1 and the very same PLC scan will turn it back off on Rung 122. Explain what you are trying to DO, then maybe me or someone else can point the correct method.

Now it won't turn at all.
Yes, that is exactly how I thought it would NOT RUN. To unlatch O:8/5, you need some other bit that says "Job Done, now Stop". When does the I:1/13 Table CW Limit go on? If it does not go on until the motor has finished, then you should be able to use it only, and forget the counter bit on Rung 122. On the other hand, in your upload, I:1/13 is already ON, so the OTU O:8/5 will unlatch the motor. It seems that the Motor CW output in Rung 127 will have to be made to work BEFORE you can make Motor CCW on Rung 122 operate at all.
 
Last edited:
Sorry kind of a newbie and not sure i understand you correctly. The ACC is going to be 2 for C5:1. Where is the toggle bit? I did not see anything in the help about a toggle bitI need this one to active every other time. And the second counter to active only one time evry time this one is activated.
Thanks for your help and time

A counter instruction just adds 1 (CTU) or subtracts 1 (CTD) from the counter's accumulator register (.ACC).

This is simple binary mathematics.

.ACC=0 in binary is 0000000000000000
.ACC=1 in binary is 0000000000000001
.ACC=2 in binary is 0000000000000010
.ACC=3 in binary is 0000000000000011
.ACC=4 in binary is 0000000000000100
.ACC=5 in binary is 0000000000000101
.ACC=6 in binary is 0000000000000110
.ACC=7 in binary is 0000000000000111

and so on.

We don't need to look at the whole value of the accumulator, because we can inspect individual bits of the .ACC value.

In binary notation, bit 0 has the binary weighting of 1 (an odd number), and the successive bits will have the binary weightings of 2, 4, 8, 16, 32, etc. (all even numbers). Bit 0 ON for odd numbers, OFF for even numbers.

So if you look at bit 0, you can see it goes on/off/on/off for each change in value of the accumulator (highlighted in red).

Simply put, when the accumulator value is ODD, bit 0 is ON, and when it is EVEN, bit 0 is OFF. There is no need to look at the value of the accumulator, bit 0 changes state each time the counter counts, so will alternate On/Off/On/Off etc.

HTH
 
A problem with the code you posted (certainly in A-B PLCs) is that the output will ALWAYS TURN ON, regardless of its previous state, if Auto-Mode is true when the processor restarts, whether that is from a power-cycle, or a change from Program to Run mode.

This is because the processor's pre-scan will turn off all non-retentive outputs, thus resetting the "one-shot" control bit.

The first (proper) scan then triggers the one-shot, and since the pre-scan turned the output off, it will be turned on... always.

daba,
You are of course correct. This can be easily solved by adding an XIO of the first scan bit in series with the XIO of B3:0/2 in the above code. This will keep the one-shot from being triggered on first scan and turning on the output. After the first scan, the hold status bit would be on, so no power-up One-Shot Rising. It would require a false-true transition.

That being said, I still prefer the counter method.

@mrbob24,

I'm not able to look at your code, as I don't have the full version of Logix500 here at home. I would say that it sounds like you are trying to increment a counter off of the motor output, and then stop the motor off of the same counter?
I don't see how this could work...
Can you give us a better description of exactly what you're wanting to do, i.e. what should start the motor, what conditions should stop it, etc?
Also, as daba said, you need to get some documentation on your program, or it's not worth anyone's time to try to decipher.

Cheers,
Dustin
 

Similar Topics

Hi All, I am a rookie at ladder programming a Micrologix 1200, and would like to know how to alternate an output from energizing every time from a...
Replies
31
Views
12,478
Today I was making an online edit to a 5/40 Series E Rev K.2 with about 14% free memory. I was removing one branch in a large rung. Accept...
Replies
4
Views
3,177
I have 2 pumps not alternating at a lift station. When im at the panel and use the test switches to initiate the pumps,it alternates in the PLC...
Replies
22
Views
5,852
Hello I have been thinking in some way to operate 3 pumps in the same way (I have schneider modicon m340 PLC): -the pumps feed a tank. - As...
Replies
3
Views
1,894
Hi Everyone, trying to get an alternating output to work. Read through the forums on flip flop, toggle, etc. Found this site...
Replies
5
Views
4,237
Back
Top Bottom