N
niv
Guest
Trying to get started with PSL assertions.
I've written a simple counter, code below, with a couple of PSL assertions at the end. However, the 2nd assertion fails on the transition from cntr_max-1 to cntr_max, but the rollover assertion seems to work.
Any ideas please?
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.numeric_std.ALL;
--------------------------------------------------------------------------------
ENTITY psl_counter_test IS
GENERIC(
my_width : NATURAL := 6
);
PORT(
rst : IN STD_LOGIC;
clk : IN STD_LOGIC;
my_count : OUT STD_LOGIC_VECTOR (my_width-1 DOWNTO 0)
);
END ENTITY psl_counter_test ;
--------------------------------------------------------------------------------
ARCHITECTURE rtl OF psl_counter_test IS
SIGNAL my_counter : UNSIGNED(my_width-1 DOWNTO 0);
SIGNAL en_counter : UNSIGNED(3 DOWNTO 0);
SIGNAL enable : STD_LOGIC;
CONSTANT cntr_max : NATURAL := 2**my_width - 1;
BEGIN
my_count <= STD_LOGIC_VECTOR(my_counter);
--------------------------------------------------------------------------------
count_en : PROCESS (rst, clk)
BEGIN
IF rst = '1' THEN
en_counter <= (OTHERS => '0'); -- reset to max
enable <= '0';
ELSIF RISING_EDGE(clk) THEN
en_counter <= en_counter + 1; -- rolls over, so div by 64.
IF en_counter = 15 THEN
enable <= '1';
ELSE
enable <= '0';
END IF;
END IF;
END PROCESS count_en;
--------------------------------------------------------------------------------
count_up : PROCESS (rst, clk)
BEGIN
IF rst = '1' THEN
my_counter <= (OTHERS => '0'); -- reset to max
ELSIF RISING_EDGE(clk) THEN
IF enable = '1' THEN
my_counter <= my_counter + 1; -- continuous count with rollover.
ELSE
NULL;
END IF;
END IF;
END PROCESS count_up;
--------------------------------------------------------------------------------
-- psl begin
--
-- default clock is rising_edge(clk);
--
-- property psl_01 is
-- ({(my_counter = cntr_max) and (enable = '1')} |=> {my_counter = 0} );
-- assert always psl_01 report"ERROR: 'my_counter' did not rollover to zero.";
--
-- property psl_02 is
-- ({(my_counter < cntr_max) and (enable = '1')} |=> {my_counter + 1} );
-- assert always psl_02 report"ERROR: 'my_counter' did not increment as expected.";
--
-- end
END ARCHITECTURE rtl;
I've written a simple counter, code below, with a couple of PSL assertions at the end. However, the 2nd assertion fails on the transition from cntr_max-1 to cntr_max, but the rollover assertion seems to work.
Any ideas please?
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.numeric_std.ALL;
--------------------------------------------------------------------------------
ENTITY psl_counter_test IS
GENERIC(
my_width : NATURAL := 6
);
PORT(
rst : IN STD_LOGIC;
clk : IN STD_LOGIC;
my_count : OUT STD_LOGIC_VECTOR (my_width-1 DOWNTO 0)
);
END ENTITY psl_counter_test ;
--------------------------------------------------------------------------------
ARCHITECTURE rtl OF psl_counter_test IS
SIGNAL my_counter : UNSIGNED(my_width-1 DOWNTO 0);
SIGNAL en_counter : UNSIGNED(3 DOWNTO 0);
SIGNAL enable : STD_LOGIC;
CONSTANT cntr_max : NATURAL := 2**my_width - 1;
BEGIN
my_count <= STD_LOGIC_VECTOR(my_counter);
--------------------------------------------------------------------------------
count_en : PROCESS (rst, clk)
BEGIN
IF rst = '1' THEN
en_counter <= (OTHERS => '0'); -- reset to max
enable <= '0';
ELSIF RISING_EDGE(clk) THEN
en_counter <= en_counter + 1; -- rolls over, so div by 64.
IF en_counter = 15 THEN
enable <= '1';
ELSE
enable <= '0';
END IF;
END IF;
END PROCESS count_en;
--------------------------------------------------------------------------------
count_up : PROCESS (rst, clk)
BEGIN
IF rst = '1' THEN
my_counter <= (OTHERS => '0'); -- reset to max
ELSIF RISING_EDGE(clk) THEN
IF enable = '1' THEN
my_counter <= my_counter + 1; -- continuous count with rollover.
ELSE
NULL;
END IF;
END IF;
END PROCESS count_up;
--------------------------------------------------------------------------------
-- psl begin
--
-- default clock is rising_edge(clk);
--
-- property psl_01 is
-- ({(my_counter = cntr_max) and (enable = '1')} |=> {my_counter = 0} );
-- assert always psl_01 report"ERROR: 'my_counter' did not rollover to zero.";
--
-- property psl_02 is
-- ({(my_counter < cntr_max) and (enable = '1')} |=> {my_counter + 1} );
-- assert always psl_02 report"ERROR: 'my_counter' did not increment as expected.";
--
-- end
END ARCHITECTURE rtl;