LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Counter reset logic

Hello everyone, I’m new to programming in Labview, having started 2 months ago. Recently I’m doing a project which involves counters, switch cases and logic gates – which I’m still trying hard to understand. I apologise if I’m not being specific on the details.

 

I’m trying to build a program to count the number of people entering and exiting the room by using 2 proximity sensors (S1 and S2). My program will have 3 counters to track the number of INs and OUTs to derive the number of people in the room. Hence the number of people in the room will be INs – OUTs. For this purpose, I am using 2 toggle switches to simulate the sensors.

 

The logic of the counters are as follows:

IN counter: When someone enters the room, S1 is activated first before S2 is activated. When this happens, IN counter will increase by ‘1’.

OUT counter: When someone exits the room, S2 is activated first before S1 is activated. When this happens, OUT counter will increase by ‘1’.

 

Whenever a cycle is complete; ie both S1 and S2 equals to ‘1’, the sensors will revert back to ‘OFF’ state in accordance to whether they are being triggered as IN or OUT.

The resets are as follow:

IN scenario: S1 is reset to ‘0’ first before S2 is reset to ‘0’.

OUT scenario: S2 is reset to ‘0’ first before S1 is reset to ‘0’.

 

The reset part is where I encounter problem. For example, when I simulate the ‘IN’ scenario, the IN Counter = 1, while the OUT Counter = 0, which is as intended. However, when I perform the reset – S1 = 0, then S2 = 0, the OUT Counter increases by ‘1’. The opposite happens when performing the reset for the ‘OUT’ scenario. Is there a way to rectify this?

 

Thanks in advanced for the help, I hope that I can learn something from this.

P.S. Screenshots are attached.

 

Cheers!

ET

0 Kudos
Message 1 of 4
(2,581 Views)

For starters, that logic is way to complex.

 

With 2 Boolean inputs and 2 Boolean outputs, two function is always enough. Work out the logic...

 

P1 P2  P1=F P2=F !(!P1AND!P2) P1<=P2  P2OR(P1<=P2) !(!P1AND!P2)=>... 
F F T T F T T T
F T T F T T T T
T F F T       T F F F
T T F F T T T T

P1 =F is the same as NOT... If you use compound arithmetic, you can invert the input. Implies is a difficult one to use. A and !B is more intuitive.

 

P1 P2  P1AND!P2) 
F F T
F T T
T F F
T T T

 Now this will do exactly the same, so it won't fix anything.

 

But when you have a problem you can't fix, the problem is usually that it's too complex. So simplification is the first step to a solution.

0 Kudos
Message 2 of 4
(2,570 Views)

Adding to Wiebe's remarks, you should (almost never) use a numeric comparison (like less than or equal to) with Booleans.  As it turns out, with the way Booleans are represented in LabVIEW, "less than or equal to" is equivalent to "implies".  However, I also agree that in the present situation, "implies" is confusing for the "non-logician" to reason out.

 

You should also learn about the Increment and Decrement functions, and the use of a Case statement to replace the awkward "Select" in your code (it works out to "If False, Increment; if True, Do Nothing = pass the wire from Input to Output tunnel).

 

You want to make the logic as simple and as "clean" as possible.

 

Here's a question -- is it possible for two people, one to enter, one to exit, at the same time?  Is is possible for one person to start to enter (tripping Sensor 1), then back out?  Can both sensors be tripped at the same time?

 

I think you need to re-think your logic.  I recommend Pencil and Paper -- make yourself a diagram (I suggest you make a tunnel with a door at each end and arranged so one person cannot hold both doors open).  Work out all the possibilities of Tunnel Transit -- it might suggest some "logical" and simple logic ...

 

Bob Schor

 

 

0 Kudos
Message 3 of 4
(2,544 Views)

@Bob_Schor wrote:

 "less than or equal to" is equivalent to "implies". 


A<= B == A implies B == A AND !B == !A NOR B

 

I'd actually prefer A<=B over the imply, but A AND !B over both. Executed with a Compound Arithmetic function.

Message 4 of 4
(2,540 Views)