Beginning FPGA Programming - Partie27
Beginning FPGA Programming - Partie27
Answers
library ieee;
use ieee.std_logic_1164.all;
entity alarm_system is
port (
A: in std_logic;
B: in std_logic;
C: in std_logic;
F: out std_logic
);
end alarm_system;
architecture behavioral of alarm_system is
signal D: std_logic;
signal E: std_logic;
begin
D <= A and B;
E <= C and B;
F <= D or E;
end behavioral;
122
Chapter 6 ■ VHDL 101
library ieee;
use ieee.std_logic_1164.all;
entity fulladder is
port (
A: in std_logic;
B: in std_logic;
C: in std_logic;
SUM: out std_logic;
Carrout: out std_logic
);
end fulladder;
architecture behavioral of fulladder is
signal D: std_logic;
begin
D <= A xor B;
SUM <= D xor C;
Carrout <= ((D and C) or (A and B));
end behavioral;
6.3 Summary
VHDL is a hardware description language. It will be much easier for you to design an FPGA when you can
start to see things from a hardware point of view. Any complex digital design should be able to be broken
down into smaller-size modules for you to implement them in VHDL.
Each VHDL has the following structure:
• library
• entity
• architecture
The chapters that follow will give more detail on how to use VHDL to design more hardware!
■■Tip Notepad ++ is a very good (and free) editor which supports VHDL!
123
CHAPTER 7
Number theory is “the Queen of Mathematics.” It is the foundation of mathematics and includes all the basic
elements. Don’t worry, you did pick up a book on FPGA (field-programmable gateway array) design, but
we’re going to have to cover just a little math in order for you to be able to actually do anything useful with
an FPGA. In this chapter we are going to show you several basic elements of VHDL (VHSIC (very high speed
integrated circuit) Hardware Description Language), such as identifiers and numbers. All of the stuff shown
in this chapter will help you write better VHDL code. You should bookmark this chapter because you will
likely come back to frequently when you actually start to write your own VHDL code.
7.1 Vocabulary in VHDL
Vocabulary is the first thing you learn in any new language such as VHDL. There are some basic rules for
VHDL words. Listing 7-1 provides an example.
• VHDL is NOT case sensitive
• It doesn’t care about how many spaces or tabs in the code
• None of the words can start with number
Listing 7-1. Not Case Sensitive and Doesn't Care About Whitespace
NotCaseSensitive <= Spaces Or Tabs;
7.1.1 Identifiers
An identifier is defined by the VHDL designer to name items in a VHDL model (Figures 7-1 and 7-2).
Examples of VHDL items are port names and signal names. The rules for identifiers are as follows:
• Can only contain a combination of alphabetic letters ( A-Z, a-z ), numbers ( 0-9 ) and
underscores (_)
• Must start with alphabetic letters (A-Z, a-z)
• Cannot end with an underscore (_) and cannot have consecutive underscores
• The identifier should be self-describing
■■Tip Smart choices for identifiers make your VHDL code easier to read and understand, which in turn
means less effort required to find and fix problems in the code.
■■Note In VHDL-93, VHDL supports extended identifiers, which allows you to use any character in any order.
We suggest you don’t use these in your design files as they tend to confuse and complicate rather than improve
the situation.
7.1.2 Reserved Words—Keywords
Some identifiers, called reserved words or keywords, are reserved for special use in VHDL, so we cannot use
them as identifiers for the items we define. Table 7-1 shows the full list of reserved words.
126
Chapter 7 ■ Number Theory for FPGAs
127