Professional Documents
Culture Documents
F2 - Modelling Styles
F2 - Modelling Styles
1
Modeling Styles
• Data flow
• Structural
2
One System –
Many VHDL Descriptions
Idea...
3
Sequential (Behavioural) vs
Concurrent (Dataflow) Statements
• VHDL provides two different types of execution:
sequential
concurrent
4
Sequential Style
XOR-gate
a Typically used to describe state machines
q
b and other complicated behaviour.
process(a,b)
begin
if (a/=b) then
q <= ‘1’;
else
q <= ‘0’;
end if;
end process;
5
Data flow Style
XOR-gate
a Typically used to describe atomic functions
q
b and other simple behaviour.
q <= a xor b;
6
Structural Style
XOR-gate
a Typically used to describe hierarchy and
q
b connect smaller, more managable,
units together.
7
Sequential & Dataflow style
8
Sequential Style
XOR-gate
a Typically used to describe state machines
q
b and other complicated behaviour.
Sensitivity list – when a signal
in the list changes value, the
Everything inside a process(a,b) process is executed
process is executed
begin
sequentially
if (a/=b) then
q <= ‘1’;
else
q <= ‘0’;
end if;
end process;
9
Sequential Style Syntax
VARIABLE
BEGIN DECLARATIONS
LOCAL TYPE
process_statements DECLARATIONS
LOCAL FUNCTION
END PROCESS [ process_label ] ; DECLARATIONS
11
Variable declaration
15
Sequential Statements
– {Signal,variable} assignments
– Flow control
• if <condition> then <statements> [elsif <statements>]
else <statements>
end if;
• for <range> loop <statements> end loop;
• while <condition> loop <statements> end loop;
• case <condition> is
when <value> => <statements>
when <value> => <statements>
when others => <statements>
end case;
Implies State Machine.
– Wait on <signal> until <expression> for <time> ; Good for Testbenches.
16
IF- vs CASE-statement Syntax
Concatenation operator
18
Synthesis of a case statement
type ENUM is (PICK_A, PICK_B, PICK_C, PICK_D);
signal VALUE: ENUM;
signal A, B, C, D, Z: BIT;
...
case VALUE is
when PICK_A => Z <= A;
when PICK_B => Z <= B;
when PICK_C => Z <= C;
when PICK_D => Z <= D;
end case;
19
FOR- vs WHILE-statement Syntax
i:=0;
while (i<9) loop A While-loop is considered to be an
FSM by some synthesis-tools. Thus,
q <= a(i) and b(i); it needs a wait statement to be
WAIT ON clk UNTIL clk=‘1’; synthesised
end loop;
20
WAIT-statement Syntax
• The wait statement causes the suspension of a process statement or a procedure
• Synthesizable combination:
22
Data flow Style
XOR-gate
a Typically used to describe atomic functions
q
b and other simple behaviour.
q <= a xor b;
23
Concurrent Process Equivalents
26
VHDL Hierarchy
Package
Concurrent Process
Concurrent
Statements
Statements 27 Sequential Statements
VHDL Hierarchy
Libraries
(sub-directories)
x
y carry
enable
x
result
y
29
Structural Statements
30
Structural Statements
31
Component Instantiation Syntax
• The instantiation statement maps the interface of the component to other
objects in the architecture
• The instantiation has 3 key parts
– Name
– Component type
– Port map
Component
Name Type
Port Map
S1 in1
out1 S3
S2 in2
32
Named vs Positional port association
U0 : and_gate
U0 : and_gate
PORT MAP
PORT MAP
(in1 => S1,
(S1,S2,S3);
in2 => S2,
out1 => S3);
33
Component Declaration
34
Component Instantiation in VHDL’93
35
Legal signal-to-port connections
37
Generics
38
Alter range of subtypes
Entity adder is
Generic(N:integer);
…
End adder;
Architecture behave of adder is
signal sum:integer range 0 to 2**N-1;
…
Begin
…
End behave;
39
Change size of arrays/vectors
Entity adder is
Generic(N:integer);
Port(A,B:IN bit_vector(N-1 downto 0);
Q:OUT bit_vector(N-1 downto 0));
End adder;
Architecture behave of adder is
…
Begin
…
End behave;
40
Technology Modeling
COMPONENT inv IS
GENERIC (tplh, tphl : TIME);
PORT ( in1 : IN BIT;
out1 : OUT BIT);
END COMPONENT;
PACKAGE my_components IS
COMPONENT inv
GENERIC ( tplh, tphl : time);
PORT ( in1 : IN BIT; out1 : OUT BIT);
END COMPONENT;
END my_components;
USE Work.my_components.ALL;
ARCHITECTURE test OF test_inv
SIGNAL S1, S3 : BIT;
BEGIN
Gate1 : my_components.inv
GENERIC MAP (2 ns, 3 ns)
PORT MAP (S1, S3);
END test;
43
Configuration Specification
44
Configuration Specification (ctd.)
45
Configuration Syntax (ctd.)
46
Component Specification Syntax
• The component specification can be of several forms
– Single component
FOR A1 : and_gate USE binding_indication;
– Multiple components
FOR A1, A2 : and_gate USE binding_indication;
– All components
FOR ALL : and_gate USE binding_indication;
All components of this type are effected
– Other components
FOR OTHERS : and_gate USE binding_indication;
Components that have not yet been specified are effected
47
Binding Indication Syntax
Entity name
Architecture name
Binding indication may also include a PORT
MAP and GENERIC MAP to adapt the entity to
the component 48
Example: BAD Configuration
Specification
• This example shows the use of the configuration specification to
allow an entity fit a component with a different interface
• NB! This is considered BAD CODING STYLE!!!
ENTITY JKFF IS
PORT (clk, preset, clear, J, K : IN BIT;
Q, Q_bar : OUT BIT);
END JKFF;
PACKAGE Global_signals IS
SIGNAL clk, preset, clear : BIT;
END Global_signals;
USE Work.Global_signals;
ENTITY config_test IS
END config_test;
49
Example: BAD Configuration
Specification
• The configuration statement maps the JKFF entity to the global signals and
the ports of the component
BEGIN
U0 : FF PORT MAP (S1, S2, S3, S4);
END structural; 50
Configuration Specification
• If the binding is not specified in the architecture, it can be done from the
outside, in a configuration specification.
• This is useful to use in testbenches, replacing test vector generators,
components and monitors without touching the architecture.
ARCHITECTURE structural OF config_test IS
SIGNAL S1, S2, S3, S4: BIT;
COMPONENT FF
PORT(J, K: IN BIT; Q, Q_bar: OUT BIT);
END COMPONENT FF;
BEGIN
U0 : FF PORT MAP (S1, S2, S3, S4); Name of entity
END structural;
Configuration config_FF of config_test is
for structural Name of architecture
FOR U0 : FF USE ENTITY Work.JKFF(structural)
PORT MAP (clk => Global_signals.CLK,
preset => Global_signals.preset,
clear => Global_signals.clear,
J => J, K => K,
Q => Q, Q_bar => Q_bar);
end for;
end for;
End config; 51
Generate Statement
52
Generate Statement Syntax
53
IF-Generate statement
54
Example: Array of AND-gates
USE work.my_gates.all;
ARCHITECTURE structural OF and_bit_vector IS
BEGIN
G1 : FOR i IN N-1 DOWNTO 0 GENERATE
and_array : and_gate
GENERIC MAP (2 ns, 3 ns)
PORT MAP (i1=>a(i),i2=>b(i),q=>q(i));
END GENERATE G1;
END structural;
a(N-1:0)
b(N-1:0)
q(N-1:0) 55
Example: Array of several gate-types
56
Example: Array with indexing
ARCHITECTURE structural OF parity_calculator IS
BEGIN
G1 : FOR i IN N-1 DOWNTO 0 GENERATE
G3 : IF (i = 0) GENERATE
xor_1 : xor_gate GENERIC MAP (3 ns, 3 ns)
PORT MAP (even_odd,b(i),c(i));
END GENERATE G3;
G4 : IF (i = N-1) GENERATE
xor_1 : xor_gate GENERIC MAP (3 ns, 3 ns)
PORT MAP (c(i-1),b(i),qout);
END GENERATE G4;
Cout Cin
FA FA FA
A+B A+B
Cin=0 A+B+0 A+B+0=A-B-1
Cin=1 A+B+1 A+B+1=A-B-1+1
A+B+Cin A-B-Cin
58
Testing structural components
59
Testing a Circuit
Test Equipment
• Pulse and Function generators
• Oscilloscope
• Logic Analyzers
• Computers
• Specialized Zigs +
Test Engineer
60
Testing a structural component
• When you test a structural component, it is
important that you jog every wire at least once
• For a structural adder, the outputs and the carry
must switch/change value.
– If we add -1 with 0, and then add +1 using cin, then the
value will ripple through the carry chain and turn sum to
0. All wires in the architecture changes value.
61
Assert Statement
62
Assert Syntax
63
Assert Example
• Assume type state is (good, reset);
• We specify the Normal operating conditions – assert triggers on
abnormal operating conditions
65