Diverter Logic

PLC Pie Guy

Member
Join Date
Jun 2013
Location
Halifax
Posts
1,144
Hey there.
I have a question about a small piece of logic that I have just posted.
It looks okay I think but on rung two, with a single toggle of the pgmrs_bit2 why is it that my SUB instruction always decrements by more than 1. Example: I toggle the pgmrs_bit1 on rung 1 and the value of N7:0 goes up by 1, but a single toggle of pgmrs_bit2 always takes it to a minus value. If I toggle the pgmrs_bit1 twelve times, then toggling bit 2 will take me to a minus 12. Any thoughts on this?

Thanks in advance!
 
I have an Idea, and will take a stab at this since no one else did.

I just learned this from a very smart fellow in a white hat.

Check and see if bit 2 of your program is actually causing bit 15 of your N7:X INT to be 1.

So in other words if N7:0 was 12 it would look like this 0000000000001100
If N7:0 is -12 it would look like this 1000000000001100.

Changing bit 15 of the word to a 1 from a 0 is what makes the value negative, so my guess would be that this is what happens when you toggle bit 2 of your program.

BCS


Edit: I don't have my software with me so I was not able to look at your specific program problem, my post is just speaking in general.
 
Last edited:
Just some guesses:

Don't use an input directly for incrementing counters.
Switches bounce, pushbuttons bounce. A PLC will see that as several counts.
Filter your inputs first.

The SUBtract instruction subtracts "B" from "A" so you are always subtracting from 1 which creates a negative number.
 
In both the ADD and SUB instructions you have the two sources reversed. What you're telling the processor is : Start with a value of '1' and ADD/SUB the value in N7:0 to/from it. Put the resulting value in N7:0.

What you want is: Get the value in N7:0 and ADD/SUB '1' to/from it. Put the resulting value in N7:0

It would be a good idea to do a bounds check and confirm that N7:0 GEQ zero before doing the subtraction. This will insure that you don't get negative values.

Didn't see GTUnit's response. With the ADD instruction order isn't so important. With SUB it is.
 
Last edited:
Hey all.
Thanks for the replies. It was the silly mistake of reversing my sub and add sources.
BCS what you mentioned was my first thought. It didn't take me long though to rule that out.
DougP, I like what you said about the bounds check. That is something I will be adding to this project and moving forward, thanks.
GTUnit. I also will be adding debounce timers. Thanks.

Thanks for all the replies guys, I work alone and for that matter it feels like I'm the only one in this trade for miles. As well my manager is half a country away from me. There is not a large amount of manufacturing in our area and therefore a scarcity of technical folks. Its good to have a place where one can get constructive criticism on their work.

Thanks again.
 

Similar Topics

Good morning fellow sea captains and wizards, I am being asked to do the above and obtain 4 values from each slave, I know about the MRX and MWX...
Replies
26
Views
311
I have a machine which is undergoing upgradation. As part of the process two SEW drives are being replaced., existing Gen B with new Gen C. The...
Replies
3
Views
185
Hello Dear users, I am writing about a problem that has been bothering me for a few days, i.e. I am trying to establish remote access to the Allen...
Replies
0
Views
84
My PLC is currently running the program and the process is still live. One of my 1769-if16C cards values are all frozen but the card is not...
Replies
1
Views
119
need to find C bits in the logic. They are hidden someplace! Thank you! Bob
Replies
5
Views
188
Back
Top Bottom