bitprolix
Junior Member level 2
- Joined
- Sep 19, 2013
- Messages
- 24
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 235
Hi,
I'm referring this book from Peter J Ashenden on Digital Design and to make my understanding solid, I'm trying to write the testbench and verify my model, However, As I've already posted this in past that, I'm really struggling with test bench at this moment, therefore would really appreciate if someone can give me some pointers on writing testbenches from the prospective of a beginner. You'll find below, both the design model and the testbench, but I think this particular testbench that i came up with is very very primitive. Please help me improve this testbench.
The model for negative edge-triggered flip flop with clock enable, negative-logic asynchronous preset and clear and both active high and active low outputs with an additional condition that, both the preset and clear cannot be active together.
And the testbench:
Thank you.
- - - Updated - - -
There was one typo from the post above. As the model is for negative edge triggered flip-flop, therefore the falling edge of the clock should be taken into account rather than the rising edge of the clock. Therefore the correct model would be:
instead of,
And in the testbench:
instead of
I'm referring this book from Peter J Ashenden on Digital Design and to make my understanding solid, I'm trying to write the testbench and verify my model, However, As I've already posted this in past that, I'm really struggling with test bench at this moment, therefore would really appreciate if someone can give me some pointers on writing testbenches from the prospective of a beginner. You'll find below, both the design model and the testbench, but I think this particular testbench that i came up with is very very primitive. Please help me improve this testbench.
The model for negative edge-triggered flip flop with clock enable, negative-logic asynchronous preset and clear and both active high and active low outputs with an additional condition that, both the preset and clear cannot be active together.
Code:
library ieee;
use ieee.std_logic_1164.all;
entity flip_flop is
port ( d: in std_logic;
clk: in std_logic;
ce: in std_logic;
pre, clr: in std_logic;
q, q_n: out std_logic );
end entity flip_flop;
architecture behave of flip_flop is
signal tmp_q : std_logic;
begin
neg_edge_flip: process(clk, pre, clr)
begin
assert not (pre = '0' and clr = '0')
report "illegal combination";
if (pre = '0') then
tmp_q <= '1';
elsif (clr = '0') then
tmp_q <= '0';
elsif (rising_edge(clk)) then
if (ce = '1') then
q <= d;
end if;
end if;
end process neg_edge_flip;
q <= tmp_q;
q_n <= not tmp_q;
end architecture behave;
And the testbench:
Code:
library ieee;
use ieee.std_logic_1164.all;
entity verify_neg_logic_flip_flop is
end entity verify_neg_logic_flip_flop;
architecture verify of verify_neg_logic_flip_flop is
signal d, clk, ce, pre, clr: std_logic;
signal q, q_n: std_logic;
begin
duv : entity work.flip_flop(behave)
port map (d => d,
clk => clk,
ce => ce,
pre => pre,
clr => clr,
q => q,
q_n => q_n);
--tmp_q => tmp_q);
apply_test_case: process is
begin
pre <= '1'; d <= '0'; wait for 1 sec;
pre <= '1'; d <= '1'; wait for 1 sec;
pre <= '0'; d <= '0'; wait for 1 sec;
pre <= '0'; d <= '0'; wait for 1 sec;
wait on clk until clk = '1';
clr <= '1'; d <= '0'; wait for 1 sec;
clr <= '1'; d <= '1'; wait for 1 sec;
clr <= '0'; d <= '0'; wait for 1 sec;
clr <= '0'; d <= '0'; wait for 1 sec;
wait on clk until clk = '1';
ce <= '1'; d <= '0'; wait for 1 sec;
ce <= '1'; d <= '1'; wait for 1 sec;
ce <= '0'; d <= '0'; wait for 1 sec;
ce <= '0'; d <= '0'; wait for 1 sec;
wait;
end process apply_test_case;
check_outputs: process is
begin
wait on pre, clr, clk, ce;
wait for 10 ms;
assert not (pre = '0' and clr = '0');
end process check_outputs;
end architecture verify;
Thank you.
- - - Updated - - -
The model for negative edge-triggered flip flop with clock enable, negative-logic asynchronous preset and clear and both active high and active low outputs with an additional condition that, both the preset and clear cannot be active together.
There was one typo from the post above. As the model is for negative edge triggered flip-flop, therefore the falling edge of the clock should be taken into account rather than the rising edge of the clock. Therefore the correct model would be:
Code:
elsif (falling_edge(clk)) then
instead of,
Code:
elsif (rising_edge(clk)) then
And in the testbench:
Code:
wait on clk until clk = '0';
instead of
Code:
wait on clk until clk = '1';