A blog documenting projects and ideas

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

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

Here is the 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.