Papilio One FPGA board , using a switch to turn on an LED

Papilio FPGA, LED, switch

Papilio Board, LED and switch

Put this together just to start learning a bit about VHDL coding. The logic is simple, if input P4 (the switch) is low, output P3 (the LED) is high, and vice versa. The circuit diagram is shown below:

Circuit Diagram

Circuit Diagram

Here is the VHDL code:

VHDL code

VHDL code

The code ” entity led_switch is “, defines the inputs, outputs and datatypes used by entity led_switch. The datatype STD_LOGIC contains three possible values, on, off and z. Z means high impedance and it’s only used when bi-directional signals are involved.

Next, the architecture of the system is defined. This means describing how the state of the output relates to the inputs. There are a few ways of describing this. One method is called ‘behavioral’ , this is the ‘black box’ kind off approach, just relate the outputs to the inputs and VHDL will figure out the details. Another way is called ‘data-flow’, this way describes how the system would operate using logic gates.

It’s important to note that the symbol ‘<=’ doesn’t mean less than or equal to. It can be thought of more like ‘depends on’. In this case, the state of LED_0 depends on the state of what is on the right hand side of the ‘<=’ symbol.

Before this code can be compiled into a bit file, a constraint file has to be added to the project. This constraint file tells the compiler where the signals LED_0 and switch_0 are physically connected to on the FPGA, it also defines things like the logic levels used and whether or not internal pull up resistors are used.

VHDL constraint file

VHDL constraint file

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s