Friday, October 30, 2009

VHDL Code examples

Code examples

In VHDL, a design consists at a minimum of an entity which describes the interface and an architecture which contains the actual implementation. In addition, most designs import library modules. Some designs also contain multiple architectures and configurations.
A simple AND gate in VHDL would look something like this:

-- import std_logic from the IEEE library

library IEEE;

use IEEE.std_logic_1164.all;
-- this is the entity

entity ANDGATE is

port (

IN1 : in std_logic;

IN2 : in std_logic;

OUT1: out std_logic);

end ANDGATE;
architecture RTL of ANDGATE is

begin
OUT1 <= IN1 and IN2;
end RTL;


 While the example above may seem very verbose to HDL beginners, one should keep in mind that many parts are either optional or need to be written only once. And generally simple functions like this are part of a larger behavioral module, instead of having a separate module for something so simple. In addition, use of elements such as the std_logic type might at first seem to be an overkill. One could easily use the built-in bit type and avoid the library import in the beginning. However, using this 9-valued logic (U,X,0,1,Z,W,H,L,-) instead of simple bits (0,1) offers a very powerful simulation and debugging tool to the designer which currently does not exist in any other HDL.

In the examples that follow, you will see that VHDL code can be written in a very compact form. However, the experienced designers usually avoid these compact forms and use a more verbose coding style for the sake of readability and maintainability. Another advantage to the verbose coding style is the smaller amount of resources used when programming to a Programmable Logic Device such as a CPLD

No comments:

Post a Comment

Popular Posts