You are on page 1of 22

The University of Alabama at Birmingham

School of Engineering
Department of Mechanical Engineering
in collaboration with
National Instruments Corporation

ME 360 Systems Modeling and Controls

DC Motor on/off Control with NI myRIO


Prepared By:

Vehicle and Robotics Engineering Laboratory


Mechanical Engineering Department
School of Engineering
University of Alabama at Birmingham, USA

Vladimir V. Vantsevich
Professor and VREL Director

Mostafa A. Salama
Graduate Research Assistant, PhD Student and VREL Supervisor

Marc A. Parker
Undergraduate Student and VREL Lab Assistant

2|Page
Contents

• Objectives.………………………………………………………………………………………..….4

• Introduction……………………………………………………………………………………….…4

• NI Kit Equipment…………………………………………………………………………………..4

• Theory…………………………………………………………………………………………………..5

• Experiment……………………………………………………………………………………………6

o Part 1 of the Lab: Building the interface circuit…………………….………6

o Part 2 of the Lab: Building the VI……………………….………………………..8

o Part 3 of the Lab: Incorporating a Physical Switch……………..……….20

• Assignment……………………………………………………………………………….…………22

• References……………………………………………………………………………….………….22

3|Page
Lab 1: DC Motor on/off Control
Objectives:
1) To experience building software and electrical tools to control a mechanical output device.
2) To understand how to use electrical, software, and mechanical components to achieve a user-
friendly and intelligent system.
3) To understand how to receive one type of signal and transform it to provide the input signal for
another device.

Introduction:
In Kinematics and Dynamics of Machinery you learned how to create a desired motion starting with a
rotating shaft by incorporating systems of linkages and gears which made an engineering basis for
learning mechatronic systems in the ME360 course. This laboratory experience goal is to provide you
with a practical knowledge and hands on skills of how to automate the rotational input to your
mechatronic system. This will be performed using National Instruments MyRIO and the MyRIO Start Kit.

In this lab your will start with a simple on/off control of a DC motor. You will build a circuit to operate
the motor on a breadboard that you will then plug into the MyRIO. You will also build a computer
program VI in LabVIEW that will control the motor. After being able to turn the motor on and off in
LabVIEW, you will on/off the motor using physical device (Slide switch) for providing inputs to myRIO.

NI Kit Equipment:

Direct Current Motor

General Purpose Rectifier


1N4001

ZVN2110A n-channel enhancement-mode


MOSFET

ZVP2110A p-channel enhancement-mode


MOSFET

4|Page
IRF510 n-channel enhancement-mode power
MOSFET

Breadboard

Jump wires, M-F (4x)

On-Off Slide Switch

Theory:
A direct current, or DC, motor works off of the fact that two electromagnets that are alike repel each
other and two that are alike attract. By constantly changing the direction of magnetic fields, rotational
motion is achieved. See Figure 1.

Figure 1: Basic components and operating principle of a DC motor

The interface circuit to operate the DC motor requires four connections to the myRIO: (i) a 5 volt power
supply, (ii) 3.3 volt power supply, (iii) ground, and (iv) the motor control. The motor requires
approximately 180mA (at 3.3 V) when unloaded and over 1000mA when running at maximum efficiency,
three times higher than the maximum available current from all three connectors combined. Stalling the
motor due to excessive loading or blocking the rotor demands even higher current because effective
resistance of the motor is less than 1. For these reasons the IRF510 n-channel enhancement power
MOSFET serves as a high-current solid-state switch to operate the motor.

5|Page
Because the IRF510 gate-to-source threshold voltage VGS(th) ranges from 2 to 4 V the NI myRIO DIO
output voltage of 3.3 V is not sufficient to turn on the IRF510. The two low-power MOSFETS arranged as
a standard CMOS logic inverter supplied by the 5 V supply act as a 3.3-to-5 V level shifter to ensure that
the IRF510 gate voltage is either 0 V (off) or 5 V (on). See Figure 2 for complete circuit diagram.

Experiment:
Part 1 of the Lab: Building the interface circuit

Refer to the schematic diagram and recommended breadboard layout. The interface circuit requires
four connections to NI MyRIO MXP Connector B:

5-volt power supply → B/+5V (pin 1)

3.3-volt power supply → B/+3.3V (pin 33)

Ground → B/GND (pin 30)

Motor control → B/DIO8 (pin 27)

Slide switch → B/DIO0 (pin 11)

Although this diagram shows circuit components connected directly to the myRIO port, the circuits in
this lab will be built on a breadboard and connected to a built-in port that is then plugged into the XMP
Port B in myRIO. In other words, the real case will have one level of separation between the circuit
components and myRIO pins, but the diagram still illustrates the same principles.

6|Page
Input
B/GND [30] B/DIO0 [11]

Output

Figure 2: Interface circuit diagram

7|Page
Part 2 of the Lab: Building the VI

Step 1: Open LabVIEW: on the desktop, double click on LabVIEW icon to start LabVIEW.

Step 2: Create New Project: by choosing “LabVIEW for MyRIO” and then click “Start LabVIEW”. See
Figure 3.

Figure 3: Choose Environment Settings

Another window will pop up. Click on “Create Project”. See Figure 4.

8|Page
Figure 4: Create Project (1)

“Create Project” window will pop up. Click on “MyRIO” on the left side list menu then click “MyRIO
Project” on the right side list menu. Click “Next”. See Figure 5.

Figure 5: Create Project (2)

Another window will appear. Change the Project Name to your Group number and the lab number as
“Group_Number_Lab_1”. Then click “Finish”. See Figure 6.

9|Page
Figure 6: Create Project (3)

Once you clicked “Finish”, the “Project Explorer” window will appear. Right click on “MyRIO-1900
(172.22.11.xx)” and “Connect”. A green light on the MyRIO icon will be ON. See Figure 7.

Figure 7: Project Explorer

10 | P a g e
Once you clicked “Connect”, a “Deployment Progress” will show you the deployment status. Click
“Close” when it is finished, or it may close automatically if the check box is selected. See Figure 8.

Figure 8: Deployment Progress Window

Again, right click on “MyRIO-1900 (172.22.11.xx)” and click “New>>VI”. A new VI “Untitled 1” will be
added to your project. See Figure 9.

Figure 9: Create a new VI

Right click on “Untitled 1” and save it in “DC motor virtual On_OFF”. Make sure that the “File Directory”
is your “Project Folder” under the name Group_A_Lab_1. See Figure 10.

11 | P a g e
Figure 10: Rename the VI

Click “OK”.

Double click on the slideshow below to refer back to the LabVIEW class lectures “LV_myRIO Intro_UAB”.

Step 3: Build the VI: In the Block Diagram window, right click to show the “Functions” palette. Hover the
cursor over “Structures” A new window will pop open, and then click on “While Loop”. See Figure 11

12 | P a g e
Figure 11: While Loop (1)

Your cursor will now change into a drawing tool. Hold the mouse and draw the square for your “While
Loop”. You will want it to be relatively large since you will be placing several virtual components inside.
Release the mouse when you’re ready to set it in place. See Figure 12

Figure 12: While Loop (2)

Right click to show the “Functions” palette. Hover the cursor over “myRIO” near the bottom of the
menu. Then select the “Digital Output” block. This will represent the output signal to the DC motor. See
Figure 13. Place the icon somewhere inside of the while loop.

13 | P a g e
Figure 13: myRIO Digital Output block

Another window will appear as shown in Figure 14. In the dropdown menu labeled “Channel,” select
B/DIO8(Pin 27). This means you are selecting digital output to Pin 27 which is digital input/output
number 8 on port B of the myRIO. You can see that the breadboard holding the entire circuit is
connected to port B.

Figure 14: Configure Digital Output Window

Right-click where it says “B/DIO8 (Pin 27)” on the “Digital Output” block and go to “Create >> Control”.
This will give you a true/false (Boolean) button that controls the digital output signal. See Figure 15.

14 | P a g e
Figure 15: Digital Output Control (1)

As shown in Figure 16, this is what your loop should now look like:

Figure 16: Digital Output Control (2)

All while loops must have a stopping condition or they continue forever. In LabVIEW the stop controller
is the red octagon in the bottom corner of the while loop. We need to connect the “error out” condition
for the “Digital Output” block to the stopping condition of the while loop. This will be done using an
“Or” Boolean operator. The “Or” operator means that if either x or y are true then execute the next
step.

Right click anywhere in the window, “Functions” palette will pop up, hover over “Boolean” and select
“Or”. Place the icon somewhere to the right of the “Digital Output” block. See Figure 17.

15 | P a g e
Figure 17: While Loop Stopping Condition (1)

An “Or” Boolean operator takes two inputs (x and y) and gives one output. If either of the inputs are
true, then the output is true. If neither input is true, then nothing happens. At the top left corner of the
“Or” icon, click, hold, and drag the cursur to the box that says “error out” on the “Digital Output” block.
This makes “error out” the x input for the Boolean “Or” statement. For the y output, right click on the
red button in the bottom right hand corner of the loop. Right click and go to Create >> Control. Instead
of connecting this control to the red button, however, connect it to the bottom left tip of the “Or” icon.
Finally, click on the right tip of the “Or” arrow and drag to the red button, which represents the loop’s
stopping condition. See Figure 18. If the new icon doesn’t look like the picture below, you may need to
select the control from the red stop conditional, disconnect it, and then connect it to the “Or” Boolean
operator.

Figure 18: While Loop Stopping Condition (2)

16 | P a g e
The myRIO input and output pins need to reset each time the program is stopped or an error occurs.
Otherwise, they will continue to transmit the same signal as when the program was running. To add the
reset capability, right click in the block diagram, select Functions >> myRIO >> Utilities >> Reset myRIO.vi
as shown below in Figure 19.

Figure 19: Reset myRIO

It would be good to also have an error message appear if any error with the digital output should occur.
To add this, right click, select Functions >> Programming >> Dialog & User Interface >> Simple Error
Handler.vi. see Figure 20.

Figure 20: Simple Error Handler

17 | P a g e
Connect both the “Simple Error Handler” icon and the “Reset myRIO.vi” to the connecting line between
the “Digital Output” and the “Or” Boolean operator. Keep the Error Handler and Reset icons outside of
the while loop. If they’re inside the while loop then the program will keep executing them over and
over. See Figure 21.

Figure 21: Error Wiring

Adding a timer in the loop will let the VI wait for a specified time between loop iterations. In this lab we
will use 10 milliseconds. Right-click, hover the cursor over “timing,” and click on the watch icon that says
“Wait (ms)”. Place the watch inside the loop. To tell it how many milliseconds to wait, you should right-
click, go to “Numeric” and then click “Numeric Constant”. Type 10, and then move it near the “wait”
block (the watch). Finally drag a line between the new numeric constant and the left side of the “Wait”
block. Do not connect it to the right side because that means a different kind of input. See Figure 22.

Figure 22: Wait Timer

Now if you go to the “Ront Panel” window, you should see the elements shown below in Figure 23. They
were automatically generated with the “Digital Output” and “Boolean” y-value elements you created in
the block diagram.

18 | P a g e
Figure 23: Front Panel

Save this VI that you just finished.

Step 4: Test the VI: Once you built the interface circuit and the VI, connect the breadboard with MXP
port B in the MyRIO as shown in Figure 24.

Figure 24: Connecting the interface circuit with the myRIO

To test your VI, click on the “Run” button in the “Front Panel” to deploy the VI. Once the VI is run, click
on the “DIO State” to on/off the motor.

NI MyRIO-1900 has 3.3 V general purpose (Digital Input Output) DIO lines on the MXP and MSP
connectors. MXP connectors A and B have 16 DIO lines per connector. On the MXP connectors, each DIO

19 | P a g e
line from 0 to 13 has a 40 kΩ pull-up resistor to 3.3 V, and DIO lines 14 and 15 have 2.2 kΩ pull-up
resistors to 3.3 V. MSP connector C has eight DIO lines. Each MSP DIO line has a 40 kΩ pull-down resistor
to ground. See Figure 25.

Figure 25: Pull-up Resistor to MXP Connector

You should notice that the DIO State is On, “High”, or “H” when the motor is not rotating. See Figure 23.

Part 3 of the Lab: Incorporating a Physical Switch

You already have a virtual switch that tells the motor whether to be on or off. It is very simple to replace
this with a physical switch. You simply have to create an input that points to the myRIO pin that is
connected to the switch. Since a switch is just on or off, it creates a digital signal. Pointing LabVIEW to a
digital input using myRIO is almost exactly like pointing it to a digital output. Make sure that you have
saved your first VI as “DC motor virtual On_OFF.” Go back to the Project Explorer windo, right click
where it says “MyRio-1900 (172.22.11.xx)” and click “New>>VI”. Call this new VI “DC motor On_OFF
Switch”. To get started, re-create the block diagram from Part 2, the virtual switch, in the new VI’s block
diagram. You can do this by repeating all of the steps in Part 2 or copy over the components from the
other VI.

Step 1: Connect Digital Input: To start changing the virtual switch VI to work with the physical switch,
right click on the “Boolean Control” icon that says “B/DIO8 (Pin 27)” above it shown in Figure 22. It’s the
one behind Digital Output. Select “Change to Indicator”. Now follow the same procedure as Part 2 for
creating Digital Output, shown in Figure 13 and Figure 14, but instead of selecting “Digital Out” select
“Digital In”. When you see the menu that has the drop-down menu of Channels, select “B/DIO0 (Pin
11)”.

Next you will need to connect the signal from Pin 11 to the output to Pin 27. Click and drag the cursor
from the black arrow right next to the word “Pin 11” on the Digital Input icon to the back of the black
arrow next to “B/DIO8 (Pin 27)” on the Digital Output icon. This creates your input to output connection,
shown by a green line as Boolean State. Now connect the “B/DIO0 state” indicator to that line. See
Figure 26.

20 | P a g e
Figure 26: Create Digital Input

Step 2: Merge All Errors: Note in the picture above that there is now a junction connecting Digital Input,
Digital Output, the Boolean operator, the Error Handler, and the Reset procedure. This connection
needs to be created so that the same operations occur when there’s an input error as they do when
there’s an output error. However, for both input and output errors to result in the same sequence of
events, their paths must be merged. There is a “Merge Errors” function, that function can be found by
right-clicking again and going to “Dialog and User Interface”. Pull the paths of both the digital input and
output error out boxes to the left side of the merge erros icon. Then drag the output to go to both the
“Or” Boolean operator and the “Simple Error Handler.vi” and “Reset myRIO.vi” blocks.

Step 3: Check the Front Panel: Look at the front panel and make sure that you have the following icons.
If not, there is something missing from your block diagram. Also, feel free to change the appearances of
elements by right-clicking on them and choosing different options.

Figure 27: Front Panel

21 | P a g e
Step 4: Save: Save this VI that you just finished under File >> Save, and make sure it is saved as “DC
motor On_OFF Switch”.

Step 5: Test the VI: Now, run the VI as shown in Figure 27 and start to slide the switch on the
breadboard back and forth. The switch is circled in Figure 28. See if the motor turns on and off or not as
you toggle the switch. At the same time, check the Front Panel to see B/DIO State if it is High (H) or Low
(L).

Figure 28: Test the Slide Switch

Assignment:
Once you finished creating the two VIs and tested them successfully, save the project
“Group_Number_Lab_1” in L:\ME360\Drop\Group\Your Group Number.

References:
“NI MyRIO Project Essentials Guide”. Ed Doering, Electrical and Computer Engineering Department,
Rose-Hulman Institute of Technology. Preliminary Draft, Sept. 20, 2013.

22 | P a g e

You might also like