ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What would be the simplest way to create a digital counter in software?

I need to count events on 20 devices (solenoid valves). I need a simple way to implement a digital event counter sub vi that can be used to detect a device going active. Each device is equipped with a simple momentary SPST switch just for this purpose. Since there are 20 devices, I cant use the hardware counters of my 6025e. I would like to have a edge detection where the falling edge means the device as gone active (5V external pullup grounded).

Each device will have an individual accumulator to tally the number of times it went active.
0 Kudos
Message 1 of 6
(3,270 Views)
If your 6025E has enough unused digital I/O, then I would connect the switches to some debounce ciruitry with latches. Use the digital I/O in a continous poll to read the status of the latches and after the read, send a signal to reset the latches so that they're ready for the next switch press. The counting is simple. If the digital line is high, increment a number held in a shift register.
0 Kudos
Message 2 of 6
(3,270 Views)
If I was going to add more hardware that would work well. However I needed a software only solution. Here is something I came up with. It seems to work reasonably well.

It stores the state in a feedback loop for comparison on the subsequent call. If the state has changed then the accumulators are incremented.
This is a Labview 7 file. I can't save it retro unless I remove the feedback loops and use shift registers. Maybe I could post some jpg images of the diagram.?
0 Kudos
Message 3 of 6
(3,270 Views)
Here is a bmp image I made.
0 Kudos
Message 4 of 6
(3,270 Views)
I don't see how a software only solution is going to detect a switch being pressed on a device. Unless you're really talking about switches on the front panel of a VI.
0 Kudos
Message 5 of 6
(3,270 Views)
It will detect the state of the switch because it is all in a controlled sequence. The whole reason for the swithces is to verify that the devices did indeed activate. The detection scheme must also be able to discern if the device remains in a particular state.

I just made a change to the diagram where I changed the feedback loops to shift registers. This was so that I could implement a proper iteration zero initialization.
0 Kudos
Message 6 of 6
(3,270 Views)