mikeexplorer
Supporting Member
OP
Genius The original post is a little different, it compares 4 bits so if more than one is on then it sends the code to an alarm word for example: if bit 0 has been selected & any of bits 1-3 is on then this is the alarm. I suppose it's a bit like having 4 selector switches (On/Off) and if more than one is turned on alarm.
This started to be 4 possibly 8 combinations, however, it turned into a competition long code versus word comparisons versus loops (bit checks) and bit tests on 32 or more bits. The one problem is I don't think any of the contributors here really know why the alarm is an integer again I think it's down to OP not posting all relevant information and of course as we all do mis-read posts have done it a number of times lol.
I didn't post the whole code because I was only asking about the 4 bit check. I probably should have explained the code in more detail, but I thought the comments in the rungs would explain it. N7:49 is my alarm code integer. A non-zero value indicates a "hard" alarm has occurred and the program will react to it by dropping the "ok to run" bit. It is also used for my HMI panel to display the alarm code.
N7:36 is used by Ladder 10 "Fwd-Rev" as a step sequence for the subroutine. As the subroutine executes and conditions are met, this number is increased by 10 until it reaches 100 which tells the main program that it has completed the request.
The four bits I asked about are 4 track sections that this routine would apply. I am doing a check here to make sure only one area is selected. If it helps, here is the entire ladder 10 program for my "Forward - Reverse" subroutine.
One note, I am using N7:41 to N7:46 as integers to energize an output if it has a non-zero value. These are six outputs that control the track power. There is a subroutine that checks these integers and will enable the output if it has a non-zero value. I need to manipulate these outputs many times in my programs and if anyone remembers my question from over a year ago, I was latching and unlatching these which caused a mess.
This way, not only can I avoid this and not have to use a ton of bit compares, it also allows me to see where in the program the track power was turned on. What I am doing is say for example this is ladder 10 and I want to energize a track section, I will move "1000" into the integer, so I know it was the first section of ladder 10 that energized the track. If later in the same ladder it needs to energize it again, I will move "1010" into it. This has helped me debug these programs as I am developing them.
Mike