Professional Documents
Culture Documents
ECE 3561 - Lecture 16 VHDL Testbenches For State Machines
ECE 3561 - Lecture 16 VHDL Testbenches For State Machines
ECE 3561 - Lecture 16 VHDL Testbenches For State Machines
state machines
More examples
More examples
ENTITY mealy101 IS
PORT (clk,x : IN bit; z : OUT bit);
END mealy101;
ENTITY moore101 IS
PORT (clk,x : IN bit; z : OUT bit);
END moore101;
PROCESS (state,x)
BEGIN
CASE state IS
WHEN s0 => IF (x='0') THEN next_state <= s0;
ELSE next_state <= s1;
END IF;
WHEN s1 => IF (x='0') THEN next_state <= s2;
ELSE next_state <= s1;
END IF;
WHEN s2 => IF (x='0') THEN next_state <= s0;
ELSE next_state <= s3;
END IF;
WHEN s3 => IF (x='0') THEN next_state <= s2;
ELSE next_state <= s1;
END IF;
END CASE;
END PROCESS;
10
Creating a testbench
11
Declarations
12
Declarative Region
13
Wire in DUT
Instantiate components
BEGIN
--Instantiate units
ml : mealy101 PORT MAP (clk,x,z1);
mo : moore101 PORT MAP (clk,x,z2);
14
Set up clocks
--Set up clock
clk <= NOT clk AFTER 5 ns;
15
Use a process
16
--Stimulus process
PROCESS
BEGIN
WAIT FOR 1 ns;
FOR i IN 1 to 30 LOOP
x <= xs(i);
WAIT FOR 10 ns;
END LOOP;
WAIT FOR 10 ns;
WAIT;
END PROCESS;
Process grabs inputs from the input vector set up in the declarative region.
A good option when a simple sequence on a single signal.
More advanced techniques may be needed for complex machines.
17
18
Simulation result 2
19
Demo of simulation
20
Lecture summary
21