Category:Electronic Components FPGA

Group Administrators: 1 | Group Member: 29 | Group Threads: 23


To Learn LabVIEW FPGA on NI myRIO
2K+ views

Giovanni Pelliccioni

This is Part 2 of the Utilising LabVIEW FPGA on NI myRIO article series. In the last article we covered the basics of what an FPGA is, how to create a LabVIEW project, how to access the myRIO embedded device, and we even wrote our first FPGA application. This article will show how to utilise what we just learned to interface with the real world. It will explain how to access the Digital Input and Output ports of the myRIO and how to use data from previous code loop iterations using a concept in LabVIEW called Shift Registers. Then we will connect a simple Light-Emitting Diode to one of the Digital Lines of the myRIO and make it blink by turning it on and off every second.
Wiring the Hardware
First we will need a Light-Emitting Diode (LED) to switch. It is recommended that you use a 3.3V LED as the myRIO is only capable of providing 3.3 Volts on the Digital Lines. As we will see in later articles, when it comes to reading it will be able to go further. Note that a regular 5V LED would also work but might not be as bright. Then we need to calculate a value for our current-limiting resistor that will be connected in series between the LED and the Digital Line. This is needed because Light-Emitting Diodes are very sensitive and without a resistor to limit the current, it would essentially "short" the digital line and the ground of the myRIO. While it would not necesserily break the myRIO, it could easily blow the LED. Not to mention that ignoring the current-limiting resistor is considered a bad wiring practise overall. There is a lot of fantastic material on the topic available online and we will not dwell too much into the theory. 
Where Vs is the source voltage, in our case 3.3V. Vf is the forward voltage of an LED, usually specified in the datasheet, in our case 1.4V. Finally i is the current needed to drive the LED to full brightness. This value can also be found in most datasheets and usually is around 20-30 mA. Substituting these numbers into our equation we find that the recommended series resistor value to limit the current flowing through the LED is between 60 and 95 Ohms. In the time of writing this article, the closest resistor value I was able to find was 330 Ohms and it worked fine. As a rule of thumb, it is better to reducemore current than less. Saying that, with resistances over 1 KOhm you would likely lose most of the brightness of the component, but there is surely some flexibility. 
Writing the FPGA Code
Just like in the first article, let's create a new LabVIEW project, save it as "myRIO FPGA Series 2.lvproj" and add the NI myRIO as the target device. Then we will need to create a new VI and save it within the same directory as "FPGA.VI". Within this VI we need to create a while loop (A) to make sure our code runs continuously. Like last time, we will wire aFalse boolean constant to the stop condition terminal (B) to make sure our code never stops executing. Then we need to drag and drop the DIO0 resource from Port C of the project (C) to our FPGA VI. By default it will be in read state so make sure to right-click on the DIO0 resource and select "Change to Write". Then we create another boolean constant that we will invert each loop iteration (D). To keep the value from previous loop iteration we will make use of Shift Registers (E). Imagine a Shift Register as a memory block that "remembers" what was wired to it the last time it ran. To add a Shift Register, first wire the data through to the while loop, then right-click on the terminal and select "Replace with Shift Register...". This way we can now keep on inverting the value each time thewhileloop runs, hence turning the LED on and off. Then we should add some timing (F), otherwise our code will keep switching the LED way too fast for us to see! Make sure the timing is configured to miliseconds by double-clicking on the timing function and selecting "Counter Units" to "mSec" (G). Finally we can also create an indicator to double-check that our inverting logic is actually working as expected (H).
Running the FPGA Code
If you have followed the tutorial correctly and ran the FPGA VI, after compilation you should now see both the LED indicator on the Front Panel and the actual LED blinking simultaneously. Congratulations, you have now successfully implemented Hardware I/O interfacing through FPGA in several easy steps using LabVIEW and the NI myRIO. Alternatively you can also try connecting the LED's Anode to another DIO line, changing the code and re-compiling to ensure you understand what the tutorial has covered.
In the next article we will cover how you can make this LED not only blinks, but also change brightness. Moreover you will be controlling this using a variable resistor known as potentiometer!
Statement: This post is only the personal view of the author and does not represent the opinions of

Erivando Sena

I am going to keep checking for new writings.