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

Hello, I am going over some old code from days gone by. I would like the expert to confirm my findings to see if I got it correct. 1. B64:22/3...
Replies
7
Views
285
Hello, I´m having a problem trying to program in Ladder. An output should be trigged by two possible contacts. Take a look on the printscreen...
Replies
5
Views
164
I got my PanelView Plus 7 working with a Micrologix 1500. How would I connect my laptop to the PanelView to view the ladder logic while operating...
Replies
6
Views
182
Hello, I am trying to replicate a piece of logic on the PLC5 onto an SEL RTAC. I am using ladder on SEL and FBD. I am having issue on the ladder...
Replies
13
Views
262
Hello again..trying something on an existing poorly written program and just wanted to double check something system is an A-B MicroLogix 1200 In...
Replies
5
Views
184
Back
Top Bottom