Difference between revisions of "Project/VHDL"

From initLab
Jump to navigation Jump to search
Line 44: Line 44:


[[File:VHDL1.png]]
[[File:VHDL1.png]]
<pre>
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity binary_counter is
generic(
  counter_width : natural := 8; -- we want an 8 bit counter by default.
);
port(
  clock : in std_logic;
  reset : in std_logic := '0';
  count : out std_logic_vector(counter_width-1 downto 0)
);
end entity binary_counter;
architecture behavioural of binary_counter is
signal count_internal : std_logic_vector(counter_width-1 downto 0);
begin
counter : process (clock)
begin
  if clock'event and clock = '1' then -- this means the rising edge of signal "clock"
  if reset = '1' then
    count_internal <= (others => '0'); -- this means all lines are defined to '0'
  else
    count_internal <= count_internal + 1;
  end if;
  end if;
end process counter;
count <= count_internal;
end architecture;
</pre>


[[Category: Project]]
[[Category: Project]]

Revision as of 21:53, 22 December 2015

Introduction

Ever wished you could make your own integrated circuits? Is regular logic just not doing the trick for you? This project is all about programmable logic, and how you can define your own digital circuits yourself. Welcome to the wonderful world of CPLD's and FPGA's!

FPGA general.png

History

There was a time that, if you wanted a new logic function on your custom PCB, you had to have more chips. TTL logic chips that is. With quad NAND gates like the 74HC00, and a whole range of different logic functions, PCB's often became very complex. Often, not all the gates of such integrated circuits were used. Late 1970's, one of the first well-known programmable logic devices hit the streets. The Programmable Array Logic or PAL chips were made by Signetics, and at a later stadium copied by National Semiconductor, Texas Instruments and AMD. With names as "PAL16L8" and "PAL22V10", you could define your own logic in a One Time Programmable chip. It worked with fuses and could be programmed only once. It was very convenient to define your own logic gates, without the need for all those specific logic chips. At a later stadium, Electrically erasable GAL devices were pin-to-pin compatible and the road was set for devices that implemented large quantities of logic gates in a single device.

The PAL and GAL devices had a very limited amount of pins, and Complex Programmable Logic Devices or CPLD's were a great improvement on both pin count and complexity. But it wasn't until the Field Programmable Gate Arrays or FPGA's when the functionality and usability really took off. Of course, all of these devices had to be programmed in a certain way, and most of the time it means really defining what gate and functions had to active. There was a great need for a programming language to define the functionality of digital circuits. The Hardware Description Language or HDL was on its way!

Different flavors

The current market for programmable logic is roughly separated in a few brands:

  • Xilinx, the largest manufacturer. Popular chips include the Spartan series, Virtex and Zynq devices.
  • Altera (now owned by Intel). Inventors of the MAX CPLD's, Cyclone FPGA's and Stratix series.
  • Actel. A smaller brand, but still the Igloo and ProAsic series are pretty well known.
  • Lattice has the iCE series, MachXO and ispMACH devices.

There are a number of other smaller manufacturers, but these are the most well known ones. But if you want to program a CPLD or FPGA, you have several options. Most software packages offer the use of schematic diagrams to define the functionality inside, but while your designs get more complex, you will want to learn a HDL or Hardware Description Language. Two are commonly known:

  • VHDL or VHSIC Hardware Description Language. This is most commonly used in Europe.
  • Verilog is more used in the USA.

Building blocks

A modern FPGA device can hold several items to implement your design:

  • Logic Elements or Cells. This is the most basic building block and it is used to implement all of your digital functions.
  • Memory. These can help to store larger amounts of data in ROM, RAM, Dual port RAM and large buffers such as a First-In, First-Out (FIFO) buffers or shift registers.
  • Multipliers. These help a great deal in signal processing and are therefore also referred as DSP blocks.
  • Transceivers. Many well-equipped FPGA's offer very fast serial communication blocks. Almost all modern digital communication protocol implement these: HDMI, USB3.x, SDI, SATA and SAS, PCI express and many others.
  • SOC's. Some FPGA's are accompanied by microprocessor blocks. Examples include a ZynQ, Cyclone V and SmartFusion devices.

When you are defining your functions in VHDL, you are using the LE's or Cells inside your FPGA. If you want to use other, device-specific blocks, this can be done in two ways. In the first way a specific specialized block is inferred. Through your definition of a function, the computer who reads your VHDL decides that it can best be implemented with a specialized block. Define a 1024-position buffer, and your compiler shortly decide it can best be implemented with a memory block. The other way is by instantiation: You specifically tell that you want to use a DSP, or transceiver block. You will have to define what settings need to be applied, and what configuration you need. This has also a disadvantage: If you want to use a different device, it might not recognize these instantiations!

VHDL first steps

So lets start with VHDL and defining our very first functionality. First, you will have to know something about the language. Every VHDL design has at least one entity. An entity can best be described as a black box. This black box can have one or more ports. Input ports, output ports, or bidirectional ports. Also, an entity can have generic declarations. You can use this to make your design flexible. For example, you can define a counter function, with a clock and reset input, and a count output port. It can be an eight bit counter, or 16, or 22, or 47.. You could define the amount of bits in a generic declaration.

Once we have our entity, with all ins and outs, we need to define what's inside our black box! In the example of the counter, we can have a regular binary counter, or one with decoded outputs. Or maybe an alternative way of counting? The functionality inside our black box is defined in the architecture.

VHDL1.png

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity binary_counter is
 generic(
  counter_width : natural := 8; -- we want an 8 bit counter by default.
 );
 port(
  clock : in std_logic;
  reset : in std_logic := '0';

  count : out std_logic_vector(counter_width-1 downto 0)
 );
end entity binary_counter;

architecture behavioural of binary_counter is

 signal count_internal : std_logic_vector(counter_width-1 downto 0);

begin

 counter : process (clock)
 begin
  if clock'event and clock = '1' then -- this means the rising edge of signal "clock"
   if reset = '1' then
    count_internal <= (others => '0'); -- this means all lines are defined to '0'
   else
    count_internal <= count_internal + 1;
   end if;
  end if;
 end process counter;

 count <= count_internal;

end architecture;