diff --git a/generic_ip/encoder_multiply/0/sim/run_sim.py b/generic_ip/encoder_multiply/0/sim/run_sim.py index ba4b9ff..a48ddb8 100644 --- a/generic_ip/encoder_multiply/0/sim/run_sim.py +++ b/generic_ip/encoder_multiply/0/sim/run_sim.py @@ -116,5 +116,6 @@ def run_msim_script(sim_job, cmd_line_mode = 1): if __name__ == "__main__": print("Running Generic-Sequencer testbench ...") - run_msim_script("sim_enc_mult", cmd_line_mode=1) + #run_msim_script("sim_enc_mult", cmd_line_mode=1) + run_msim_script("sim_all", cmd_line_mode=1) diff --git a/generic_ip/encoder_multiply/0/sim/sim_enc_mult.do b/generic_ip/encoder_multiply/0/sim/sim_enc_mult.do index 4a320e7..44baed2 100644 --- a/generic_ip/encoder_multiply/0/sim/sim_enc_mult.do +++ b/generic_ip/encoder_multiply/0/sim/sim_enc_mult.do @@ -19,7 +19,7 @@ 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_0.vhd +vcom -2008 -work $WORKLIB ./../src/lut_divider_0.vhd vcom -2008 -work $WORKLIB ./../src/encoder_speed_detect_0.vhd vcom -2008 -work $WORKLIB ./../src/encoder_multiply_0.vhd diff --git a/generic_ip/encoder_multiply/0/sim/sim_speed_detect.do b/generic_ip/encoder_multiply/0/sim/sim_speed_detect.do index 1ca696e..743566f 100644 --- a/generic_ip/encoder_multiply/0/sim/sim_speed_detect.do +++ b/generic_ip/encoder_multiply/0/sim/sim_speed_detect.do @@ -19,8 +19,7 @@ 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_0.vhd -#vcom -2008 -work $WORKLIB ./../src/serial_divide_uu.vhd +vcom -2008 -work $WORKLIB ./../src/lut_divider_0.vhd vcom -2008 -work $WORKLIB ./../src/encoder_speed_detect_0.vhd # Compile the constrained random related packages diff --git a/generic_ip/encoder_multiply/0/sim/wave_enc_mult.do b/generic_ip/encoder_multiply/0/sim/wave_enc_mult.do index d052f64..5782124 100644 --- a/generic_ip/encoder_multiply/0/sim/wave_enc_mult.do +++ b/generic_ip/encoder_multiply/0/sim/wave_enc_mult.do @@ -15,6 +15,7 @@ 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 +add wave -noupdate -radix decimal /encoder_multiply_tb/abs_pos_vel add wave -noupdate -radix decimal /encoder_multiply_tb/m_abs_pos add wave -noupdate /encoder_multiply_tb/m_abs_pos_r add wave -noupdate /encoder_multiply_tb/setup @@ -50,6 +51,8 @@ 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/delay_vect +add wave -noupdate /encoder_multiply_tb/iMULT/time_realign_flag +add wave -noupdate -radix unsigned /encoder_multiply_tb/iMULT/time_realign_cnt add wave -noupdate /encoder_multiply_tb/iMULT/realign_pos_i add wave -noupdate /encoder_multiply_tb/iMULT/realign_neg_i add wave -noupdate /encoder_multiply_tb/iMULT/realign_pos @@ -60,7 +63,6 @@ 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 @@ -102,7 +104,6 @@ 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 @@ -114,8 +115,16 @@ 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 +add wave -noupdate -divider {LUT Divider} +add wave -noupdate /encoder_multiply_tb/iSPEED/iLUT_DIV/clk +add wave -noupdate /encoder_multiply_tb/iSPEED/iLUT_DIV/dividend +add wave -noupdate /encoder_multiply_tb/iSPEED/iLUT_DIV/divisor +add wave -noupdate /encoder_multiply_tb/iSPEED/iLUT_DIV/quotient +add wave -noupdate /encoder_multiply_tb/iSPEED/iLUT_DIV/addr +add wave -noupdate /encoder_multiply_tb/iSPEED/iLUT_DIV/lut_q +add wave -noupdate /encoder_multiply_tb/iSPEED/iLUT_DIV/mult TreeUpdate [SetDefaultTree] -WaveRestoreCursors {{Cursor 1} {1702355000 ps} 0} +WaveRestoreCursors {{Cursor 1} {1234195270 ps} 0} quietly wave cursor active 1 configure wave -namecolwidth 260 configure wave -valuecolwidth 126 @@ -131,4 +140,4 @@ configure wave -griddelta 40 configure wave -timeline 0 configure wave -timelineunits ps update -WaveRestoreZoom {16300524428 ps} {32624493452 ps} +WaveRestoreZoom {989186793 ps} {2009434857 ps} diff --git a/generic_ip/encoder_multiply/0/sim/wave_enc_speed_detect.do b/generic_ip/encoder_multiply/0/sim/wave_enc_speed_detect.do index bf78b9c..001d48e 100644 --- a/generic_ip/encoder_multiply/0/sim/wave_enc_speed_detect.do +++ b/generic_ip/encoder_multiply/0/sim/wave_enc_speed_detect.do @@ -15,6 +15,7 @@ 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 -radix decimal /encoder_speed_detect_tb/abs_pos_out add wave -noupdate /encoder_speed_detect_tb/setup add wave -noupdate /encoder_speed_detect_tb/running add wave -noupdate /encoder_speed_detect_tb/passed @@ -31,6 +32,16 @@ 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_i +add wave -noupdate /encoder_speed_detect_tb/iUUT/step_neg_i +add wave -noupdate /encoder_speed_detect_tb/iUUT/step_pos_filt +add wave -noupdate /encoder_speed_detect_tb/iUUT/step_neg_filt +add wave -noupdate /encoder_speed_detect_tb/iUUT/busy +add wave -noupdate /encoder_speed_detect_tb/iUUT/pending_pos +add wave -noupdate /encoder_speed_detect_tb/iUUT/pending_neg +add wave -noupdate /encoder_speed_detect_tb/iUUT/inc_pending_cnt +add wave -noupdate /encoder_speed_detect_tb/iUUT/dec_pending_cnt +add wave -noupdate -radix decimal /encoder_speed_detect_tb/iUUT/pending_cnt 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 @@ -38,8 +49,6 @@ 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 @@ -57,16 +66,13 @@ 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 unsigned /encoder_speed_detect_tb/iUUT/delta_t_ii -add wave -noupdate -radix unsigned /encoder_speed_detect_tb/iUUT/delta_t_iii -add wave -noupdate /encoder_speed_detect_tb/iUUT/div_done 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} {20565000 ps} 0} +WaveRestoreCursors {{Cursor 1} {719366 ps} 0} quietly wave cursor active 1 configure wave -namecolwidth 330 configure wave -valuecolwidth 145 @@ -82,4 +88,4 @@ configure wave -griddelta 40 configure wave -timeline 0 configure wave -timelineunits ps update -WaveRestoreZoom {0 ps} {1907949568 ps} +WaveRestoreZoom {572096 ps} {1037904 ps} diff --git a/generic_ip/encoder_multiply/0/src/encoder_multiply_0.vhd b/generic_ip/encoder_multiply/0/src/encoder_multiply_0.vhd index 3452c90..2f81fd3 100644 --- a/generic_ip/encoder_multiply/0/src/encoder_multiply_0.vhd +++ b/generic_ip/encoder_multiply/0/src/encoder_multiply_0.vhd @@ -6,7 +6,7 @@ -- Author : Gianmarco Girau -- Company : Global Inkjet Systems -- Created : 2019-02-27 --- Last update: 2019-03-20 +-- Last update: 2019-04-25 -- SVN ID : Git -- Standard : VHDL'2008 ------------------------------------------------------------------------------- @@ -43,7 +43,8 @@ entity encoder_multiply_0 is step_pos_in : in std_logic; step_neg_in : in std_logic; step_pos_out : out std_logic; - step_neg_out : out std_logic); + step_neg_out : out std_logic; + align_error : out std_logic_vector(19 downto 0)); end encoder_multiply_0; architecture rtl of encoder_multiply_0 is @@ -66,11 +67,6 @@ architecture rtl of encoder_multiply_0 is variable result : shft_left_vec_t; begin result := operand; - /* - for n in 1 to shf_val loop - result := result(operand'left-1 downto 0) & '0'; - end loop; -- n - */ for n in 1 to 7 loop if(n <= shf_val) then result := result(operand'left-1 downto 0) & '0'; @@ -83,11 +79,6 @@ architecture rtl of encoder_multiply_0 is variable result : shft_right_vec_t; begin result := operand; - /* - for n in 1 to shf_val loop - result := result(operand'left) & result(operand'left downto 1); - end loop; -- n - */ for n in 1 to 7 loop if(n <= shf_val) then result := result(operand'left) & result(operand'left downto 1); @@ -100,14 +91,18 @@ architecture rtl of encoder_multiply_0 is signal m_step_pos, m_step_neg : std_logic; signal sign, sign_i : std_logic; signal time_cnt_tc : std_logic; - signal norm_pos, norm_pos_d : std_logic; - signal norm_neg, norm_neg_d : std_logic; + signal norm_pos, norm_neg : std_logic; + signal m_step_pos_d, m_step_neg_d : std_logic; signal kickoff, pending_kickoff : std_logic; signal realign_pos, realign_neg : std_logic; signal realign_pos_d, realign_neg_d : std_logic; signal realign_pos_i, realign_neg_i : std_logic; - signal delay_vect : std_logic_vector(3 downto 0); - --signal mult_val : std_logic_vector(MULT_W-1 downto 0); + signal time_realign_flag : std_logic; + signal delta_m_pos, delta_m_neg : std_logic; + signal post_m_step_pos : std_logic; + signal post_m_step_neg : std_logic; + signal delay_vect : std_logic_vector( 3 downto 0); + signal time_realign_cnt : std_logic_vector( 7 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 : std_logic_vector(M_PULSE_CNT_W downto 0); @@ -117,20 +112,6 @@ architecture rtl of encoder_multiply_0 is begin - /* - pSEQ_LOGIC_RST : process(reset_n, clk) - begin - if(reset_n = '0') then - mult_val <= (0 => '1', others => '0'); - elsif(clk = '1' and clk'event) then - if(init_d = '1') then - --mult_val <= std_logic_vector(to_unsigned(1, MULT_W) sla(to_integer(unsigned(mult_sel)))); - mult_val <= shift_left(std_logic_vector(to_unsigned(1, MULT_W)),to_integer(unsigned(mult_sel))); - 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); begin @@ -143,50 +124,56 @@ begin end if; if(init_d = '1') then pulse_cnt <= (others => '0'); + elsif(norm_pos = '1') then + pulse_cnt <= std_logic_vector(signed(pulse_cnt)-NORM_VALUE+1); + elsif(norm_neg = '1') then + pulse_cnt <= std_logic_vector(signed(pulse_cnt)+NORM_VALUE-1); elsif(step_pos = '1') then pulse_cnt <= std_logic_vector(signed(pulse_cnt)+1); elsif(step_neg = '1') then pulse_cnt <= std_logic_vector(signed(pulse_cnt)-1); - elsif(norm_pos = '1') then - pulse_cnt <= std_logic_vector(signed(pulse_cnt)-NORM_VALUE); - elsif(norm_neg = '1') then - pulse_cnt <= std_logic_vector(signed(pulse_cnt)+NORM_VALUE); end if; if(init_d = '1') then m_pulse_cnt <= (others => '0'); - elsif(m_step_pos = '1') then - m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt)+1); - elsif(m_step_neg = '1') then - m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt)-1); elsif(norm_pos = '1') then m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt)-signed(m_norm_value)); elsif(norm_neg = '1') then m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt)+signed(m_norm_value)); + elsif(m_step_pos = '1' or post_m_step_pos = '1') then + m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt)+1); + elsif(m_step_neg = '1' or post_m_step_neg = '1') then + m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt)-1); + end if; + if((norm_pos = '1' or norm_neg = '1') and m_step_pos = '1') then + post_m_step_pos <= '1'; + else + post_m_step_pos <= '0'; + end if; + if((norm_pos = '1' or norm_neg = '1') and m_step_neg = '1') then + post_m_step_neg <= '1'; + else + post_m_step_neg <= '0'; end if; if(m_step_pos = '1' or m_step_neg = '1') then time_cnt <= m_delta_t(27 downto 0); elsif(time_cnt_tc = '0') then time_cnt <= std_logic_vector(unsigned(time_cnt)-1); end if; - --m_delta_t <= std_logic_vector(unsigned(delta_t_i) sra to_integer(unsigned(mult_sel))); m_delta_t <= shift_right(std_logic_vector(unsigned(delta_t_i)), to_integer(unsigned(mult_sel))); sign <= sign_i; - --mult_pulse_cnt := std_logic_vector(resize(signed(pulse_cnt), M_PULSE_CNT_W) sla to_integer(signed('0' & mult_sel))); mult_pulse_cnt := shift_left(std_logic_vector(resize(signed(pulse_cnt), M_PULSE_CNT_W)),to_integer(signed('0' & mult_sel))); delta_m <= std_logic_vector(resize(signed(m_pulse_cnt),delta_m'length) - resize(signed(mult_pulse_cnt),delta_m'length)); - if(m_step_pos = '1' or m_step_neg = '1') then + if(step_pos = '1' or step_neg = '1' or m_step_pos = '1' or m_step_neg = '1' or realign_pos_i = '1' or realign_neg_i = '1') then delay_vect <= (others => '1'); else delay_vect <= '0' & delay_vect(3 downto 1); end if; - --if(delay_vect(0) = '0' and signed(delta_m) = ((to_signed(-1, M_PULSE_CNT_W)) sla(to_integer(unsigned(mult_sel))+2))) then - if(delay_vect(0) = '0' and signed(delta_m) = signed(shift_left(std_logic_vector(to_signed(-4, M_PULSE_CNT_W)), to_integer(unsigned(mult_sel))))) then + if(delay_vect(0) = '0' and (signed(delta_m) <= signed(shift_left(std_logic_vector(to_signed(-4, M_PULSE_CNT_W)), to_integer(unsigned(mult_sel)))))) then realign_pos <= '1'; else realign_pos <= '0'; end if; - --if(delay_vect(0) = '0' and signed(delta_m) = ((to_signed(1, M_PULSE_CNT_W)) sla(to_integer(unsigned(mult_sel))+2))) then - if(delay_vect(0) = '0' and signed(delta_m) = signed(shift_left(std_logic_vector(to_signed(4, M_PULSE_CNT_W)), to_integer(unsigned(mult_sel))))) then + if(delay_vect(0) = '0' and (signed(delta_m) >= signed(shift_left(std_logic_vector(to_signed(4, M_PULSE_CNT_W)), to_integer(unsigned(mult_sel)))))) then realign_neg <= '1'; else realign_neg <= '0'; @@ -195,12 +182,18 @@ begin realign_neg_d <= realign_neg; step_pos_out <= m_step_pos; step_neg_out <= m_step_neg; - norm_pos_d <= norm_pos; - norm_neg_d <= norm_neg; - --m_norm_value <= std_logic_vector(to_unsigned(NORM_VALUE, M_PULSE_CNT_W) sla (to_integer(unsigned(mult_sel)))); m_norm_value <= shift_left(std_logic_vector(to_unsigned(NORM_VALUE, M_PULSE_CNT_W)), to_integer(unsigned(mult_sel))); + -- Time based re-alignment + if(m_step_pos = '1' or m_step_neg = '1') then + time_realign_cnt <= std_logic_vector(to_unsigned(50,time_realign_cnt'length)); + elsif(time_realign_flag = '0') then + time_realign_cnt <= std_logic_vector(unsigned(time_realign_cnt)-1); + end if; + align_error <= std_logic_vector(resize(signed(delta_m), 20)); end if; end process pSEQ_LOGIC; + + time_realign_flag <= '1' when unsigned(time_realign_cnt) = 0 else '0'; realign_pos_i <= realign_pos and not realign_pos_d; realign_neg_i <= realign_neg and not realign_neg_d; @@ -213,12 +206,19 @@ begin time_cnt_tc <= '1' when unsigned(time_cnt) = 1 else '0'; - m_step_pos <= '1' when sign = '0' and (kickoff = '1' or realign_pos_i = '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_i = '1' or (time_cnt_tc = '1' and signed(delta_m) > 0)) else '0'; + -- Output pulses are generated in the following situations: + -- 1. Kickoff + -- 2. with delta_m /= 0, with a time interval correlated to the speed + -- 3. Quick realignment, irrespective of the encoder speed, when delta_m starts getting too big + m_step_pos <= '1' when realign_pos_i = '1' or (sign = '0' and (kickoff = '1' or (time_cnt_tc = '1' and delta_m_neg = '1'))) else '0'; + m_step_neg <= '1' when realign_neg_i = '1' or (sign = '1' and (kickoff = '1' or (time_cnt_tc = '1' and delta_m_pos = '1'))) else '0'; kickoff <= pending_kickoff and (step_pos or step_neg); + + norm_pos <= '1' when step_pos = '1' and signed(pulse_cnt) >= 2*NORM_VALUE else '0'; + norm_neg <= '1' when step_neg = '1' and signed(pulse_cnt) <= -2*NORM_VALUE else '0'; - norm_pos <= '1' when signed(pulse_cnt) = 2*NORM_VALUE and norm_pos_d = '0' and unsigned(time_cnt(4 downto 0)) > 4 else '0'; - norm_neg <= '1' when signed(pulse_cnt) = -2*NORM_VALUE and norm_neg_d = '0' and unsigned(time_cnt(4 downto 0)) > 4 else '0'; + delta_m_pos <= '1' when signed(delta_m) > 0 else '0'; + delta_m_neg <= '1' when signed(delta_m) < 0 else '0'; end architecture rtl; diff --git a/generic_ip/encoder_multiply/0/src/encoder_speed_detect_0.vhd b/generic_ip/encoder_multiply/0/src/encoder_speed_detect_0.vhd index 8d8f9db..f543753 100644 --- a/generic_ip/encoder_multiply/0/src/encoder_speed_detect_0.vhd +++ b/generic_ip/encoder_multiply/0/src/encoder_speed_detect_0.vhd @@ -6,7 +6,7 @@ -- Author : Gianmarco Girau -- Company : Global Inkjet Systems -- Created : 2019-02-27 --- Last update: 2019-03-22 +-- Last update: 2019-04-18 -- SVN ID : Git -- Standard : VHDL'2008 ------------------------------------------------------------------------------- @@ -40,7 +40,7 @@ entity encoder_speed_detect_0 is clk : in std_logic; init : in std_logic; enable : in std_logic; - avg_steps : in std_logic_vector( 7 downto 0); + avg_steps : in std_logic_vector( 6 downto 0); delta_init : in std_logic_vector(27 downto 0); time_out : in std_logic_vector(27 downto 0); step_pos : in std_logic; @@ -54,39 +54,66 @@ end encoder_speed_detect_0; architecture rtl of encoder_speed_detect_0 is -- number of pipeline stages for the divider - constant DIV_PIPE_STAGES : natural := 1; - -- multicycle-path clock cycles - constant DIV_MULTICYCLE_PATH_N : natural := 4; - - attribute altera_attribute : string; - attribute altera_attribute of rtl : architecture is - "-name SDC_STATEMENT ""set_multicycle_path -from {*iDIVIDE|lpm_divide*} -to {*:iVEL_MEAS|delta_t[*]*} -setup 4 -end""; " & - "-name SDC_STATEMENT ""set_multicycle_path -from {*iVEL_MEAS|step_bal_m1[*]} -to {*iDIVIDE|lpm_divide*} -setup -end 4""; " & - "-name SDC_STATEMENT ""set_multicycle_path -from {*iVEL_MEAS|time_diff_i[*]} -to {*iDIVIDE|lpm_divide*} -setup -end 4""; " & - "-name SDC_STATEMENT ""set_multicycle_path -from {*iDIVIDE|lpm_divide*} -to {*:iVEL_MEAS|delta_t[*]*} -hold -end 3""; " & - "-name SDC_STATEMENT ""set_multicycle_path -from {*iVEL_MEAS|step_bal_m1[*]} -to {*iDIVIDE|lpm_divide*} -hold -end 3""; " & - "-name SDC_STATEMENT ""set_multicycle_path -from {*iVEL_MEAS|time_diff_i[*]} -to {*iDIVIDE|lpm_divide*} -hold -end 3"""; - + constant DIV_PIPE_STAGES : natural := 2; + signal step_type, step_pos_i, step_neg_i : std_logic; + signal step_pos_filt, step_neg_filt, busy : std_logic; + signal pending_pos, pending_neg : std_logic; + signal inc_pending_cnt, dec_pending_cnt : std_logic; signal inc_last, inc_first, avg_transient_on : std_logic; signal init_i, time_out_flag_i, new_step : std_logic; 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, enforce_delta_min : std_logic; - --signal div_done : std_logic; -- - signal data_valid : std_logic_vector(DIV_MULTICYCLE_PATH_N*(DIV_PIPE_STAGES+1)+2 downto 0); - signal step_cnt, first_addr, last_addr : std_logic_vector( 7 downto 0); - signal step_balance, step_bal_m1 : std_logic_vector( 9 downto 0); + signal data_valid : std_logic_vector((DIV_PIPE_STAGES+1)+2 downto 0); + signal step_cnt, step_bal_m1, step_balance : std_logic_vector( 6 downto 0); + signal pending_cnt : std_logic_vector( 7 downto 0); + signal first_addr, last_addr : std_logic_vector( 7 downto 0); signal loc_time, time_out_cnt : std_logic_vector(27 downto 0); signal time_diff : std_logic_vector(29 downto 0); - signal time_diff_i, delta_t_i, delta_t_ii : std_logic_vector(30 downto 0); + signal time_diff_i, delta_t_i : std_logic_vector(30 downto 0); signal new_tag, tag_last_i : std_logic_vector(31 downto 0); signal tag_first, tag_last : std_logic_vector(31 downto 0); begin + ----------------------------------------------------------------------------- + -- Noise Filter + ----------------------------------------------------------------------------- + + -- a noise filter is added at the input to make sure a new pulse is not fed + -- into the rest of the velocity estimation block, before the processing of + -- the previous pulse is completed. + pNOISE_FILT: process(clk) + begin + if(clk = '1' and clk'event) then + --step_pos_filt <= (step_pos_i and not busy) or pending_pos; + --step_neg_filt <= (step_neg_i and not busy) or pending_neg; + if(init_i = '1') then + pending_cnt <= (others => '0'); + elsif(inc_pending_cnt = '1') then + pending_cnt <= std_logic_vector(signed(pending_cnt)+1); + elsif(dec_pending_cnt = '1') then + pending_cnt <= std_logic_vector(signed(pending_cnt)-1); + end if; + end if; + end process pNOISE_FILT; + + pending_pos <= '1' when signed(pending_cnt) > 0 and busy = '0' and step_pos_i = '0' and step_neg_i = '0' else '0'; + pending_neg <= '1' when signed(pending_cnt) < 0 and busy = '0' and step_pos_i = '0' and step_neg_i = '0' else '0'; + + inc_pending_cnt <= (step_pos_i and busy) or pending_neg; + dec_pending_cnt <= (step_neg_i and busy) or pending_pos; + + step_pos_filt <= (step_pos_i and not busy) or pending_pos; + step_neg_filt <= (step_neg_i and not busy) or pending_neg; + + ----------------------------------------------------------------------------- + -- Multiplier Logic + ----------------------------------------------------------------------------- + pSEQ_LOGIC_RST : process(reset_n, clk) begin if(reset_n = '0') then @@ -112,6 +139,11 @@ begin if(clk = '1' and clk'event) then step_pos_i <= step_pos and enable; step_neg_i <= step_neg and enable; + if(init_i = '1' or data_valid(data_valid'left) = '1') then + busy <= '0'; + elsif(new_step = '1') then + busy <= '1'; + end if; if(init_i = '1') then loc_time <= (others => '0'); else @@ -153,6 +185,8 @@ begin else step_bal_m1 <= std_logic_vector(-signed(step_balance)-1); end if; + end if; + if(data_valid(2) = '1') then time_diff_i <= std_logic_vector(resize(unsigned(time_diff),31)); end if; if(init = '1' or new_step = '1') then @@ -181,18 +215,16 @@ begin end if; end process pSEQ_LOGIC; - delta_t_i <= delta_t_ii; - time_out_flag_i <= '1' when unsigned(time_out_cnt) = 1 else '0'; time_out_flag <= time_out_flag_d; init_i <= init or (time_out_flag_i and not time_out_flag_d); - inc_step_balance <= step_pos_i or ((not avg_transient_on) and (data_valid(0) and tag_first(31))); - dec_step_balance <= step_neg_i or ((not avg_transient_on) and (data_valid(0) and not tag_first(31))); + inc_step_balance <= step_pos_filt or ((not avg_transient_on) and (data_valid(0) and tag_first(31))); + dec_step_balance <= step_neg_filt or ((not avg_transient_on) and (data_valid(0) and not tag_first(31))); - new_step <= step_pos_i or step_neg_i; + new_step <= step_pos_filt or step_neg_filt; inc_step_cnt <= new_step and avg_transient_on; @@ -217,20 +249,17 @@ begin data_b => (others => '0'), q_b => tag_first); - write_last <= step_pos_i or step_neg_i; - step_type <= '1' when step_neg_i = '1' else '0'; + write_last <= step_pos_filt or step_neg_filt; + step_type <= '1' when step_neg_filt = '1' else '0'; new_tag <= step_type & std_logic_vector(resize(unsigned(loc_time), 31)); time_diff <= std_logic_vector(resize(unsigned(tag_last_i(loc_time'range))-unsigned(tag_first(loc_time'range)),30)); - iDIVIDE: entity work.divider_0 - generic map( - PIPELINE_STAGES => 1) + iLUT_DIV: entity work.lut_divider_0 port map ( - clock => clk, - denom => step_bal_m1(5 downto 0), - numer => time_diff_i, - quotient => delta_t_ii, - remain => open); + clk => clk, + dividend => time_diff_i, + divisor => ("00" & step_bal_m1(5 downto 0)), + quotient => delta_t_i); end architecture rtl; diff --git a/generic_ip/encoder_multiply/0/src/gen_lut.py b/generic_ip/encoder_multiply/0/src/gen_lut.py new file mode 100644 index 0000000..f325755 --- /dev/null +++ b/generic_ip/encoder_multiply/0/src/gen_lut.py @@ -0,0 +1,23 @@ +# This script generate the content of the Look-Up-Table for a LUT based divider: +# The divider works in this way: +# x/y = x * (1/y), with the factor alpha = 1/y stored in a LUT as a fixed point number with a sufficient number of bits of mantissa. +# Since the divisor is a eight bit number, the LUT contains 256 elements. Using a single M10k block the LUT width is 32 bits, which is +# more than needed for the mantissa + +# Generate the LUT content +lut_size = 256 +lut_width = 32 +lut = [] + +''' +for x in range (1,lut_size+1): + lut.append(int((1/x)*(2.0**lut_width-1))) +''' + +# Division by zero has the same value of division by 1 in the LUT +lut.append(int(2.0**lut_width-1)) +for x in range (1,lut_size): + lut.append(int((1/x)*(2.0**lut_width-1))) + +for x in range (0,int(lut_size/8)): + print('X"{0:08X}", X"{1:08X}", X"{2:08X}", X"{3:08X}", X"{4:08X}", X"{5:08X}", X"{6:08X}", X"{7:08X}",'.format(lut[int(8*x+0)], lut[int(8*x+1)], lut[int(8*x+2)], lut[int(8*x+3)],lut[int(8*x+4)], lut[int(8*x+5)], lut[int(8*x+6)], lut[int(8*x+7)])) diff --git a/generic_ip/encoder_multiply/0/src/intel/divider_0.vhd b/generic_ip/encoder_multiply/0/src/intel/divider_0.vhd deleted file mode 100644 index 08f721a..0000000 --- a/generic_ip/encoder_multiply/0/src/intel/divider_0.vhd +++ /dev/null @@ -1,141 +0,0 @@ --- megafunction wizard: %LPM_DIVIDE% --- GENERATION: STANDARD --- VERSION: WM1.0 --- MODULE: LPM_DIVIDE - --- ============================================================ --- File Name: divider_0.vhd --- Megafunction Name(s): --- LPM_DIVIDE --- --- Simulation Library Files(s): --- lpm --- ============================================================ --- ************************************************************ --- THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE! --- --- 18.0.0 Build 614 04/24/2018 SJ Standard Edition --- ************************************************************ - - ---Copyright (C) 2018 Intel Corporation. All rights reserved. ---Your use of Intel Corporation's design tools, logic functions ---and other software and tools, and its AMPP partner logic ---functions, and any output files from any of the foregoing ---(including device programming or simulation files), and any ---associated documentation or information are expressly subject ---to the terms and conditions of the Intel Program License ---Subscription Agreement, the Intel Quartus Prime License Agreement, ---the Intel FPGA IP License Agreement, or other applicable license ---agreement, including, without limitation, that your use is for ---the sole purpose of programming logic devices manufactured by ---Intel and sold by Intel or its authorized distributors. Please ---refer to the applicable agreement for further details. - - -library ieee; -use ieee.std_logic_1164.all; - -library lpm; -use lpm.all; - -entity divider_0 is - generic( - PIPELINE_STAGES : natural range 1 to 8 := 3); - port - ( - clock : in std_logic; - denom : in std_logic_vector (5 downto 0); - numer : in std_logic_vector (30 downto 0); - quotient : out std_logic_vector (30 downto 0); - remain : out std_logic_vector (5 downto 0) - ); -end divider_0; - - -architecture SYN of divider_0 is - - signal sub_wire0 : std_logic_vector (30 downto 0); - signal sub_wire1 : std_logic_vector (5 downto 0); - - - - component lpm_divide - generic ( - lpm_drepresentation : string; - lpm_hint : string; - lpm_nrepresentation : string; - lpm_pipeline : natural; - lpm_type : string; - lpm_widthd : natural; - lpm_widthn : natural - ); - port ( - clock : in std_logic; - denom : in std_logic_vector (5 downto 0); - numer : in std_logic_vector (30 downto 0); - quotient : out std_logic_vector (30 downto 0); - remain : out std_logic_vector (5 downto 0) - ); - end component; - -begin - quotient <= sub_wire0(30 downto 0); - remain <= sub_wire1(5 downto 0); - - LPM_DIVIDE_component : LPM_DIVIDE - generic map ( - lpm_drepresentation => "UNSIGNED", - lpm_hint => "MAXIMIZE_SPEED=6,LPM_REMAINDERPOSITIVE=TRUE", - lpm_nrepresentation => "UNSIGNED", - lpm_pipeline => PIPELINE_STAGES, - lpm_type => "LPM_DIVIDE", - lpm_widthd => 6, - lpm_widthn => 31 - ) - port map ( - clock => clock, - denom => denom, - numer => numer, - quotient => sub_wire0, - remain => sub_wire1 - ); - - - -end SYN; - --- ============================================================ --- CNX file retrieval info --- ============================================================ --- Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "Cyclone V" --- Retrieval info: PRIVATE: PRIVATE_LPM_REMAINDERPOSITIVE STRING "TRUE" --- Retrieval info: PRIVATE: PRIVATE_MAXIMIZE_SPEED NUMERIC "6" --- Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0" --- Retrieval info: PRIVATE: USING_PIPELINE NUMERIC "1" --- Retrieval info: PRIVATE: VERSION_NUMBER NUMERIC "2" --- Retrieval info: PRIVATE: new_diagram STRING "1" --- Retrieval info: LIBRARY: lpm lpm.lpm_components.all --- Retrieval info: CONSTANT: LPM_DREPRESENTATION STRING "UNSIGNED" --- Retrieval info: CONSTANT: LPM_HINT STRING "MAXIMIZE_SPEED=6,LPM_REMAINDERPOSITIVE=TRUE" --- Retrieval info: CONSTANT: LPM_NREPRESENTATION STRING "UNSIGNED" --- Retrieval info: CONSTANT: LPM_PIPELINE NUMERIC "3" --- Retrieval info: CONSTANT: LPM_TYPE STRING "LPM_DIVIDE" --- Retrieval info: CONSTANT: LPM_WIDTHD NUMERIC "6" --- Retrieval info: CONSTANT: LPM_WIDTHN NUMERIC "31" --- Retrieval info: USED_PORT: clock 0 0 0 0 INPUT NODEFVAL "clock" --- Retrieval info: USED_PORT: denom 0 0 6 0 INPUT NODEFVAL "denom[5..0]" --- Retrieval info: USED_PORT: numer 0 0 31 0 INPUT NODEFVAL "numer[30..0]" --- Retrieval info: USED_PORT: quotient 0 0 31 0 OUTPUT NODEFVAL "quotient[30..0]" --- Retrieval info: USED_PORT: remain 0 0 6 0 OUTPUT NODEFVAL "remain[5..0]" --- Retrieval info: CONNECT: @clock 0 0 0 0 clock 0 0 0 0 --- Retrieval info: CONNECT: @denom 0 0 6 0 denom 0 0 6 0 --- Retrieval info: CONNECT: @numer 0 0 31 0 numer 0 0 31 0 --- Retrieval info: CONNECT: quotient 0 0 31 0 @quotient 0 0 31 0 --- Retrieval info: CONNECT: remain 0 0 6 0 @remain 0 0 6 0 --- Retrieval info: GEN_FILE: TYPE_NORMAL divider_0.vhd TRUE --- Retrieval info: GEN_FILE: TYPE_NORMAL divider_0.inc FALSE --- Retrieval info: GEN_FILE: TYPE_NORMAL divider_0.cmp FALSE --- Retrieval info: GEN_FILE: TYPE_NORMAL divider_0.bsf FALSE --- Retrieval info: GEN_FILE: TYPE_NORMAL divider_0_inst.vhd FALSE --- Retrieval info: LIB_FILE: lpm diff --git a/generic_ip/encoder_multiply/0/src/lut_divider_0.vhd b/generic_ip/encoder_multiply/0/src/lut_divider_0.vhd new file mode 100644 index 0000000..5b03f83 --- /dev/null +++ b/generic_ip/encoder_multiply/0/src/lut_divider_0.vhd @@ -0,0 +1,134 @@ +------------------------------------------------------------------------------- +-- Title : lut_divider_0 +-- Project : Generic +------------------------------------------------------------------------------- +-- File : lut_divider_0.vhd +-- Author : Gianmarco Girau +-- Company : Global Inkjet Systems +-- Created : 2019-04-17 +-- Last update: 2019-04-17 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: +-- The divider works in this way: +-- x/y = x * (1/y), with the factor alpha = 1/y stored in a LUT as a fixed point +-- number with a sufficient number of bits of mantissa. +-- Since the divisor is a eight bit number, the LUT contains 256 elements. +-- Using a single M10k block the LUT width is 32 bits, which is more than needed +-- for the mantissa. +------------------------------------------------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +library work; +use work.common_pkg.all; + +entity lut_divider_0 is + port( + clk : in std_logic; + dividend : in std_logic_vector(30 downto 0); + divisor : in std_logic_vector( 7 downto 0); + quotient : out std_logic_vector(30 downto 0)); +end lut_divider_0; + +architecture rtl of lut_divider_0 is + + type rom_t is array(0 to 255) of std_logic_vector(31 downto 0); + + signal lut : rom_t := ( + X"FFFFFFFF", X"FFFFFFFF", X"7FFFFFFF", X"55555555", X"3FFFFFFF", X"33333333", X"2AAAAAAA", X"24924924", + X"1FFFFFFF", X"1C71C71C", X"19999999", X"1745D174", X"15555555", X"13B13B13", X"12492492", X"11111111", + X"0FFFFFFF", X"0F0F0F0F", X"0E38E38E", X"0D79435E", X"0CCCCCCC", X"0C30C30C", X"0BA2E8BA", X"0B21642C", + X"0AAAAAAA", X"0A3D70A3", X"09D89D89", X"097B425E", X"09249249", X"08D3DCB0", X"08888888", X"08421084", + X"07FFFFFF", X"07C1F07C", X"07878787", X"07507507", X"071C71C7", X"06EB3E45", X"06BCA1AF", X"06906906", + X"06666666", X"063E7063", X"06186186", X"05F417D0", X"05D1745D", X"05B05B05", X"0590B216", X"0572620A", + X"05555555", X"05397829", X"051EB851", X"05050505", X"04EC4EC4", X"04D4873E", X"04BDA12F", X"04A7904A", + X"04924924", X"047DC11F", X"0469EE58", X"0456C797", X"04444444", X"04325C53", X"04210842", X"04104104", + X"03FFFFFF", X"03F03F03", X"03E0F83E", X"03D22635", X"03C3C3C3", X"03B5CC0E", X"03A83A83", X"039B0AD1", + X"038E38E3", X"0381C0E0", X"03759F22", X"0369D036", X"035E50D7", X"03531DEC", X"03483483", X"033D91D2", + X"03333333", X"0329161F", X"031F3831", X"03159721", X"030C30C3", X"03030303", X"02FA0BE8", X"02F14990", + X"02E8BA2E", X"02E05C0B", X"02D82D82", X"02D02D02", X"02C8590B", X"02C0B02C", X"02B93105", X"02B1DA46", + X"02AAAAAA", X"02A3A0FD", X"029CBC14", X"0295FAD4", X"028F5C28", X"0288DF0C", X"02828282", X"027C4597", + X"02762762", X"02702702", X"026A439F", X"02647C69", X"025ED097", X"02593F69", X"0253C825", X"024E6A17", + X"02492492", X"0243F6F0", X"023EE08F", X"0239E0D5", X"0234F72C", X"02302302", X"022B63CB", X"0226B902", + X"02222222", X"021D9EAD", X"02192E29", X"0214D021", X"02108421", X"020C49BA", X"02082082", X"02040810", + X"01FFFFFF", X"01FC07F0", X"01F81F81", X"01F44659", X"01F07C1F", X"01ECC07B", X"01E9131A", X"01E573AC", + X"01E1E1E1", X"01DE5D6E", X"01DAE607", X"01D77B65", X"01D41D41", X"01D0CB58", X"01CD8568", X"01CA4B30", + X"01C71C71", X"01C3F8F0", X"01C0E070", X"01BDD2B8", X"01BACF91", X"01B7D6C3", X"01B4E81B", X"01B20364", + X"01AF286B", X"01AC5701", X"01A98EF6", X"01A6D01A", X"01A41A41", X"01A16D3F", X"019EC8E9", X"019C2D14", + X"01999999", X"01970E4F", X"01948B0F", X"01920FB4", X"018F9C18", X"018D3018", X"018ACB90", X"01886E5F", + X"01861861", X"0183C977", X"01818181", X"017F405F", X"017D05F4", X"017AD220", X"0178A4C8", X"01767DCE", + X"01745D17", X"01724287", X"01702E05", X"016E1F76", X"016C16C1", X"016A13CD", X"01681681", X"01661EC6", + X"01642C85", X"01623FA7", X"01605816", X"015E75BB", X"015C9882", X"015AC056", X"0158ED23", X"01571ED3", + X"01555555", X"01539094", X"0151D07E", X"01501501", X"014E5E0A", X"014CAB88", X"014AFD6A", X"0149539E", + X"0147AE14", X"01460CBC", X"01446F86", X"0142D662", X"01414141", X"013FB013", X"013E22CB", X"013C995A", + X"013B13B1", X"013991C2", X"01381381", X"013698DF", X"013521CF", X"0133AE45", X"01323E34", X"0130D190", + X"012F684B", X"012E025C", X"012C9FB4", X"012B404A", X"0129E412", X"01288B01", X"0127350B", X"0125E227", + X"01249249", X"01234567", X"0121FB78", X"0120B470", X"011F7047", X"011E2EF3", X"011CF06A", X"011BB4A4", + X"011A7B96", X"01194538", X"01181181", X"0116E068", X"0115B1E5", X"011485F0", X"01135C81", X"0112358E", + X"01111111", X"010FEF01", X"010ECF56", X"010DB20A", X"010C9714", X"010B7E6E", X"010A6810", X"010953F3", + X"01084210", X"01073260", X"010624DD", X"0105197F", X"01041041", X"0103091B", X"01020408", X"01010101"); +/* + X"FFFFFFFF", X"7FFFFFFF", X"55555555", X"3FFFFFFF", X"33333333", X"2AAAAAAA", X"24924924", X"1FFFFFFF", + X"1C71C71C", X"19999999", X"1745D174", X"15555555", X"13B13B13", X"12492492", X"11111111", X"0FFFFFFF", + X"0F0F0F0F", X"0E38E38E", X"0D79435E", X"0CCCCCCC", X"0C30C30C", X"0BA2E8BA", X"0B21642C", X"0AAAAAAA", + X"0A3D70A3", X"09D89D89", X"097B425E", X"09249249", X"08D3DCB0", X"08888888", X"08421084", X"07FFFFFF", + X"07C1F07C", X"07878787", X"07507507", X"071C71C7", X"06EB3E45", X"06BCA1AF", X"06906906", X"06666666", + X"063E7063", X"06186186", X"05F417D0", X"05D1745D", X"05B05B05", X"0590B216", X"0572620A", X"05555555", + X"05397829", X"051EB851", X"05050505", X"04EC4EC4", X"04D4873E", X"04BDA12F", X"04A7904A", X"04924924", + X"047DC11F", X"0469EE58", X"0456C797", X"04444444", X"04325C53", X"04210842", X"04104104", X"03FFFFFF", + X"03F03F03", X"03E0F83E", X"03D22635", X"03C3C3C3", X"03B5CC0E", X"03A83A83", X"039B0AD1", X"038E38E3", + X"0381C0E0", X"03759F22", X"0369D036", X"035E50D7", X"03531DEC", X"03483483", X"033D91D2", X"03333333", + X"0329161F", X"031F3831", X"03159721", X"030C30C3", X"03030303", X"02FA0BE8", X"02F14990", X"02E8BA2E", + X"02E05C0B", X"02D82D82", X"02D02D02", X"02C8590B", X"02C0B02C", X"02B93105", X"02B1DA46", X"02AAAAAA", + X"02A3A0FD", X"029CBC14", X"0295FAD4", X"028F5C28", X"0288DF0C", X"02828282", X"027C4597", X"02762762", + X"02702702", X"026A439F", X"02647C69", X"025ED097", X"02593F69", X"0253C825", X"024E6A17", X"02492492", + X"0243F6F0", X"023EE08F", X"0239E0D5", X"0234F72C", X"02302302", X"022B63CB", X"0226B902", X"02222222", + X"021D9EAD", X"02192E29", X"0214D021", X"02108421", X"020C49BA", X"02082082", X"02040810", X"01FFFFFF", + X"01FC07F0", X"01F81F81", X"01F44659", X"01F07C1F", X"01ECC07B", X"01E9131A", X"01E573AC", X"01E1E1E1", + X"01DE5D6E", X"01DAE607", X"01D77B65", X"01D41D41", X"01D0CB58", X"01CD8568", X"01CA4B30", X"01C71C71", + X"01C3F8F0", X"01C0E070", X"01BDD2B8", X"01BACF91", X"01B7D6C3", X"01B4E81B", X"01B20364", X"01AF286B", + X"01AC5701", X"01A98EF6", X"01A6D01A", X"01A41A41", X"01A16D3F", X"019EC8E9", X"019C2D14", X"01999999", + X"01970E4F", X"01948B0F", X"01920FB4", X"018F9C18", X"018D3018", X"018ACB90", X"01886E5F", X"01861861", + X"0183C977", X"01818181", X"017F405F", X"017D05F4", X"017AD220", X"0178A4C8", X"01767DCE", X"01745D17", + X"01724287", X"01702E05", X"016E1F76", X"016C16C1", X"016A13CD", X"01681681", X"01661EC6", X"01642C85", + X"01623FA7", X"01605816", X"015E75BB", X"015C9882", X"015AC056", X"0158ED23", X"01571ED3", X"01555555", + X"01539094", X"0151D07E", X"01501501", X"014E5E0A", X"014CAB88", X"014AFD6A", X"0149539E", X"0147AE14", + X"01460CBC", X"01446F86", X"0142D662", X"01414141", X"013FB013", X"013E22CB", X"013C995A", X"013B13B1", + X"013991C2", X"01381381", X"013698DF", X"013521CF", X"0133AE45", X"01323E34", X"0130D190", X"012F684B", + X"012E025C", X"012C9FB4", X"012B404A", X"0129E412", X"01288B01", X"0127350B", X"0125E227", X"01249249", + X"01234567", X"0121FB78", X"0120B470", X"011F7047", X"011E2EF3", X"011CF06A", X"011BB4A4", X"011A7B96", + X"01194538", X"01181181", X"0116E068", X"0115B1E5", X"011485F0", X"01135C81", X"0112358E", X"01111111", + X"010FEF01", X"010ECF56", X"010DB20A", X"010C9714", X"010B7E6E", X"010A6810", X"010953F3", X"01084210", + X"01073260", X"010624DD", X"0105197F", X"01041041", X"0103091B", X"01020408", X"01010101", X"00FFFFFF"); +*/ + + + signal addr : std_logic_vector( 7 downto 0); + signal lut_q : std_logic_vector(31 downto 0); + signal mult : std_logic_vector(62 downto 0); + +begin + + pLUT : process(clk) + begin + if(clk = '1' and clk'event) then + lut_q <= lut(to_integer(unsigned(addr))); + end if; + end process pLUT; + + addr <= divisor; + + pMULT : process(clk) + begin + if(clk = '1' and clk'event) then + mult <= std_logic_vector(unsigned(dividend)*unsigned(lut_q)); + end if; + end process pMULT; + + quotient <= mult(62 downto 32); + +end architecture rtl; diff --git a/generic_ip/encoder_multiply/0/src/test/encoder_multiply_tb.vhd b/generic_ip/encoder_multiply/0/src/test/encoder_multiply_tb.vhd index a170c7b..8751733 100644 --- a/generic_ip/encoder_multiply/0/src/test/encoder_multiply_tb.vhd +++ b/generic_ip/encoder_multiply/0/src/test/encoder_multiply_tb.vhd @@ -6,7 +6,7 @@ -- Author : GMG -- Company : Global Inkjet Systems -- Created : 2019-03-05 --- Last update: 2019-03-20 +-- Last update: 2019-04-25 -- SVN ID : Git -- Standard : VHDL'2008 ------------------------------------------------------------------------------- @@ -42,7 +42,7 @@ architecture behav of encoder_multiply_tb is constant MAX_SIM_TIME : time := 40.0 ms; -- Maximum simulation time - constant RUN_TEST : integer_vector(0 to 2) := (0, 1, 0); + constant RUN_TEST : integer_vector(0 to 2) := (0, 1, 1); CONSTANT MULT_VALUE : integer := to_integer(unsigned(std_logic_vector(to_unsigned(1, 8)) sll(MULT_SELECTION))); @@ -69,7 +69,7 @@ architecture behav of encoder_multiply_tb is signal mult_sel : std_logic_vector(2 downto 0); signal delta_t : std_logic_vector(39 downto 0); signal delta_t_i : std_logic_vector(39 downto 0); - signal avg_steps : std_logic_vector( 7 downto 0); + signal avg_steps : std_logic_vector( 6 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; @@ -81,6 +81,7 @@ architecture behav of encoder_multiply_tb is signal step_neg_out : std_logic; -- signal abs_pos : std_logic_vector(31 downto 0); + signal abs_pos_vel : std_logic_vector(31 downto 0); signal m_abs_pos : std_logic_vector(39 downto 0); signal m_abs_pos_r : real; signal delta_t_norm : integer; @@ -95,6 +96,10 @@ architecture behav of encoder_multiply_tb is shared variable error_flag : boolean := false; + shared variable suspend_error_check : boolean := false; + shared variable accurate_pos_check : boolean := false; + + ----------------------------------------------------------------------------- -- Subprograms ----------------------------------------------------------------------------- @@ -121,7 +126,29 @@ architecture behav of encoder_multiply_tb is end if; end if; end procedure check_pos; - + + ----------------------------------------------------------------------------- + -- Issue Step + ----------------------------------------------------------------------------- + + procedure issue_step( + step_type : in std_logic; + signal pos_step : out std_logic; + signal neg_step : out std_logic) is + begin + wait_clk_cycles(1); + if(step_type = '0') then + pos_step <= '1'; + neg_step <= '0'; + else + pos_step <= '0'; + neg_step <= '1'; + end if; + wait_clk_cycles(1); + pos_step <= '0'; + neg_step <= '0'; + + end procedure issue_step; ----------------------------------------------------------------------------- -- Encoder Profile #1: fixed frequency @@ -300,6 +327,151 @@ architecture behav of encoder_multiply_tb is end procedure run_encoder_profile_2; + ----------------------------------------------------------------------------- + -- Encoder Profile #3: Position Noise: added random pulses in the opposite + -- direction + ----------------------------------------------------------------------------- + + procedure run_encoder_profile_3 ( + /* + freq : in real range 1.0e3 to 4000.0e3; + dir : in std_logic; + max_steps : in natural; + period_noise : in natural range 0 to 100; + */ + signal enable : out std_logic; + signal delta_t : out std_logic_vector(39 downto 0); + signal step_pos : out std_logic; + signal step_neg : out std_logic; + init : in boolean := false) is + + variable step_cnt : natural := 0; + variable dir : std_logic; + variable delta_period : integer; + variable t_period : real; + variable t_period_int : natural; + variable freq : real range 1.0e3 to 4000.0e3; + /* + variable t_ref : time; + variable rv : RandomPType; + */ + + begin + + freq := 250.0e3; + t_period := 1.0e6/freq; + t_period_int := natural(t_period/0.01); + + if(error_flag = true) then + return; + end if; + + enable <= '0'; + step_pos <= '0'; + step_neg <= '0'; + + suspend_error_check := true; + + log("run_encoder_profile_3: Running ...", VMEDIUM); + + dir := '0'; + + -- 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)); + 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; + delta_t(delta_t'left) <= dir; + wait_clk_cycles(1); + -- enable the multiplier + enable <= '1'; + wait_clk_cycles(5); + + -- run a custom made noise sequence + for m in 0 to 99 loop + issue_step('0', step_pos, step_neg); + wait_clk_cycles(5); + issue_step('1', step_pos, step_neg); + wait_clk_cycles(1); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(t_period_int); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(5); + issue_step('1', step_pos, step_neg); + wait_clk_cycles(1); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(1); + issue_step('1', step_pos, step_neg); + wait_clk_cycles(t_period_int); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(5); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(t_period_int); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(4); + issue_step('1', step_pos, step_neg); + wait_clk_cycles(1); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(t_period_int); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(6); + issue_step('1', step_pos, step_neg); + wait_clk_cycles(1); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(t_period_int); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(4); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(t_period_int); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(6); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(t_period_int); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(2); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(t_period_int); + issue_step('1', step_pos, step_neg); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + + wait_clk_cycles(t_period_int); + issue_step('0', step_pos, step_neg); + + wait_clk_cycles(t_period_int); + -- end of the custom made sequence + end loop; -- m + wait for 1000 us; + + accurate_pos_check := true; + suspend_error_check := false; + wait_clk_cycles(100); + + -- disable the multiplier + enable <= '0'; + + log("run_encoder_profile_3: Completed.", VMEDIUM); + + accurate_pos_check := false; + suspend_error_check := false; + wait_clk_cycles(100); + + end procedure run_encoder_profile_3; + begin -- architecture behav clk <= not clk after 0.5*CLK_PERIOD; @@ -353,6 +525,13 @@ begin -- architecture behav elsif(step_neg_in = '1') then abs_pos <= std_logic_vector(unsigned(abs_pos)-1); end if; + if(init = '1') then + abs_pos_vel <= (others => '0'); + elsif(step_pos = '1') then + abs_pos_vel <= std_logic_vector(unsigned(abs_pos_vel)+1); + elsif(step_neg = '1') then + abs_pos_vel <= std_logic_vector(unsigned(abs_pos_vel)-1); + end if; if(init = '1') then m_abs_pos <= (others => '0'); elsif(step_pos_out = '1') then @@ -385,7 +564,7 @@ begin -- architecture behav enable <= '0'; mult_sel <= (others => '0'); - avg_steps <= std_logic_vector(to_unsigned(FILT_AVG,8)); + avg_steps <= std_logic_vector(to_unsigned(FILT_AVG,7)); 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)); @@ -552,6 +731,16 @@ begin -- architecture behav check_pos(true); end if; + if(RUN_TEST(2) = 1) then + wait_clk_cycles(10); + log_separator_line(VLOW); + log("Tests with custom made position noise:", VLOW); + log_separator_line(VLOW); + run_encoder_profile_3(enable, delta_t, step_pos_in, step_neg_in, true); + wait for 10 us; + + end if; + --------------------------------------------------------------------------- -- End --------------------------------------------------------------------------- @@ -560,6 +749,8 @@ begin -- architecture behav wait for 10 us; if(error_flag = false) then passed <= true; + else + failed <= true; end if; wait; @@ -568,16 +759,22 @@ begin -- architecture behav pERROR_DETECT : process(clk) 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)))+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); + if(suspend_error_check = false) then + if(accurate_pos_check = true) 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 + 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; + else + 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 if; end if; end process pERROR_DETECT; - failed <= true after 1 us when error_flag = true else false; - CHECK_SIM_TIMEOUT: process begin -- process CHECK_SIM_TIMEOUT while now < MAX_SIM_TIME loop diff --git a/generic_ip/encoder_multiply/0/src/test/encoder_speed_detect_tb.vhd b/generic_ip/encoder_multiply/0/src/test/encoder_speed_detect_tb.vhd index 3b5f949..03bb7ce 100644 --- a/generic_ip/encoder_multiply/0/src/test/encoder_speed_detect_tb.vhd +++ b/generic_ip/encoder_multiply/0/src/test/encoder_speed_detect_tb.vhd @@ -6,7 +6,7 @@ -- Author : GMG -- Company : Global Inkjet Systems -- Created : 2019-03-05 --- Last update: 2019-03-22 +-- Last update: 2019-04-18 -- SVN ID : Git -- Standard : VHDL'2008 ------------------------------------------------------------------------------- @@ -40,7 +40,7 @@ architecture behav of encoder_speed_detect_tb is constant MAX_SIM_TIME : time := 40.0 ms; -- Maximum simulation time - constant RUN_TEST : integer_vector(0 to 2) := (1, 0, 0); + constant RUN_TEST : integer_vector(0 to 2) := (0, 0, 1); -- delta_tmin : minimum value of delta_t, corresponding to the maximum tx -- rate over the POF (4M events/sec => 250 ns) @@ -62,7 +62,7 @@ architecture behav of encoder_speed_detect_tb is signal clk : std_logic := '0'; signal init : std_logic; signal enable : std_logic; - signal avg_steps : std_logic_vector( 7 downto 0); + signal avg_steps : std_logic_vector( 6 downto 0); signal delta_init : std_logic_vector(27 downto 0); signal time_out : std_logic_vector(27 downto 0); signal step_pos : std_logic; @@ -73,6 +73,7 @@ architecture behav of encoder_speed_detect_tb is signal time_out_flag : std_logic; -- signal abs_pos : std_logic_vector(31 downto 0); + signal abs_pos_out : std_logic_vector(31 downto 0); signal delta_t_norm : integer; -- TB specific signals @@ -94,7 +95,30 @@ architecture behav of encoder_speed_detect_tb is for n in 0 to cycles-1 loop wait until clk = '1' and clk'event; end loop; -- n - end procedure wait_clk_cycles; + end procedure wait_clk_cycles; + + ----------------------------------------------------------------------------- + -- Issue Step + ----------------------------------------------------------------------------- + + procedure issue_step( + step_type : in std_logic; + signal pos_step : out std_logic; + signal neg_step : out std_logic) is + begin + wait_clk_cycles(1); + if(step_type = '0') then + pos_step <= '1'; + neg_step <= '0'; + else + pos_step <= '0'; + neg_step <= '1'; + end if; + wait_clk_cycles(1); + pos_step <= '0'; + neg_step <= '0'; + + end procedure issue_step; ----------------------------------------------------------------------------- -- Encoder Profile #1: fixed frequency @@ -250,6 +274,117 @@ architecture behav of encoder_speed_detect_tb is end procedure run_encoder_profile_2; + ----------------------------------------------------------------------------- + -- Encoder Profile #3: Position Noise: added random pulses in the opposite + -- direction + ----------------------------------------------------------------------------- + + procedure run_encoder_profile_3 ( + signal enable : out std_logic; + signal step_pos : out std_logic; + signal step_neg : out std_logic; + init : in boolean := false) is + + variable step_cnt : natural := 0; + variable dir : std_logic; + variable delta_period : integer; + variable t_period : real; + variable t_period_int : natural; + variable freq : real range 1.0e3 to 4000.0e3; + + begin + + freq := 250.0e3; + t_period := 1.0e6/freq; + t_period_int := natural(t_period/0.01); + + if(error_flag = true) then + return; + end if; + + enable <= '0'; + step_pos <= '0'; + step_neg <= '0'; + + log("run_encoder_profile_3: Running ...", VMEDIUM); + + dir := '0'; + + wait_clk_cycles(1); + -- enable the multiplier + enable <= '1'; + wait_clk_cycles(5); + + -- run a custom made noise sequence + issue_step('0', step_pos, step_neg); + wait_clk_cycles(5); + issue_step('1', step_pos, step_neg); + wait_clk_cycles(1); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(t_period_int); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(5); + issue_step('1', step_pos, step_neg); + wait_clk_cycles(1); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(1); + issue_step('1', step_pos, step_neg); + wait_clk_cycles(t_period_int); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(5); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(t_period_int); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(4); + issue_step('1', step_pos, step_neg); + wait_clk_cycles(1); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(t_period_int); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(6); + issue_step('1', step_pos, step_neg); + wait_clk_cycles(1); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(t_period_int); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(4); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(t_period_int); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(6); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(t_period_int); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(2); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + wait_clk_cycles(t_period_int); + issue_step('1', step_pos, step_neg); + issue_step('1', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + issue_step('0', step_pos, step_neg); + + wait_clk_cycles(t_period_int); + issue_step('0', step_pos, step_neg); + -- end of the custom made sequence + + wait_clk_cycles(100); + -- disable the multiplier + enable <= '0'; + + end procedure run_encoder_profile_3; + begin -- architecture behav clk <= not clk after 0.5*CLK_PERIOD; @@ -282,12 +417,19 @@ begin -- architecture behav begin if(clk = '1' and clk'event) then if(init = '1') then - abs_pos <= (others => '0'); - elsif(step_pos_out = '1') then + abs_pos <= (others => '0'); + elsif(step_pos = '1') then abs_pos <= std_logic_vector(unsigned(abs_pos)+1); - elsif(step_neg_out = '1') then + elsif(step_neg = '1') then abs_pos <= std_logic_vector(unsigned(abs_pos)-1); end if; + if(init = '1') then + abs_pos_out <= (others => '0'); + elsif(step_pos_out = '1') then + abs_pos_out <= std_logic_vector(unsigned(abs_pos_out)+1); + elsif(step_neg_out = '1') then + abs_pos_out <= std_logic_vector(unsigned(abs_pos_out)-1); + end if; end if; end process pGEN_POS; @@ -313,7 +455,7 @@ begin -- architecture behav init <= '0'; enable <= '0'; - avg_steps <= std_logic_vector(to_unsigned(FILT_AVG,8)); + avg_steps <= std_logic_vector(to_unsigned(FILT_AVG,7)); delta_init <= std_logic_vector(to_unsigned(DELTA_TMIN, delta_init'length)); -- time_out <= std_logic_vector(to_unsigned(6000, time_out'length)); @@ -341,6 +483,9 @@ begin -- architecture behav --------------------------------------------------------------------------- running <= true; + + wait_clk_cycles(10); + log_separator_line(VLOW); log("Encoder-Speed-Detection verification:", VLOW); log_separator_line(VLOW); @@ -428,6 +573,16 @@ begin -- architecture behav wait for 20 us; end if; + if(RUN_TEST(2) = 1) then + wait_clk_cycles(10); + log_separator_line(VLOW); + log("Tests with custom made position noise:", VLOW); + log_separator_line(VLOW); + run_encoder_profile_3(enable, step_pos, step_neg, true); + wait for 20 us; + + end if; + --------------------------------------------------------------------------- -- End --------------------------------------------------------------------------- diff --git a/generic_ip/pulse_generator/1/src/test/spitting_verify_tb.vhd b/generic_ip/pulse_generator/1/src/test/spitting_verify_tb.vhd new file mode 100644 index 0000000..18f284d --- /dev/null +++ b/generic_ip/pulse_generator/1/src/test/spitting_verify_tb.vhd @@ -0,0 +1,307 @@ +------------------------------------------------------------------------------- +-- Title : spitting_verify_tb +-- Project : Pulse-Generator +------------------------------------------------------------------------------- +-- File : spitting_verify_tb.vhd +-- Author : GMG +-- Company : Global Inkjet Systems +-- Created : 2018-09-11 +-- Last update: 2019-04-04 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: +-- Verify the spitting logic in pulse-generator +------------------------------------------------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; +use ieee.math_real.all; + +use work.log_pkg.all; +use work.avalon_verify_pkg.all; + +use work.pulse_generator_1_pkg.all; + +entity spitting_verify_tb is + -- .. +end entity spitting_verify_tb; + +architecture behav of spitting_verify_tb is + + constant CLK_PERIOD : time := 10 ns; + + -- Logging Verbosity Level + constant VERBOSITY_LEVEL : verb_level_t := VMEDIUM; + + ----------------------------------------------------------------------------- + -- TB Functions / Procedures + ----------------------------------------------------------------------------- + + procedure wait_latency( + signal clk : in std_logic; + cycles : in natural) is + begin + for i in 1 to cycles loop + wait until clk = '1' and clk'event; + end loop; -- i + end procedure wait_latency; + + ----------------------------------------------------------------------------- + -- Signal declarations + ----------------------------------------------------------------------------- + + signal reset_n : std_logic := '0'; + signal clk : std_logic := '0'; + signal init : std_logic; + signal pd_in : std_logic; + signal abs_position : std_logic_vector(31 downto 0); + signal dp_dir : std_logic; + signal pulse_out : std_logic; + signal filtered_pd : std_logic; + signal ch_pd : std_logic; + signal ch_mask : std_logic; + signal raw_pulse_out : std_logic; + signal avs_address : std_logic_vector(9 downto 0); + signal avs_write : std_logic; + signal avs_writedata : std_logic_vector(31 downto 0); + signal avs_read : std_logic; + signal avs_readdatavalid : std_logic; + signal avs_readdata : std_logic_vector(31 downto 0); + -- + signal avs_m : mm_m_rec_t; + signal avs_s : mm_s_rec_t; + -- + signal pd_in_cnt : integer; + signal pd_out_cnt : integer; + -- + signal test_completed : boolean; + signal setup : boolean; + signal running : boolean; + signal error_flag : boolean; + signal passed : boolean; + signal failed : boolean; + +begin -- architecture behav + + clk <= not clk after 0.5*CLK_PERIOD; + + ----------------------------------------------------------------------------- + -- UUT + ----------------------------------------------------------------------------- + + iUUT: entity work.pulse_generator_1 + generic map ( + pulse_delay_equal_en => true, + out_pulse_condition => true) + port map ( + clk => clk, + reset_n => reset_n, + init => init, + pd_in => pd_in, + abs_position => abs_position, + dp_dir => dp_dir, + pulse_out => pulse_out, + filtered_pd => filtered_pd, + ch_pd => ch_pd, + ch_mask => ch_mask, + raw_pulse_out => raw_pulse_out, + avs_address => avs_address, + avs_write => avs_write, + avs_writedata => avs_writedata, + avs_read => avs_read, + avs_readdatavalid => avs_readdatavalid, + avs_readdata => avs_readdata); + + ----------------------------------------------------------------------------- + -- Avalon interface + ----------------------------------------------------------------------------- + + clk_clk <= clk; + reset_reset_n <= reset_n; + + avs_s.mm_readdata <= avs_readdata; + + avs_s.mm_readdatavalid <= avs_readdatavalid; + + avs_s.mm_waitrequest <= '0'; + avs_s.use_readvalid <= true; + + avs_address <= avs_m.mm_address(avs_address'range); + avs_write <= avs_m.mm_write; + avs_writedata <= avs_m.mm_writedata; + avs_read <= avs_m.mm_read; + + pCNT_CH_PD : process(reset_n, clk) + begin + if(reset_n = '0') then + pd_out_cnt <= 0; + elsif(clk = '1' and clk'event) then + if(ch_pd = '1') then + pd_out_cnt <= pd_out_cnt + 1; + end if; + end if; + end process pCNT_CH_PD; + + ----------------------------------------------------------------------------- + -- Testbench Logic + ----------------------------------------------------------------------------- + + pTB_CTRL : process + + alias dp_dir is <>; + + procedure issue_pd(valid_pd : boolean := true) is + begin + + wait until clk = '1' and clk'event; + pd_in <= '1'; + wait until clk = '1' and clk'event; + pd_in <= '0'; + if(valid_pd = true) then + pd_in_cnt <= pd_in_cnt + 1; + end if; + + end procedure issue_pd; + + procedure check_pd is + begin + for i in 1 to 12 loop + wait until clk = '1' and clk'event; + end loop; -- i + if(pd_out_cnt /= pd_in_cnt) then + if(pd_out_cnt > pd_in_cnt) then + log("ERROR: Detected faulty Channel PD.", VLOW); + else + log("ERROR: Missing Channel PD.", VLOW); + end if; + error_flag <= true; + end if; + + end procedure check_pd; + + variable addr : std_logic_vector(31 downto 0) := (others => '0'); + variable data : std_logic_vector(31 downto 0) := (others => '0'); + + begin + + -- Set the verbosity level for logging + set_log_verbosity(VERBOSITY_LEVEL); + --set_log_verbosity(VHIGH); + + -- initilialize the Avalon master-bus + mm_m_init(avs_m); + + log_header("PD Jitter verification:", VLOW); + + setup <= false; + running <= false; + passed <= false; + error_flag <= false; + + init <= '0'; + pd_in <= '0'; + pd_in_cnt <= 0; + abs_position <= (others => '0'); + + -- Reset + reset_n <= '0'; + wait for 100 ns; + wait until clk = '1' and clk'event; + reset_n <= '1'; + + wait for 200 ns; + -- enable the pulse generator + addr := std_logic_vector(resize(unsigned(PULSE_GEN_CTRL_REG), 32)); + data := X"0000_0001"; + mm_32b_write(addr, data, avs_s, avs_m); + + --------------------------------------------------------------------------- + -- DP-DIR = '0' + --------------------------------------------------------------------------- + + log("DP-DIR = '0'", VLOW); + log_separator_line(VLOW); + + + dp_dir <= force '0'; + + wait for 200 ns; + wait until clk = '1' and clk'event; + init <= '1'; + wait until clk = '1' and clk'event; + wait until clk = '1' and clk'event; + wait until clk = '1' and clk'event; + init <= '0'; + wait for 200 ns; + wait until clk = '1' and clk'event; + + --------------------------------------------------------------------------- + -- DIR-0, Init Pos = 0 + --------------------------------------------------------------------------- + + log("Issueing PD on ABS_POS = 0", VLOW); + + for n in 0 to 9 loop + issue_pd; + check_pd; + wait_latency(clk, 10); + abs_position <= std_logic_vector(signed(abs_position)+ 1); + end loop; -- n + + log("Go back to ABS_POS = 0", VLOW); + for n in 0 to 9 loop + wait_latency(clk, 10); + abs_position <= std_logic_vector(signed(abs_position)- 1); + end loop; -- n + + log("Issueing again PD on ABS_POS = 0", VLOW); + for n in 0 to 9 loop + issue_pd(false); + check_pd; + wait_latency(clk, 10); + abs_position <= std_logic_vector(signed(abs_position)+ 1); + end loop; -- n + + for n in 0 to 9 loop + issue_pd; + check_pd; + wait_latency(clk, 10); + abs_position <= std_logic_vector(signed(abs_position)+ 1); + end loop; -- n + + wait for 1 us; + + + + + + + + wait for 20 us; + + running <= false; + passed <= true after 100 ns; + wait; + + end process pTB_CTRL; + + failed <= error_flag after 100 ns; + + pREPORT_RESULT : process + begin + wait until failed = true or passed = true; + wait for 1 us; + log_separator_line(VLOW); + if(failed = true) then + log("FAILURE: test completed with errors.", VLOW); + elsif(passed = true) then + log("SUCCESS: test successfully completed.", VLOW); + end if; + log_separator_line(VLOW); + test_completed <= true; + end process pREPORT_RESULT; + + +end architecture behav;