Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Hands-on Lab
This lab introduces digital input and output (DIO) with LabVIEW software and USB-6211
hardware. Understanding DIO is important because one can learn to turn on/off transistors
(digital output) and read toggle or tactile switches (digital input).
First, right click and then select Array, Matrix and Cluster control (see Figure 1-1A).
Next drag and drop this control on the front panel (gray area).
1 © Copyright Paul Oh
MEM 639 Real World Microcomputer Control 1
Right click, select the Boolean control, and select the Vertical Toggle switch (see Figure
1-2A). Drag this switch into the Array control (see Figure 1-2B).
Figure 1-2A: Select Vertical Toggle Figure 1-2B: Drag and drop into the Array
In the block diagram window, right click and select Measurement I/O – NI-DAQmx – DAQ
Assist (see Figure 1-3A). This will bring up the pop up box.
2 © Copyright Paul Oh
MEM 639 Real World Microcomputer Control 1
In the pop up box (Figure 1-3B), click on Digital Output and select Line Output. The pop
up box will refresh (Figure 1-3C). Select port1/line 0. This selection refers to the USB-
6211’s first digital output line (recall, digital systems often start counting with 0). One will notice
the USB-6211 has four digital lines (line0 to line3). Click Finish.
The pop up box will refresh (Figure 1-3D). Make sure the Generation Mode reads “1 Sample
(On Demand)” and click OK. Save your program as usb6211DigitalOutput1_0.vi
3 © Copyright Paul Oh
MEM 639 Real World Microcomputer Control 1
The pop up box will disappear and one can now drag the DAQ Assistant element into the
block diagram. Select the wire tool and connect the Array element’s output into the DAQ
Assistant’s data input (see Figure 1-3E)
Figure 1-3E: Wire up the Array to the DAQ Assistant (digital output)
Step 4: Physically wire up the LED circuit and run the program.
Use a screwdriver to secure jumpers between the USB-6211 and solderless breadboard. Hook
up the resistor and LED as shown in Figure 1-4 and refer to the schematic. Make sure LED’s
cathode (short leg and flat end of the colored plastic housing) is hooked up to ground
Figure 1-4: Wiring photo and schematic. NB: LED’s negative end (cathode) goes to ground
Execute the VI by clicking the Continuous Play (arrows in a circle) button on the Front end.
Toggle the switch and note the LED turning on and off.
4 © Copyright Paul Oh
MEM 639 Real World Microcomputer Control 1
+'ve
COM
1.1. Set a multimeter to read current (up to 400 mA). Hook up the meter’s leads as shown in the
figure. Toggle the switch from your Digital Output program usb6211DigitalOutput1_0.vi).
What current does the multimeter read? This is called a source current.
1.2. If the digital output voltage is 5 Volts and the LED voltage is 0.7 Volts, what value resistor
should one use? Hint: Use the source current value with Ohm’s Law. What value resistor
was used in the experiment?
1.3. Search for “sink current”. Sketch a schematic where the USB-6211 digital line acts to sink
current for the LED circuit. What are the advantages of sinking vs. sourcing current?
5 © Copyright Paul Oh
MEM 639 Real World Microcomputer Control 1
Drop an array control into the blank VI. Next, drop a numeric control into the array as shown in
Figure 2-1A. Move the mouse cursor over the numeric control to highlight it. Right click and
select Representation. Select U32, which means unsigned 32-bit integer (see Figure 2-1B).
Select the DAQ Assistant (recall Concept 1 Step 3). This time, select Port Output.
6 © Copyright Paul Oh
MEM 639 Real World Microcomputer Control 1
Make sure the Generation Mode is set to “1 Sample (On Demand)”. See Figure 2-2C.
Finish by wiring the Array’s output to the DAQ Assist’s data input (see Figure 2-2D). Save
your program as usb6211DigitalOutputPort1_0.vi
Step 3: Breadboard all 4 LEDs using the USB-6211’s 4 digital output lines.
Connect Ports P1.0 (pin 6) through P1.3 (pin 9) to resistors and LEDs as shown in Figure 2-3.
Click the continuous play button. Cycle the numeric control from 0 to 15 to light LEDs.
7 © Copyright Paul Oh
MEM 639 Real World Microcomputer Control 1
Exercise 2:
2-1. For usb6211DigitalOutputPort1_0.vi what happens over the numeric control is set
to 16? What is this?
2-2. To light LED #0 and LED #3, what is the numeric control number? Hint: binary to decimal
conversion.
2-3. Write a LabVIEW program with a For-Next structure that runs from 0 to 15 and lights up the
LEDs in binary fashion. Hint: Use the Build Array element in the block diagram. Save
as usb6211DigitalOutputPortWhileLoop1_0.vi
Step 1: Employ an LED which will light if the digital line is +5 Volts
Refer to Figures 3-1A and 3-1B to create the front panel and block diagram respectively. The 1-
D array in the front panel is created by dropping a Boolean LED into it. The DAQ Assistant is
configured with Acquire Signals – Digital Input – Line Input and port0/line0.
The Acquisition Mode is set for “1 Sample (On Demand)”. Save the program as
usb6211DigitalInput1_0.vi
Figure 3-1A: 1-D Array of Boolean LED Figure 3-1B: Digital Input setup
8 © Copyright Paul Oh
MEM 639 Real World Microcomputer Control 1
The USB-6211 has a built-in +5 Volt supply (on Pin 10). Refer to Figure 3-2 and execute the
program. When Pin 10 is brought to Pin 1 (digital input P0.0), the front panel LED will light.
Exercise 3
3-1. Write and demonstrate a LabVIEW program that tells the user the state of all 4 digital input
lines. Build upon usb6211DigitalInput1_0.vi to include 4 LEDs.
3-2. Consider the following schematic. Why is this the preferred method to set a digital input line HI
or LO? Hint: a non-connected digital line does not mean GND.
9 © Copyright Paul Oh