08-03-2017 01:01 PM
Hi,
Im new to the LavView programming and i have an NI USB-6008 DAQ.
Can someone please explain me or e-mail me a code how can i use my digital input where i connected the push button as a counter so that every time when i push the push button the number will increment by one.
Please help
Igor
I only managed to do a single array
08-04-2017 02:04 AM - edited 08-04-2017 02:04 AM
Dear Igor,
I am sending a simple VI that I think will have the functionality you are looking for. It is using a counter input to count edges (button pushes). On the front panel you can indicate the loop time in ms, so how often you read the value of the counter. Your device has only one counter so probably on the drop down list in the counter control you will have only one to choose from. The counter indicator with show you what is the value of the counter each time it will be called in the while loop. For NI USB 9008 the counter input is the PFI0, so plug the wire from the button there. I would also recommend to check out the variety of examples provided by LabVIEW which you can find in Help/Find Exa1mples. They are categorized and might help you with your first steps in LabVIEW. Please let me know if I managed to help.
Good luck!
Kamila
08-04-2017 07:24 AM
Hi Kamila,
This did not solve my problem and yes i did try to locate example program included in LabView. I specifically want to use one of my digital inputs to do the count, and i would like to have an action when the button is pressed for example 5 times.
After button is pressed five times i would like to have analog output on one of the channels that i have to drive the led.
Can you please help.
Igor
08-04-2017 07:32 AM
Your DAQ has a single Event Counter in it. So create a Counter task to count your button presses.. When you create it, the DAQ Assistant should tell you which digital line you have to use.
08-04-2017 07:49 AM
Dear Igor,
I don't really understand why don't you want to use the counter input, which is the most reliable resource to count the digital edges created by your button. The indicated value in the VI I sent you (count) might be monitored, and provided it reaches a specific value (for example 5) you could start your analog output. Please tell me more about the functionality you want to obtain so I can help you acheive it. If I undestand it correctly, you want to count the button pushes and with a specific number of pushes trigger an analog output to light up an LED?
Best regards,
Kamila
08-04-2017 08:56 AM
I do not know hoe to do a single count in a digital counter im just a beginner and i would still like to use a digital input as a counter because i have them mote than one.
08-08-2017 06:37 AM
Dear Igor,
If you want to use the digital input, you would have to count the edges in software. This solution is not the best idea, since pushing a button changes state of the digital signal just for the time when its pushed, you need to make sure you "catch" that behavior in your software. I would recommend creating a while loop with the highest possible rate of execution and I would compare the state of the digital input with the one from the last execution of the loop (you should use shift registers http://www.ni.com/getting-started/labview-basics/shift-registers) Then, when you detect a change, you could add it to the counter value. As I said, the disadvantage of that solution is that if you push the button too quickly you might not detect it. Let me know if you encounter any problems developing your program if that option interests you.
Best regards,
Kamila
08-11-2017 07:45 AM
While I'm generally a big fan of counters, one pitfall would be the possibility of switch bounce that could register lots of high speed counts for a single button press. A simple digital input with, say, a 20 msec polling loop wouldn't be so easily "fooled" and is still far faster than a human could toggle a physical button back and forth. Just food for thought...
-Kevin P
12-01-2018 01:47 PM
You can use "Boolean Crossing PtbyPt.vi". Set the inputs as edge triggered and feed it with your digital input. This VI will give true value when there is edge crossing, so you can just increment your counter whenever it will give true.
See this example for making while loop counter -
https://forums.ni.com/t5/Example-Programs/Simple-While-Loop-Counter-Using-LabVIEW/ta-p/3510297
Modify this example by adding your digital input from Daq before/into "Select" function.
Regards
Rishav