Beruflich Dokumente
Kultur Dokumente
Digital world
Digital world in 2050
Design methodologies
Ad-hoc Structured - Top-Down - Bottom-Up - Mixed
Algorithmic design
Architecture design Logic (gate) design Circuit (transistor) design Physical (layout) design
Verification must be done at each phase.
Tape-out
VHDL
Government Developed Ada based Strongly Type Cast Difficult to learn More Powerful
vs.
Verilog
Commercially Developed C based Mildly Type Cast Easy to Learn Less Powerful
Reconfigurability
Specification
Synthesis
Front End
Post-synthesis sim.
Back End
Fabrication
ASIC
FPGA
Logic synthesis
RTL code (Verilog/ VHDL) Gate-level netlist (Verilog/ VHDL) Area report Timing report Power consumption report
Logic synthesis
Constraints
Logic synthesis(Cont.)
LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY flipflop IS PORT ( D, Clock : IN STD_LOGIC ; Q : OUT STD_LOGIC ); END flipflop ;
Synthesis
ARCHITECTURE Behavior_1 OF flipflop IS BEGIN PROCESS ( Clock ) BEGIN IF Clock'EVENT AND Clock = '1' THEN Q <= D ; END IF ; END PROCESS ;
END Behavior_1 ;
D Clock
Control Signals
Data Outputs
Control Outputs
Provides all necessary resources and interconnects among them to perform specified task Examples of resources
Adders, multipliers, registers, memories, etc.
Moore FSM
Output is a function of a present state only
Inputs Next State function
Next State clock reset Present state register Present State
Output function
Outputs
Mealy FSM
Output is a function of a present state and inputs
Inputs Next State function Next State clock reset Present State Register Present State
Output function
Outputs
transition condition 2
state 2 / output 2
Mealy FSM has richer description and usually requires smaller number of states
Smaller circuit area
state 1
transition condition 2 / output 2
state 2
1
S1 / 0
0 1 S2 / 1
0 S1: 1 observed
S2: 10 observed
1/0
S1
1/0
clock
0 input 1 0 0 0
S0
Moore S0 Mealy
S1
S1
S2
S0
S0
S0
S0
S0
w = 1
C z = 1
resetn
w = 1
w = 1 z = 0 A w = 0 z = 0 B
w = 0 z = 0
w = 1 z = 1
VHDL
VHDL
VHDL is a language for describing digital hardware used by industry worldwide
VHDL is an acronym for VHSIC (Very High Speed Integrated Circuit) Hardware Description Language
Genesis of VHDL
Multiple design entry methods and hardware description languages in use No or limited portability of designs between CAD tools from different vendors Objective: shortening the time from a design concept to implementation
Features of VHDL
Technology/vendor independent Portable
Reusable
Design entity
Design Entity
Entity Declaration
Architecture 1 Architecture 2
Architecture 3
Entity declaration
Entity Declaration describes the interface of the component, i.e. input and output ports.
Entity name
Port names
No Semicolon
Reserved words
ENTITY entity_name IS PORT ( port_name : signal_mode signal_type; port_name : signal_mode signal_type; . port_name : signal_mode signal_type); END entity_name;
Architecture
Describes an implementation of a design entity. Architecture example:
ARCHITECTURE model OF nand_gate IS BEGIN z <= a NAND b; END model;
3.
4. 5.
Free format
VHDL is a free format language No formatting conventions, such as spacing or indentation imposed by VHDL compilers. Space and carriage return treated the same way.
Example:
if (a=b) then
or
if (a=b) then
or
if (a = b) then
Comments
Comments in VHDL are indicated with a double dash, i.e., --
- Comment indicator can be placed anywhere in the line - Any text that follows in the same line is treated as a comment - Carriage return terminates a comment - No method for commenting a block extending over a couple of lines Examples: -- main subcircuit Data_in <= Data_bus; -- reading data from the input FIFO
Comments(Cont.)
Explain function of module to other designers Explanatory, not just restatement of code Locate close to code described
Put near executable code, not just in a header
Port modes
Port signal Entity Entity
Port signal
a z c
Driver resides outside the entity Cant read out within an entity
c <= z
Driver may reside both inside and outside the entity
IN mode
OUT mode
INOUT mode
Port modes(Cont.)
Entity
Port signal
Entity
Port signal
x
Port signal Z can be read inside the entity
z
Signal can be read inside the entity
c
Driver resides inside the entity
c <= z
x c <= x
BUFFER mode
Port modes(Cont.)
In: Data comes in this port and can only be read within the entity. It can appear only on the right side of a signal or variable assignment. Out: The value of an output port can only be updated within the entity. It cannot be read. It can only appear on the left side of a signal assignment.
Inout: The value of a bi-directional port can be read and updated within the entity model. It can appear on both sides of a signal assignment.
Buffer: Used for a signal that is an output from an entity. The value of the signal can be used inside the entity, which means that in an assignment statement the signal can appear on the left and right sides of the <= operator
Library declarations
LIBRARY ieee; USE ieee.std_logic_1164.all; ENTITY nand_gate IS PORT( a : IN STD_LOGIC; b : IN STD_LOGIC; z : OUT STD_LOGIC ); END nand_gate; ARCHITECTURE model OF nand_gate IS BEGIN z <= a NAND b; END model;
Library declaration Use all definitions from the package std_logic_1164
PACKAGE 1
TYPES CONSTANTS FUNCTIONS PROCEDURES COMPONENTS
PACKAGE 2
TYPES CONSTANTS FUNCTIONS PROCEDURES COMPONENTS
Libraries
Ieee
Specifies multi-level logic system, including STD_LOGIC, and STD_LOGIC_VECTOR data types
Std
Specifies pre-defined data types (BIT, BOOLEAN, INTEGER, REAL, SIGNED, UNSIGNED, etc.), arithmetic operations, basic type conversion functions, basic text i/o functions, etc.
Visible by default
work
Current designs after compilation
STD_LOGIC type
LIBRARY ieee; USE ieee.std_logic_1164.all;
Z
W
High Impedance
Weak (Weakly driven) Unknown Weak (Weakly driven) 0. Models a pull down. Weak (Weakly driven) 1. Models a pull up. Don't Care
L
H -
X
Contention on the bus
X
0
VDD
1 L
1
X X 1 1 1 1 1 X
Z
X 0 1 Z W L H X
W
X 0 1 W W W W X
L
X 0 1 L W L W X
H
X 0 1 H W W H X
X X X X X X X X
X 0 1 Z W L H -
X X X X X X X X
Signals
SIGNAL a : STD_LOGIC;
a
1
wire
b
8
bus
a <= 1; b <= 0000; c <= B0000; d <= 0110_0111; e <= XAF67; f <= O723;
<<< 3
a(12) a(11) a(10) a(9) a(8) a(7) a(6) a(5) a(4) a(3) a(2) a(1) a(0) a(15) a(14) a(13)
a(15) a(14) a(13) a(12) a(11) a(10) a(9) a(8) a(7) a(6) a(5) a(4) a(3) a(2) a(1) a(0)
<<< 5
a(10) a(9) a(8) a(7) a(6) a(5) a(4) a(3) a(2) a(1) a(0) a(15) a(14) a(13) a(12) a(11)
END dataflow ;
Dataflow
Concurrent statements
Structural
Components and interconnects
Behavioral
Sequential statements Registers State machines Test benches
XOR3 Example(Cont.)
Dataflow architecture
ARCHITECTURE XOR3_DATAFLOW OF XOR3 IS SIGNAL U1_OUT: STD_LOGIC; BEGIN U1_OUT <= A XOR B; RESULT <= U1_OUT XOR C; END XOR3_DATAFLOW;
Dataflow description
Describes how data moves through the system and the various processing steps. Data Flow uses series of concurrent statements to realize logic. Concurrent statements are evaluated at the same time; thus, order of these statements doesnt matter. Data Flow is most useful style when series of Boolean equations can represent a logic.
XOR3 Example(Cont.)
Structural architecture
ARCHITECTURE XOR3_STRUCTURAL OF XOR3 IS SIGNAL U1_OUT : STD_LOGIC; COMPONENT XOR2 IS PORT( I1 : IN STD_LOGIC; I2 : IN STD_LOGIC; Y : OUT STD_LOGIC ); END COMPONENT; BEGIN U1: XOR2 PORT MAP (I1 => A, I2 => B, Y => U1_OUT); U2: XOR2 PORT MAP (I1 => U1_OUT, I2 => C, Y => RESULT); END XOR3_STRUCTURAL;
Structural description
Structural design is the simplest to understand. This style is the closest to schematic capture and utilizes simple building blocks to compose logic functions. Components are interconnected in a hierarchical manner. Structural descriptions may connect simple gates or complex, abstract components. Structural style is useful when expressing a design that is naturally composed of sub-blocks.
XOR3 Example(Cont.)
Behavioral architecture
ARCHITECTURE XOR3_BEHAVIORAL OF XOR3 IS BEGIN XOR3_BEHAVE: PROCESS (A,B,C) BEGIN IF ((A xor B xor C) = '1') THEN RESULT <= '1'; ELSE RESULT <= '0'; END IF; END PROCESS XOR3_BEHAVE; END XOR3_BEHAVIORAL;
Behavioral description
It accurately models what happens on the inputs and outputs of the black box (no matter what is inside and how it works). This style uses Process statements in VHDL.
Test bench
Test bench applies stimuli (drives the inputs) to the Design Under Test (DUT) and (optionally) verifies expected outputs. The results can be viewed in a waveform window or written to a file. Since test bench is written in VHDL, it is not restricted to a single simulation tool (portability). The same Test bench can be easily adapted to test different implementations (i.e. different architectures) of the same design.
Test bench(Cont.)
Simulated Outputs
Rule of Thumb: Usually ports from DUT entities are declared as signals within test bench
Test bench(Cont.)
Representative Inputs
Test bench(Cont.)
The same test bench can be used to test multiple implementations of the same circuit (multiple architectures) Test bench
Design entity
Architecture 1
Architecture 2
....
Architecture N
Test bench(Cont.)
XOR3 Example(Cont.)
Test bench
LIBRARY ieee; USE ieee.std_logic_1164.all;
BEGIN UUT : xor3 PORT MAP ( A => TEST_VECTOR(0), B => TEST_VECTOR(1), C => TEST_VECTOR(2), RESULT => TEST_RESULT); TESTING: PROCESS BEGIN TEST_VECTOR<="000"; WAIT FOR 10 ns; TEST_VECTOR<="001"; WAIT FOR 10 ns; TEST_VECTOR<="010"; WAIT FOR 10 ns; TEST_VECTOR<="011"; WAIT FOR 10 ns; TEST_VECTOR<="100"; WAIT FOR 10 ns; TEST_VECTOR<="101"; WAIT FOR 10 ns; TEST_VECTOR<="110"; WAIT FOR 10 ns; TEST_VECTOR<="111"; WAIT FOR 10 ns; END PROCESS TESTING; END XOR3_TB_ARCHITECTURE;
The execution of statements continues sequentially till the last statement in the process. After execution of the last statement, the control is again passed to the beginning of the process.
Order of execution
WAIT : waveform will keep its state after the last wait instruction.
BEGIN .......
testing: PROCESS BEGIN WAIT FOR 10 ns; test_vector <= test_vector + 1; END PROCESS testing; ........ END behavioral;
ASSERT syntax
ASSERT condition [REPORT "message] [SEVERITY severity_level ];
The message is written when the condition is FALSE. Severity_level can be: NOTE, WARNING, ERROR (default), or FAILURE.
REPORT syntax
REPORT "message" [SEVERITY severity_level ];
Dataflow
Concurrent statements
Structural
Components and interconnects
Behavioral
Sequential statements Registers State machines Test benches
Concurrent signal assignment () Conditional concurrent signal assignment (WHEN-ELSE) Selected concurrent signal assignment (WITH-SELECT-WHEN) Generate scheme for equations (FOR-GENERATE)
Logic operators
Logic operators
and or nand nor xor not xnor
only in VHDL-93
xnor
Logic operators(Cont.)
No Implied Precedence
Wanted: y = ab + cd Incorrect y <= a and b or c and d ; equivalent to y <= ((a and b) or c) and d ; equivalent to y = (ab + c)d Correct y <= (a and b) or (c and d) ;
Arithmetic operators
To use basic arithmetic operations involving std logic vectors you need to include the following library packages: LIBRARY ieee; USE ieee.std_logic_1164.all; USE ieee.std_logic_unsigned.all;
or
USE ieee.std_logic_signed.all; You can use standard +, -, * operators to perform addition, subtraction, and multiplication:
SIGNAL a : STD_LOGIC_VECTOR (3 DOWNTO 0); SIGNAL b : STD_LOGIC_VECTOR (3 DOWNTO 0); SIGNAL c : STD_LOGIC_VECTOR (3 DOWNTO 0); C <= A + B;
Y Cin S
16
Cout
: IN : IN : OUT : OUT
ARCHITECTURE Behavior OF adder16 IS SIGNAL Sum : SIGNED (16 DOWNTO 0) ; BEGIN Sum <= ('0' & X) + Y + Cin ; S <= Sum(15 DOWNTO 0) ; Cout <= Sum(16) ; Overflow <= Sum(16) XOR X(15) XOR Y(15) XOR Sum(15) ; END Behavior ;
: IN : OUT
WHEN-ELSE
target_signal <= value1 value2
. . . WHEN condition1 WHEN condition2 ELSE ELSE
Condition N-1
Relational operators
Relational operators
= /= < <= > >=
= and
/= or
> xor
>= xnor
Relational operators(Cont.)
compare a = bc
VHDL operators
w0 w1
ENTITY tri_state IS PORT ( ena : IN STD_LOGIC; input : IN STD_LOGIC_VECTOR (7 DOWNTO 0); output : OUT STD_LOGIC_VECTOR (7 DOWNTO 0) ); input END tri_state;
ARCHITECTURE tri_state_dataflow OF tri_state IS BEGIN output <= input WHEN (ena = 1) ELSE (OTHERS => Z); END tri_state_dataflow;
output
ena
ARCHITECTURE Behavior OF compare IS BEGIN AeqB <= '1' WHEN A = B ELSE '0' ; AgtB <= '1' WHEN A > B ELSE '0' ; AltB <= '1' WHEN A < B ELSE '0' ; END Behavior ;
4 4
A
B
AeqB
AgtB
AltB
: IN : OUT
ARCHITECTURE Behavior OF compare IS BEGIN AeqB <= '1' WHEN A = B ELSE '0' ; AgtB <= '1' WHEN A > B ELSE '0' ; AltB <= '1' WHEN A < B ELSE '0' ; END Behavior ;
w0 w1 w2 w3
y0 y1 z
WITH-SELECT-WHEN
WITH choice_expression SELECT target_signal <= expression1 WHEN choices_1, expression2 WHEN choices_2, . . . expressionN WHEN choices_N;
expression1 expression2
expressionN
WITH sel SELECT y <= a WHEN "000", b WHEN "011" to "110", c WHEN "001" | "111", d WHEN OTHERS;
ARCHITECTURE Behavior OF mux4to1 IS BEGIN WITH s SELECT f <= w0 WHEN "00", w1 WHEN "01", w2 WHEN "10", w3 WHEN OTHERS ; END Behavior ;
ARCHITECTURE Behavior OF dec2to4 IS SIGNAL Enw : STD_LOGIC_VECTOR (2 DOWNTO 0) ; BEGIN Enw <= En & w ; WITH Enw SELECT y <= "1000" WHEN "100", "0100" WHEN "101", "0010" WHEN "110", "0001" WHEN "111", "0000" WHEN OTHERS ; END Behavior ;
FOR-GENERATE
label: FOR identifier IN range GENERATE BEGIN {Concurrent Statements} END GENERATE;
Dataflow
Concurrent statements
Structural
Components and interconnects
Behavioral
Sequential statements Registers & counters Finite state machines Test benches
Component instantiation (PORT MAP) Generate scheme for component instantiations (FOR-GENERATE) Component instantiation with generic (GENERIC MAP, PORT MAP)
Example
s(0) r(0) r(1) p(1) r(2) r(3) r(4) r(5) s(1) p(0)
w0 w1 w2 w3
priority
y0 y1 z
w w
0
1
y y y
0
1 2
z(0) z(1)
z(2) z(3)
p(2)
p(3)
En
dec2to4
ARCHITECTURE structural OF priority_resolver IS SIGNAL p : STD_LOGIC_VECTOR (3 DOWNTO 0) ; SIGNAL q : STD_LOGIC_VECTOR (1 DOWNTO 0) ; SIGNAL ena : STD_LOGIC ;
CONSTANTs
CONSTANT name : type := value;
CONSTANT init_value : STD_LOGIC_VECTOR (3 DOWNTO 0) := "0100"; CONSTANT ANDA_EXT : STD_LOGIC_VECTOR (7 DOWNTO 0) := X"B4"; CONSTANT counter_width : INTEGER := 16; CONSTANT buffer_address : INTEGER := 16#FFFE#; CONSTANT clk_period : TIME := 20 ns; CONSTANT strobe_period : TIME := 333.333 ms;
CONSTANTs features
CONSTANTs can be declared in a PACKAGE, ENTITY, ARCHITECTURE When declared in a PACKAGE, CONSTANT is truly global, for the package can be used in several entities. When declared in an ARCHITECTURE, CONSTANT is local, i.e., it is visible only within this ARCHITECTURE. When declared in an ENTITY declaration, CONSTANT can be used in all ARCHITECTUREs associated with this ENTITY.
ROM
LIBRARY ieee; USE ieee.std_logic_1164.all; -----------------------------------------------------------------------------------------------ENTITY rom IS GENERIC (bits : INTEGER:=8; -- # of bits per word words: INTEGER:=8 -- # of words in the memory ); PORT ( addr: IN INTEGER RANGE 0 TO words-1; data: OUT STD_LOGIC_VECTOR (bits 1 DOWNTO 0) ); END rom;
ROM (Cont.)
ARCHITECTURE behavioral OF rom IS TYPE vector_array IS ARRAY (0 TO words-1) OF STD_L OGIC_VECTOR (bits 1 DOWNTO 0);
CONSTANT memory: vector_array := ("0000_0000", "0000_0010", "0000_0100", "0000_1000", "0001_0000", "0010_0000", "0100_0000", "1000_0000");
BEGIN data <= memory(addr); END rom;
COMPONENT dec2to4 PORT (w : IN STD_LOGIC_VECTOR (1 DOWNTO 0) ; En : IN STD_LOGIC ; y : OUT STD_LOGIC_VECTOR (0 TO 3) ) ; END COMPONENT ;
ARCHITECTURE structural OF priority_resolver IS SIGNAL p : STD_LOGIC_VECTOR (3 DOWNTO 0) ; SIGNAL q : STD_LOGIC_VECTOR (1 DOWNTO 0) ; SIGNAL ena : STD_LOGIC ;
u1: mux2to1 PORT MAP (w0 => r(0) , w1 => r(1), s => s(0), f => p(0)); p(1) <= r(2); p(1) <= r(3); u2: mux2to1 PORT MAP (w0 => r(4) , w1 => r(5), s => s(1), f => p(3)); u3: priority PORT MAP (w => p, y => q, z => ena);
u4: dec2to4 PORT MAP (w => q, En => ena, y => z); END structural;
Configuration declaration
CONFIGURATION SimpleCfg OF priority_resolver IS FOR structural
w4 w7
s2 s3 f
w8 w 11
w 12 w 15
Straightforward code
LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY Example1 IS PORT ( w : IN s : IN f : OUT ); END Example1 ;
: IN : IN : OUT
w(2), w(3), s(1 DOWNTO 0), m(0) ) ; w(6), w(7), s(1 DOWNTO 0), m(1) ) ; w(10), w(11), s(1 DOWNTO 0), m(2) ) ; w(14), w(15), s(1 DOWNTO 0), m(3) ) ; m(2), m(3), s(3 DOWNTO 2), f ) ;
Modified code
ARCHITECTURE Structure OF Example1 IS COMPONENT mux4to1 PORT ( w0, w1, w2, w3 s f END COMPONENT ; : IN : IN : OUT STD_LOGIC ; STD_LOGIC_VECTOR (1 DOWNTO 0) ; STD_LOGIC ) ;
SIGNAL m : STD_LOGIC_VECTOR (0 TO 3) ; BEGIN G1: FOR i IN 0 TO 3 GENERATE Muxes: mux4to1 PORT MAP ( w(4*i), w(4*i+1), w(4*i+2), w(4*i+3), s(1 DOWNTO 0), m(i) ) ; END GENERATE ; Mux5: mux4to1 PORT MAP ( m(0), m(1), m(2), m(3), s(3 DOWNTO 2), f ) ; END Structure ;
A
16
A <<< B
16
STD_LOGIC_VECTOR (15 DOWNTO 0); STD_LOGIC_VECTOR (15 DOWNTO 0); STD_LOGIC ; STD_LOGIC_VECTOR(15 DOWNTO 0)
COMPONENT fixed_rotator_left_16 GENERIC ( L : INTEGER := 1); PORT ( a : IN STD_LOGIC_VECTOR (15 DOWNTO 0); y : OUT STD_LOGIC_VECTOR (15 DOWNTO 0) ); END COMPONENT ;
Dataflow
Concurrent statements
Structural
Components and interconnects
Behavioral
Sequential statements Registers & counters Finite state machines Test bench
PROCESSes
PROCESSes describe sequential behavior PROCESSes in VHDL are very powerful statements
Allow to define an arbitrary behavior that may be difficult to represent by a real circuit Not every process can be synthesized
Use PROCESSes with caution in the code to be synthesized Use PROCESSes freely in test benches
What is a PROCESS?
A process is a sequence of instructions referred to as sequential statements.
The keyword PROCESS
All statements within the process are executed SEQUENTIALLY. Hence, the order of statements is important
A process must end with the keywords END PROCESS
testing: PROCESS BEGIN test_vector<=00; WAIT FOR 10 ns; test_vector<=01; WAIT FOR 10 ns; test_vector<=10; WAIT FOR 10 ns; test_vector<=11; WAIT FOR 10 ns; END PROCESS;
Anatomy of a Process
OPTIONAL
[label:] PROCESS [(sensitivity list)] [declaration part] BEGIN statement part END PROCESS [label];
label: PROCESS (sensitivity list) declaration part BEGIN statement part END PROCESS;
Statement Part
Contains sequential statements to be executed each time the process Is activated Analogous to conventional programming languages
priority
All signals which appear on the left of signal assignment statement (<=) are outputs e.g. y, z All signals which appear on the right of signal assignment statement (<=) or in logic expressions are inputs e.g. w, a, b, c All signals which appear in the sensitivity list are inputs e.g. clk Note that not all inputs need to be included in the sensitivity list
D latch
LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY latch IS PORT ( D, Clock : IN Q : OUT ); END latch ; STD_LOGIC ; STD_LOGIC
ARCHITECTURE Behavior OF latch IS BEGIN PROCESS ( D, Clock) BEGIN IF Clock = '1' THEN Q <= D ; END IF ; END PROCESS ; END Behavior;
D Clock
D flip-flop
LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY flipflop IS PORT ( D, Clock : IN STD_LOGIC ; Q : OUT STD_LOGIC ); END flipflop ;
ARCHITECTURE Behavior_1 OF flipflop IS BEGIN PROCESS ( Clock ) BEGIN IF Clock'EVENT AND Clock = '1' THEN Q <= D ; END IF ; END PROCESS ;
END Behavior_1 ;
D Clock
ARCHITECTURE Behavior_2 OF flipflop IS BEGIN PROCESS BEGIN WAIT UNTIL Clock'EVENT AND Clock = '1' ; Q <= D ; END PROCESS ;
END Behavior_2 ;
D Clock
: IN : OUT
STD_LOGIC ; STD_LOGIC
ARCHITECTURE Behavior OF flipflop IS BEGIN PROCESS ( Resetn, Clock ) BEGIN IF Resetn = '0' THEN Q <= '0' ; ELSIF Clock'EVENT AND Clock = '1' THEN Q <= D ; END IF ; END PROCESS ; END Behavior ;
D Clock Resetn
ARCHITECTURE Behavior OF flipflop IS BEGIN PROCESS BEGIN WAIT UNTIL Clock'EVENT AND Clock = '1' ; IF Resetn = '0' THEN Q <= '0' ; ELSE Q <= D ; END IF ; END PROCESS ; END Behavior ;
D Clock Resetn
ARCHITECTURE Behavior OF reg8 IS BEGIN PROCESS ( Resetn, Clock ) BEGIN IF Resetn = '0' THEN Q <= "00000000" ; ELSIF Clock'EVENT AND Clock = '1' THEN Q <= D ; END IF ; END PROCESS ; END Behavior ;
Resetn 8 D Q
Clock
reg8
: IN : OUT
upcount
Clock Resetn
upcount
Clock
Sequence 10 recognizer
TYPE state IS (S0, S1, S2); SIGNAL Moore_state: state; U_Moore: PROCESS (clock, reset) BEGIN IF(reset = 1) THEN Moore_state <= S0; ELSIF (clock = 1 AND clockEVENT) THEN CASE Moore_state IS WHEN S0 => IF input = 1 THEN Moore_state <= S1; ELSE Moore_state <= S0; END IF; WHEN S1 => IF input = 0 THEN Moore_state <= S2; ELSE Moore_state <= S1; END IF; WHEN S2 => IF input = 0 THEN Moore_state <= S0; ELSE Moore_state <= S1; END IF; END CASE; END IF; END PROCESS; Output <= 1 WHEN Moore_state = S2 ELSE 0;
WHEN S1 => IF input = 0 THEN Mealy_state <= S0; ELSE Mealy_state <= S1; END IF; END CASE; END IF; END PROCESS;
Sequence 11 recognizer
USE ieee.std_logic_1164.all ; ENTITY simple IS PORT ( clock resetn w z ); END simple ;
ARCHITECTURE Behavior OF simple IS TYPE State_type IS (A, B, C) ; SIGNAL y : State_type ; BEGIN PROCESS ( resetn, clock ) BEGIN IF resetn = '0' THEN y <= A ; ELSIF (Clock'EVENT AND Clock = '1') THEN
CASE y IS WHEN A => IF w = '0' THEN y <= A ; ELSE y <= B ; END IF ; WHEN B => IF w = '0' THEN y <= A ; ELSE y <= C ; END IF ; WHEN C => IF w = '0' THEN y <= A ; ELSE y <= C ; END IF ; END CASE ;
END IF ; END PROCESS ; z <= '1' WHEN y = C ELSE '0' ; END Behavior ;
: IN : IN : IN : OUT
ARCHITECTURE Behavior OF Mealy IS TYPE State_type IS (A, B) ; SIGNAL y : State_type ; BEGIN PROCESS ( resetn, clock ) BEGIN IF resetn = '0' THEN y <= A ; ELSIF (clock'EVENT AND clock = '1') THEN
Using enumerated types for states in VHDL leaves encoding problem for synthesis tool
--(ENTITY declaration not shown) ARCHITECTURE Behavior OF simple IS TYPE State_type IS (A, B, C) ; ATTRIBUTE ENUM_ENCODING : STRING ; ATTRIBUTE ENUM_ENCODING OF State_type : TYPE IS "00 01 11" ; SIGNAL y_present, y_next : State_type ; BEGIN cont ...
SIGNAL y_present, y_next : ABC_STATE; ------------------------------------------------------------------------------------------BEGIN PROCESS ( w, y_present ) BEGIN CASE y_present IS WHEN A => IF w = '0' THEN y_next <= A ; ELSE y_next <= B ; END IF ; cont
Arbiter circuit
Reset 000
Idle
0xx 1xx
reset
x0x
r1 r2 r3
g1
Arbiter
g2
g3
xx0
gnt2 g 2 = 1
x1x 001
gnt3 g 3 = 1
clock
xx1
END ARCHITECTURE_NAME;
Multiple concurrent assignment to one signal is not allowed in tools without resolved logic support
Inside PROCESS: If multiple assignments occur to SIGNAL X, the last assignment X <= ? overrides previous ones
In fact there is no effect even if we put synchronous inputs in the sensitivity list in case of clocked processes with synchronous inputs
Subprograms
Include FUNCTIONs and PROCEDUREs Commonly used pieces of code Can be placed in a library, and then reused and shared among various projects Abstract operations that are repeatedly performed Type conversions Use only sequential statements, the same as processes
Subprograms(Cont.)
global
FUNCTION / PROCEDURE ENTITY
FUNCTIONs
FUNCTIONs always return a single value as a result FUNCTIONs are called using formal and actual parameters the same way as components FUNNCTIONs never modify parameters passed to them Parameters can only be constants (including generics) and signals (including ports); variables are not allowed; the default is a CONSTANT When passing parameters, no range specification should be included (for example no RANGE for INTEGERS, or TO/DOWNTO for STD_LOGIC_VECTOR) FUNCTIONs are always used in some expression, and not called on their own
FUNCTIONs(Cont.)
FUNCTION syntax
FUNCTION function_name (<parameter_list>) RETURN data_type IS [declarations] BEGIN (sequential statements) END function_name;
FUNCTIONs(Cont.)
FUNCTIONs(Cont.)
FUNCTIONs(Cont.)
Example
LIBRARY IEEE; USE IEEE.std_logic_1164.all;
ARCHITECTURE behavioral OF powerOfFour IS
FUNCTION Pow ( SIGNAL N: INTEGER; Exp : INTEGER) RETURN INTEGER IS VARIABLE Result : INTEGER := 1; BEGIN FOR i IN 1 TO Exp LOOP Result := Result * N; END LOOP; RETURN( Result ); END Pow; BEGIN Y <= Pow(X, 4); END behavioral;
FUNCTIONs(Cont.)
END specialFunctions
FUNCTIONs(Cont.)
PROCEDUREs
PROCEDUREs do not return a value PROCEDUREs are called using formal and actual parameters the same way as components PROCEDUREs may modify parameters passed to them Each parameter must have a mode: IN, OUT, INOUT Parameters can be constants (including generics), signals (including ports), and variables; the default for inputs (mode in) is a constant, the default for outputs (modes out and inout) is a variable When passing parameters, range specification should be included (for example RANGE for INTEGERS, and TO/DOWNTO for STD_LOGIC_VECTOR) Procedure calls are statements on their own
PROCEDUREs(Cont.)
PROCEDURE syntax
PROCEDURE procedure_name (<parameter_list>)IS [declarations] BEGIN (sequential statements) END procedure_name;
PROCEDUREs(Cont.)
PROCEDUREs(Cont.)
PROCEDUREs(Cont.)
Example
LIBRARY ieee; USE ieee.std_logic_1164.all; ENTITY min_max IS GENERIC (limit: INTEGER := 255); PORT ( ena : IN BIT; inp1, inp2 : IN INTEGER RANGE 0 TO limit; min_out, max_out: OUT INTEGER RANGE 0 TO limit ); END min_max;
PROCEDUREs(Cont.) Example(Cont.)
ARCHITECTURE my_architecture OF min_max IS PROCEDURE sort (SIGNAL in1, in2: IN INTEGER RANGE 0 TO limit; SIGNAL min, max: OUT INTEGER RANGE 0 TO limit) IS BEGIN
IF (in1 > in2) THEN max <= in1; min <= in2; ELSE max <= in2; min <= in1; END IF; END sort;
BEGIN PROCESS (ena) BEGIN IF (ena=1) THEN sort (inp1, inp2, min_out, max_out); END IF; END PROCESS; END my_architecture;
Operator as a FUNCTION
LIBRARY ieee; USE ieee.std_logic_1164.al; ---------------------------------------------------------PACKAGE my_package IS FUNCTION "+" (a, b: STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR; END my_package;
Operator as a FUNCTION(Cont.)
PACKAGE BODY my_package IS FUNCTION "+" (a, b: STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR; VARIABLE result: STD_LOGIC_VECTOR; VARIABLE carry: STD_LOGIC; BEGIN carry := 0; FOR i IN aREVERSE_RANGE LOOP result(i) := a(i) XOR b(i) XOR carry; carry := (a(i) AND b(i)) OR (a(i) AND carry) OR (b(i) AND carry)); END LOOP; RETURN result; END "+" ; END my_package;
Operator overloading
Operator overloading allows different argument types for a given operation (function) The VHDL tools resolve which of these functions to select based on the types of the inputs This selection is transparent to the user as long as the function has been defined for the given argument types.
Operator overloading(Cont.)
Examples
SIGNAL count: STD_LOGIC_VECTOR (7 DOWNTO 0); You can use
count <= count + 0000_0001; or count <= count + 1; or count <= count + 1;
Read about
Array attributes Records Physical data types
Block B
Combinatorial Logic2
Block C
Combinatorial Logic3
reg1
reg2
The path between reg1 and reg2 is divided between three different block
Due to hierarchical boundaries, optimization of the combinational logic cannot be achieved
reg2
Recommended practice
All the combinational circuitry is grouped in the same block that has its output connected the destination flip flop It allows the optimal minimization of the combinational logic during synthesis Allows simplified description of the timing interface
reg2
reg3
Simplifies the synthesis design environment: Inputs to the individual block arrive within the same relative delay (caused by wire delays)
Dont really need to specify output requirements since paths starts at flip flop outputs.
Due to time pressures, and a bug found that can be simply be fixed by adding some simple glue logic. RESIST THE TEMPTATION!!! At this level in the hierarchy, this implementation will not allow the glue logic to be absorbed within any lower level block.
reg1 may be driven by time critical function, hence will have different optimization constraints reg3 may be driven by slow logic, hence no need to constrain it for speed
Slow Logic
reg3
Top
Use different entities to partition design blocks Allows different constraints during synthesis to optimize for area or speed or both.
Separation of the FSM and the random logic allows you to use FSM optimized synthesis
FSM
reg1
reg3
thanks
digital design