AMP Chap3 Synchronous Design Using VHDL SP2016
AMP Chap3 Synchronous Design Using VHDL SP2016
AMP Chap3 Synchronous Design Using VHDL SP2016
Chapter 3
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 1
Presentation Progress
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 2
Synchronous sequential systems
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 4
Synchronous sequential systems
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 5
D Latch
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 6
Edge-triggered D flip-flop with asynchronous Set and Reset
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 7
Rising_edge and falling_edge functions
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 8
Synchronous set and reset and clock enable
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 9
Synchronous set and reset and clock enable
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 10
Synchronous set and reset and clock enable
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 11
Registers and shift registers
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 12
Registers and shift registers
Shift registers
– An extension of the above model of a register includes the
ability to shift the bits of the register to the left or to the right.
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 13
Registers and shift registers
Shift registers
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 14
Registers and shift registers
Shift registers
– A more general shift register is the universal shift register.
This can shift bits to the left or to the right, and can load an
entire new word in parallel. To do this, two control bits are
needed.
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 15
Registers and shift registers
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 16
Registers and shift registers
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 17
Registers and shift registers
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 18
Counters
Binary counter
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 19
Counters
Binary counter
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 20
Counters
Binary counter
– Note that the contents of the counter are stored as a variable
inside a process. The variable has type unsigned (allowing
the + operator to be used).
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 21
Counters - Examples
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 22
Counters - Examples
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 23
Counters - Examples
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 24
Counters - Examples
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 25
Up-Down Counter - Example
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 26
Up-Down Counter - Example
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 27
INTEGER vs. STD_LOGIC_VECTOR
library ieee;
use ieee.std_logic_1164.all;
entity adder is
port ( x, y : in std_logic_vector (7 downto 0);
z : out std_logic_vector (7 downto 0));
end prj1;
architecture add of adder is
begin
z <= x + y;
end add;
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 28
INTEGER vs. STD_LOGIC_VECTOR
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 29
INTEGER vs. STD_LOGIC_VECTOR
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 30
Typical Errors
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 31
Typical Errors
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 32
Typical Errors
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 33
Typical Errors: Two solutions
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 34
Typical Errors: Two solutions
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 35
Typical Errors: Two solutions
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 36
BCD Counter
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 37
BCD Counter
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 38
BCD Counter
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 39
Up-Down Counter - Example
Library ieee;
Use ieee.std_logic_1164.all;
entity counter is
port ( load : in std_logic;
data : in integer range 0 to 255;
clk : in std_logic;
up_down : in std_logic;
sum : out integer range 0 to 255
);
end counter;
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 40
Up-Down Counter - Example
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 41
Memory
The contents of a ROM chip are defined once. Hence we can use
a constant array to model a ROM device in VHDL. Below is the
seven-segment decoder described as a ROM.
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 43
ROM
The contents of a ROM chip are defined once. Hence we can use
a constant array to model a ROM device in VHDL. Below is the
seven-segment decoder described as a ROM.
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 44
ROM Memory – Example 1
entity program_ROM is
port ( address : in std_logic_vector (14 downto 0);
data : out std_logic_vector (7 downto 0);
enable : in std_logic );
end entity program_ROM;
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 45
ROM Memory – Example 2
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity ROM_2 is
port (clk : in std_logic;
en : in std_logic;
addr : in std_logic_vector (5 downto 0);
data : out std_logic_vector (19 downto 0));
end ROM_2 ;
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 46
ROM Memory – Example 2
Begin
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 47
ROM Memory – Example 2
process (clk) is
begin
if (clk'event and clk = '1') then
if (en = '1') then
data <= ROM(conv_integer(addr));
end if;
end if;
end process;
end behavior ;
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 48
Static RAM
Because data may be stored in the RAM as well as read from it,
the data signal is declared to be of mode inout.
– In addition, three control signals are provided.
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 49
Static RAM
All the control signals are active low. Like the ROM, the
memory array is modeled as an array, this time as a variable in a
process.
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 50
Static RAM
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 51
Static RAM
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 52
Synchronous RAM
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 53
Synchronous RAM
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 54
Synchronous RAM
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 55
Synchronous RAM
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 56
Presentation Progress
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 57
Clocked synchronous FSM
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 59
FSM Types
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 60
Clocked synchronous FSM structure
Mealy machine
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 61
Clocked synchronous FSM structure
Moore machine
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 62
Comparison of Mealy and Moore FSM
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 63
Comparison of Mealy and Moore FSM
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 64
FSM in VHDL
entity state_machine is
port (clk : in std_logic;
input: in std_logic;
reset: in std_logic;
output: out std_logic_vector (1 downto 0) );
end state_machine;
s0 input
Behavioral description
input
s2
end fsm;
/input
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 65
Behavioral description of the FSM
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 66
Moore FSM: Example – 1
-- state register
Register : process(clk, reset)
begin
if (reset = '1') then
state_reg <= zero,
elsif (clk'event and clk = '1') then
state_reg <= state_next;
end if;
end process Register;
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 67
Moore FSM: Example – 1
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 68
Mealy FSM: Example – 2
-- state register
Register : process(clk, reset)
begin
if (reset = '1') then
state_reg <= zero,
elsif (clk'event and clk = '1') then
state_reg <= state_next;
end if;
end process Register;
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 69
Mealy FSM: Example – 2
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 70
Moore vs. Mealy
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 71
Example – Sequential Shift/Add Multiplier
M1
Ready
M2 N-bit
Unsigned Result
Start Multiplier
clk
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 72
Example – Sequential Shift/Add Multiplier
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;
entity multiplier is
generic ( nbr_bits : natural := 4);
port ( M1 : in std_logic_vector
(nbr_bits-1 downto 0) ; -- first number
M2 : in std_logic_vector
(nbr_bits-1 downto 0); -- second number
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 73
Example – Sequential Shift/Add Multiplier
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 74
Example – Sequential Shift/Add Multiplier
Initialize : n2 = M2 ; n1 = M1 ; accu = 0
While (n2 # 0) do
If (LSB_n2 = 1) then
accu = accu + n1
End if
Shift n1 to left, n2 to right (with 0 at MSB)
End while
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 75
Example – Sequential Shift/Add Multiplier
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 76
Example – Sequential Shift/Add Multiplier
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 77
Example – Sequential Shift/Add Multiplier
M1
initialize
Start add M2
Controller shift Operators
Ready Result
lsb
zero
clk
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 78
Example – Sequential Shift/Add Multiplier
This makes it very easy to generate RTL code for this part
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 79
Example – Sequential Shift/Add Multiplier
This makes it very easy to generate RTL code for this part
operators: process
begin
wait until rising_edge(clk);
if initialize then n2 <= unsigned(M2);
n1 <= resize(unsigned(M1),n1’length);
accu <= (others => ’0’);
elsif add then accu <= accu + n1;
elsif shift then
n2 <= ’0’ & n2(nbr_bits-1 downto 1);
n1 <= n1(2*nbr_bits-2 downto 0) & ’0’;
end if;
end process operators;
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 80
Example – Sequential Shift/Add Multiplier
This makes it very easy to generate RTL code for this part
-- . . .
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 81
Example – Sequential Shift/Add Multiplier
Controller
– The controller has as inputs signals zero , lsb and start and as outputs the
signals initialize, shift and add. It is treated as a Moore machine.
𝑺𝒕𝒂𝒓𝒕
St_Init 𝒛𝒆𝒓𝒐
𝒛𝒆𝒓𝒐. 𝒍𝒔𝒃
𝒛𝒆𝒓𝒐. 𝒍𝒔𝒃
𝒛𝒆𝒓𝒐. 𝒍𝒔𝒃
𝒛𝒆𝒓𝒐
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 82
Example – Sequential Shift/Add Multiplier
-- other declarations
begin
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 83
Example – Sequential Shift/Add Multiplier
Controller: process
begin
wait until falling_edge(clk);
if (Start = ’1’) then State <= St_Init;
else
case State is
when St_Init =>
if zero then State <= St_End;
elsif lsb then State <= St_Add;
else State <= St_Shift;
end if;
when St_Add =>
State <= St_Shift;
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 84
Example – Sequential Shift/Add Multiplier
end rtl;
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 85
Example – Sequential Shift/Add Multiplier
Dr. Mroué DTR 8431 – Architecture des Microprocesseurs et Open Core Chapter 3 86