You are on page 1of 7

VIDEO 1

In this video were going to learn how to add MyRio to your project and choose
the programming mode.
Now weve already gone through the process of communicating with MyRio
making sure that we can see MyRio measurement and automation explorer, so
were ready to go, were ready to begin the process of programming.
So what Im going to do is open a brand new project in LabVIEW and I can do
that by clicking on the create project button on LabVIEW getting started screen.
And Im going to choose the blank project here, so Ill click finish down at the
bottom, and thats going to open just a generic blank LabVIEW project, and Im
going to go ahead and save this project as Learn RIO
Ok, so now the project is ready to go, and youll in the project that I have
something called my computer.
My computer refers to the machine that Im currently developing on the
Windows machine that Im using. Now remember the MyRio has a processor in
it, so effectively its another computer and if Im going to write code for that
computer I need to add it to the project, so lets take a look at how to do that.
I can right click on the project title here and choose New, Targets and Devices.
This is going to pop open a dialogue that gives me a few different options
So I can choose to use an existing target or device, which would be the case
that Im going to choose because I have a MyRio already connected to my
system.
But I can also choose to use a new target or device, and I may want to do that
if I want to write code now, but then use the hardware later. So maybe I dont
have access to the hardware right now but I want to go ahead program for it.
That would be a good option for me.
But today I have MyRio already connected, so Im going to use existing
targeting device, and Im going to navigate down here to the folder called Real
Time MyRio because Im using a MyRio; Ill expand it out and LabVIEW will
search for the MyRio that is connected to the system. So MyRio popped up
here, Ill click it, and click OK.
Now a dialogue opens thats pretty important and I need to make a choice
here, and this choice totally depends on the application, theres no right or
wrong. So Im going to choose the programming mode. Now I can choose scan
interface mode and Id want to do that if all Im interested in doing is accessing
I/O. Maybe doing some basic digital logical like PWMs. But Im not interested in
putting specialized functionality on the FPGA, just want to use basic I/O.
If I want to put specialized functionality on the FPGA, like maybe emergency
stop functionality, analysis that need to run really fast, things like that, and I

want to program the FPGA, then I need to use the LabVIEW FPGA interface
mode, and thats what Im going to do today.
So Ill click on LabVIEW FPGA interface, click Continue and wait just a second
while LabVIEW discovers all the specs about the MyRio that I have connected,
the different modules Im using, things like that; and after that, everything is
added to the project and Im ready to start programming.

VIDEO 3
In this video were going to talk about accessing I/O through the FPGA so were
actually going to do some real FPGA programming, so lets dive in. Were going
to start in our LabVIEW project, where we have our MyRio already added and
were going to create new VI for the FPGA, so in order to do that, well right
click on the FPGA target, choose new VI, and Im just going to quickly save this
with the name FPGA.
So I have an FPGA VI here and any functionality that I put on this block diagram
is going to be specific to the FPGA so Ill drag this over to the right hand side,
and Ill just quickly make a comment called FPGA and Ill also open up a VI that
I made earlier, called host, which is a VI under my computer, that means its
going to run on the windows developer machine that Im currently
programming on.
So Ill open that up and take a look at its block diagram so we can compare
really quickly and Ill call this, in the comments here, host. Now lets take a look
at the difference between the host VI and the FPGA VI. So in the host VI, at the
top here, youll see a lot of different debugging options in this toolbar that you
dont see on the FPGA VI, and thats one difference.
Also, if I right click on the host VI to access my functions pallet, youll see
theres a lot of stuff that I can use to program a host VI; if I right click on the
FPGA VI, youll see the selection is little bit smaller, and thats due to the
special nature of the FPGA, I have selected items here, that are specific for
FPGA programming, that I get to use.
So now that weve seen some of the differences, Ill close out this host VI, and
well just focus on programming FPGA.
So in order to begin accessing I/O through the FPGA, Ill right click, and Ill go to
the FPGA I/O pallet, and Im just going to pin this palate sown because were
going to spend a lot of time using this pallet when we do FPGA programming,
so I like to keep it there, and Ill go grab an I/O node, Ill grab this I/O node onto
the block diagram, and through this I/0 node I can access all of the different
modules that are in my chassis, so Ill click on it and youll see here, it
automatically finds the three different modules that I have in my MyRio chassis.
So mode one is an analog module; mod two is analog output; and Mod three is
digital I/O, so lets do some digital programming.

Ill go ahead and choose a digital I/O zero, and we click on it gets added to this
I/O node here, and Im able to read or write to that digital line. In this case, y
default, the terminals on the right hand side, so I know what Im reading from
it; bit if I want to write to it, all I have to do is right click and choose change to
write. And Ill just quickly right click on the terminal and say create control, and
Ill call it digital write.

Now maybe I want to add some more I/O, so I can do that quite easily by just
dragging down this I/O node, and I can choose a different I/O line to read or
write to. So automatically the I/O node chooses the next digital line, which is
the I/O one, and I could use that if I want to, or I can click on that and choose
I/O from any of the others modules in my chassis, and Ill actually just use DIO
four here and the terminals on the left hand side, so its set up for me to write
to that line, but if I want to read from it, all I need to do is right click and choose
change to read, now the terminals on the right side and I can right click on it
and say create indicator, and Ill call It digital read.
The digital module that Im using is bidirectional, so theres some properties
associated with this module that mean I can choose some lines to be read and
some lines to be write. The way that I can set this properties is through the
project, so if I right click on mod three in the project and select properties, a
dialogue opens up and you can see here that right now all the lines are set as
input, but if you remember, we said we would write to DIO zero and read from
DIO four, so we need to make sure that thats reflected here, so Im going to
change DIO zero through three to be output, so those four lines will always be
output, and then Im going to leave DIO four through seven as input. Ill click
OK, and now our digital module is configured to match our code here. The next
thing that Ill want to do as Im programming is Ill probably want to make sure
that I can write to and read from this digital module continuously, so in order to
do that, Ill want to put my code in a loop.
Now this point youve probably used WHILE loops and FOR loops in your
LabVIEW programming, but lets take a look at the loop you may not have used
yet. So in order to find that loop, Ill tight click on the block diagram and head
over to structures, and on the structures pallet I see something called time
structures, and there I see a timed loop, so grab that and drag it around my
digital code.
In FPGA programming, we actually call time loops single cycle timed loops, and
thats for a very specific reason; if you look over at our LabVIEW project, you
see that by default, the clock of the FPGA is set at 40 megahertz, so a single
cycle timed loop actually guarantees timing because everything in that loop
will execute within one tick of that FPGA 40 megahertz clock, so that means
every 25 nanoseconds, all the code Ive place in that loop will execute
completely, which is really fast. So because Im able to guarantee timing
though this type of loop, Im able to keep track of time, which can be handy
with things like PWMs, for instance. So that wraps up our digital section.

Analog Section
Lets talk about analog now. What if I want to add some analog I/O to this block
diagram? Well I could go over and drag another I/O node from my FPGA I/O
pallet, or I can come over to the LabVIEW project and expand out the analog
module that I want to use, maybe the analog N module that I have here, and I
can actually drag I/O from the project onto the block diagram. Both ways work,
just different way to do it. So here I have analog input zero on this I/O node,
and it is set up to read, which would be right because its analog in, so Ill click
on that terminal and say create indicator and Ill call this analog in. And then If
want to say, maybe, add an analog output channel to this, I can drag down the
I/O node, and I can click on it, and Ill go to mod two, which is my analog out
module, and Ill choose analog out zero. And now I can create a control that Ill
call analog out.
So just like with the digital code, Ill probably want to write to read from these
analog channels continuously as well, so Ill want to put this in a loop, so let me
right click and go to the structures pallet and this time Im actually going to
grab a while loop, Ill drag it around the analog code.
We just talk about how cool single cycle timed loops are, so you might be
wondering why Im using a while loop in this case. Well, if you think about it, an
analog module has an analog to digital converter on it, and that analog to
digital converter just cannot go at 40 megahertz, so it cannot run as fast as
that single cycle timed loop is going to run. So if I were to put the analog code
in the single cycle timed loop, it would actually fail to compile. So thats why
Im going to use a while loop in this case.
Another thing that you may have picked up on in my analog code is that it has
kind of a different wire color than you may have seen so far in your LabVIEW
programming and you know that the wire colors indicate data types in
LabVIEW, and in this case, the wire color that were seeing is indicating a fixed
point.
Fixed point is a common data type in FPGA programming. So if you think about
it, an FPGA has a fixed size, and a fixed point allows us to dictate how many
bits were going to use to represent a number, so if youre ever interested in
playing with that or looking a little bit further, you can actually right click on
any control or indicator or function in your FPGA programming, go down to
properties, and take a look at data representation. You dont need to worry
about this most basic applications, LabVIEW has algorithms to handle all this

fixed points for you, so you dont need to think about it, but if youre running
into really complex applications, where youre running out of space you may
need to be a little bit smarter about how many bits youre allocating for
everything that youre doing, then youll just want to right click and go to
properties.

So now that we have our code completed were ready to finish this up by wiring
our loop conditions, so well right click on each loop condition and say create
constant and actually on both of them, Im going to leave it as the default,
which is false, and thats kind of interesting because normally in LabVIEW
programming we think about how am I going to stop this loop. But if you think
about it on an FPGA, were programming a circuit here, so we want that circuit
to run as long as it has power provided to it, so Im going to let these loops run
continuously. Now, also something worth pointing out is on this clock diagram.
Youll see that both of these loops are in parallel on the block diagram, and
thats exactly how theyre going to run, in parallel. Thats one of the big
benefits of FPGAs. We dont have to do any extra programming in order to
make parallel execution happen. So you can think about this kind of like a
bread board, right, that you might use in a class. In a bread board youre able
to put lots of different circuits on that bread board, until you run out of space,
and they all run in parallel as long as you provide power to that bread board:
its the same thing here. You can kind of think of each of these loops as its own
circuit, so theyre running in parallel by nature.
So now were done with our FPGA programming, were ready to compile. So
lets take a look at how well do that. So over in the project here, well find our
FPGA VI right here, and Well right click on it, and we will say create build
specification. When we do that, it pops up something called FPGA, which is the
same name as the VI, under build specifications, which is under FPGA in the
hierarchy of our project here. We can right click on this FPGA build specification
and choose properties, and this will bring up a dialogue where were able to
maybe change its name if we want to. We can change the source files if we had
another VI we were programming for an FPGA that we wanted to use. We could
bring that over, but if all of this looks good to me, which it does, Im going to hit
build and click OK.
Im going to compile locally here on my computer and now my code is
compiling, so Ill save it and let LabVIEW go ahead and compile this code. So

compiling is like a built in break for embedded programmers, so Im going to


take a break, and then Ill come back and program the RT side.

You might also like