VHDL Cypress
VHDL Cypress
VHDL Cypress
VHDL Training
VHDL Training
VHDL Training
Design Entry
Schematic Simulation
Text
Design Compilation
Front End
Sim. Model
Design Verification
JEDEC File
Simulation Programmer
Prog. File
Back End
VHDL Training
VHDL Training
VHDL Training
The Entity
A BLACK BOX The ENTITY describes the periphery of the black box (i.e., the design I/O)
BLACK_BOX rst q[7:0] co
d[7:0]
clk
VHDL Training
BLACK_BOX
More shortly
q[7:0] co
VHDL Training
entity_name is an arbitrary name generics are used for defining parameterized components name is the signal/port identifier and may be a comma separate list for ports of identical modes and types mode describes the direction the data is flowing type indicates the set of values the port name may be assigned
1997 Cypress Semiconductor, rev 2.5.3
VHDL Training
Ports
The Entity (BLACK BOX) has PORTS PORTS are points of communication PORTS are often associated with the device pins PORTS are a special class of SIGNAL PORTS have an associated SIGNAL name, mode, and type
10
VHDL Training
PORT modes
A ports MODE is the direction data is transferred: IN Data goes into the entity but not out
OUT
INOUT
Data goes out of the entity but not in (and is not used internally)
Data is bi-directional (goes into and out of the entity)
BUFFER Data that goes out of the entity and is also fed-back internally within the entity
11
VHDL Training
12
VHDL Training
13
VHDL Training
IEEE 1164
"Multi-value logic system for VHDL interoperability" A package created as an aid to VHDL users Nine values as opposed to two ('0' and '1') Allows increased flexibility in behavioral VHDL coding, synthesis, and simulation std_logic and std_logic_vector are used as opposed to bit and bit_vector when a multi-valued logic system is required. std_logic and std_logic_vector are used when tri-state logic is required.
14
VHDL Training
1164 Types
std_logic and std_logic_vector are the industry standard logic type for digital design All 9 values are valid in a VHDL simulator, however only: 0 -- Forcing 0 1 -- Forcing 1 Z -- High Impedance L -- Weak 0 H -- Weak 1 - -- Dont care are recognized for logic synthesis
1997 Cypress Semiconductor, rev 2.5.3
15
VHDL Training
16
VHDL Training
d[11:0]
oe clk
ad[11:0]
a[11:0] int as
17
VHDL Training
18
VHDL Training
The Architecture
Architectures describe what is in the black box (i.e., the structure or behavior of entities) Descriptions can be either a combination of Structural descriptions Instantiations (placements of logic much like in a schematic and their connections) of building blocks referred to as components Behavioral/Dataflow descriptions Algorithmic (or high-level) descriptions:
IF a = b THEN state <= state5;
19
VHDL Training
arch_name is an arbitrary name optional signal declarations are used for signals local to the architecture body (that is, not the entitys I/O). entity_name is the entity name statements describe the function or contents of the entity
20
VHDL Training
21
VHDL Training
22
VHDL Training
23
VHDL Training
24
VHDL Training
a b
d g1 f
c USE WORK.gatespkg.ALL; ARCHITECTURE archlogic OF logic IS SIGNAL d: std_logic; BEGIN Behavioral/Dataflow d <= a AND b; Structural g1: nor2 PORT MAP (c, d, f); END archlogic;
1997 Cypress Semiconductor, rev 2.5.3
25
VHDL Training
VHDL Statements
There are two types of statements Sequential Though hardware is concurrent, it may be modeled with algorithms, by a series of sequential statements By definition, sequential statements are grouped using a process statement. Concurrent Statements outside of a process are evaluated concurrently during simulation Processes are concurrent statements
1997 Cypress Semiconductor, rev 2.5.3
26
VHDL Training
Concurrent Statements
Concurrent statements include: boolean equations conditional/selective signal assignments (when/else, with/select) instantiations Examples of concurrent statements:
-- Examples of boolean equations x <= (a AND (NOT sel1)) OR (b AND sel1); g <= NOT (y AND sel2); -- Examples of conditional assignments y <= d WHEN (sel1 = '1') ELSE c; h <= '0' WHEN (x = '1' AND sel2 = '0') ELSE '1'; -- Examples of instantiation inst: nand2 PORT MAP (h, g, f);
1997 Cypress Semiconductor, rev 2.5.3
27
VHDL Training
28
VHDL Training
The process label and variable declarations are optional The process executes when one of the signals in the sensitivity list has an event (changes value).
1997 Cypress Semiconductor, rev 2.5.3
29
VHDL Training
Process (contd.)
Processes are executing or suspended (active or inactive/awake or asleep) A process typically has a sensitivity list When a signal in the sensitivity list changes value, the process is executed by the simulator e.g., a process with a clock signal in its sensitivity list becomes active on changes of the clock signal All signal assignments occur at the END PROCESS statement in terms of simulation The process is then suspended until there is an event (change in value) on a signal in the sensitivity list
1997 Cypress Semiconductor, rev 2.5.3
30
VHDL Training
Combinational Logic
Can be described with concurrent statements e.g. with-select-when, when-else, boolean equations, component instantiatons Can be described with sequential statements e.g. if-then-else, case-when
31
VHDL Training
x <= (a AND NOT(s(1)) AND NOT(s(0))) OR (b AND NOT(s(1)) AND s(0)) OR (c AND s(1) AND NOT(s(0))) OR (d AND s(1) AND s(0)) ;
a b c d
mux
32
VHDL Training
WITH selection_signal SELECT signal_name <= value_1 WHEN value_1 of selection_signal, value_2 WHEN value_2 of selection_signal, ... value_n WHEN value_n of selection_signal, value_x WHEN OTHERS;
1997 Cypress Semiconductor, rev 2.5.3
33
VHDL Training
34
VHDL Training
More on with-select-when
You can use a range of values
35
VHDL Training
VHDL Training
x <= a when (s = 00) else b when (s = 01) else c when (s = 10) else d;
37
VHDL Training
38
VHDL Training
39
VHDL Training
40
VHDL Training
if-then-else
Absence of ELSE results in implicit memory 4-1 mux shown below mux4_1: process (a, b, c, d, s) begin if s = 00 then x <= a ; elsif s = 01 then x <= b ; elsif s = 10 then x <= c ; else x <= d ; end process mux4_1 ;
41
VHDL Training
42
VHDL Training
43
VHDL Training
Note: logic within a process can be registered or combinatorial Note: the order of the signals in the sensitivity list is not important
Note: the process mux is sensitive to signals a, b, and s; i.e., whenever one or more of those signals changes value, the statements inside of the process are executed
1997 Cypress Semiconductor, rev 2.5.3
44
VHDL Training
a a
clock clock
1997 Cypress Semiconductor, rev 2.5.3
45
VHDL Training
46
VHDL Training
VARIABLES
When a concurrent signal assignment cannot be used, the previous problem can be avoided using a VARIABLE Variables can only exist within a PROCESS, they cannot be used to communicate information between processes Variables can be of any valid data type The value assigned to a variable is available immediately The variable assignment statement is used to assign values to variables, e.g.,
c := a AND b;
1997 Cypress Semiconductor, rev 2.5.3
47
VHDL Training
48
VHDL Training
Native Operators
Logical - defined for type bit, bit_vector, boolean* AND, NAND OR, NOR XOR, XNOR NOT Relational - defined for types bit, bit_vector, integer* = (equal to) /= (not equal to) < (less than) <= (less than or equal to) > (greater than) >= (greater than or equal to) * overloaded for std_logic, std_logic_vector
1997 Cypress Semiconductor, rev 2.5.3
49
VHDL Training
50
VHDL Training
Overloaded Operators
In VHDL, the scope of all of the previous operators can be extended (or overloaded) to accept any type supported by the language, e.g.,
----assume a declaration of a 16-bit vector as SIGNAL pc IS std_logic_vector(15 DOWNTO 0); then a valid signal assignment is pc <= pc + 3; assuming the '+' operator has been overloaded to accept std_logic_vector and integer operands
The std_logic_1164 package defines overloaded logical operators (AND, OR, NOT, etc.,) for the std_logic and std_logic_vector types In this training, you will learn to use overloaded operators, but not to define them
1997 Cypress Semiconductor, rev 2.5.3
51
VHDL Training
Module Generation
In Warp release 4.0, a package called std_arith can be used to overload the arithmetic (+, -, etc.) and relational operators (=, /=, <, etc.,) for std_logic, std_logic_vector and integer types Using this package causes adders, counters, comparators, etc., to automatically replace the operators in the design. These are optimized for the target architecture and synthesis goal (area/speed) This is known as module generation
52
VHDL Training
53
VHDL Training
Produces the equation x = c To assign dont cares in VHDL: mysig <= '-'; 'X' means "unknown" and is not useful for synthesis
1997 Cypress Semiconductor, rev 2.5.3
54
VHDL Training
Comparing Vectors to Strings -more on don't cares Comparing "1101" to "11-1" will return FALSE Use std_match(a,"string") Must include std_arith package Example:
55
VHDL Training
56
VHDL Training
57
VHDL Training
58
VHDL Training
aeqb
59
VHDL Training
60
VHDL Training
Menus
Project Menu - Creating, opening, saving projects Files menu - Adding/deleting files from a project, file ordering, locking down pins, nodes, and FF locations Info menu - Report file and control file viewing/editing, tool versions, source file statistics Search menu - Allows searching of all VHDL and project files Tools Menu - Launches Nova Fonts Menu - Sets fonts for editor and error tracking Help - On-line help
1997 Cypress Semiconductor, rev 2.5.3
61
VHDL Training
Project Menu
62
VHDL Training
Files Menu
63
VHDL Training
Project Management
Galaxy project terminology Creating a project Adding/Deleting files from a project File ordering
64
VHDL Training
65
VHDL Training
A New Design
First step in a new design is to create a project Project->New Second step: Edit design files in the VHDL editor Third step: Add design files to the project Only .vhd files in the same directory as the project (.wpr) will be available Files added/removed by Files->Add, Files -> Add all and Files->Remove File ordering controlled by Files->Move Up and Files->Move Down Top level file should be at the bottom of the list
1997 Cypress Semiconductor, rev 2.5.3
66
VHDL Training
67
VHDL Training
68
VHDL Training
69
VHDL Training
70
VHDL Training
Compiling a design
Smart Compile Compiles all project files in specified order Knows if a file has been modified Makes recompiling large designs easy Compile Selected Compiles only the selected file Useful for code verification or to simply compile a file to a library
71
VHDL Training
Error Tracking
Galaxy has an integrated VHDL syntax error tracking/location mechanism Highlighting an error and clicking on magnifying glass launches editor with cursor at location of error Up and down arrows bring you to previous/next error
72
VHDL Training
73
VHDL Training
VHDL Editor
Used for editing design files Allows searching all project files Provides VHDL Browser (VHDL templates) Allows you to compile the file you are editing by using VHDL->Compile A much improved editor will be available with release 4.2 (send in those registration cards)
74
VHDL Training
Report File
Two output options: detailed or concise (default) Shows where UltraGenTM modules were synthesized Shows timing, device resource utilization, and pinout.
75
VHDL Training
Back Annotation
Back Annotation means passing design information back to a previous design stage Physical Information back annotation Pin numbers (schematic or control file) FLASH370 node numbers (control file) Simulation value back annotation (schematic) For control file, use Files->Annotate in Galaxy
76
VHDL Training
77
VHDL Training
gnd en(1)
nOE LE
control[7:0]
en(2) en(3)
78
VHDL Training
Exercise #3
Use Warp to compile the VHDL design description of the truth table below:
addr nvalid en(0) en(1) en(2) en(3) dir L H H H H H H H
L L H L L L L L
H H H H L H H H
L L L L L L H L
L H H H L H H H
Write the Architecture for the given Entity (next) Save design in file named ex3.vhd
79
VHDL Training
dir en
PLD
80
VHDL Training
81
VHDL Training
82
VHDL Training
83
VHDL Training
Signals can be pulled from larger vectors Good for grouping outputs as an alias Sizes on both sides must match
rw <= ctrl(0); ce <= ctrl(1); oe <= ctrl(2); highcount <= count(7 DOWNTO 4);
1997 Cypress Semiconductor, rev 2.5.3
84
VHDL Training
85
VHDL Training
86
VHDL Training
d clk
ARCHITECTURE archregistered OF registered IS BEGIN flipflop: Mff generic map (lpm_width=>1,lpm_fftyp=>lpm_dff) PORT MAP (data=>d,clock=>clk,enable=>one,q=>q); END archregistered;
87
VHDL Training
88
VHDL Training
89
VHDL Training
This process is only sensitive to changes in clk, i.e., it will become active only when the clock transitions
1997 Cypress Semiconductor, rev 2.5.3
90
VHDL Training
ELSIF clkEVENT AND clk = '1' THEN count <= count + 1; END IF; END PROCESS upcount;
This process is sensitive to changes in both clk and rst, i.e., it will become active during clock or reset transitions.
1997 Cypress Semiconductor, rev 2.5.3
91
VHDL Training
upcount: PROCESS (clk, rst) BEGIN IF rst = '1' THEN count <= x"0" ; ELSIF clkEVENT AND clk = '1' THEN IF load = '1' THEN count <= data; ELSE count <= count + 1; END IF; END IF;
92
VHDL Training
q_out
93
VHDL Training
Implicit memory
Signals in VHDL have a current value and may be scheduled for a future value If the future value of a signal cannot be determined, a latch will be synthesized to preserve its current value Advantages: Simplifies the creation of memory in logic design Disadvantages: Can generate unwanted latches, e.g., when all of the options in a conditional sequential statement are not specified
1997 Cypress Semiconductor, rev 2.5.3
94
VHDL Training
a c b
END IF;
END PROCESS im_mem; END archincomplete;
Note: the incomplete specification of the IF...THEN... statement causes a latch to be synthesized to store the previous state of c
1997 Cypress Semiconductor, rev 2.5.3
95
VHDL Training
a b
The conditional statement is fully specified, and this causes the process to synthesize to a single gate
1997 Cypress Semiconductor, rev 2.5.3
96
VHDL Training
97
VHDL Training
Exercise #4
Making use of the previous examples, write an entity/architecture pair for the following design:
ENC
COUNTER
DATA LD CLOCK
DIN LD ENC
COUNT Q
4
COMPARATOR
RST
RESET (sync)
P P=Q Q
REGISTER
98
VHDL Training
99
VHDL Training
100
VHDL Training
101
VHDL Training
State machines
Moore Machines A finite state machine in which the outputs change due to a change of state Mealy Machines A finite state machine in which the outputs can change asynchronously i.e., an input can cause an output to change immediately
102
VHDL Training
Moore machines
Outputs may change only with a change of state Multiple implementations include: Arbitrary state assignment outputs must be decoded from the state bits combinatorial decode registered decode Specific state assignment outputs may be encoded within the state bits one-hot encoding
103
VHDL Training
Inputs
Logic
State Registers
Output Logic
Outputs
104
VHDL Training
Current State
State Registers
Inputs
Output Logic
105
VHDL Training
Inputs
Logic
State Registers
Outputs
106
VHDL Training
ACK 10
107
VHDL Training
108
VHDL Training
Example: Solution 1
Combinatorial outputs decoded from the state bits
ARCHITECTURE archmoore1 OF moore1 IS TYPE fsm_states IS (idle, retry, ack); SIGNAL wait_gen : fsm_states; BEGIN fsm: PROCESS (clock, reset) BEGIN IF reset = '1' THEN wait_gen <= idle; -- asynchronous reset ELSIF clock'EVENT AND clock = '1' THEN CASE wait_gen IS WHEN idle => IF req = '0' THEN wait_gen <= retry; ELSE wait_gen <= idle; END IF; WHEN retry => IF pwait='1' THEN wait_gen <= ack; ELSE wait_gen <= retry; END IF;
1997 Cypress Semiconductor, rev 2.5.3
109
VHDL Training
110
VHDL Training
Example: Solution 2
111
VHDL Training
WHEN ack
WHEN OTHERS => wait_gen <= idle; ack_out <= '0'; --END CASE; -END IF; -END PROCESS fsm; -END archmoore2; --
note must define what happens to ack_out here or a latch will be synthesized to preserve its current state
112
VHDL Training
Example: Solution 3
Outputs encoded within the state bits
ARCHITECTURE archmoore3 OF moore3 IS SIGNAL wait_gen: std_logic_vector(1 DOWNTO 0); CONSTANT idle: std_logic_vector(1 DOWNTO 0) := CONSTANT retry: std_logic_vector(1 DOWNTO 0) := CONSTANT ack: std_logic_vector(1 DOWNTO 0) := BEGIN fsm: PROCESS (clock, reset) BEGIN IF reset = '1' THEN wait_gen <= idle; ELSIF clock'EVENT AND clock = '1' THEN CASE wait_gen IS WHEN idle => IF req = '0' THEN wait_gen <= ELSE wait_gen <= END IF;
retry; idle;
113
VHDL Training
114
VHDL Training
115
VHDL Training
116
VHDL Training
117
VHDL Training
118
VHDL Training
Mealy Machines
Outputs may change with a change of state OR with a change of inputs Mealy outputs are non-registered because they are functions of the present inputs
State Registers
Inputs
Logic
Outputs
119
VHDL Training
RESET (async)
IDLE 0 REQ RETRY 1 RETRY_OUT='1' if, ENABLE='0'
REQ PWAIT
120
VHDL Training
121
VHDL Training
Exercise #5
Design a state machine to implement the function shown below:
RESET POS
hold
POS RESET
sample
extend
clear='0' track='1'
122
VHDL Training
123
VHDL Training
124
VHDL Training
125