Monday, March 12, 2012

Simple external LED circuit with FPGA

After spending a couple hours playing around with an Arduino Uno, I wanted to play some more with LEDs. But I wanted to do it in hardware instead of software. I had a Nexys 2 FPGA board by Digilent and spent awhile searching the internet for just really simple examples. I found some on youtube but I was looking for some more explanation. 



Here's a vid of the FPGA controlling the brightness of the LEDs with 2 buttons.






This small write-up will show you how to control the output pin in VHDL as well as wire it to the board.
The following circuit set up is true for microcontroller boards as well, the only difference is the way you drive them and interact with them in code. 


The thing that I was confused was how to connect the digital output to an external LED. I figured out how to wire the circuit to the output. Here is the diagram:


The thing to note here is that you have to make sure from where you're getting your source voltage. Here I use the 3.3V signal coming from the output pin on the board. The LEDs I had were already 3 V diodes, so I just have the resistors there for limiting a little current. In this setup, setting the output pin high will turn the LEDs on.


As an alternative method of drivng an LED circuit, you could wire it this way where the left end is the output pin on the board and the right end is a supply voltage for the diode. For some circuits, this will work better as its easier to sink current than to drive current. In this set up, driving the output pin low will turn the LEDs on. When the output pin is high, there is no potential drop across the circuit. When the output pin goes low, it creates the ground and completes the circuit. 


Here is a picture of my setup:


I use the PMOD connectors on the side of the Nexys2 Board. They're pretty much just pins with a a standard header to fit a wide variety of custom boards like ADC, or DAC, Ethernet... bla bla.


The PMOD output pads are labeled by JA1, JB1, JC1, JD1. I chose JA and then connected it this way:


PMOD Header - When looking straight on
5 4 3 2 1 0 - Top Row 
5 4 3 2 1 0 - Bottom Row 


Column 4 is GND and Column 5 is Vdd. For this circuit, I run a wire from GND to the LED GND and then a wire from Top Row - 3 to the positive side of the circuit as shown on the circuit diagram. 


In this configuration, JA<3> is the output pin. I use JA<3> for the output LED, SW<0> as a switch for the LED.


For this, I wrote it in VHDL. The entity is as follows:




In the architecture, I tie the switches together and thats it. Just flick the switch and turn on the lights.


EDIT - Change sw(2) to sw(0)


Lastly, just make sure you comment/uncomment the stuff in the constraints file. Here we uncomment the lines for SW<0> and for JA<3>.



No comments:

Post a Comment