SMB-87 - Encoder Multiplier block - WIP (5): Completed simulations with velocity estimation

This commit is contained in:
gianmarcogirau 2019-03-19 15:01:54 +00:00
commit f3cf0fec49
6 changed files with 259 additions and 131 deletions

View file

@ -17,6 +17,10 @@ vlib ./work
vmap work ./work
# Compile the UUT
vcom -2008 -work $WORKLIB $COMMON_PATH/common_pkg.vhd
vcom -2008 -work $WORKLIB $COMMON_PATH/dpram_sclk.vhd
vcom -2008 -work $WORKLIB ./../src/intel/divider.vhd
vcom -2008 -work $WORKLIB ./../src/encoder_speed_detect_0.vhd
vcom -2008 -work $WORKLIB ./../src/encoder_multiply_0.vhd
# Compile the constrained random related packages

View file

@ -6,10 +6,12 @@ add wave -noupdate /encoder_multiply_tb/init
add wave -noupdate /encoder_multiply_tb/enable
add wave -noupdate /encoder_multiply_tb/mult_sel
add wave -noupdate -radix hexadecimal /encoder_multiply_tb/delta_t
add wave -noupdate -radix unsigned /encoder_multiply_tb/kmax
add wave -noupdate /encoder_multiply_tb/max_speed_error
add wave -noupdate -radix hexadecimal /encoder_multiply_tb/delta_t_i
add wave -noupdate /encoder_multiply_tb/delta_t_norm
add wave -noupdate /encoder_multiply_tb/step_pos_in
add wave -noupdate /encoder_multiply_tb/step_neg_in
add wave -noupdate /encoder_multiply_tb/step_pos
add wave -noupdate /encoder_multiply_tb/step_neg
add wave -noupdate /encoder_multiply_tb/step_pos_out
add wave -noupdate /encoder_multiply_tb/step_neg_out
add wave -noupdate -radix decimal /encoder_multiply_tb/abs_pos
@ -22,44 +24,93 @@ add wave -noupdate /encoder_multiply_tb/failed
add wave -noupdate /encoder_multiply_tb/test_timeout
add wave -noupdate /encoder_multiply_tb/test_completed
add wave -noupdate /encoder_multiply_tb/error_flag
add wave -noupdate /encoder_multiply_tb/iUUT/reset_n
add wave -noupdate /encoder_multiply_tb/iUUT/clk
add wave -noupdate /encoder_multiply_tb/iUUT/init
add wave -noupdate /encoder_multiply_tb/iUUT/enable
add wave -noupdate /encoder_multiply_tb/iUUT/mult_sel
add wave -noupdate -radix decimal /encoder_multiply_tb/iUUT/delta_t
add wave -noupdate -radix unsigned /encoder_multiply_tb/iUUT/kmax
add wave -noupdate /encoder_multiply_tb/iUUT/max_speed_error
add wave -noupdate /encoder_multiply_tb/iUUT/step_pos_in
add wave -noupdate /encoder_multiply_tb/iUUT/step_neg_in
add wave -noupdate /encoder_multiply_tb/iUUT/step_pos_out
add wave -noupdate /encoder_multiply_tb/iUUT/step_neg_out
add wave -noupdate /encoder_multiply_tb/iUUT/init_d
add wave -noupdate /encoder_multiply_tb/iUUT/step_pos
add wave -noupdate /encoder_multiply_tb/iUUT/step_neg
add wave -noupdate /encoder_multiply_tb/iUUT/m_step_pos
add wave -noupdate /encoder_multiply_tb/iUUT/m_step_neg
add wave -noupdate /encoder_multiply_tb/iUUT/kickoff
add wave -noupdate /encoder_multiply_tb/iUUT/pending_kickoff
add wave -noupdate /encoder_multiply_tb/iUUT/sign
add wave -noupdate /encoder_multiply_tb/iUUT/sign_i
add wave -noupdate /encoder_multiply_tb/iUUT/time_cnt_tc
add wave -noupdate /encoder_multiply_tb/iUUT/norm_pos
add wave -noupdate /encoder_multiply_tb/iUUT/norm_pos_d
add wave -noupdate /encoder_multiply_tb/iUUT/norm_neg
add wave -noupdate /encoder_multiply_tb/iUUT/norm_neg_d
add wave -noupdate -radix unsigned /encoder_multiply_tb/iUUT/mult_val
add wave -noupdate -radix decimal /encoder_multiply_tb/iUUT/pulse_cnt
add wave -noupdate -radix decimal /encoder_multiply_tb/iUUT/m_pulse_cnt
add wave -noupdate -radix unsigned /encoder_multiply_tb/iUUT/m_norm_value
#add wave -noupdate -radix decimal /encoder_multiply_tb/iUUT/delta_m_pos
#add wave -noupdate -radix decimal /encoder_multiply_tb/iUUT/delta_m_neg
add wave -noupdate -radix decimal /encoder_multiply_tb/iUUT/delta_m
add wave -noupdate /encoder_multiply_tb/iUUT/time_cnt
add wave -noupdate -radix unsigned /encoder_multiply_tb/iUUT/m_delta_t
add wave -noupdate -radix unsigned /encoder_multiply_tb/iUUT/delta_t_i
add wave -noupdate /encoder_multiply_tb/time_out_flag
add wave -noupdate -radix unsigned /encoder_multiply_tb/avg_steps
add wave -noupdate -radix unsigned /encoder_multiply_tb/delta_init
add wave -noupdate -radix unsigned /encoder_multiply_tb/time_out
add wave -noupdate -divider Multiplier
add wave -noupdate /encoder_multiply_tb/iMULT/reset_n
add wave -noupdate /encoder_multiply_tb/iMULT/clk
add wave -noupdate /encoder_multiply_tb/iMULT/init
add wave -noupdate /encoder_multiply_tb/iMULT/enable
add wave -noupdate /encoder_multiply_tb/iMULT/mult_sel
add wave -noupdate -radix decimal /encoder_multiply_tb/iMULT/delta_t
add wave -noupdate /encoder_multiply_tb/iMULT/step_pos_in
add wave -noupdate /encoder_multiply_tb/iMULT/step_neg_in
add wave -noupdate /encoder_multiply_tb/iMULT/step_pos_out
add wave -noupdate /encoder_multiply_tb/iMULT/step_neg_out
add wave -noupdate /encoder_multiply_tb/iMULT/init_d
add wave -noupdate /encoder_multiply_tb/iMULT/step_pos
add wave -noupdate /encoder_multiply_tb/iMULT/step_neg
add wave -noupdate /encoder_multiply_tb/iMULT/m_step_pos
add wave -noupdate /encoder_multiply_tb/iMULT/m_step_neg
add wave -noupdate /encoder_multiply_tb/iMULT/kickoff
add wave -noupdate /encoder_multiply_tb/iMULT/pending_kickoff
add wave -noupdate /encoder_multiply_tb/iMULT/sign
add wave -noupdate /encoder_multiply_tb/iMULT/sign_i
add wave -noupdate /encoder_multiply_tb/iMULT/time_cnt_tc
add wave -noupdate /encoder_multiply_tb/iMULT/realign_pos
add wave -noupdate /encoder_multiply_tb/iMULT/realign_neg
add wave -noupdate /encoder_multiply_tb/iMULT/norm_pos
add wave -noupdate /encoder_multiply_tb/iMULT/norm_pos_d
add wave -noupdate /encoder_multiply_tb/iMULT/norm_neg
add wave -noupdate /encoder_multiply_tb/iMULT/norm_neg_d
add wave -noupdate -radix unsigned /encoder_multiply_tb/iMULT/mult_val
add wave -noupdate -radix decimal /encoder_multiply_tb/iMULT/pulse_cnt
add wave -noupdate -radix decimal /encoder_multiply_tb/iMULT/m_pulse_cnt
add wave -noupdate -radix unsigned /encoder_multiply_tb/iMULT/m_norm_value
add wave -noupdate -radix decimal /encoder_multiply_tb/iMULT/delta_m
add wave -noupdate /encoder_multiply_tb/iMULT/time_cnt
add wave -noupdate -radix unsigned /encoder_multiply_tb/iMULT/m_delta_t
add wave -noupdate -radix unsigned /encoder_multiply_tb/iMULT/delta_t_i
add wave -noupdate -divider Velocity
add wave -noupdate /encoder_multiply_tb/iSPEED/reset_n
add wave -noupdate /encoder_multiply_tb/iSPEED/clk
add wave -noupdate /encoder_multiply_tb/iSPEED/init
add wave -noupdate /encoder_multiply_tb/iSPEED/enable
add wave -noupdate /encoder_multiply_tb/iSPEED/avg_steps
add wave -noupdate -radix hexadecimal /encoder_multiply_tb/iSPEED/delta_init
add wave -noupdate -radix unsigned /encoder_multiply_tb/iSPEED/time_out
add wave -noupdate /encoder_multiply_tb/iSPEED/step_pos
add wave -noupdate /encoder_multiply_tb/iSPEED/step_neg
add wave -noupdate -radix hexadecimal /encoder_multiply_tb/iSPEED/delta_t
add wave -noupdate /encoder_multiply_tb/iSPEED/step_pos_out
add wave -noupdate /encoder_multiply_tb/iSPEED/step_neg_out
add wave -noupdate /encoder_multiply_tb/iSPEED/time_out_flag
add wave -noupdate /encoder_multiply_tb/iSPEED/step_type
add wave -noupdate /encoder_multiply_tb/iSPEED/step_pos_i
add wave -noupdate /encoder_multiply_tb/iSPEED/step_neg_i
add wave -noupdate /encoder_multiply_tb/iSPEED/inc_last
add wave -noupdate /encoder_multiply_tb/iSPEED/inc_first
add wave -noupdate /encoder_multiply_tb/iSPEED/avg_transient_on
add wave -noupdate /encoder_multiply_tb/iSPEED/init_i
add wave -noupdate /encoder_multiply_tb/iSPEED/time_out_flag_i
add wave -noupdate /encoder_multiply_tb/iSPEED/new_step
add wave -noupdate /encoder_multiply_tb/iSPEED/inc_step_balance
add wave -noupdate /encoder_multiply_tb/iSPEED/dec_step_balance
add wave -noupdate /encoder_multiply_tb/iSPEED/inc_step_cnt
add wave -noupdate /encoder_multiply_tb/iSPEED/write_last
add wave -noupdate /encoder_multiply_tb/iSPEED/first_step
add wave -noupdate /encoder_multiply_tb/iSPEED/time_out_flag_d
add wave -noupdate /encoder_multiply_tb/iSPEED/last_step_type
add wave -noupdate /encoder_multiply_tb/iSPEED/data_valid
add wave -noupdate /encoder_multiply_tb/iSPEED/step_cnt
add wave -noupdate -radix unsigned /encoder_multiply_tb/iSPEED/first_addr
add wave -noupdate -radix unsigned /encoder_multiply_tb/iSPEED/last_addr
add wave -noupdate /encoder_multiply_tb/iSPEED/div_remain
add wave -noupdate -radix decimal /encoder_multiply_tb/iSPEED/step_balance
add wave -noupdate -radix decimal /encoder_multiply_tb/iSPEED/step_bal_m1
add wave -noupdate -radix unsigned /encoder_multiply_tb/iSPEED/loc_time
add wave -noupdate -radix unsigned /encoder_multiply_tb/iSPEED/time_out_cnt
add wave -noupdate -radix decimal /encoder_multiply_tb/iSPEED/time_diff
add wave -noupdate -radix decimal /encoder_multiply_tb/iSPEED/time_diff_i
add wave -noupdate -format Analog-Step -height 74 -max 10903.0 -radix decimal /encoder_multiply_tb/iSPEED/delta_t_i
add wave -noupdate -radix hexadecimal /encoder_multiply_tb/iSPEED/new_tag
add wave -noupdate -radix hexadecimal /encoder_multiply_tb/iSPEED/tag_last_i
add wave -noupdate -radix hexadecimal /encoder_multiply_tb/iSPEED/tag_first
add wave -noupdate -radix hexadecimal /encoder_multiply_tb/iSPEED/tag_last
TreeUpdate [SetDefaultTree]
WaveRestoreCursors {{Cursor 1} {2606443 ps} 0}
WaveRestoreCursors {{Cursor 1} {2725654906 ps} 0}
quietly wave cursor active 1
configure wave -namecolwidth 260
configure wave -valuecolwidth 126
@ -75,4 +126,4 @@ configure wave -griddelta 40
configure wave -timeline 0
configure wave -timelineunits ps
update
WaveRestoreZoom {0 ps} {63764768 ps}
WaveRestoreZoom {0 ps} {8161984512 ps}

View file

@ -0,0 +1,82 @@
onerror {resume}
quietly WaveActivateNextPane {} 0
add wave -noupdate /encoder_speed_detect_tb/reset_n
add wave -noupdate /encoder_speed_detect_tb/clk
add wave -noupdate /encoder_speed_detect_tb/init
add wave -noupdate /encoder_speed_detect_tb/enable
add wave -noupdate -radix unsigned /encoder_speed_detect_tb/avg_steps
add wave -noupdate -radix unsigned /encoder_speed_detect_tb/delta_init
add wave -noupdate -radix unsigned /encoder_speed_detect_tb/time_out
add wave -noupdate /encoder_speed_detect_tb/step_pos
add wave -noupdate /encoder_speed_detect_tb/step_neg
add wave -noupdate -radix hexadecimal /encoder_speed_detect_tb/delta_t
add wave -noupdate /encoder_speed_detect_tb/step_pos_out
add wave -noupdate /encoder_speed_detect_tb/step_neg_out
add wave -noupdate /encoder_speed_detect_tb/delta_t_norm
add wave -noupdate /encoder_speed_detect_tb/time_out_flag
add wave -noupdate -radix decimal /encoder_speed_detect_tb/abs_pos
add wave -noupdate /encoder_speed_detect_tb/setup
add wave -noupdate /encoder_speed_detect_tb/running
add wave -noupdate /encoder_speed_detect_tb/passed
add wave -noupdate /encoder_speed_detect_tb/failed
add wave -noupdate /encoder_speed_detect_tb/test_timeout
add wave -noupdate /encoder_speed_detect_tb/test_completed
add wave -noupdate /encoder_speed_detect_tb/iUUT/reset_n
add wave -noupdate /encoder_speed_detect_tb/iUUT/clk
add wave -noupdate /encoder_speed_detect_tb/iUUT/init
add wave -noupdate /encoder_speed_detect_tb/iUUT/enable
add wave -noupdate -radix unsigned /encoder_speed_detect_tb/iUUT/avg_steps
add wave -noupdate -radix unsigned /encoder_speed_detect_tb/iUUT/delta_init
add wave -noupdate -radix unsigned /encoder_speed_detect_tb/iUUT/time_out
add wave -noupdate /encoder_speed_detect_tb/iUUT/step_pos
add wave -noupdate /encoder_speed_detect_tb/iUUT/step_neg
add wave -noupdate -radix hexadecimal /encoder_speed_detect_tb/iUUT/delta_t
add wave -noupdate /encoder_speed_detect_tb/iUUT/step_pos_out
add wave -noupdate /encoder_speed_detect_tb/iUUT/step_neg_out
add wave -noupdate /encoder_speed_detect_tb/iUUT/time_out_flag
add wave -noupdate /encoder_speed_detect_tb/iUUT/new_step
add wave -noupdate /encoder_speed_detect_tb/iUUT/data_valid
add wave -noupdate /encoder_speed_detect_tb/iUUT/step_type
add wave -noupdate /encoder_speed_detect_tb/iUUT/last_step_type
add wave -noupdate /encoder_speed_detect_tb/iUUT/step_pos_i
add wave -noupdate /encoder_speed_detect_tb/iUUT/step_neg_i
add wave -noupdate /encoder_speed_detect_tb/iUUT/inc_last
add wave -noupdate /encoder_speed_detect_tb/iUUT/inc_first
add wave -noupdate /encoder_speed_detect_tb/iUUT/avg_transient_on
add wave -noupdate /encoder_speed_detect_tb/iUUT/init_i
add wave -noupdate /encoder_speed_detect_tb/iUUT/time_out_flag_i
add wave -noupdate /encoder_speed_detect_tb/iUUT/inc_step_balance
add wave -noupdate -radix unsigned /encoder_speed_detect_tb/iUUT/dec_step_balance
add wave -noupdate -radix decimal /encoder_speed_detect_tb/iUUT/step_balance
add wave -noupdate -radix unsigned /encoder_speed_detect_tb/iUUT/step_bal_m1
add wave -noupdate /encoder_speed_detect_tb/iUUT/inc_step_cnt
add wave -noupdate /encoder_speed_detect_tb/iUUT/write_last
add wave -noupdate -radix unsigned /encoder_speed_detect_tb/iUUT/step_cnt
add wave -noupdate -radix unsigned /encoder_speed_detect_tb/iUUT/first_addr
add wave -noupdate -radix unsigned /encoder_speed_detect_tb/iUUT/last_addr
add wave -noupdate -radix unsigned /encoder_speed_detect_tb/iUUT/loc_time
add wave -noupdate -radix unsigned /encoder_speed_detect_tb/iUUT/time_diff_i
add wave -noupdate -radix unsigned /encoder_speed_detect_tb/iUUT/delta_t_i
add wave -noupdate -radix decimal /encoder_speed_detect_tb/iUUT/time_diff
add wave -noupdate -radix unsigned /encoder_speed_detect_tb/iUUT/tag_last_i
add wave -noupdate -radix hexadecimal /encoder_speed_detect_tb/iUUT/new_tag
add wave -noupdate -radix hexadecimal /encoder_speed_detect_tb/iUUT/tag_first
add wave -noupdate -radix hexadecimal /encoder_speed_detect_tb/iUUT/tag_last
TreeUpdate [SetDefaultTree]
WaveRestoreCursors {{Cursor 1} {10535000 ps} 0}
quietly wave cursor active 1
configure wave -namecolwidth 330
configure wave -valuecolwidth 145
configure wave -justifyvalue left
configure wave -signalnamewidth 0
configure wave -snapdistance 10
configure wave -datasetprefix 0
configure wave -rowmargin 4
configure wave -childrowmargin 2
configure wave -gridoffset 0
configure wave -gridperiod 1
configure wave -griddelta 40
configure wave -timeline 0
configure wave -timelineunits ps
update
WaveRestoreZoom {1695718995 ps} {2649693779 ps}

View file

@ -6,7 +6,7 @@
-- Author : Gianmarco Girau
-- Company : Global Inkjet Systems
-- Created : 2019-02-27
-- Last update: 2019-03-12
-- Last update: 2019-03-19
-- SVN ID : Git
-- Standard : VHDL'2008
-------------------------------------------------------------------------------
@ -40,8 +40,6 @@ entity encoder_multiply_0 is
enable : in std_logic;
mult_sel : in std_logic_vector( 2 downto 0);
delta_t : in std_logic_vector(39 downto 0);
kmax : in std_logic_vector( 4 downto 0);
max_speed_error : out std_logic;
step_pos_in : in std_logic;
step_neg_in : in std_logic;
step_pos_out : out std_logic;
@ -79,11 +77,10 @@ architecture rtl of encoder_multiply_0 is
signal norm_pos, norm_pos_d : std_logic;
signal norm_neg, norm_neg_d : std_logic;
signal kickoff, pending_kickoff : std_logic;
--signal mult_val, kmax : std_logic_vector(MULT_W-1 downto 0);
signal realign_pos, realign_neg : std_logic;
signal mult_val : std_logic_vector(MULT_W-1 downto 0);
signal pulse_cnt : std_logic_vector(PULSE_CNT_W-1 downto 0);
signal m_pulse_cnt, m_norm_value : std_logic_vector(M_PULSE_CNT_W-1 downto 0);
--signal delta_m_pos, delta_m_neg : std_logic_vector(M_PULSE_CNT_W-1 downto 0);
signal delta_m : std_logic_vector(M_PULSE_CNT_W downto 0);
signal time_cnt : std_logic_vector(27 downto 0);
signal m_delta_t : std_logic_vector(30 downto 0);
@ -92,32 +89,21 @@ architecture rtl of encoder_multiply_0 is
begin
pSEQ_LOGIC_RST : process(reset_n, clk)
variable err_thres : std_logic_vector(MULT_W+4 downto 0);
begin
if(reset_n = '0') then
mult_val <= (0 => '1', others => '0');
max_speed_error <= '0';
elsif(clk = '1' and clk'event) then
if(init_d = '1') then
mult_val <= std_logic_vector(to_unsigned(1, MULT_W)) sll(to_integer(unsigned(mult_sel)));
end if;
err_thres := std_logic_vector(unsigned(mult_val)*unsigned(kmax));
if(init = '1') then
max_speed_error <= '0';
elsif(signed(delta_m) >= signed('0' & err_thres) or signed(delta_m) <= -signed('0' & err_thres)) then
max_speed_error <= '1';
end if;
end if;
end process pSEQ_LOGIC_RST;
pSEQ_LOGIC : process(clk)
variable mult_pulse_cnt : std_logic_vector(M_PULSE_CNT_W-1 downto 0);
variable err_thres : std_logic_vector(MULT_W+4 downto 0);
begin
if(clk = '1' and clk'event) then
init_d <= init;
--kmax <= std_logic_vector(unsigned(mult_val)-1);
--kmax <= (others => '0');
if(init = '1') then
pending_kickoff <= '1';
elsif(kickoff = '1') then
@ -153,8 +139,6 @@ begin
m_delta_t <= delta_t_i srl to_integer(unsigned(mult_sel));
sign <= sign_i;
mult_pulse_cnt := std_logic_vector(resize(signed(pulse_cnt), M_PULSE_CNT_W)) sll to_integer(signed('0' & mult_sel));
--delta_m_pos <= std_logic_vector(signed(mult_pulse_cnt) + signed(kmax));
--delta_m_neg <= std_logic_vector(signed(mult_pulse_cnt) - signed(kmax));
delta_m <= std_logic_vector(resize(signed(m_pulse_cnt),delta_m'length) - resize(signed(mult_pulse_cnt),delta_m'length));
step_pos_out <= m_step_pos;
step_neg_out <= m_step_neg;
@ -172,13 +156,13 @@ begin
time_cnt_tc <= '1' when unsigned(time_cnt) = 1 else '0';
/*
m_step_pos <= '1' when sign = '0' and (kickoff = '1' or (time_cnt_tc = '1' and signed(m_pulse_cnt) < signed(delta_m_pos))) else '0';
--m_step_neg <= '1' when sign = '1' and (kickoff = '1' or (time_cnt_tc = '1' and signed(m_pulse_cnt) > signed(delta_m_pos))) else '0';
m_step_neg <= '1' when sign = '1' and (kickoff = '1' or (time_cnt_tc = '1' and signed(m_pulse_cnt) > signed(delta_m_neg))) else '0';
*/
m_step_pos <= '1' when sign = '0' and (kickoff = '1' or (time_cnt_tc = '1' and signed(delta_m) < 0)) else '0';
m_step_neg <= '1' when sign = '1' and (kickoff = '1' or (time_cnt_tc = '1' and signed(delta_m) > 0)) else '0';
--realign_pos <= '1' when signed(delta_m) = -4 else '0';
--realign_neg <= '1' when signed(delta_m) = +4 else '0';
realign_pos <= '1' when signed(delta_m) = ((to_signed(-1, M_PULSE_CNT_W)) sll(to_integer(unsigned(mult_sel))+2)) else '0';
realign_neg <= '1' when signed(delta_m) = ((to_signed(1, M_PULSE_CNT_W)) sll(to_integer(unsigned(mult_sel))+2)) else '0';
m_step_pos <= '1' when sign = '0' and (kickoff = '1' or realign_pos = '1' or (time_cnt_tc = '1' and signed(delta_m) < 0)) else '0';
m_step_neg <= '1' when sign = '1' and (kickoff = '1' or realign_neg = '1' or (time_cnt_tc = '1' and signed(delta_m) > 0)) else '0';
kickoff <= pending_kickoff and (step_pos or step_neg);

View file

@ -59,7 +59,7 @@ architecture rtl of encoder_speed_detect_0 is
signal inc_step_balance, dec_step_balance : std_logic;
signal inc_step_cnt, write_last : std_logic;
signal first_step, time_out_flag_d : std_logic;
signal last_step_type : std_logic;
signal last_step_type, enforce_delta_min : std_logic;
--
signal data_valid : std_logic_vector( 5 downto 0);
signal step_cnt, first_addr, last_addr : std_logic_vector( 7 downto 0);
@ -155,7 +155,7 @@ begin
if(init_i = '1') then
delta_t <= "0000" & delta_init & 8x"0";
elsif(data_valid(data_valid'left) = '1') then
if(first_step = '1' or last_step_type /= step_balance(step_balance'left)) then
if(first_step = '1' or enforce_delta_min = '1' or last_step_type /= step_balance(step_balance'left)) then
delta_t <= last_step_type & 3x"0" & delta_init & 8x"0";
else
delta_t <= step_balance(step_balance'left) & delta_t_i & 8x"0";
@ -180,6 +180,8 @@ begin
inc_last <= new_step;
inc_first <= new_step and (not avg_transient_on);
enforce_delta_min <= '1' when unsigned(delta_t_i) < unsigned(delta_init) else '0';
-- This RAM is for storing tag (time and encoder step-type
iTIMING_RAM: entity work.dpram_sclk
generic map (

View file

@ -6,7 +6,7 @@
-- Author : GMG
-- Company : Global Inkjet Systems
-- Created : 2019-03-05
-- Last update: 2019-03-12
-- Last update: 2019-03-19
-- SVN ID : Git
-- Standard : VHDL'2008
-------------------------------------------------------------------------------
@ -28,7 +28,8 @@ use work.log_pkg.all;
entity encoder_multiply_tb is
generic(
MULT_SELECTION : integer range 0 to 7 := 0);
MULT_SELECTION : integer range 0 to 7 := 0;
FILT_AVG : integer range 0 to 255 := 8);
-- ..
end entity encoder_multiply_tb;
@ -43,6 +44,8 @@ architecture behav of encoder_multiply_tb is
constant RUN_TEST : integer_vector(0 to 2) := (0, 1, 0);
CONSTANT MULT_VALUE : integer := to_integer(unsigned(std_logic_vector(to_unsigned(1, 8)) sll(MULT_SELECTION)));
-- delta_tmin : minimum value of delta_t, corresponding to the maximum tx
-- rate over the POF (4M events/sec => 250 ns)
constant DELTA_TMIN : natural := 25;
@ -65,8 +68,13 @@ architecture behav of encoder_multiply_tb is
signal enable : std_logic;
signal mult_sel : std_logic_vector(2 downto 0);
signal delta_t : std_logic_vector(39 downto 0);
signal kmax : std_logic_vector(4 downto 0);
signal max_speed_error : std_logic;
signal delta_t_i : std_logic_vector(39 downto 0);
signal avg_steps : std_logic_vector( 7 downto 0);
signal delta_init : std_logic_vector(27 downto 0);
signal time_out : std_logic_vector(27 downto 0);
signal time_out_flag : std_logic;
signal step_pos : std_logic;
signal step_neg : std_logic;
signal step_pos_in : std_logic;
signal step_neg_in : std_logic;
signal step_pos_out : std_logic;
@ -74,7 +82,8 @@ architecture behav of encoder_multiply_tb is
--
signal abs_pos : std_logic_vector(31 downto 0);
signal m_abs_pos : std_logic_vector(39 downto 0);
signal m_abs_pos_r : real;
signal m_abs_pos_r : real;
signal delta_t_norm : integer;
-- TB specific signals
signal setup : boolean;
@ -101,13 +110,16 @@ architecture behav of encoder_multiply_tb is
-- Check Pos
-----------------------------------------------------------------------------
procedure check_pos is
procedure check_pos(error_mode : in boolean := false) is
begin
if(to_integer(signed(abs_pos)) /= integer(m_abs_pos_r)) then
log("ERROR: Abs-Pos = " & to_string(to_integer(signed(abs_pos))) & ". Equivalent M-Abs-Pos: " & to_string(m_abs_pos_r), VLOW);
error_flag := true;
if(error_mode = true) then
log("ERROR: Abs-Pos = " & to_string(to_integer(signed(abs_pos))) & ". Equivalent M-Abs-Pos: " & to_string(m_abs_pos_r), VLOW);
error_flag := true;
else
log("WARNING: Potential Position Misalignment => Abs-Pos = " & to_string(to_integer(signed(abs_pos))) & ". Equivalent M-Abs-Pos: " & to_string(m_abs_pos_r), VLOW);
end if;
end if;
end procedure check_pos;
@ -128,7 +140,6 @@ architecture behav of encoder_multiply_tb is
variable step_cnt : natural := 0;
variable t_ref : time;
variable t_period : real;
variable mult_value : integer := to_integer(unsigned(std_logic_vector(to_unsigned(1, 8)) sll(MULT_SELECTION)));
begin
@ -149,18 +160,7 @@ architecture behav of encoder_multiply_tb is
-- set the initial velocity estimation
if(init = true) then
delta_t(delta_t'left-1 downto 0) <=std_logic_vector(to_unsigned(integer(maximum(DELTA_TMIN,2*mult_value))*256, 39));
/*
if(MULT_SELECTION < 5) then
delta_t(delta_t'left-1 downto 0) <=std_logic_vector(to_unsigned(max(DELTA_TMIN,2*mult_value)*256, 39));
elsif(MULT_SELECTION = 5) then
delta_t(delta_t'left-1 downto 0) <= std_logic_vector(to_unsigned(64*256, 39));
elsif(MULT_SELECTION = 6) then
delta_t(delta_t'left-1 downto 0) <= std_logic_vector(to_unsigned(128*256, 39));
else
delta_t(delta_t'left-1 downto 0) <= std_logic_vector(to_unsigned(256*256, 39));
end if;
*/
delta_t(delta_t'left-1 downto 0) <=std_logic_vector(to_unsigned(integer(maximum(DELTA_TMIN,2*MULT_VALUE))*256, 39));
else
delta_t(delta_t'left-1 downto 0) <= std_logic_vector(to_unsigned(integer(t_period*100.0*256.0), delta_t'left));
end if;
@ -203,7 +203,7 @@ architecture behav of encoder_multiply_tb is
end loop;
wait_clk_cycles(0);
wait_clk_cycles(10);
-- disable the multiplier
enable <= '0';
@ -228,9 +228,7 @@ architecture behav of encoder_multiply_tb is
variable t_ref : time;
variable t_period : real;
variable rv : RandomPType;
variable delta_period : integer;
variable mult_value : integer := to_integer(unsigned(std_logic_vector(to_unsigned(1, 8)) sll(MULT_SELECTION)));
variable delta_period : integer;
begin
@ -251,18 +249,7 @@ architecture behav of encoder_multiply_tb is
-- set the initial velocity estimation
if(init = true) then
delta_t(delta_t'left-1 downto 0) <=std_logic_vector(to_unsigned(maximum(DELTA_TMIN,2*mult_value)*256, 39));
/*
if(MULT_SELECTION < 5) then
delta_t(delta_t'left-1 downto 0) <= std_logic_vector(to_unsigned(DELTA_TMIN*256, 39));
elsif(MULT_SELECTION = 5) then
delta_t(delta_t'left-1 downto 0) <= std_logic_vector(to_unsigned(50*256, 39));
elsif(MULT_SELECTION = 6) then
delta_t(delta_t'left-1 downto 0) <= std_logic_vector(to_unsigned(100*256, 39));
else
delta_t(delta_t'left-1 downto 0) <= std_logic_vector(to_unsigned(200*256, 39));
end if;
*/
delta_t(delta_t'left-1 downto 0) <=std_logic_vector(to_unsigned(maximum(DELTA_TMIN,2*MULT_VALUE)*256, 39));
else
delta_t(delta_t'left-1 downto 0) <= std_logic_vector(to_unsigned(integer(t_period*100.0*256.0), delta_t'left));
end if;
@ -307,7 +294,7 @@ architecture behav of encoder_multiply_tb is
end loop;
wait_clk_cycles(0);
wait_clk_cycles(10);
-- disable the multiplier
enable <= '0';
@ -321,27 +308,42 @@ begin -- architecture behav
-- UUTs
-----------------------------------------------------------------------------
iUUT : entity work.encoder_multiply_0
-- Encoder Multiplier
iMULT : entity work.encoder_multiply_0
port map (
reset_n => reset_n,
clk => clk,
init => init,
enable => enable,
mult_sel => mult_sel,
delta_t => delta_t,
kmax => kmax,
max_speed_error => max_speed_error,
step_pos_in => step_pos_in,
step_neg_in => step_neg_in,
delta_t => delta_t_i,
step_pos_in => step_pos,
step_neg_in => step_neg,
step_pos_out => step_pos_out,
step_neg_out => step_neg_out);
--Speed Detection
iSPEED: entity work.encoder_speed_detect_0
port map (
reset_n => reset_n,
clk => clk,
init => init,
enable => enable,
avg_steps => avg_steps,
delta_init => delta_init,
time_out => time_out,
step_pos => step_pos_in,
step_neg => step_neg_in,
delta_t => delta_t_i,
step_pos_out => step_pos,
step_neg_out => step_neg,
time_out_flag => time_out_flag);
-----------------------------------------------------------------------------
-- Support Logic
-----------------------------------------------------------------------------
pGEN_POS : process(clk)
variable mult_value : integer;
begin
if(clk = '1' and clk'event) then
if(init = '1') then
@ -358,11 +360,11 @@ begin -- architecture behav
elsif(step_neg_out = '1') then
m_abs_pos <= std_logic_vector(unsigned(m_abs_pos)-1);
end if;
--mult_value := 2**to_integer(unsigned(mult_sel));
mult_value := to_integer(unsigned(std_logic_vector(to_unsigned(1, 8)) sll(to_integer(unsigned(mult_sel)))));
m_abs_pos_r <= real(to_integer(signed(m_abs_pos)))/real(mult_value);
m_abs_pos_r <= real(to_integer(signed(m_abs_pos)))/real(MULT_VALUE);
end if;
end process pGEN_POS;
delta_t_norm <= to_integer(unsigned(delta_t_i(38 downto 8))) when delta_t_i(39) = '0' else -1*to_integer(unsigned(delta_t_i(38 downto 8)));
-----------------------------------------------------------------------------
-- Testbench Logic
@ -371,7 +373,6 @@ begin -- architecture behav
pTEST_PROC : process
variable period_variance : integer range 0 to 100;
variable mult_value : integer := to_integer(unsigned(std_logic_vector(to_unsigned(1, 8)) sll(MULT_SELECTION)));
begin
@ -384,7 +385,10 @@ begin -- architecture behav
enable <= '0';
mult_sel <= (others => '0');
kmax <= 5x"8";
avg_steps <= std_logic_vector(to_unsigned(FILT_AVG,8));
delta_init <= std_logic_vector(to_unsigned(maximum(DELTA_TMIN,2*MULT_VALUE), delta_init'length));
--
time_out <= std_logic_vector(to_unsigned(6000, time_out'length));
delta_t <= (others => '0');
step_pos_in <= '0';
@ -422,7 +426,7 @@ begin -- architecture behav
init <= '1';
wait until clk = '1' and clk'event;
init <= '0';
log("Encoder-Multiplication set to " & to_string(mult_value) & "." , VLOW);
log("Encoder-Multiplication set to " & to_string(MULT_VALUE) & "." , VLOW);
wait_clk_cycles(10);
@ -431,16 +435,16 @@ begin -- architecture behav
log("Tests at constant frequency:", VLOW);
log_separator_line(VLOW);
run_encoder_profile_1(100.0e3, '0', 50, enable, delta_t, step_pos_in, step_neg_in, true);
wait for 50 us;
wait for 20 us;
check_pos;
run_encoder_profile_1(100.0e3, '0', 25, enable, delta_t, step_pos_in, step_neg_in);
wait for 50 us;
wait for 20 us;
check_pos;
run_encoder_profile_1(100.0e3, '0', 25, enable, delta_t, step_pos_in, step_neg_in);
wait for 50 us;
wait for 20 us;
check_pos;
run_encoder_profile_1(100.0e3, '1', 25, enable, delta_t, step_pos_in, step_neg_in);
wait for 50 us;
wait for 20 us;
check_pos;
run_encoder_profile_1(100.0e3, '0', 1, enable, delta_t, step_pos_in, step_neg_in);
wait for 20 us;
@ -483,7 +487,7 @@ begin -- architecture behav
check_pos;
run_encoder_profile_1(100.0e3, '0', 1000, enable, delta_t, step_pos_in, step_neg_in);
wait for 100 us;
check_pos;
check_pos(true);
end if;
period_variance := 45;
@ -493,16 +497,16 @@ begin -- architecture behav
log("Tests at variable frequency (+/-" & to_string(period_variance) & "%):", VLOW);
log_separator_line(VLOW);
run_encoder_profile_2(100.0e3, '0', 50, period_variance, enable, delta_t, step_pos_in, step_neg_in, true);
wait for 50 us;
wait for 20 us;
check_pos;
run_encoder_profile_2(100.0e3, '0', 25, period_variance, enable, delta_t, step_pos_in, step_neg_in);
wait for 50 us;
wait for 20 us;
check_pos;
run_encoder_profile_2(100.0e3, '0', 25, period_variance, enable, delta_t, step_pos_in, step_neg_in);
wait for 50 us;
wait for 20 us;
check_pos;
run_encoder_profile_2(100.0e3, '1', 25, period_variance, enable, delta_t, step_pos_in, step_neg_in);
wait for 50 us;
wait for 20 us;
check_pos;
run_encoder_profile_2(100.0e3, '0', 1, period_variance, enable, delta_t, step_pos_in, step_neg_in);
wait for 20 us;
@ -545,7 +549,7 @@ begin -- architecture behav
check_pos;
run_encoder_profile_2(100.0e3, '0', 1000, period_variance, enable, delta_t, step_pos_in, step_neg_in);
wait for 50 us;
check_pos;
check_pos(true);
end if;
---------------------------------------------------------------------------
@ -565,13 +569,14 @@ begin -- architecture behav
begin
if(enable = '1') then
--if((m_abs_pos_r > real(to_integer(signed(abs_pos)))+1.0) or (m_abs_pos_r < real(to_integer(signed(abs_pos)))-1.0)) then
if((m_abs_pos_r > real(to_integer(signed(abs_pos)))+2.0) or (m_abs_pos_r < real(to_integer(signed(abs_pos)))-2.0)) then
if((m_abs_pos_r > real(to_integer(signed(abs_pos)))+7.0) or (m_abs_pos_r < real(to_integer(signed(abs_pos)))-7.0)) then
error_flag := true;
log("ERROR: Abs-Pos = " & to_string(to_integer(signed(abs_pos))) & ". Equivalent M-Abs-Pos: " & to_string(m_abs_pos_r), VLOW);
end if;
end if;
end process pERROR_DETECT;
failed <= error_flag after 100 ns;
failed <= true after 1 us when error_flag = true else false;
CHECK_SIM_TIMEOUT: process
begin -- process CHECK_SIM_TIMEOUT