By Jamil Khatib

Copyright 2002

Introduction to Programmable logic devices

The main aim of this article is to give a small introduction to electronics design through describing programmable logic design techniques. It is useful for new electronics engineers and hobbies who like to build there own circuits and designs in easy and modern way. This article requires the basic knowledge of electronics and digital design.

(Introduction to digital design may come in the future)

Electronics design

The invention of the transistor has changed not only the electronics industry but the whole world because of its size speed and design simplicity. Transistor circuits are used in many circuits starting from amplifiers up to musical instruments circuits.

The transistors are used as switches to turn circuits on and off. This phenomenon helped in the design of many circuits such as alarms, control circuits and all circuits that are based on on-off technique.

Digital design makes use of this on-off that is symbolized by 1-0. These 0s and 1s are the basics of the Boolean arithmetic.

Digital design

Digital design makes use of the Boolean functions to implement its circuits. AND, OR, NOT are the basic functions that can generate all other functions. All Arithmetic and logic functions can be implemented using these functions.

2-bit half adder example:

Sum = (x AND NOT y) OR (NOT x AND y)

Carry =(x AND y)

Besides that, Flip-flops and registers are used in digital design to implement memory or storage element in the design, so the circuit can remember its old state to calculate the new state and act accordingly.

There are two types of digital circuits synchronous (Clocked) and asynchronous (non-clocked) circuits.

Advantages of digital design:

Digital Logic devices

The figure below shows the structure of a PAL device. It is composed of AND and OR gates connected together via fuse array.

Structure of PAL

 

Generic FPGA architecture

FPGA resources and architecture

FPGAs are mainly characterized by their logic size and resources and their speed.

FPGA Components

Xilinx's Virtex Slice

Altera's Apex Logic Element

FPGA boards

There are many FPGA demo and application boards. These boards range from small FPGA with some external headers and connectors to very large and complex boards with lot of interfaces chips and even FPGAs.

Here are some resources where you can find some boards

 

Design flow techniques

FPGA design flow is the same for professional engineers, students and hobbies; the only difference is the complexity of the design and tools with extra optimization options.

- Specification or definition: Defining the problem and what need in an important step before the design.

The last 3 steps are usually done by FPGA vendor specific tools.

HDL technique

Hardware Description Languages (HDL)

As described earlier HDL is one of the design entry methods for FPGA design. In fact it could be a generic method for hardware design. It is simply a way of hardware design description in a human like language, which looks like software programming.

There are several HDL languages some are so simple and some are complex. Most languages can describe digital hardware using the basic digital operators such as AND, OR etc. Other languages are more complex and advanced so that it allows the user to describe the design in more human readable logic. For example it allows the user to use if, case and loops statements which make him focus on the design itself not on the hardware. Most HDL languages define IO pins of the design and its internal functionality. VHDL, Verilog and AHLD are examples of HDLs.

For examples about the VHDL check the design examples section later on.

 

Tools

Simulation: Modelsim, Active-HDL, NC-SIM

Synthesis: Leonardo, Synplify, Synopsys

Place and Route: Altera Quartus, Xilinx Foundation.

Examples of Free tools

Most of FPGA vendors provide free light version of simulation, synthesis and place and route tools that are useful for small and mid size designs. These tools are suitable for hobbies and students and even companies that do not need lot of features.

Design Examples in VHDL

LIBRARY ieee;

USE ieee.std_logic_1164.ALL;

ENTITY Adder_ent IS

PORT (

Op1 : IN std_logic; -- Operand 1

op2 : IN std_logic; -- Operand 2

carry : OUT std_logic; -- Output carry

Result : OUT std_logic); -- Result

END Adder_ent;

ARCHITECTURE behavior OF Adder_ent IS

BEGIN -- behavior

Result <= (Op1 AND NOT Op2) OR (NOT Op1 AND Op2);

Carry <= Op1 AND Op2;

END behavior;

LIBRARY ieee;

USE ieee.std_logic_1164.ALL;

USE ieee.std_logic_unsigned.ALL;

ENTITY Adder_ent IS

PORT (

clk : IN std_logic; -- System clock

rst_n : IN std_logic; -- System reset

Op1 : IN std_logic_vector(7 DOWNTO 0); -- Operand 1

op2 : IN std_logic_vector(7 DOWNTO 0); -- Operand 2

Result : OUT std_logic_vector(7 DOWNTO 0)); -- Result

END Adder_ent;

ARCHITECTURE behavior OF Adder_ent IS

BEGIN -- behavior

PROCESS (clk, rst_n)

BEGIN -- PROCESS

IF rst_n = '0' THEN -- asynchronous reset (active low)

Result <= (OTHERS => '0');

ELSIF clk'event AND clk = '1' THEN -- rising clock edge

Result <= Op1 + op2;

END IF;

END PROCESS;

END behavior;

 

LIBRARY ieee;

USE ieee.std_logic_1164.ALL;

USE ieee.std_logic_unsigned.ALL;

ENTITY Adder_ent IS

PORT (

clk : IN std_logic; -- System clock

rst_n : IN std_logic; -- System reset

Count : OUT std_logic_vector(7 DOWNTO 0)); -- Count

END Adder_ent;

ARCHITECTURE behavior OF Adder_ent IS

SIGNAL counter : std_logic_vector(7 DOWNTO 0); -- internal counter

BEGIN -- behavior

PROCESS (clk, rst_n)

BEGIN -- PROCESS

IF rst_n = '0' THEN -- asynchronous reset (active low)

Counter <= (OTHERS => '0');

ELSIF clk'event AND clk = '1' THEN -- rising clock edge

Counter <= counter + 1;

END IF;

END PROCESS;

count <= counter;

END behavior;

 

LIBRARY ieee;

USE ieee.std_logic_1164.ALL;

ENTITY Decoder IS

PORT (

InBin : IN std_logic_vector (3 DOWNTO 0);

Display : OUT std_logic_vector (6 DOWNTO 0));

END Decoder;

ARCHITECTURE rtl OF decoder IS

SIGNAL t : std_logic_vector (6 DOWNTO 0);

BEGIN

seg_process : PROCESS (InBin)

BEGIN

CASE InBin IS

WHEN "0000" => t <= "1111110";

WHEN "0001" => t <= "0110000";

WHEN "0010" => t <= "1101101";

WHEN "0011" => t <= "1111001";

WHEN "0100" => t <= "0110011";

WHEN "0101" => t <= "1011011";

WHEN "0110" => t <= "0011111";

WHEN "0111" => t <= "1110000";

WHEN "1000" => t <= "1111111";

WHEN "1001" => t <= "1110011";

WHEN "1010" => t <= "1110111";

WHEN "1011" => t <= "0011111";

WHEN "1100" => t <= "1001110";

WHEN "1101" => t <= "0111101";

WHEN "1110" => t <= "1001111";

WHEN OTHERS => t <= "1000111";

END CASE;

Display <= NOT t;

END PROCESS seg_process;

END rtl;

Why programmable logic

Building Custom CPUs

Since the FPGAs can be easily programmed and designed, companies can build and implement their own custom CPUs. For that reason there are many Free CPUs on the web like: OpenRISC from opencores.org .

 

Run time reconfigurable logic

One of the advantages of configurable logic that can it can be reprogrammed dynamically on run time. This means that the FPGA configuration can be changed during operation. The advantage of this feature that one can put in an FPGA several designs. These designs are not operating on the FPGA at the same time, they are loaded only when they are needed. In this case we can put designs in a single FPGA much more than its actual physical size. For example there are some designs need to run only at the beginning of the system, after that they are not used (such as initialization). Other designs can operate only when the user requests them. So if we put all these designs together on the FPGA we will need large FPGA, but if we load and unload them as needed we can reduce the FPGA size we need.

Open Source Hardware

As in the world of open source free software, hardware designs can also be open source and free through the use of the FPGAs and HDLs. Designers and hobbies can write HDL code simulate it and then program it to the FPGA board. The HDL code can be shared between designers all over the world and they can review and edit it by their own. In short HDL code and FPGA board are like software code and computers for open source software. As there is a free open source Linux operating system, one day we will have free open source CPUs and computers.

References

 

Request for help