Sei sulla pagina 1di 9

MEM 639 Real World Microcomputer Control 1

Hands-on Lab

LabVIEW – NI-DAQ Digital Inputs and Outputs

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).

Concept 1: Create a VI that uses a digital line to turn an LED on or off.


The USB-6211 provides 4 digital input and 4 digital
output lines. One of these digital output lines will be
wired to a real LED (see Photo). A VI, featuring one
toggle switch, will provide the graphical user
interface. When executed, the user will use the
mouse to toggle the switch which consequently turn
the real LED on or off.

Photo: USB-6211 turns LED on or off

Step 1: Place an array control on the empty VI.

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).

Figure 1-1A: Select Array, Matrix, Cluster Control

1 © Copyright Paul Oh
MEM 639 Real World Microcomputer Control 1

Step 2: Drag a toggle switch into the Array control.

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

Step 3: Wire up the block diagram. Invoke the DAQ Assist.

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.

Figure 1-3A: Launch DAQ Assist

2 © Copyright Paul Oh
MEM 639 Real World Microcomputer Control 1

Figure 1-3B: Select Line Output Figure 1-3C: Select port1/line0

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

Figure 1-3D: Select “1 Sample (on Demand)” and click OK

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

Exercise 1: In LabVIEW create programs for the following:

+'ve
COM

Photo E1-1: Wiring setup for reading current

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

Concept 2: Digital Output Port


The USB-6211 has 4 digital output lines. Together, these lines make up one port. One will
invoke decimal-to-binary conversion to light up 4 LEDs in 16 different combinations.

Step 1: Create a 1-D array of 32-bit unsigned integers

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).

Figure 2-1A: Create an array of integers

Figure 2-1B: Select unsigned 32-bit integers

Step 2: Create the Block Diagram.

Select the DAQ Assistant (recall Concept 1 Step 3). This time, select Port Output.

Figure 2-1A: Select Port Output Figure 2-2B: Select port1

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

Figure 2-2D: Wire Array and DAQ Assist

Figure 2-2C: Select “1 Sample (On Demand)”

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.

Figure 2-3: USB-6211 4-bit digital output port

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

Concept 3: Digital Inputs


The USB-6211 also features 4 digital input lines. These can be configured to sense binary
states. Here, +5 Volts in a digital input line denotes a HI state. GND (or close to 0 Volts)
connotes a LO state. As such, the position of a binary device, like a SPST toggle switch, can be
sensed.

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

Step 2: Wire a +5V digital input

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.

Figure 3-2: Wiring up a digital input line

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.

Figure E3-2: Preferred setup for digital inputs

9 © Copyright Paul Oh

Potrebbero piacerti anche