Вы находитесь на странице: 1из 3

Using Counters and Digital I/O: Step-by-Step Procedure

The following procedure outlines how to count the number of digital pulses received on the counter pin of an
NI Educational Laboratory Virtual Instrumentation Suite (NI ELVIS) II device, and then how to output the digital
value to the digital port of the device in binary format. This procedure requires a single-pole double-throw
(SPDT) switch as well as eight 330 Ω resistors and eight LEDs.
Note: If you have a jumper wire connected to your counter input pins that is toggled between DGND, the
+5 V rail achieves the same results as an SPDT switch.

1. Connect the USB DAQ device to your PC


a. You can locate the device pinouts for your DAQ device by searching for your device online at ni.com
b. The user guide and specifications contain this diagram
c. Right-click your device in NI Measurement & Automation Explorer (MAX) and select Device Pinouts

2. Configure the SPDT switch to output 5 V pulses


a. Wire one throw to the +5 V terminal of your device
b. Wire the second throw to the DGND terminal of your device
c. Wire the output pole to PFI8 (ctr0 SOURCE) of your device

3. Connect the resistor and LED indicator network – using a breadboard is recommended but not required
a. Connect eight LEDs and a 330 Ω resistor in series – the resistor is used to regulate the current flow
through the LED to prevent it from overheating
b. Connect the other terminal of the LED to one of the port0/line0 terminals on your device
c. Connect the other terminal of the resistor to the DGND of your device
d. See the figure below for proper configuration of one LED

e. Repeat for the remaining lines 1–7 of port0 and LEDs

Note: LEDs are diodes, so they allow current to flow in only one direction. If an LED does not light up when
the 5 V voltage is applied, reverse the direction/polarity of the LED because this is most likely happening
because the LED is reversed. If it still does not light up, the LED may no longer be working.

ni.com/students/learnlabview
4. Create a new VI in LabVIEW
a. Open LabVIEW and select File >> New VI

5. Place a counter input DAQ Assistant on the block diagram


a. Right-click on the block diagram and select Express >> Input >> DAQ Assistant
b. Place the DAQ Assistant on the block diagram by left-clicking

6. Configure DAQ Assistant type


a. Select Acquire Signals
b. Select Counter Input
c. Select Edge Count
d. Select Dev1 (or the name of your device if not Dev1)
e. Select ctr0 for counter input channel 0

7. Configure acquisition settings


a. Ensure 1 Sample (On Demand) is selected for Acquisition Mode
b. Select OK to apply configuration
c. Select Yes when prompted to automatically create a While Loop

8. Right-click the Data output terminal and select Create >> Numeric Indicator

9. Run the VI and toggle the SPDT switch


a. Notice the edges being counted on the front panel indicator

10. Place a digital output DAQ Assistant on the block diagram


a. Right-click on the block diagram and select Express >> Output >> DAQ Assistant
b. Place the DAQ Assistant on the block diagram to the right of the counter input DAQ Assistant by
left-clicking

11. Configure DAQ Assistant type


a. Select Generate Signals
b. Select Digital Input
c. Select Port Output
d. Select Dev1 (or the name of your device if not Dev1)
e. Select port0 for port output channel 0

12. Configure acquisition settings


a. Ensure 1 Sample (On Demand) is selected for Acquisition Mode
b. Select OK to apply configuration

ni.com/students/learnlabview
13. Wire the output from the counter input DAQ Assistant Data output terminal to the Data input terminal of
the digital output DAQ Assistant
a. Notice that a Convert from Dynamic Data VI is automatically inserted
b. This is because the counter input’s data type is dynamic, and the digital output requires a 1D array
of numeric

14. Wire the Stopped output from the counter input DAQ Assistant to the Stop (T) input of the digital output
DAQ Assistant
a. This stops the digital generation if the Stop button is pressed

15. Create the stop condition to include when the Stop button is pressed or an error is detected
a. Unwire the Conditional Terminal from the Stopped output terminal of the counter input
DAQ Assistant
b. Right-click the block diagram and select Programming >> Boolean >> Or
c. Wire the output from the Stop button control to the bottom input of the Or Boolean function
d. Right-click the block diagram and select Programming >> Cluster, Class, & Variant >> Unbundle by
Name and place this to the right of the digital output DAQ Assistant
e. Wire the Error Out output terminal of the digital output DAQ Assistant to the input of the Unbundle by
Name function and ensure Status is selected to be unbundled
f. Wire the output of the Unbundle by Name function to the top input of the Or function
g. Wire the output of the Or function to the input of the Conditional Terminal

16. Run the VI and observe the results


a. The Edge Count indicator should match the binary output of the LEDs
You can convert your DAQ Assistant Express VIs into low-level NI-DAQmx functions by right-clicking the DAQ
Assistant and selecting Generate NI-DAQmx Code. The low-level NI-DAQmx API exposes more functionality
and customization options for programming.

©2011 National Instruments. All rights reserved. LabVIEW, National Instruments, NI, and ni.com are trademarks of National Instruments.
Other product and company names listed are trademarks or trade names of their respective companies.

ni.com/students/learnlabview

Вам также может понравиться