Re: simplest manner of sampling from mult. inputs to produce one value


[ Follow Ups ] [ Post Followup ] [ Internet PLC Forum ] [ FAQ ]

Posted ByLeon on December 29, 2001 at 00:19:50:

In Reply to: simplest manner of sampling from mult. inputs to produce one value posted byKen Talley on December 28, 2001 at 17:22:43:

It is simpler if you work on a channel of 16-bits. In your case we can work on 16-bit and leave the last two inputs using your method, which is not wrong, just tideous to input.

What you need to know is that you can use the Exclusive OR operator ^ to filter out which bit of the variable has changed state. We have to store the last bit pattern of INPUT[1] using a DM[1]. Then we can apply the logical operation INPUT[1] ^ DM[1]. If any bit in INPUT[1] becomes different from DM[1] the result is non-zero, and we will then test each bit to find out which one has changed state. After identifying the bit that has changed state, we can then test the INPUT[1] variable at that bit position to find out if it has changed from ON to OFF or OFF to ON and act accordingly.

You need to construct a custom function that continuously monitor the state of INPUT[1] vs DM[1]:

Norm.ON Fn_#1
|-----||--------------{dCusF}

Within the Fn_#1, enter the following codes:

IF INPUT[1]=DM[1] RETURN ' DM[1] store the last state of INPUT[1]
ENDIF ' if no change then ignore.

DM[10] = INPUT[1] ^ DM[1] ' get the bits that has changed state
FOR I = 0 TO 15
IF TESTBIT(DM[10],I) ' BIT I HAS CHANGED STATE
IF TESTBIT(INPUT[1],I) ' BIT I has been turned ON.
X = X + Y ' increment X by Y
ELSE
X = X - Y ' decrement X by Y
ENDIF
ENDIF
NEXT
DM[1] = INPUT[1] ' store the state of INPUT[1]

I will email a sample program to you so that you can test the outcome using the simulator.


: I have started working with your product and like it very much. I have run into a problem that I am sure can be solved much easier than the route that I have currently taken. The situation is this. I have 18 different input switches that control 18 different outputs directly. What I am trying to do is to use a custom function in parallel on each circuit to increase integer x by a value y when on and subtract when off. The manner that I have been able to do it is with a seperate relay and 2 custom functions for each of the circuits for a total of 54 different items.

: Thanks in advance,
: Ken




Follow Ups



Post Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ Internet PLC Forum ] [ FAQ ]