lecture 8: vhdl processes

24
CWRU EECS 318 EECS 318 CAD Computer Aided Design EECS 318 CAD Computer Aided Design LECTURE 8: VHDL PROCESSES LECTURE 8: VHDL PROCESSES Instructor: Francis G. Wolff [email protected] Case Western Reserve University This presentation uses powerpoint animation: please viewshow

Upload: others

Post on 17-Feb-2022

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

EECS 318 CADComputer Aided Design

EECS 318 CADComputer Aided Design

LECTURE 8: VHDL PROCESSES

LECTURE 8: VHDL PROCESSES

Instructor: Francis G. Wolff [email protected]

Case Western Reserve UniversityThis presentation uses powerpoint animation: please viewshow

Page 2: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

2-to-1 Multiplexor: and Datapath multiplexor

0

1

a

b

S

Y

WITH s SELECT Y <= a WHEN ‘0’,

b WHEN OTHERS;

WITH s SELECT Y <= a WHEN ‘0’,

b WHEN OTHERS;

behavioral

WITH s SELECT Y <= a WHEN ‘0’,

b WHEN OTHERS;

WITH s SELECT Y <= a WHEN ‘0’,

b WHEN OTHERS;

Datapath is n bits wideDatapath is n bits wide

Where is the difference?Where is the difference?

0

1

a

b

S

Yn

n

n

Page 3: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

Generic 2-to-1 Datapath Multiplexor Entity

0

1

a

b

S

Yn

n

nLIBRARY IEEE;USE IEEE.std_logic_1164.all;USE IEEE.std_logic_arith.all;

ENTITY Generic_Mux ISGENERIC (n: INTEGER);

PORT (Y: OUT std_logic_vector(n-1 downto 0); a: IN std_logic_vector(n-1 downto 0); b: IN std_logic_vector(n-1 downto 0); S: IN std_logic_vector(0 downto 0) );END ENTITY;

Page 4: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

Generic 2-to-1 Datapath Multiplexor Architecture

ARCHITECTURE Generic_Mux_arch OF Generic_Mux ISBEGIN WITH S SELECT Y <= a WHEN "1",

b WHEN OTHERS;END ARCHITECTURE;

Configurations arerequire for simulation

Configurations arerequire for simulation

CONFIGURATION Generic_Mux_cfg OF Generic_Mux IS FOR Generic_Mux_arch END FOR;END CONFIGURATION;

Page 5: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

Structural SR Flip-Flop (Latch)

NANDR S Qn+1

0 0 U0 1 11 0 01 1 Qn

R

S

Q

Q

ENTITY Latch ISPORT(R, S: IN std_logic; Q, NQ: OUT std_logic);

END ENTITY;

ARCHITECTURE latch_arch OF Latch ISBEGIN

Q <= R NAND NQ;NQ <= S NAND Q;

END ARCHITECTURE;

Page 6: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

Inferring Behavioral Latches: Asynchronous

ARCHITECTURE Latch2_arch OF Latch ISBEGIN

PROCESS (R, S) BEGINIF R= ‘0’ THEN

Q <= ‘1’; NQ<=‘0’;ELSIF S=‘0’ THEN

Q <= ‘0’; NQ<=‘1’;END IF;

END PROCESS;END ARCHITECTURE;

NANDR S Qn+1

0 0 U0 1 11 0 01 1 Qn

R

S

Q

Q

Sensitivity list of signals:Every time a change ofstate or event occurs onthese signals thisprocess will be called

Sensitivity list of signals:Every time a change ofstate or event occurs onthese signals thisprocess will be called

SequentialStatements

SequentialStatements

Page 7: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

Gated-Clock SR Flip-Flop (Latch Enable)

S

R

Q

Q

LE

ARCHITECTURE Latch_arch OF GC_Latch IS BEGINPROCESS (R, S, LE) BEGIN

IF LE=‘1’ THENIF R= ‘0’ THEN

Q <= ‘1’; NQ<=‘0’;ELSIF S=‘0’ THEN

Q <= ‘0’; NQ<=‘1’;END IF;

END IF;END PROCESS;

END ARCHITECTURE;

Page 8: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

Inferring D-Flip Flops: Synchronous

ARCHITECTURE Dff_arch OF Dff ISBEGIN

PROCESS (Clock) BEGINIF Clock’EVENT AND Clock=‘1’ THEN

Q <= D;END IF;

END PROCESS;END ARCHITECTURE;

Sensitivity listscontain signals usedin conditionals (i.e. IF)

Sensitivity listscontain signals usedin conditionals (i.e. IF)

Notice the Processdoes not contain D:PROCESS(Clock, D)

Notice the Processdoes not contain D:PROCESS(Clock, D)

Clock’EVENT is whatdistinguishes a D-FlipFlip from a Latch

Clock’EVENT is whatdistinguishes a D-FlipFlip from a Latch

Page 9: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

Inferring D-Flip Flops: rising_edge

ARCHITECTURE Dff_arch OF Dff IS BEGINPROCESS (Clock) BEGIN

IF Clock’EVENT AND Clock=‘1’ THENQ <= D;

END IF;END PROCESS;

END ARCHITECTURE;

ARCHITECTURE dff_arch OF dff IS BEGINPROCESS (Clock) BEGIN

IF rising_edge(Clock) THENQ <= D;

END IF;END PROCESS;

END ARCHITECTURE;

Alternate andmore readable way isto use therising_edge function

Alternate andmore readable way isto use therising_edge function

Page 10: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

Inferring D-Flip Flops: Asynchronous Reset

ARCHITECTURE dff_reset_arch OF dff_reset IS BEGIN

PROCESS (Clock, Reset) BEGIN

IF Reset= ‘1’ THEN -- Asynchronous ResetQ <= ‘0’

ELSIF rising_edge(Clock) THEN --SynchronousQ <= D;

END IF;END PROCESS;

END ARCHITECTURE;

Page 11: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

Inferring D-Flip Flops: Synchronous Reset

PROCESS (Clock, Reset) BEGINIF rising_edge(Clock) THEN

IF Reset=‘1’ THENQ <= ‘0’

ELSEQ <= D;

END IF;END IF;

END PROCESS;

PROCESS (Clock, Reset) BEGINIF rising_edge(Clock) THEN

IF Reset=‘1’ THENQ <= ‘0’

ELSEQ <= D;

END IF;END IF;

END PROCESS;

PROCESS (Clock, Reset) BEGINIF Reset=‘1’ THEN

Q <= ‘0’ELSIF rising_edge(Clock) THEN

Q <= D;END IF;

END PROCESS;

PROCESS (Clock, Reset) BEGINIF Reset=‘1’ THEN

Q <= ‘0’ELSIF rising_edge(Clock) THEN

Q <= D;END IF;

END PROCESS;

Synchronous Reset

Synchronous FF

Synchronous Reset

Synchronous FF

Asynchronous Reset

Synchronous FF

Asynchronous Reset

Synchronous FF

Page 12: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

D-Flip Flops: Asynchronous Reset & Preset

PROCESS (Clock, Reset, Preset) BEGINIF Reset=‘1’ THEN --highest priority

Q <= ‘0’;ELSIF Preset=‘1’ THEN

Q <= ‘0’;ELSIF rising_edge(Clock) THEN

Q <= D;END IF;

END PROCESS;

PROCESS (Clock, Reset, Preset) BEGINIF Reset=‘1’ THEN --highest priority

Q <= ‘0’;ELSIF Preset=‘1’ THEN

Q <= ‘0’;ELSIF rising_edge(Clock) THEN

Q <= D;END IF;

END PROCESS;

Page 13: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

RTL Multi-cycle Datapath: with controller

Shift�left 2

PCM�u�x

0

1

RegistersWrite�register

Write�data

Read�data 1

Read�data 2

Read�register 1

Read�register 2

Instruction�[15– 11]

M�u�x

0

1

M�u�x

0

1

4

Instruction�[15– 0]

Sign�extend

3216

Instruction�[25– 21]

Instruction�[20– 16]

Instruction�[15– 0]

Instruction�register

ALU�control

ALU�result

ALUZero

Memory�data�

register

�A

B

IorD

MemRead

MemWrite

MemtoReg

PCWriteCond

PCWrite

IRWrite

ALUOp

ALUSrcB

ALUSrcA

RegDst

PCSource

RegWrite

Control

Outputs

Op�[5– 0]

Instruction�[31-26]

Instruction [5– 0]

M�u�x

0

2

Jump�address [31-0]Instruction [25– 0] 26 28

Shift�left 2

PC [31-28]

1

1 M�u�x

0

3

2

M�u�x

0

1ALUOut

Memory

MemData

Write�data

Address

Register Transfer Level (RTL) ViewRegister Transfer Level (RTL) View

Page 14: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

CPU controller: Finite State Machine

ALUzero

PCWriteEnable

IRWrite

MemtoReg

MemWrite

PCWriteCond PCSourceMux

ALUSrcAMux

RegDstMux

RegWrite

ALUSrcBMux

ALUOp

IorDMux

MemRead

PCWrite

IRopcodeResetClock

FSM

Page 15: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

CPU Controller: Entity

ENTITY cpu_controller is PORT(CLK, RST :IN std_logic;IRopcode :IN std_logic_vector(5 downto 0);ALUzero :IN std_logic;PCWriteEnable :OUT std_logic;PCSourceMux :OUT std_logic_vector(1 downto 0);MemRead, MemWrite :OUT std_logic;IorDMux :OUT std_logic;IRWrite :OUT std_logic;RegWrite :OUT std_logic;RegDstMux :OUT std_logic;MemtoRegMux :OUT std_logic;ALUOp :OUT std_logic_vector(2 downto 0)ALUSrcAMux :OUT std_logic;ALUSrcBMux :OUT std_logic_vector(1 downto 0);

); END ENTITY;

Page 16: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

CPU controller: R-Format State Machine

Decode

FetchExecRtype

WriteRtype

Clock=1 Clock=1

Clock=1Clock=1

Cycle 1 Cycle 2 Cycle 3 Cycle 4

Ifetch Reg/Dec Exec WrR-Format

Page 17: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

CPU Controller: Current State Process

ARCHITECTURE cpu_controller_arch OF cpu_controller IS TYPE CPUStates IS (Fetch, Decode, ExecRtype, WriteRtype); SIGNAL State, NextState :CPUStates;BEGIN

PROCESS (State) BEGIN CASE State IS

WHEN Fetch => NextState <= Decode; WHEN Decode => NextState <= ExecRtype; WHEN ExecRtype => NextState <= WriteRtype; WHEN WriteRtype => NextState <= Fetch; WHEN OTHERS => NextState <= Fetch; END CASE; END PROCESS; • • •

Page 18: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

CPU controller: NextState Clock Process

PROCESS (CLK, RST) BEGIN IF RST='1' THEN -- Asynchronous Reset State <= Fetch;

ELSIF rising_edge(CLK) THEN State <= NextState; END IF; END PROCESS;

END ARCHITECTURE;

Page 19: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

T1 Fetch: State machine

MemRead=1, MemWrite=0IorD=1 (MemAddr←←←←PC)IRWrite=1 (IR←←←←Mem[PC])ALUOP=ADD (PC←←←←4+PC)ALUSrcA=0 (=PC)ALUSrcB=1 (=4)PCWrite=1, PCSource=1 (=ALU)RegWrite=0,RegDst=X, MemtoReg=X

MemRead=1, MemWrite=0IorD=1 (MemAddr←←←←PC)IRWrite=1 (IR←←←←Mem[PC])ALUOP=ADD (PC←←←←4+PC)ALUSrcA=0 (=PC)ALUSrcB=1 (=4)PCWrite=1, PCSource=1 (=ALU)RegWrite=0,RegDst=X, MemtoReg=X

Start

Instruction Fetch

Decode

Exec

WriteReg

Cycle 1 Cycle 2 Cycle 3 Cycle 4

Ifetch Reg/Dec Exec WrR-Format

Page 20: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

T1 Fetch: VHDL with Moore Output States

PROCESS (State) BEGIN CASE State IS WHEN Fetch => NextState <= Decode; MemRead <= '1'; MemWrite <= '0'; IorD <= '1' IRWrite <= '1'; ALUOp <= "010”; --add ALUSrcAMux <= '1'; --PC ALUSrcBMux <= "01"; --4 PCWriteEnable<= '1'; PCSourceMux <= "00"; --ALU (not ALUOut) RegWrite <= '0'; RegDstMux <= 'D'; MemtoReg <= 'D';

MemRead=1, MemWrite=0IorD=1 (MemAddr←←←←PC)IRWrite=1 (IR←←←←Mem[PC])ALUOP=ADD (PC←←←←4+PC)ALUSrcA=0 (=PC)ALUSrcB=1 (=4)PCWrite=1, PCSource=1 (=ALU)RegWrite=0,RegDst=X, MemtoReg=X

MemRead=1, MemWrite=0IorD=1 (MemAddr←←←←PC)IRWrite=1 (IR←←←←Mem[PC])ALUOP=ADD (PC←←←←4+PC)ALUSrcA=0 (=PC)ALUSrcB=1 (=4)PCWrite=1, PCSource=1 (=ALU)RegWrite=0,RegDst=X, MemtoReg=X

Instruction Fetch

'D' for Don’t Care'D' for Don’t Care

Page 21: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

VHDL inferred Latches: WARNING

In VHDL case statement

The same signal must be defined for each case

Otherwise that signal will be inferred as a latch

and not as combinatorial logic!

For example,

Even though RegDstMux <= 'D' is not used

and was removed from the Decode state

This will result in a RegDstMuxbeing inferred as latch not as logic

even though in the WriteRtype state it is set

Page 22: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

Assignment #3: CPU Architecture design (1/3)

Cyber Dynamics Corporation (18144 El Camino Real, S’ValeCalifornia) needs the following embedded model 101microprocessor designed by Thursday October 5, 2000 withthe following specifications

• 16 bit instruction memory using ROM• 8 bit data memory using RAM• There are eight 8-bit registers• The instruction set is as follows

• All Arithmetic and logical instructions set a Zero one-bit flag(Z) based on ALU result

• add, adc, sub, sbc set the Carry/Borrow one-bit Flag (C) based on ALU result

Page 23: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

Assignment #3: CPU Architecture design (2/3)Arithmetic and logical instructions

add $rt,$rs #$rt = $rt +$rs; C=ALUcarry; Z=$rtadc $rt, $rs #$rt = $rt +$rs+C; C=ALUcarry; Z;sub $rt, $rs #$rt = $rt - $rs; C=ALUborrow; Z;sub $rt, $rs #$rt = $rt - $rs - borrow; C; Z;and $rt, $rs #$rt = $rt & $rs; C=0; Z=$rt;or $rt, $rs #$rt = $rt | $rs; C=0; Z=$rt;xor $rt, $rs #$rt = $rt ^ $rs; C=1; Z=$rt;

Other Instructions continued):lbi $r, immed #$r = immediatelbr $rt,$rs #$rt = Mem[$rs]lb $r, address #$r = Mem[address]stb $r, address #Mem[address]=$rbz address #if zero then pc=pc+2+addrbc address #if carry then pc=pc+2+addrj address #pc = addressjr $r #pc = $r

Page 24: LECTURE 8: VHDL PROCESSES

CWRU EECS 318

Assignment #3: CPU Architecture design (2/3)

(1a) Design an RTL diagram of the model 101 processor and

(1b) Opcode formats and

(1c) Opcode bits of a Harvard Architecture CPU (determineyour own field sizes).

(1d) What is the size of the Program Counter?

(2) Write the assembly code for a 32 bit add Z=X+Y located inmemory address for @X = 0x80 @Y = 0x84 and @Z=0x88

(3) Draw the state diagram for your FSM controller

(4) Write the VHDL code for the FSM controller

Note: this will be part of your final project report