[[dt-code-statem]]

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
dt-code-statem [2011/01/13 09:17]
beckmanf created
dt-code-statem [2011/05/10 11:26] (current)
beckmanf added more tests
Line 19: Line 19:
 end;  end; 
  
-architecture rtl of edge is  ​+architecture rtl of automat ​is  ​
   type state_type is (start_s, erste_eins_s,​ null_in_der_mitte_s,​ fertig_s);   type state_type is (start_s, erste_eins_s,​ null_in_der_mitte_s,​ fertig_s);
   signal current_state,​ next_state : state_type;   signal current_state,​ next_state : state_type;
Line 68: Line 68:
 end architecture;​ end architecture;​
 </​code>​ </​code>​
 +
 +
 +Und hier ist eine geeignete Testbench:
 +
 +<code vhdl>
 +library ieee;
 +use ieee.std_logic_1164.all;​
 +use ieee.math_real.all;​
 + 
 +entity automat_tb is 
 +  port (
 +    clk_i: ​           in std_ulogic;
 +    reset_ni: ​        in std_ulogic;
 +    in_i:             in std_ulogic;  ​
 +    out_o: ​           out std_ulogic ​
 +  );
 +end; 
 + 
 +architecture beh of automat_tb is
 +
 +component automat is 
 +  port (
 +    clk_i: ​           in std_ulogic;
 +    reset_ni: ​        in std_ulogic;
 +    in_i:             in std_ulogic;  ​
 +    out_o: ​           out std_ulogic ​
 +  );
 +end component;
 +
 +signal clk, reset, stim, output : std_ulogic; ​
 +
 +begin
 +
 +-- This process generates the clock
 +clk_p : process
 +begin
 +  clk <= '​0';​
 +  wait for 5 ns;
 +  clk <= '​1';​
 +  wait for 5 ns;
 +end process;
 +
 +-- Here the automat is instantiated as the device under test
 +dut: automat ​
 +port map (
 +  clk_i           => clk,
 +  reset_ni ​       => reset,
 +  in_i            => stim,
 +  out_o           => output
 +);
 +
 +
 +test : process
 +begin
 +  reset <= '​0';​
 +  -- Wait for some time
 +  wait for 100 ns; 
 +
 +  wait until falling_edge(clk);​
 +  -- Reset Release
 +  reset <= '​1'; ​
 +  -- Now the positive 101 Sequence
 +  stim <= '​1';​
 +  wait until falling_edge(clk);​
 +
 +  stim <= '​0';​
 +  wait until falling_edge(clk);​
 +
 +  stim <= '​1';​
 +  wait until falling_edge(clk);​
 +
 +  stim <= '​0';​
 +  wait until falling_edge(clk);​
 +  wait until falling_edge(clk);​
 +
 +  wait; 
 +end process test; 
 +
 + 
 +end architecture;​
 +</​code>​
 +
 +The previous testbench only produced a stimuli sequence which results in the output going high. The testbench did not check the output signal however. For checking the output, the assert command is used in VHDL. The following modified testbench checks the output. ​
 +
 +<code vhdl>
 +
 +test : process
 +begin
 +  reset <= '​0';​
 +  -- Wait for some time
 +  wait for 100 ns; 
 +  report "​Checking Reset Value";​
 +  assert output = '​0'​ report "​Resetvalue of output is not o.k." severity error;
 +  wait until falling_edge(clk);​
 +  -- Reset Release
 +  reset <= '​1'; ​
 +  -- Now the positive 101 Sequence
 +  stim <= '​1';​
 +  wait until falling_edge(clk);​
 +  assert output = '​0'​ report "​Output is not zero after first one" severity error;
 +  stim <= '​0';​
 +  wait until falling_edge(clk);​
 +  assert output = '​0'​ report "​Output is not zero after zero in the middle"​ severity error;
 +  stim <= '​1';​
 +  wait until falling_edge(clk);​
 +  assert output = '​1'​ report "​Output is not O.K." severity error;
 +  stim <= '​0';​
 +  wait until falling_edge(clk);​
 +  wait until falling_edge(clk);​
 +
 +  assert false report "End of Simulation"​ severity failure;
 +end process test; 
 +</​code>​
 +
 +In addition the simulation is stopped with the final assert false statement. The previous stimuli sequence only shows one positive example for the good case. It is not tested that other sequences may also trigger the output going high. 
 +
 +The following code test process produces a random sequence for the input pattern. It is checked if the "​101"​ sequence is in the random pattern. With "​101"​ the output is checked for "​1",​ otherwise the output has to be "​0"​. ​
 +
 +<code vhdl>
 +use ieee.math_real.all;​
 +
 +--- architecture and begin follows
 +
 +test2_p : process ​
 +  variable zufall : real;
 +  variable seed1 : integer := 5;
 +  variable seed2 : integer := 17; 
 +  variable inp_letzter,​ inp_vorletzter : std_ulogic; ​
 +begin
 +  reset <= '​0';​
 +  wait for 10 ns; 
 +  reset <= '​1'; ​
 +  for count in  0 to 1500 loop
 +    wait until falling_edge(clk);​
 +    if (inp_vorletzter = '​1'​ and inp_letzter = '​0'​ and stim = '​1'​) then
 +      assert output = '​1'​ report "​Fehler:​ Habe eine Eins erwartet"​ severity error;
 +    else
 +      assert output = '​0'​ report "​Fehler am Ausgang - Null erwartet"​ severity error; ​
 +    end if; 
 +    inp_vorletzter := inp_letzter;​
 +    inp_letzter := stim; 
 +    uniform(seed1,​ seed2, zufall); ​   ​
 +    if (zufall <= 0.5) then 
 +      stim <= '​0';​
 +    else
 +      stim <= '​1';​
 +    end if;
 +  end loop;  ​
 +  assert false report "End of Simulation"​ severity failure; ​
 +end process test2_p; ​
 +</​code> ​
 +
 +This code simulates 1500 cycles. Also this code does not test all possible input sequences - which is not possible anyway. Without knowledge about the internal state it is not possible to do a 100% verification of the statemachine implementation. ​
 +
  • dt-code-statem.1294906658.txt.gz
  • Last modified: 2011/01/13 09:17
  • by beckmanf