defcon.klaxon
Lifetime Supporting Member
Hi guys,
I have a sequence for my water treatment units and I'm running it with a "sort of" state machine. I say that because I'm not sure if this technically qualifies, but that's at least what I was going for. Here's how it works:
Upon first scan, clear all bits in a "state" DINT, then set bit 0 (offline state). When the filter is called to run, reset bit 0 and set bit 1 (start up state). Once start up is done, reset bit 1 and set bit 2 (filtering state). If I'm running a clarifier flush it's bit 3 through 8 (depending on step), and if I'm running a filter backwash it's bit 9-13 (again, depending on step).
My sequence is a big ladder logic routine, with the "state" bit in front of each rung; thus, they only energize if the state is set. It actually works quite well but one problem I came across today is, each state isn't exclusive and that could really mess things up. I was in the final stage of a backwash (step 13), and long story short I made an HMI change that resulted in the start up bit (bit 1) being set simultaneously.
What I need to program in is some sort of exclusivity, so that only one bit can be set at any time. I'm trying to figure out the best way to do this but I'm not sure the best way to go about it. Is there some sort of XOR function I could do, or some sort of bit mask? I'm guessing the solution is pretty straightforward but I'm not sure of what the most elegant, efficient solution would be.
I have a sequence for my water treatment units and I'm running it with a "sort of" state machine. I say that because I'm not sure if this technically qualifies, but that's at least what I was going for. Here's how it works:
Upon first scan, clear all bits in a "state" DINT, then set bit 0 (offline state). When the filter is called to run, reset bit 0 and set bit 1 (start up state). Once start up is done, reset bit 1 and set bit 2 (filtering state). If I'm running a clarifier flush it's bit 3 through 8 (depending on step), and if I'm running a filter backwash it's bit 9-13 (again, depending on step).
My sequence is a big ladder logic routine, with the "state" bit in front of each rung; thus, they only energize if the state is set. It actually works quite well but one problem I came across today is, each state isn't exclusive and that could really mess things up. I was in the final stage of a backwash (step 13), and long story short I made an HMI change that resulted in the start up bit (bit 1) being set simultaneously.
What I need to program in is some sort of exclusivity, so that only one bit can be set at any time. I'm trying to figure out the best way to do this but I'm not sure the best way to go about it. Is there some sort of XOR function I could do, or some sort of bit mask? I'm guessing the solution is pretty straightforward but I'm not sure of what the most elegant, efficient solution would be.