From 0e8151f3e1567c6154ba922b5683fdb71cdae944 Mon Sep 17 00:00:00 2001 From: gianmarcogirau Date: Fri, 8 Mar 2019 17:32:20 +0000 Subject: [PATCH 1/9] SMB-87 - Encoder Multiplier block - WIP (2): Basic behaviour looks good. Need to add velocity estimation block --- .../encoder_multiply/0/sim/sim_enc_mult.do | 12 +- .../encoder_multiply/0/sim/wave_enc_mult.do | 74 +++ .../0/src/encoder_multiply_0.vhd | 52 +- .../0/src/test/encoder_multiply_0_tb.vhd | 438 --------------- .../0/src/test/encoder_multiply_tb.vhd | 499 ++++++++++++++++++ 5 files changed, 606 insertions(+), 469 deletions(-) create mode 100644 generic_ip/encoder_multiply/0/sim/wave_enc_mult.do delete mode 100644 generic_ip/encoder_multiply/0/src/test/encoder_multiply_0_tb.vhd create mode 100644 generic_ip/encoder_multiply/0/src/test/encoder_multiply_tb.vhd 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 021ac83..bbb81c6 100644 --- a/generic_ip/encoder_multiply/0/sim/sim_enc_mult.do +++ b/generic_ip/encoder_multiply/0/sim/sim_enc_mult.do @@ -35,9 +35,9 @@ vcom -2008 -work $WORKLIB $COMMON_PATH/test/log_pkg.vhd vcom -2008 -work $WORKLIB $COMMON_PATH//test/avalon_verify_pkg.vhd # Compile the testbench -#vcom -2008 -work $WORKLIB ./../src/test/encoder_mulyiply_tb.vhd +vcom -2008 -work $WORKLIB ./../src/test/encoder_multiply_tb.vhd -#vsim -t ps work.encoder_multiply_tb +vsim -t ps work.encoder_multiply_tb #add wave /encoder_multiply_tb/* @@ -47,9 +47,9 @@ vcom -2008 -work $WORKLIB $COMMON_PATH//test/avalon_verify_pkg.vhd set StdArithNoWarnings 1 set NumericStdNoWarnings 1 -#do wave_enc_mult.do +do wave_enc_mult.do -#when -label end_of_simulation {test_completed == true} {echo "Simulation Completed"; stop ;} -#run -all +when -label end_of_simulation {test_completed == true} {echo "Simulation Completed"; stop ;} +run -all -#run 100 us; \ No newline at end of file +#run 3.0 ms; \ No newline at end of file diff --git a/generic_ip/encoder_multiply/0/sim/wave_enc_mult.do b/generic_ip/encoder_multiply/0/sim/wave_enc_mult.do new file mode 100644 index 0000000..e09b856 --- /dev/null +++ b/generic_ip/encoder_multiply/0/sim/wave_enc_mult.do @@ -0,0 +1,74 @@ +onerror {resume} +quietly WaveActivateNextPane {} 0 +add wave -noupdate /encoder_multiply_tb/reset_n +add wave -noupdate /encoder_multiply_tb/clk +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 /encoder_multiply_tb/step_pos_in +add wave -noupdate /encoder_multiply_tb/step_neg_in +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/m_abs_pos +add wave -noupdate /encoder_multiply_tb/m_abs_pos_r +add wave -noupdate /encoder_multiply_tb/setup +add wave -noupdate /encoder_multiply_tb/running +add wave -noupdate /encoder_multiply_tb/passed +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 /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 unsigned /encoder_multiply_tb/iUUT/kmax +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 /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 +TreeUpdate [SetDefaultTree] +WaveRestoreCursors {{Cursor 1} {1010975000 ps} 0} +quietly wave cursor active 1 +configure wave -namecolwidth 260 +configure wave -valuecolwidth 126 +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 {1181469471 ps} {1245234239 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 b09d9e4..adf265c 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-04 +-- Last update: 2019-03-08 -- SVN ID : Git -- Standard : VHDL'2008 ------------------------------------------------------------------------------- @@ -39,7 +39,7 @@ entity encoder_multiply is init : in std_logic; enable : in std_logic; mult_sel : in std_logic_vector( 2 downto 0); - delta_t : in std_logic_vector(47 downto 0); + delta_t : in std_logic_vector(39 downto 0); step_pos_in : in std_logic; step_neg_in : in std_logic; step_pos_out : out std_logic; @@ -66,23 +66,24 @@ architecture rtl of encoder_multiply is -- To prevent counter saturation, subtract a fixed amount each time the -- counters exceed a given value - constant NORM_VALUE : natural := 2**(PULSE_CNT_W-2); + constant NORM_VALUE : natural := 2**(PULSE_CNT_W-3); signal init_d, step_pos, step_neg : std_logic; signal m_step_pos, m_step_neg : std_logic; signal sign, sign_i : std_logic; - signal time_cnt_zero : 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 kickoff, pending_kickoff : std_logic; signal mult_val, kmax : 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 time_cnt : std_logic_vector(27 downto 0); - signal m_delta_t : std_logic_vector(38-MULT_W downto 0); - signal delta_t_i : std_logic_vector(38 downto 0); + signal m_delta_t : std_logic_vector(30 downto 0); + signal delta_t_i : std_logic_vector(30 downto 0); begin @@ -102,7 +103,13 @@ begin begin if(clk = '1' and clk'event) then init_d <= init; - kmax <= std_logic_vector(unsigned(mult_val)-1); + --kmax <= std_logic_vector(unsigned(mult_val)-1); + kmax <= (others => '0'); + if(init = '1') then + pending_kickoff <= '1'; + elsif(kickoff = '1') then + pending_kickoff <= '0'; + end if; if(init_d = '1') then pulse_cnt <= (others => '0'); elsif(step_pos = '1') then @@ -127,27 +134,17 @@ begin end if; if(m_step_pos = '1' or m_step_neg = '1') then time_cnt <= m_delta_t(27 downto 0); - elsif(time_cnt_zero = '0') then + elsif(time_cnt_tc = '0') then time_cnt <= std_logic_vector(unsigned(time_cnt)-1); end if; m_delta_t <= delta_t_i srl to_integer(unsigned(mult_sel)); sign <= sign_i; - mult_pulse_cnt := pulse_cnt sll to_integer(unsigned(mult_sel)); + 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_neg <= std_logic_vector(signed(mult_pulse_cnt) - signed(kmax)); step_pos_out <= m_step_pos; step_neg_out <= m_step_neg; - if(signed(pulse_cnt) = NORM_VALUE and norm_pos_d = '0') then - norm_pos <= '1'; - else - norm_pos <= '0'; - end if; norm_pos_d <= norm_pos; - if(signed(pulse_cnt) = -NORM_VALUE and norm_neg_d = '0') then - norm_neg <= '1'; - else - norm_neg <= '0'; - end if; norm_neg_d <= norm_neg; m_norm_value <= std_logic_vector(to_unsigned(NORM_VALUE, M_PULSE_CNT_W)) sll (to_integer(unsigned(mult_sel))); end if; @@ -156,12 +153,17 @@ begin step_pos <= step_pos_in and enable; step_neg <= step_neg_in and enable; - delta_t_i <= delta_t(46 downto 8); - sign_i <= delta_t(47); + delta_t_i <= delta_t(38 downto 8); + sign_i <= delta_t(39); - time_cnt_zero <= '1' when unsigned(time_cnt) = 0 else '0'; + time_cnt_tc <= '1' when unsigned(time_cnt) = 1 else '0'; - m_step_pos <= '1' when sign = '0' and time_cnt_zero = '1' and signed(m_pulse_cnt) < signed(delta_m_pos) else '0'; - m_step_neg <= '1' when sign = '1' and time_cnt_zero = '1' and signed(m_pulse_cnt) > signed(delta_m_pos) 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'; + + kickoff <= pending_kickoff and (step_pos or step_neg); + + norm_pos <= '1' when signed(pulse_cnt) = 2*NORM_VALUE and norm_pos_d = '0' else '0'; + norm_neg <= '1' when signed(pulse_cnt) = -2*NORM_VALUE and norm_neg_d = '0' else '0'; end architecture rtl; diff --git a/generic_ip/encoder_multiply/0/src/test/encoder_multiply_0_tb.vhd b/generic_ip/encoder_multiply/0/src/test/encoder_multiply_0_tb.vhd deleted file mode 100644 index 2aa1d2d..0000000 --- a/generic_ip/encoder_multiply/0/src/test/encoder_multiply_0_tb.vhd +++ /dev/null @@ -1,438 +0,0 @@ -------------------------------------------------------------------------------- --- Title : encoder_multiply_tb --- Project : EMB/SMB -------------------------------------------------------------------------------- --- File : encoder_multiply_tb.vhd --- Author : GMG --- Company : Global Inkjet Systems --- Created : 2019-03-05 --- Last update: 2019-03-05 --- SVN ID : Git --- Standard : VHDL'2008 -------------------------------------------------------------------------------- --- Description: --- Testbench for the encoder_multiply block -------------------------------------------------------------------------------- - -library ieee; -use ieee.std_logic_1164.all; -use ieee.numeric_std.all; -use ieee.math_real.all; - -library OSVVM; -use OSVVM.RandomBasePkg.all; -use OSVVM.RandomPkg.all; - -use work.log_pkg.all; - -entity encoder_multiply_tb is - -- .. -end entity encoder_multiply_tb; - -architecture behav of encoder_multiply_tb is - - constant CLK_PERIOD : time := 10 ns; - - -- Logging Verbosity Level - constant VERBOSITY_LEVEL : verb_level_t := VMEDIUM; - - constant MAX_DIST : natural := 10000; - - -- define the percentage of reverse steps, with respect to the intended - -- direction, while advancing the position: - -- 0 => no reverse movement at all - -- 20 => 20% of position increments are in the opposite dirtection - -- 49 => Essentially this is an oscillation around the centre position with a - -- tiny bias in the intended direction! - constant POS_RANDOM_PERC : natural range 0 to 49 := 0; -- define - - ----------------------------------------------------------------------------- - -- 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 test_completed : boolean; - signal configuring : boolean; - signal running : boolean; - signal passed : boolean; - signal failed : boolean; - -begin -- architecture behav - - clk <= not clk after 0.5*CLK_PERIOD; - - ----------------------------------------------------------------------------- - -- UUTs - ----------------------------------------------------------------------------- - - iUUT: entity work.encoder_multiply - port map ( - reset_n => reset_n, - clk => clk, - init => init, - enable => enable, - mult_sel => mult_sel, - delta_t => delta_t, - step_pos_in => step_pos_in, - step_neg_in => step_neg_in, - step_pos_out => step_pos_out, - step_neg_out => step_neg_out); - - ----------------------------------------------------------------------------- - -- Support Logic - ----------------------------------------------------------------------------- - - pGEN_POS : process(clk) - begin - if(clk = '1' and clk'event) then - if(init = '1') then - abs_pos <= (others => '0'); - elsif(step_pos_in = '1') then - abs_pos <= std_logic_vector(unsigned(abs_pos)+1); - elsif(step_neg_in = '1') then - abs_pos <= std_logic_vector(unsigned(abs_pos)-1); - end if; - if(init = '1') then - m_abs_pos <= (others => '0'); - elsif(step_pos_out = '1') then - m_abs_pos <= std_logic_vector(unsigned(m_abs_pos)+1); - elsif(step_neg_out = '1') then - m_abs_pos <= std_logic_vector(unsigned(m_abs_pos)-1); - end if; - end if; - end process pGEN_POS; - - ----------------------------------------------------------------------------- - -- Testbench Logic - ----------------------------------------------------------------------------- - - pTB_CTRL : process - variable delta_pos : integer := 0; - variable init_pos : integer; - variable dir_m : integer; - variable tot_steps : integer; - variable result : boolean; - variable test_idx : natural; - variable rv : RandomPType; - - procedure run_test is - variable steps : integer; - variable sel_dir : integer; - begin - log_header("Test-case " & to_string(test_idx), VMEDIUM); - wait_latency(clk, 1); - if dir = '0' then - dir_m := 1; - else - dir_m := -1; - end if; - init_pos := pos; - -- reset the absolute position memory - enable <= '0'; - upd_max_pos <= '0'; - upd_min_pos <= '0'; - wait_latency(clk, 1); - upd_max_pos <= '1'; - upd_min_pos <= '1'; - wait_latency(clk, 1); - upd_max_pos <= '0'; - upd_min_pos <= '0'; - -- restart the divider - wait_latency(clk, 1); - enable <= '1'; - wait_latency(clk, INTRA_POS_LATENCY); - -- run the steps - steps := 0; - loop_pos: while steps < tot_steps loop - wait_latency(clk, INTRA_POS_LATENCY); - /* - -- check the result and report - delta_pos := dir_m * (pos - init_pos); - result := check_result(div_ratio, pixel_offset, delta_pos, tot_fire_num, true); - exit loop_pos when result = false; - */ - sel_dir := rv.RandInt(1, 100); - if(sel_dir > POS_RANDOM_PERC) then - -- move in the intended direction - pos <= pos + dir_m; - steps := steps + 1; - else - -- move in the opposite direction - pos <= pos - dir_m; - steps := steps - 1; - end if; - end loop loop_pos; - -- wait the propagation of the latency - wait_latency(clk, INTRA_POS_LATENCY); - -- check the result and report - delta_pos := dir_m * (pos - init_pos); - if(result /= false) then - result := check_result(div_ratio, pixel_offset, delta_pos, tot_fire_num); - end if; - - log("div_ratio = " & to_string(div_ratio), VMEDIUM); - - end procedure run_test; - - begin - - -- Set the verbosity level for logging - set_log_verbosity(VERBOSITY_LEVEL); - --set_log_verbosity(VHIGH); - - log_header("Fractional Divider verification:", VLOW); - - test_completed <= false; - configuring <= false; - running <= false; - passed <= false; - failed <= false; - - enable <= '0'; - dir <= '1'; - - -- Reset - reset_n <= '0'; - wait for 100 ns; - wait until clk = '1' and clk'event; - reset_n <= '1'; - - result := true; - - test_idx := 0; - - --------------------------------------------------------------------------- - -- Test-00 - --------------------------------------------------------------------------- - if(result /= false) then - test_idx := test_idx+1; - div_ratio <= 4.000; - pixel_offset <= 0.0; - dir <= '0'; - tot_steps := 100000; - run_test; - end if; - - - --------------------------------------------------------------------------- - -- Test-01 - --------------------------------------------------------------------------- - if(result /= false) then - test_idx := test_idx+1; - div_ratio <= 1.001; - pixel_offset <= 0.0; - dir <= '0'; - tot_steps := 10000; - run_test; - end if; - - --------------------------------------------------------------------------- - -- Test-02 - --------------------------------------------------------------------------- - if(result /= false) then - test_idx := test_idx+1; - div_ratio <= 1.002; - pixel_offset <= 0.9; - dir <= '1'; - tot_steps := 10000; - run_test; - end if; - - --------------------------------------------------------------------------- - -- Test-03 - --------------------------------------------------------------------------- - if(result /= false) then - test_idx := test_idx+1; - div_ratio <= 1.333; - pixel_offset <= 1.5; - dir <= '0'; - tot_steps := 10000; - run_test; - end if; - - --------------------------------------------------------------------------- - -- Test-04 - --------------------------------------------------------------------------- - if(result /= false) then - test_idx := test_idx+1; - div_ratio <= 4.008; - pixel_offset <= 0.25; - dir <= '0'; - tot_steps := 10000; - run_test; - end if; - - --------------------------------------------------------------------------- - -- Test-05 - --------------------------------------------------------------------------- - if(result /= false) then - test_idx := test_idx+1; - div_ratio <= 4.000; - pixel_offset <= 0.0; - dir <= '0'; - tot_steps := 10000; - run_test; - end if; - - --------------------------------------------------------------------------- - -- Test-06 - --------------------------------------------------------------------------- - if(result /= false) then - test_idx := test_idx+1; - div_ratio <= 4.000; - pixel_offset <= 0.25; - dir <= '0'; - tot_steps := 10000; - run_test; - end if; - - --------------------------------------------------------------------------- - -- Test-07 - --------------------------------------------------------------------------- - if(result /= false) then - test_idx := test_idx+1; - div_ratio <= 4.000; - pixel_offset <= 0.5; - dir <= '0'; - tot_steps := 10000; - run_test; - end if; - - --------------------------------------------------------------------------- - -- Test-08 - --------------------------------------------------------------------------- - if(result /= false) then - test_idx := test_idx+1; - div_ratio <= 4.000; - pixel_offset <= 0.75; - dir <= '0'; - tot_steps := 10000; - run_test; - end if; - - --------------------------------------------------------------------------- - -- Test-09 - --------------------------------------------------------------------------- - if(result /= false) then - test_idx := test_idx+1; - div_ratio <= 4.000; - pixel_offset <= 1.0; - dir <= '0'; - tot_steps := 10000; - run_test; - end if; - - --------------------------------------------------------------------------- - -- Test-10 - --------------------------------------------------------------------------- - if(result /= false) then - test_idx := test_idx+1; - div_ratio <= 4.000; - pixel_offset <= 0.12; - dir <= '0'; - tot_steps := 10000; - run_test; - end if; - - --------------------------------------------------------------------------- - -- Test-11 - --------------------------------------------------------------------------- - if(result /= false) then - test_idx := test_idx+1; - div_ratio <= 4.000; - pixel_offset <= 0.13; - dir <= '0'; - tot_steps := 10000; - run_test; - end if; - - --------------------------------------------------------------------------- - -- Test-12 - --------------------------------------------------------------------------- - if(result /= false) then - test_idx := test_idx+1; - div_ratio <= 126.0; - pixel_offset <= 0.99; - dir <= '0'; - tot_steps := 10000; - run_test; - end if; - - --------------------------------------------------------------------------- - -- Test-13 - --------------------------------------------------------------------------- - if(result /= false) then - test_idx := test_idx+1; - div_ratio <= 126.0; - pixel_offset <= 0.0; - dir <= '0'; - tot_steps := 10000; - run_test; - end if; - - --------------------------------------------------------------------------- - -- Test-14 - Very long test to check internal-reg-saturation - --------------------------------------------------------------------------- - if(result /= false) then - test_idx := test_idx+1; - div_ratio <= 4.000; - pixel_offset <= 0.0; - dir <= '0'; - tot_steps := 100000; - run_test; - end if; - - --------------------------------------------------------------------------- - -- Random Tests - --------------------------------------------------------------------------- - - for n in 1 to 20 loop - if(result /= false) then - test_idx := test_idx+1; - -- the div_ratio fractional part must be a multiple of 0.001 - div_ratio <= 0.001*real(rv.RandInt(1000, 50000)); - if((rv.RandInt(1,10) mod 2) = 0) then - dir <= '0'; - else - dir <= '1'; - end if; - tot_steps := rv.RandInt(5000, 20000); - run_test; - end if; - end loop; -- n - - wait for 200 ns; - - log_separator_line(VLOW); - if(result = false) then - failed <= true; - log("FAILURE: test completed with errors.", VLOW); - else - passed <= true; - log("SUCCESS: test successfully completed.", VLOW); - end if; - log_separator_line(VLOW); - - test_completed <= true; - running <= false; - - wait; - - end process pTB_CTRL; - - -end architecture behav; 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 new file mode 100644 index 0000000..8ee2c57 --- /dev/null +++ b/generic_ip/encoder_multiply/0/src/test/encoder_multiply_tb.vhd @@ -0,0 +1,499 @@ +------------------------------------------------------------------------------- +-- Title : encoder_multiply_tb +-- Project : EMB/SMB +------------------------------------------------------------------------------- +-- File : encoder_multiply_tb.vhd +-- Author : GMG +-- Company : Global Inkjet Systems +-- Created : 2019-03-05 +-- Last update: 2019-03-08 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: +-- Testbench for the encoder_multiply block +------------------------------------------------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; +use ieee.math_real.all; + +library OSVVM; +use OSVVM.RandomBasePkg.all; +use OSVVM.RandomPkg.all; + +use work.log_pkg.all; + +entity encoder_multiply_tb is + -- .. +end entity encoder_multiply_tb; + +architecture behav of encoder_multiply_tb is + + constant CLK_PERIOD : time := 10 ns; + + -- Logging Verbosity Level + constant VERBOSITY_LEVEL : verb_level_t := VMEDIUM; + + constant MAX_SIM_TIME : time := 30.0 ms; -- Maximum simulation time + + constant MAX_DIST : natural := 1000; + + -- 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; + + -- define the percentage of reverse steps, with respect to the intended + -- direction, while advancing the position: + -- 0 => no reverse movement at all + -- 20 => 20% of position increments are in the opposite dirtection + -- 49 => Essentially this is an oscillation around the centre position with a + -- tiny bias in the intended direction! + constant POS_RANDOM_PERC : natural range 0 to 49 := 0; -- define + + ----------------------------------------------------------------------------- + -- Signal declarations + ----------------------------------------------------------------------------- + + signal reset_n : std_logic; + signal clk : std_logic := '0'; + signal init : std_logic; + signal enable : std_logic; + signal mult_sel : std_logic_vector(2 downto 0); + signal delta_t : std_logic_vector(39 downto 0); + signal step_pos_in : std_logic; + signal step_neg_in : std_logic; + signal step_pos_out : std_logic; + signal step_neg_out : std_logic; + -- + 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; + + -- TB specific signals + signal setup : boolean; + signal running : boolean; + signal passed : boolean := false; + signal failed : boolean := false; + signal test_timeout : boolean := false; + signal test_completed : boolean := false; + + signal error_flag : boolean := false; + + ----------------------------------------------------------------------------- + -- Subprograms + ----------------------------------------------------------------------------- + + procedure wait_clk_cycles(cycles : in natural) is + begin + for n in 0 to cycles-1 loop + wait until clk = '1' and clk'event; + end loop; -- n + end procedure wait_clk_cycles; + + ----------------------------------------------------------------------------- + -- Encoder Profile #1: fixed frequency + ----------------------------------------------------------------------------- + + procedure run_encoder_profile_1 ( + freq : in real range 1.0e3 to 4000.0e3; + dir : in std_logic; + max_steps : in natural; + 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 t_ref : time; + variable t_period : real; + + begin + + enable <= '0'; + step_pos <= '0'; + step_neg <= '0'; + + log("run_encoder_profile_1: Running " & to_string(max_steps) & " steps in direction " & to_string(dir) & ", at " & to_string(freq/1000.0) & " kHz ...", VMEDIUM); + + -- normalize to us + t_period := 1.0e6/freq; + + wait_clk_cycles(5); + + -- set the initial velocity estimation + if(init = true) then + delta_t(delta_t'left-1 downto 0) <= std_logic_vector(to_unsigned(DELTA_TMIN*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); + -- issue the first step + t_ref := now; + if(dir = '0') then + step_pos <= '1'; + else + step_neg <= '1'; + end if; + step_cnt := step_cnt + 1; + wait_clk_cycles(1); + step_pos <= '0'; + step_neg <= '0'; + + while step_cnt < max_steps loop + + if(now-t_ref > (1.0 us)*(real(step_cnt)*t_period)) then + wait until clk = '1' and clk'event; + -- issue the next step + delta_t(delta_t'left-1 downto 0) <= std_logic_vector(to_unsigned(integer(t_period*100.0*256.0), delta_t'left)); + delta_t(delta_t'left) <= dir; + if(dir = '0') then + step_pos <= '1'; + else + step_neg <= '1'; + end if; + step_cnt := step_cnt + 1; + wait_clk_cycles(1); + step_pos <= '0'; + step_neg <= '0'; + end if; + + wait for 0.1*CLK_PERIOD; + + end loop; + + wait_clk_cycles(0); + -- disable the multiplier + enable <= '0'; + + end procedure run_encoder_profile_1; + + ----------------------------------------------------------------------------- + -- Encoder Profile #2: average frequency + noise + ----------------------------------------------------------------------------- + + procedure run_encoder_profile_2 ( + 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 t_ref : time; + variable t_period : real; + variable rv : RandomPType; + variable delta_period : integer; + + + begin + + enable <= '0'; + step_pos <= '0'; + step_neg <= '0'; + + log("run_encoder_profile_2: Running " & to_string(max_steps) & " steps in direction " & to_string(dir) & ", at " & to_string(freq/1000.0) & " kHz ...", VMEDIUM); + + -- normalize to us + t_period := 1.0e6/freq; + + wait_clk_cycles(5); + + -- set the initial velocity estimation + if(init = true) then + delta_t(delta_t'left-1 downto 0) <= std_logic_vector(to_unsigned(DELTA_TMIN*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); + -- issue the first step + t_ref := now; + if(dir = '0') then + step_pos <= '1'; + else + step_neg <= '1'; + end if; + step_cnt := step_cnt + 1; + wait_clk_cycles(1); + step_pos <= '0'; + step_neg <= '0'; + + delta_period := 0; + while step_cnt < max_steps loop + + if(now-t_ref > (1.0 us)*((real(step_cnt-1)+((100.0+real(delta_period))/100.0))*t_period)) then + wait until clk = '1' and clk'event; + -- issue the next step + delta_t(delta_t'left-1 downto 0) <= std_logic_vector(to_unsigned(integer(t_period*100.0*256.0), delta_t'left)); + delta_t(delta_t'left) <= dir; + if(dir = '0') then + step_pos <= '1'; + else + step_neg <= '1'; + end if; + step_cnt := step_cnt + 1; + wait_clk_cycles(1); + step_pos <= '0'; + step_neg <= '0'; + delta_period := rv.RandInt(-period_noise, period_noise); + end if; + + wait for 0.1*CLK_PERIOD; + + end loop; + + wait_clk_cycles(0); + -- disable the multiplier + enable <= '0'; + + end procedure run_encoder_profile_2; + +begin -- architecture behav + + clk <= not clk after 0.5*CLK_PERIOD; + + ----------------------------------------------------------------------------- + -- UUTs + ----------------------------------------------------------------------------- + + iUUT: entity work.encoder_multiply + port map ( + reset_n => reset_n, + clk => clk, + init => init, + enable => enable, + mult_sel => mult_sel, + delta_t => delta_t, + step_pos_in => step_pos_in, + step_neg_in => step_neg_in, + step_pos_out => step_pos_out, + step_neg_out => step_neg_out); + + ----------------------------------------------------------------------------- + -- Support Logic + ----------------------------------------------------------------------------- + + pGEN_POS : process(clk) + variable mult_value : integer; + begin + if(clk = '1' and clk'event) then + if(init = '1') then + abs_pos <= (others => '0'); + elsif(step_pos_in = '1') then + abs_pos <= std_logic_vector(unsigned(abs_pos)+1); + elsif(step_neg_in = '1') then + abs_pos <= std_logic_vector(unsigned(abs_pos)-1); + end if; + if(init = '1') then + m_abs_pos <= (others => '0'); + elsif(step_pos_out = '1') then + m_abs_pos <= std_logic_vector(unsigned(m_abs_pos)+1); + 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); + end if; + end process pGEN_POS; + + ----------------------------------------------------------------------------- + -- Testbench Logic + ----------------------------------------------------------------------------- + + pTEST_PROC : process + + variable period_variance : natural := 20; + + begin + + --------------------------------------------------------------------------- + -- Initialize & Configure + --------------------------------------------------------------------------- + + reset_n <= '0'; + init <= '0'; + enable <= '0'; + mult_sel <= (others => '0'); + + delta_t <= (others => '0'); + step_pos_in <= '0'; + step_neg_in <= '0'; + + setup <= false; + running <= false; + + --Set the verbosity level for logging + set_log_verbosity(VERBOSITY_LEVEL); + -- + wait for 100 ns; + reset_n <= '1'; + + wait for 100 ns; + wait until clk = '1' and clk'event; + + -- Nothing really to do here + setup <= true; + + --------------------------------------------------------------------------- + -- Running + --------------------------------------------------------------------------- + + running <= true; + log_separator_line(VLOW); + log("Encoder-Multiply verification:", VLOW); + log_separator_line(VLOW); + + wait_clk_cycles(10); + + wait until clk = '1' and clk'event; + mult_sel <= "011"; + -- assert init to provide a clean configuration + init <= '1'; + wait until clk = '1' and clk'event; + init <= '0'; + log("Encoder-Multiplication set to 8", VLOW); + + wait_clk_cycles(10); + + /* + log_separator_line(VLOW); + 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; + run_encoder_profile_1(100.0e3, '0', 25, enable, delta_t, step_pos_in, step_neg_in); + wait for 50 us; + run_encoder_profile_1(100.0e3, '0', 25, enable, delta_t, step_pos_in, step_neg_in); + wait for 50 us; + run_encoder_profile_1(100.0e3, '1', 25, enable, delta_t, step_pos_in, step_neg_in); + wait for 50 us; + run_encoder_profile_1(100.0e3, '0', 1, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_1(100.0e3, '0', 1, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_1(100.0e3, '0', 1, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_1(100.0e3, '1', 1, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_1(100.0e3, '0', 1, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_1(100.0e3, '1', 1, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_1(100.0e3, '0', 1, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_1(100.0e3, '1', 3, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_1(100.0e3, '0', 125, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_1(100.0e3, '1', 250, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_1(100.0e3, '0', 150, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_1(100.0e3, '0', 500, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_1(100.0e3, '1', 1000, enable, delta_t, step_pos_in, step_neg_in); + wait for 100 us; + */ + + period_variance := 30; + log_separator_line(VLOW); + 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; + run_encoder_profile_2(100.0e3, '0', 25, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 50 us; + run_encoder_profile_2(100.0e3, '0', 25, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 50 us; + run_encoder_profile_2(100.0e3, '1', 25, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 50 us; + run_encoder_profile_2(100.0e3, '0', 1, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_2(100.0e3, '0', 1, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_2(100.0e3, '0', 1, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_2(100.0e3, '1', 1, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_2(100.0e3, '0', 1, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_2(100.0e3, '1', 1, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_2(100.0e3, '0', 1, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_2(100.0e3, '1', 3, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_2(100.0e3, '0', 125, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_2(100.0e3, '1', 250, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_2(100.0e3, '0', 150, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_2(100.0e3, '0', 500, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + run_encoder_profile_2(100.0e3, '1', 1000, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 100 us; + + --------------------------------------------------------------------------- + -- End + --------------------------------------------------------------------------- + + passed <= true after 1 us; + wait; + + end process pTEST_PROC; + + 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)))+2.0) or (m_abs_pos_r < real(to_integer(signed(abs_pos)))-2.0)) then + error_flag <= true; + end if; + end if; + end process pERROR_DETECT; + + failed <= error_flag after 100 ns; + + CHECK_SIM_TIMEOUT: process + begin -- process CHECK_SIM_TIMEOUT + while now < MAX_SIM_TIME loop + wait for 100 us; + end loop; + test_timeout <= true; + wait; + end process CHECK_SIM_TIMEOUT; + + pREPORT_RESULT : process + begin + wait until failed = true or passed = true or test_timeout = 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); + elsif(test_timeout = true) then + log("FAILURE: test achieved max-sim-time without reaching ", VLOW); + log(" failed/passed condition.", VLOW); + end if; + log_separator_line(VLOW); + test_completed <= true; + end process pREPORT_RESULT; + +end architecture behav; From e6b1151b787a4d7174b828b80ebd00198784e1c6 Mon Sep 17 00:00:00 2001 From: gianmarcogirau Date: Tue, 12 Mar 2019 14:51:11 +0000 Subject: [PATCH 2/9] SMB-87 - Encoder Multiplier block - WIP (3): Improved Testbench, Fixed a couple of issues. Need to add velocity estimation block --- generic_ip/encoder_multiply/0/sim/run_sim.py | 120 +++++++ .../encoder_multiply/0/sim/sim_enc_mult.do | 8 + .../encoder_multiply/0/sim/wave_enc_mult.do | 14 +- .../0/src/encoder_multiply_0.vhd | 57 ++- .../0/src/test/encoder_multiply_tb.vhd | 325 ++++++++++++------ 5 files changed, 389 insertions(+), 135 deletions(-) create mode 100644 generic_ip/encoder_multiply/0/sim/run_sim.py diff --git a/generic_ip/encoder_multiply/0/sim/run_sim.py b/generic_ip/encoder_multiply/0/sim/run_sim.py new file mode 100644 index 0000000..ba4b9ff --- /dev/null +++ b/generic_ip/encoder_multiply/0/sim/run_sim.py @@ -0,0 +1,120 @@ +##///////////////////////////////////////////////////////////////////////////// +## Title : Run Simulation script +##///////////////////////////////////////////////////////////////////////////// +## File : run_sim.py +## Author : Gianmarco Girau +## Company : GIS +## Target : Re-usable across multiple projects with minor customizations +## Dependency : none +##///////////////////////////////////////////////////////////////////////////// +## Description: Script for running in Jenkins custom ModelSim testbenches +##///////////////////////////////////////////////////////////////////////////// +## Last update: 2017-09-26 +##///////////////////////////////////////////////////////////////////////////// +## Revisions : +## Date Version Author Description +## 2017-09-26 01.00.0a gmg Created +##///////////////////////////////////////////////////////////////////////////// + +import os, sys, subprocess + +##///////////////////////////////////////////////////////////////////////////// +## Check Simulation Results +##///////////////////////////////////////////////////////////////////////////// + +def check_result(logfile): + searchfile = open(logfile, "r") + ok = 0 + for line in searchfile: + if "SUCCESS" in line: + print("/////////////////////////////////////////////////////////////////////////////") + print('TEST SUCCESSFUL') + print("/////////////////////////////////////////////////////////////////////////////") + ok = 1 + break + if "FAILURE" in line: + print("/////////////////////////////////////////////////////////////////////////////") + print('TEST FAILED') + print("/////////////////////////////////////////////////////////////////////////////") + break + + searchfile.close() + if ok == 0: + sys.exit(1) + +##///////////////////////////////////////////////////////////////////////////// +## Run Modelsim Simulation script +##///////////////////////////////////////////////////////////////////////////// + +def run_msim_script(sim_job, cmd_line_mode = 1): + + # create a copy of the do file, edit the copy as necessary + orig_do_file = "./{0}.do".format(sim_job) + + print("/////////////////////////////////////////////////////////////////////////////") + print("Running {0} ...".format(orig_do_file)) + print("/////////////////////////////////////////////////////////////////////////////") + + + + + if os.path.isfile(orig_do_file) == False: + print("ERROR: Cannot find do file " + orig_do_file) + sys.exit(1) + + do_file = "./{0}_tmp.do".format(sim_job) + orig_do_file_cnt = open(orig_do_file , "r") + do_file_cnt = open(do_file, "w") + + # Remove command ".main clear" in cmd line mode + for line in orig_do_file_cnt: + if cmd_line_mode == 1 and line.strip() == ".main clear": + do_file_cnt.write("#.main clear\n") + elif cmd_line_mode == 1 and line.find("do wave_") != -1: + do_file_cnt.write("#" + line) + else: + do_file_cnt.write(line) + + # manually add commands to exit from modelsim at the end of simulation + if cmd_line_mode == 1: + do_file_cnt.write("\n") + do_file_cnt.write("quit -sim; quit -f\n") + + orig_do_file_cnt.close() + do_file_cnt.close() + + log_file = "./{0}.log".format(sim_job) + + vsim_cmd = os.environ['QUARTUS_ROOTDIR']+"\\..\\modelsim_ase\\win32aloem\\vsim" + + if cmd_line_mode == 1: + cmd_opt = "-c" + else: + cmd_opt = "" + sub_call = "{0} {1} -l {2} -do {3}".format(vsim_cmd, cmd_opt, log_file, do_file) + subprocess.call(sub_call) + + ''' + if cmd_line_mode == 1: + # Run in command line mode + subprocess.call([vsim_cmd, "-c", "-l", log_file, "-do", do_file]) + else: + # Run in GUI mode + subprocess.call([os.environ['QUARTUS_ROOTDIR']+"\\..\\modelsim_ase\\win32aloem\\vsim", + "-do", do_file, "-l", log_file]) + ''' + + # remove the local copy of the do file + os.remove(do_file) + + check_result(log_file) + +##///////////////////////////////////////////////////////////////////////////// +## Execute Simulation Scripts +##///////////////////////////////////////////////////////////////////////////// + +if __name__ == "__main__": + + print("Running Generic-Sequencer testbench ...") + run_msim_script("sim_enc_mult", 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 bbb81c6..5e75254 100644 --- a/generic_ip/encoder_multiply/0/sim/sim_enc_mult.do +++ b/generic_ip/encoder_multiply/0/sim/sim_enc_mult.do @@ -39,6 +39,14 @@ vcom -2008 -work $WORKLIB ./../src/test/encoder_multiply_tb.vhd vsim -t ps work.encoder_multiply_tb +if { $argc == 0 } { + puts "Running default generic!" + vsim -t ps work.encoder_multiply_tb +} else { + puts "Running custom generic ($1)" + vsim -t ps work.encoder_multiply_tb -GMULT_SELECTION=$1 +} + #add wave /encoder_multiply_tb/* #add wave /encoder_multiply_tb/iUUT/* 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 e09b856..d6c420c 100644 --- a/generic_ip/encoder_multiply/0/sim/wave_enc_mult.do +++ b/generic_ip/encoder_multiply/0/sim/wave_enc_mult.do @@ -6,6 +6,8 @@ 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 /encoder_multiply_tb/step_pos_in add wave -noupdate /encoder_multiply_tb/step_neg_in add wave -noupdate /encoder_multiply_tb/step_pos_out @@ -26,6 +28,8 @@ 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 @@ -45,17 +49,17 @@ 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 unsigned /encoder_multiply_tb/iUUT/kmax 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_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 TreeUpdate [SetDefaultTree] -WaveRestoreCursors {{Cursor 1} {1010975000 ps} 0} +WaveRestoreCursors {{Cursor 1} {2606443 ps} 0} quietly wave cursor active 1 configure wave -namecolwidth 260 configure wave -valuecolwidth 126 @@ -71,4 +75,4 @@ configure wave -griddelta 40 configure wave -timeline 0 configure wave -timelineunits ps update -WaveRestoreZoom {1181469471 ps} {1245234239 ps} +WaveRestoreZoom {0 ps} {63764768 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 adf265c..c60279e 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-08 +-- Last update: 2019-03-12 -- SVN ID : Git -- Standard : VHDL'2008 ------------------------------------------------------------------------------- @@ -34,16 +34,18 @@ use ieee.numeric_std.all; entity encoder_multiply is port( - reset_n : in std_logic; - clk : in std_logic; - init : in std_logic; - enable : in std_logic; - mult_sel : in std_logic_vector( 2 downto 0); - delta_t : in std_logic_vector(39 downto 0); - step_pos_in : in std_logic; - step_neg_in : in std_logic; - step_pos_out : out std_logic; - step_neg_out : out std_logic); + reset_n : in std_logic; + clk : in std_logic; + init : in std_logic; + 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; + step_neg_out : out std_logic); end encoder_multiply; architecture rtl of encoder_multiply is @@ -77,10 +79,12 @@ architecture rtl of encoder_multiply 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 mult_val, kmax : std_logic_vector(MULT_W-1 downto 0); + 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_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); signal delta_t_i : std_logic_vector(30 downto 0); @@ -88,23 +92,32 @@ architecture rtl of encoder_multiply 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'); + --kmax <= (others => '0'); if(init = '1') then pending_kickoff <= '1'; elsif(kickoff = '1') then @@ -140,8 +153,9 @@ 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_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; norm_pos_d <= norm_pos; @@ -158,12 +172,17 @@ 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_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'; kickoff <= pending_kickoff and (step_pos or step_neg); - norm_pos <= '1' when signed(pulse_cnt) = 2*NORM_VALUE and norm_pos_d = '0' else '0'; - norm_neg <= '1' when signed(pulse_cnt) = -2*NORM_VALUE and norm_neg_d = '0' 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'; 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 8ee2c57..5de07b5 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-08 +-- Last update: 2019-03-12 -- SVN ID : Git -- Standard : VHDL'2008 ------------------------------------------------------------------------------- @@ -26,6 +26,9 @@ use OSVVM.RandomPkg.all; use work.log_pkg.all; entity encoder_multiply_tb is + generic( + + MULT_SELECTION : integer range 0 to 7 := 0); -- .. end entity encoder_multiply_tb; @@ -36,9 +39,9 @@ architecture behav of encoder_multiply_tb is -- Logging Verbosity Level constant VERBOSITY_LEVEL : verb_level_t := VMEDIUM; - constant MAX_SIM_TIME : time := 30.0 ms; -- Maximum simulation time + constant MAX_SIM_TIME : time := 40.0 ms; -- Maximum simulation time - constant MAX_DIST : natural := 1000; + constant RUN_TEST : integer_vector(0 to 2) := (0, 1, 0); -- delta_tmin : minimum value of delta_t, corresponding to the maximum tx -- rate over the POF (4M events/sec => 250 ns) @@ -56,16 +59,18 @@ architecture behav of encoder_multiply_tb is -- Signal declarations ----------------------------------------------------------------------------- - signal reset_n : std_logic; - signal clk : std_logic := '0'; - signal init : std_logic; - signal enable : std_logic; - signal mult_sel : std_logic_vector(2 downto 0); - signal delta_t : std_logic_vector(39 downto 0); - signal step_pos_in : std_logic; - signal step_neg_in : std_logic; - signal step_pos_out : std_logic; - signal step_neg_out : std_logic; + signal reset_n : std_logic; + signal clk : std_logic := '0'; + signal init : std_logic; + 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 step_pos_in : std_logic; + signal step_neg_in : std_logic; + signal step_pos_out : std_logic; + signal step_neg_out : std_logic; -- signal abs_pos : std_logic_vector(31 downto 0); signal m_abs_pos : std_logic_vector(39 downto 0); @@ -79,7 +84,7 @@ architecture behav of encoder_multiply_tb is signal test_timeout : boolean := false; signal test_completed : boolean := false; - signal error_flag : boolean := false; + shared variable error_flag : boolean := false; ----------------------------------------------------------------------------- -- Subprograms @@ -92,6 +97,20 @@ architecture behav of encoder_multiply_tb is end loop; -- n end procedure wait_clk_cycles; + ----------------------------------------------------------------------------- + -- Check Pos + ----------------------------------------------------------------------------- + + procedure check_pos 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; + end if; + + end procedure check_pos; + + ----------------------------------------------------------------------------- -- Encoder Profile #1: fixed frequency ----------------------------------------------------------------------------- @@ -106,12 +125,17 @@ architecture behav of encoder_multiply_tb is signal step_neg : out std_logic; init : in boolean := false) is - variable step_cnt : natural := 0; - variable t_ref : time; - variable t_period : real; + 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 + if(error_flag = true) then + return; + end if; + enable <= '0'; step_pos <= '0'; step_neg <= '0'; @@ -125,7 +149,18 @@ 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(DELTA_TMIN*256, 39)); + 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; + */ 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; @@ -194,10 +229,15 @@ architecture behav of encoder_multiply_tb is 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))); begin + if(error_flag = true) then + return; + end if; + enable <= '0'; step_pos <= '0'; step_neg <= '0'; @@ -211,7 +251,18 @@ 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(DELTA_TMIN*256, 39)); + 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; + */ 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; @@ -270,18 +321,20 @@ begin -- architecture behav -- UUTs ----------------------------------------------------------------------------- - iUUT: entity work.encoder_multiply + iUUT : entity work.encoder_multiply port map ( - reset_n => reset_n, - clk => clk, - init => init, - enable => enable, - mult_sel => mult_sel, - delta_t => delta_t, - step_pos_in => step_pos_in, - step_neg_in => step_neg_in, - step_pos_out => step_pos_out, - step_neg_out => step_neg_out); + 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, + step_pos_out => step_pos_out, + step_neg_out => step_neg_out); ----------------------------------------------------------------------------- -- Support Logic @@ -317,7 +370,8 @@ begin -- architecture behav pTEST_PROC : process - variable period_variance : natural := 20; + 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 @@ -330,6 +384,8 @@ begin -- architecture behav enable <= '0'; mult_sel <= (others => '0'); + kmax <= 5x"8"; + delta_t <= (others => '0'); step_pos_in <= '0'; step_neg_in <= '0'; @@ -361,99 +417,146 @@ begin -- architecture behav wait_clk_cycles(10); wait until clk = '1' and clk'event; - mult_sel <= "011"; + mult_sel <= std_logic_vector(to_unsigned(MULT_SELECTION, 3)); -- assert init to provide a clean configuration init <= '1'; wait until clk = '1' and clk'event; init <= '0'; - log("Encoder-Multiplication set to 8", VLOW); + log("Encoder-Multiplication set to " & to_string(mult_value) & "." , VLOW); wait_clk_cycles(10); - /* - log_separator_line(VLOW); - 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; - run_encoder_profile_1(100.0e3, '0', 25, enable, delta_t, step_pos_in, step_neg_in); - wait for 50 us; - run_encoder_profile_1(100.0e3, '0', 25, enable, delta_t, step_pos_in, step_neg_in); - wait for 50 us; - run_encoder_profile_1(100.0e3, '1', 25, enable, delta_t, step_pos_in, step_neg_in); - wait for 50 us; - run_encoder_profile_1(100.0e3, '0', 1, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_1(100.0e3, '0', 1, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_1(100.0e3, '0', 1, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_1(100.0e3, '1', 1, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_1(100.0e3, '0', 1, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_1(100.0e3, '1', 1, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_1(100.0e3, '0', 1, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_1(100.0e3, '1', 3, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_1(100.0e3, '0', 125, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_1(100.0e3, '1', 250, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_1(100.0e3, '0', 150, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_1(100.0e3, '0', 500, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_1(100.0e3, '1', 1000, enable, delta_t, step_pos_in, step_neg_in); - wait for 100 us; - */ + if(RUN_TEST(0) = 1) then + log_separator_line(VLOW); + 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; + check_pos; + run_encoder_profile_1(100.0e3, '0', 25, enable, delta_t, step_pos_in, step_neg_in); + wait for 50 us; + check_pos; + run_encoder_profile_1(100.0e3, '0', 25, enable, delta_t, step_pos_in, step_neg_in); + wait for 50 us; + check_pos; + run_encoder_profile_1(100.0e3, '1', 25, enable, delta_t, step_pos_in, step_neg_in); + wait for 50 us; + check_pos; + run_encoder_profile_1(100.0e3, '0', 1, enable, delta_t, step_pos_in, step_neg_in); + 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; + check_pos; + run_encoder_profile_1(100.0e3, '0', 1, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + check_pos; + run_encoder_profile_1(100.0e3, '1', 1, enable, delta_t, step_pos_in, step_neg_in); + 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; + check_pos; + run_encoder_profile_1(100.0e3, '1', 1, enable, delta_t, step_pos_in, step_neg_in); + 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; + check_pos; + run_encoder_profile_1(100.0e3, '1', 3, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + check_pos; + run_encoder_profile_1(100.0e3, '0', 125, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + check_pos; + run_encoder_profile_1(100.0e3, '1', 250, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + check_pos; + run_encoder_profile_1(100.0e3, '0', 150, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + check_pos; + run_encoder_profile_1(100.0e3, '0', 500, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + check_pos; + run_encoder_profile_1(100.0e3, '1', 1000, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + 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; + end if; - period_variance := 30; + period_variance := 45; log_separator_line(VLOW); - 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; - run_encoder_profile_2(100.0e3, '0', 25, period_variance, enable, delta_t, step_pos_in, step_neg_in); - wait for 50 us; - run_encoder_profile_2(100.0e3, '0', 25, period_variance, enable, delta_t, step_pos_in, step_neg_in); - wait for 50 us; - run_encoder_profile_2(100.0e3, '1', 25, period_variance, enable, delta_t, step_pos_in, step_neg_in); - wait for 50 us; - run_encoder_profile_2(100.0e3, '0', 1, period_variance, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_2(100.0e3, '0', 1, period_variance, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_2(100.0e3, '0', 1, period_variance, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_2(100.0e3, '1', 1, period_variance, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_2(100.0e3, '0', 1, period_variance, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_2(100.0e3, '1', 1, period_variance, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_2(100.0e3, '0', 1, period_variance, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_2(100.0e3, '1', 3, period_variance, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_2(100.0e3, '0', 125, period_variance, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_2(100.0e3, '1', 250, period_variance, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_2(100.0e3, '0', 150, period_variance, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_2(100.0e3, '0', 500, period_variance, enable, delta_t, step_pos_in, step_neg_in); - wait for 20 us; - run_encoder_profile_2(100.0e3, '1', 1000, period_variance, enable, delta_t, step_pos_in, step_neg_in); - wait for 100 us; + + if(RUN_TEST(1) = 1) then + 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; + 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; + 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; + 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; + 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; + 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; + 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; + check_pos; + run_encoder_profile_2(100.0e3, '1', 1, period_variance, enable, delta_t, step_pos_in, step_neg_in); + 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; + check_pos; + run_encoder_profile_2(100.0e3, '1', 1, period_variance, enable, delta_t, step_pos_in, step_neg_in); + 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; + check_pos; + run_encoder_profile_2(100.0e3, '1', 3, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + check_pos; + run_encoder_profile_2(100.0e3, '0', 125, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + check_pos; + run_encoder_profile_2(100.0e3, '1', 250, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + check_pos; + run_encoder_profile_2(100.0e3, '0', 150, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + check_pos; + run_encoder_profile_2(100.0e3, '0', 500, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + check_pos; + run_encoder_profile_2(100.0e3, '1', 1000, period_variance, enable, delta_t, step_pos_in, step_neg_in); + wait for 20 us; + 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; + end if; --------------------------------------------------------------------------- -- End --------------------------------------------------------------------------- - passed <= true after 1 us; + running <= false; + wait for 10 us; + if(error_flag = false) then + passed <= true; + end if; wait; end process pTEST_PROC; @@ -463,7 +566,7 @@ begin -- architecture behav 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 - error_flag <= true; + error_flag := true; end if; end if; end process pERROR_DETECT; From bc64c2a6082dc3d166f3e5dcc7fd3087d74bfe24 Mon Sep 17 00:00:00 2001 From: gianmarcogirau Date: Tue, 19 Mar 2019 10:20:48 +0000 Subject: [PATCH 3/9] SMB-87 - Encoder Multiplier block - Speed detection block seems to work --- generic_ip/common/0/src/dpram_sclk.vhd | 74 +++ .../encoder_multiply/0/sim/sim_enc_mult.do | 2 - .../0/sim/sim_speed_detect.do | 65 +++ .../0/src/encoder_multiply_0.vhd | 6 +- .../0/src/encoder_speed_detect_0.vhd | 215 ++++++++ .../encoder_multiply/0/src/intel/divider.vhd | 140 +++++ .../0/src/test/encoder_multiply_tb.vhd | 2 +- .../0/src/test/encoder_speed_detect_tb.vhd | 484 ++++++++++++++++++ 8 files changed, 982 insertions(+), 6 deletions(-) create mode 100644 generic_ip/common/0/src/dpram_sclk.vhd create mode 100644 generic_ip/encoder_multiply/0/sim/sim_speed_detect.do create mode 100644 generic_ip/encoder_multiply/0/src/encoder_speed_detect_0.vhd create mode 100644 generic_ip/encoder_multiply/0/src/intel/divider.vhd create mode 100644 generic_ip/encoder_multiply/0/src/test/encoder_speed_detect_tb.vhd diff --git a/generic_ip/common/0/src/dpram_sclk.vhd b/generic_ip/common/0/src/dpram_sclk.vhd new file mode 100644 index 0000000..0ae1912 --- /dev/null +++ b/generic_ip/common/0/src/dpram_sclk.vhd @@ -0,0 +1,74 @@ +------------------------------------------------------------------------------- +-- Title : dpram_sclk +-- Project : Dual-Port, single clock RAM +------------------------------------------------------------------------------- +-- File : dpram_sclk.vhd +-- Author : GMG +-- Company : Global Inkjet Systems +-- Created : 2018-04-24 +-- Last update: 2019-03-12 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: +-- True Dual-Port, single clock RAM +------------------------------------------------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +use work.common_pkg.all; + +entity dpram_sclk is + generic( + WIDTH : natural := 32; + DEPTH : natural := 256); + port( + clk : in std_logic; + -- Port-A + addr_a : in std_logic_vector(log2(DEPTH)-1 downto 0); + we_a : in std_logic := '1'; + data_a : in std_logic_vector(WIDTH-1 downto 0); + q_a : out std_logic_vector(WIDTH-1 downto 0); + -- Port-B + addr_b : in std_logic_vector(log2(DEPTH)-1 downto 0); + we_b : in std_logic := '1'; + data_b : in std_logic_vector(WIDTH-1 downto 0); + q_b : out std_logic_vector(WIDTH-1 downto 0)); +end dpram_sclk; + +architecture rtl of dpram_sclk is + + -- Build a 2-D array type for the RAM + subtype word_t is std_logic_vector(WIDTH-1 downto 0); + type memory_t is array(DEPTH-1 downto 0) of word_t; + + -- Declare the RAM + shared variable ram : memory_t; + +begin + + -- Port A + pPORT_A : process(clk) + begin + if(clk = '1' and clk'event) then + if(we_a = '1') then + ram(to_integer(unsigned(addr_a))) := data_a; + end if; + q_a <= ram(to_integer(unsigned(addr_a))); + end if; + end process pPORT_A; + + -- Port B + pPORT_B : process(clk) + begin + if(clk = '1' and clk'event) then + if(we_b = '1') then + ram(to_integer(unsigned(addr_b))) := data_b; + end if; + q_b <= ram(to_integer(unsigned(addr_b))); + end if; + end process pPORT_B; + +end rtl; 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 5e75254..215fd64 100644 --- a/generic_ip/encoder_multiply/0/sim/sim_enc_mult.do +++ b/generic_ip/encoder_multiply/0/sim/sim_enc_mult.do @@ -37,8 +37,6 @@ vcom -2008 -work $WORKLIB $COMMON_PATH//test/avalon_verify_pkg.vhd # Compile the testbench vcom -2008 -work $WORKLIB ./../src/test/encoder_multiply_tb.vhd -vsim -t ps work.encoder_multiply_tb - if { $argc == 0 } { puts "Running default generic!" vsim -t ps work.encoder_multiply_tb diff --git a/generic_ip/encoder_multiply/0/sim/sim_speed_detect.do b/generic_ip/encoder_multiply/0/sim/sim_speed_detect.do new file mode 100644 index 0000000..d4b0bbf --- /dev/null +++ b/generic_ip/encoder_multiply/0/sim/sim_speed_detect.do @@ -0,0 +1,65 @@ +# Simulation macro + +#.main clear + +# Cleanup libraries +foreach lib [list work OSVVM] { + file delete -force -- $lib + vlib $lib +} + +set OSVVM_PATH ../../../common/0/src/test/OSVVM +set COMMON_PATH ../../../common/0/src + +set WORKLIB work + +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 + +# Compile the constrained random related packages +vlib OSVVM +vcom -2008 -work OSVVM \ + $OSVVM_PATH/RandomBasePkg.vhd \ + $OSVVM_PATH/SortListPkg_int.vhd \ + $OSVVM_PATH/RandomPkg.vhd \ + $OSVVM_PATH/NamePkg.vhd \ + $OSVVM_PATH/MessagePkg.vhd \ + $OSVVM_PATH/CoveragePkg.vhd + +# Compile support files +vcom -2008 -work $WORKLIB $COMMON_PATH/test/common_test_pkg.vhd +vcom -2008 -work $WORKLIB $COMMON_PATH/test/log_pkg.vhd +vcom -2008 -work $WORKLIB $COMMON_PATH//test/avalon_verify_pkg.vhd + +# Compile the testbench +vcom -2008 -work $WORKLIB ./../src/test/encoder_speed_detect_tb.vhd + +if { $argc == 0 } { + puts "Running default generic!" + vsim -t ps work.encoder_speed_detect_tb +} else { + puts "Running custom generic ($1)" + vsim -t ps work.encoder_speed_detect_tb -GMULT_SELECTION=$1 +} + + +#add wave /encoder_speed_detect_tb/* +#add wave /encoder_speed_detect_tb/iUUT/* + +# remove warnings from standard numeric/arithmetic packages (speed-up simulation) +set StdArithNoWarnings 1 +set NumericStdNoWarnings 1 + +do wave_enc_speed_detect.do + +when -label end_of_simulation {test_completed == true} {echo "Simulation Completed"; stop ;} +run -all + +#run 3.0 ms; + 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 c60279e..c799b77 100644 --- a/generic_ip/encoder_multiply/0/src/encoder_multiply_0.vhd +++ b/generic_ip/encoder_multiply/0/src/encoder_multiply_0.vhd @@ -32,7 +32,7 @@ library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -entity encoder_multiply is +entity encoder_multiply_0 is port( reset_n : in std_logic; clk : in std_logic; @@ -46,9 +46,9 @@ entity encoder_multiply is step_neg_in : in std_logic; step_pos_out : out std_logic; step_neg_out : out std_logic); -end encoder_multiply; +end encoder_multiply_0; -architecture rtl of encoder_multiply is +architecture rtl of encoder_multiply_0 is /* function compute_mult(mult_sel : std_logic_vector(2 downto 0)) return std_logic_vector(7 downto 0) is 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 new file mode 100644 index 0000000..7755a55 --- /dev/null +++ b/generic_ip/encoder_multiply/0/src/encoder_speed_detect_0.vhd @@ -0,0 +1,215 @@ +------------------------------------------------------------------------------- +-- Title : encoder_speed_detect +-- Project : Generic +------------------------------------------------------------------------------- +-- File : encoder_speed_detect_0.vhd +-- Author : Gianmarco Girau +-- Company : Global Inkjet Systems +-- Created : 2019-02-27 +-- Last update: 2019-03-19 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: +-- Encoder Speed Detection +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- +-- Port Map: +-- init : clears the internal state when '1' +-- enable : do not update the internal state when '0' +-- avg_steps : number of encoder steps for the averaging process +-- delta_init : initial value of delta_t (first step or after timoe-out) +-- time_out : time-out value +-- step_pos : encoder positive step +-- step_neg : encoder negative step +-- delta_t : estimated average time between encoder steps +-- time_out_flag : time-out flag +------------------------------------------------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +library work; +use work.common_pkg.all; + +entity encoder_speed_detect_0 is + port( + reset_n : in std_logic; + clk : in std_logic; + init : in std_logic; + enable : in std_logic; + avg_steps : in std_logic_vector( 7 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; + step_neg : in std_logic; + delta_t : out std_logic_vector(39 downto 0); + step_pos_out : out std_logic; + step_neg_out : out std_logic; + time_out_flag : out std_logic); +end encoder_speed_detect_0; + +architecture rtl of encoder_speed_detect_0 is + + signal step_type, step_pos_i, step_neg_i : 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 : std_logic; + -- + signal data_valid : std_logic_vector( 5 downto 0); + signal step_cnt, first_addr, last_addr : std_logic_vector( 7 downto 0); + signal div_remain : std_logic_vector( 7 downto 0); + signal step_balance, step_bal_m1 : std_logic_vector( 9 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 : 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 + + pSEQ_LOGIC_RST : process(reset_n, clk) + begin + if(reset_n = '0') then + data_valid <= (others => '0'); + step_pos_out <= '0'; + step_neg_out <= '0'; + elsif(clk = '1' and clk'event) then + data_valid <= data_valid(data_valid'left-1 downto 0) & new_step; + step_pos_out <= '0'; + step_neg_out <= '0'; + if(data_valid(data_valid'left) = '1') then + if(last_step_type = '0') then + step_pos_out <= '1'; + else + step_neg_out <= '1'; + end if; + end if; + end if; + end process pSEQ_LOGIC_RST; + + pSEQ_LOGIC : process(clk) + 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') then + loc_time <= (others => '0'); + else + loc_time <= std_logic_vector(unsigned(loc_time)+1); + end if; + if(init_i = '1') then + step_cnt <= (others => '0'); + elsif(inc_step_cnt = '1') then + step_cnt <= std_logic_vector(unsigned(step_cnt)+1); + end if; + if(init_i = '1') then + step_balance <= (others => '0'); + elsif(inc_step_balance = '1') then + step_balance <= std_logic_vector(signed(step_balance)+1); + elsif(dec_step_balance = '1') then + step_balance <= std_logic_vector(signed(step_balance)-1); + end if; + if(init_i = '1') then + first_addr <= (others => '0'); + elsif(inc_first = '1') then + first_addr <= std_logic_vector(unsigned(first_addr)+1); + end if; + if(init_i = '1') then + last_addr <= (others => '0'); + elsif(inc_last = '1') then + last_addr <= std_logic_vector(unsigned(last_addr)+1); + end if; + if(unsigned(step_cnt) < unsigned(avg_steps)) then + avg_transient_on <= '1'; + else + avg_transient_on <= '0'; + end if; + if(data_valid(0) = '1') then + tag_last_i <= tag_last; + end if; + if(step_balance(step_balance'left) = '0') then + step_bal_m1 <= std_logic_vector(signed(step_balance)-1); + else + step_bal_m1 <= std_logic_vector(-signed(step_balance)-1); + end if; + if(init = '1' or new_step = '1') then + time_out_cnt <= time_out; + elsif(time_out_flag_i = '0') then + time_out_cnt <= std_logic_vector(unsigned(time_out_cnt)-1); + end if; + time_out_flag_d <= time_out_flag_i; + if(init_i = '1') then + first_step <= '1'; + elsif(data_valid(data_valid'left) = '1') then + first_step <= '0'; + end if; + if(new_step = '1') then + last_step_type <= step_type; + end if; + 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 + delta_t <= last_step_type & 3x"0" & delta_init & 8x"0"; + else + delta_t <= step_balance(step_balance'left) & delta_t_i & 8x"0"; + end if; + end if; + end if; + end process pSEQ_LOGIC; + + 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))); + + new_step <= step_pos_i or step_neg_i; + + inc_step_cnt <= new_step and avg_transient_on; + + inc_last <= new_step; + inc_first <= new_step and (not avg_transient_on); + + -- This RAM is for storing tag (time and encoder step-type + iTIMING_RAM: entity work.dpram_sclk + generic map ( + WIDTH => 32, + DEPTH => 256) + port map ( + clk => clk, + addr_a => last_addr, + we_a => write_last, + data_a => new_tag, + q_a => tag_last, + addr_b => first_addr, + we_b => '0', + 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'; + 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)); + + time_diff_i <= std_logic_vector(resize(unsigned(time_diff),31)); + + iDIVIDE: entity work.divider + port map ( + clock => clk, + denom => step_bal_m1(7 downto 0), + numer => time_diff_i, + quotient => delta_t_i, + remain => div_remain); + +end architecture rtl; diff --git a/generic_ip/encoder_multiply/0/src/intel/divider.vhd b/generic_ip/encoder_multiply/0/src/intel/divider.vhd new file mode 100644 index 0000000..25d4d68 --- /dev/null +++ b/generic_ip/encoder_multiply/0/src/intel/divider.vhd @@ -0,0 +1,140 @@ +-- megafunction wizard: %LPM_DIVIDE% +-- GENERATION: STANDARD +-- VERSION: WM1.0 +-- MODULE: LPM_DIVIDE + +-- ============================================================ +-- File Name: divider.vhd +-- Megafunction Name(s): +-- LPM_DIVIDE +-- +-- Simulation Library Files(s): +-- lpm +-- ============================================================ +-- ************************************************************ +-- THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE! +-- +-- 16.0.2 Build 222 07/20/2016 SJ Lite Edition +-- ************************************************************ + + +--Copyright (C) 1991-2016 Altera Corporation. All rights reserved. +--Your use of Altera 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 Altera Program License +--Subscription Agreement, the Altera Quartus Prime License Agreement, +--the Altera MegaCore Function License Agreement, or other +--applicable license agreement, including, without limitation, +--that your use is for the sole purpose of programming logic +--devices manufactured by Altera and sold by Altera 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 IS + PORT + ( + clock : IN STD_LOGIC ; + denom : IN STD_LOGIC_VECTOR (7 DOWNTO 0); + numer : IN STD_LOGIC_VECTOR (30 DOWNTO 0); + quotient : OUT STD_LOGIC_VECTOR (30 DOWNTO 0); + remain : OUT STD_LOGIC_VECTOR (7 DOWNTO 0) + ); +END divider; + + +ARCHITECTURE SYN OF divider IS + + SIGNAL sub_wire0 : STD_LOGIC_VECTOR (30 DOWNTO 0); + SIGNAL sub_wire1 : STD_LOGIC_VECTOR (7 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 (7 DOWNTO 0); + numer : IN STD_LOGIC_VECTOR (30 DOWNTO 0); + quotient : OUT STD_LOGIC_VECTOR (30 DOWNTO 0); + remain : OUT STD_LOGIC_VECTOR (7 DOWNTO 0) + ); + END COMPONENT; + +BEGIN + quotient <= sub_wire0(30 DOWNTO 0); + remain <= sub_wire1(7 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 => 3, + lpm_type => "LPM_DIVIDE", + lpm_widthd => 8, + 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 "8" +-- 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 8 0 INPUT NODEFVAL "denom[7..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 8 0 OUTPUT NODEFVAL "remain[7..0]" +-- Retrieval info: CONNECT: @clock 0 0 0 0 clock 0 0 0 0 +-- Retrieval info: CONNECT: @denom 0 0 8 0 denom 0 0 8 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 8 0 @remain 0 0 8 0 +-- Retrieval info: GEN_FILE: TYPE_NORMAL divider.vhd TRUE +-- Retrieval info: GEN_FILE: TYPE_NORMAL divider.inc FALSE +-- Retrieval info: GEN_FILE: TYPE_NORMAL divider.cmp FALSE +-- Retrieval info: GEN_FILE: TYPE_NORMAL divider.bsf FALSE +-- Retrieval info: GEN_FILE: TYPE_NORMAL divider_inst.vhd FALSE +-- Retrieval info: LIB_FILE: lpm 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 5de07b5..cdf9687 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 @@ -321,7 +321,7 @@ begin -- architecture behav -- UUTs ----------------------------------------------------------------------------- - iUUT : entity work.encoder_multiply + iUUT : entity work.encoder_multiply_0 port map ( reset_n => reset_n, clk => clk, 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 new file mode 100644 index 0000000..04bd6c6 --- /dev/null +++ b/generic_ip/encoder_multiply/0/src/test/encoder_speed_detect_tb.vhd @@ -0,0 +1,484 @@ +------------------------------------------------------------------------------- +-- Title : encoder_speed_detect_tb +-- Project : EMB/SMB +------------------------------------------------------------------------------- +-- File : encoder_speed_detect_tb.vhd +-- Author : GMG +-- Company : Global Inkjet Systems +-- Created : 2019-03-05 +-- Last update: 2019-03-19 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: +-- Testbench for the encoder_speed_detect_0 block +------------------------------------------------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; +use ieee.math_real.all; + +library OSVVM; +use OSVVM.RandomBasePkg.all; +use OSVVM.RandomPkg.all; + +use work.log_pkg.all; + +entity encoder_speed_detect_tb is + generic( + FILT_AVG : integer range 0 to 255 := 8); + -- .. +end entity encoder_speed_detect_tb; + +architecture behav of encoder_speed_detect_tb is + + constant CLK_PERIOD : time := 10 ns; + + -- Logging Verbosity Level + constant VERBOSITY_LEVEL : verb_level_t := VMEDIUM; + + constant MAX_SIM_TIME : time := 40.0 ms; -- Maximum simulation time + + constant RUN_TEST : integer_vector(0 to 2) := (1, 0, 0); + + -- 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; + + -- define the percentage of reverse steps, with respect to the intended + -- direction, while advancing the position: + -- 0 => no reverse movement at all + -- 20 => 20% of position increments are in the opposite dirtection + -- 49 => Essentially this is an oscillation around the centre position with a + -- tiny bias in the intended direction! + constant POS_RANDOM_PERC : natural range 0 to 49 := 0; -- define + + ----------------------------------------------------------------------------- + -- Signal declarations + ----------------------------------------------------------------------------- + + signal reset_n : std_logic; + signal clk : std_logic := '0'; + signal init : std_logic; + signal enable : std_logic; + 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 step_pos : std_logic; + signal step_neg : std_logic; + signal delta_t : std_logic_vector(39 downto 0); + signal step_pos_out : std_logic; + signal step_neg_out : std_logic; + signal time_out_flag : std_logic; + -- + signal abs_pos : std_logic_vector(31 downto 0); + signal delta_t_norm : integer; + + -- TB specific signals + signal setup : boolean; + signal running : boolean; + signal passed : boolean := false; + signal failed : boolean := false; + signal test_timeout : boolean := false; + signal test_completed : boolean := false; + + shared variable error_flag : boolean := false; + + ----------------------------------------------------------------------------- + -- Subprograms + ----------------------------------------------------------------------------- + + procedure wait_clk_cycles(cycles : in natural) is + begin + for n in 0 to cycles-1 loop + wait until clk = '1' and clk'event; + end loop; -- n + end procedure wait_clk_cycles; + + ----------------------------------------------------------------------------- + -- Encoder Profile #1: fixed frequency + ----------------------------------------------------------------------------- + + procedure run_encoder_profile_1 ( + freq : in real range 1.0e3 to 4000.0e3; + dir : in std_logic; + max_steps : in natural; + 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 t_ref : time; + variable t_period : real; + + begin + + if(error_flag = true) then + return; + end if; + + enable <= '0'; + step_pos <= '0'; + step_neg <= '0'; + + log("run_encoder_profile_1: Running " & to_string(max_steps) & " steps in direction " & to_string(dir) & ", at " & to_string(freq/1000.0) & " kHz ...", VMEDIUM); + + -- normalize to us + t_period := 1.0e6/freq; + + wait_clk_cycles(5); + + enable <= '1'; + wait_clk_cycles(5); + -- issue the first step + t_ref := now; + if(dir = '0') then + step_pos <= '1'; + else + step_neg <= '1'; + end if; + step_cnt := step_cnt + 1; + wait_clk_cycles(1); + step_pos <= '0'; + step_neg <= '0'; + + while step_cnt < max_steps loop + + if(now-t_ref > (1.0 us)*(real(step_cnt)*t_period)) then + wait until clk = '1' and clk'event; + -- issue the next step + if(dir = '0') then + step_pos <= '1'; + else + step_neg <= '1'; + end if; + step_cnt := step_cnt + 1; + wait_clk_cycles(1); + step_pos <= '0'; + step_neg <= '0'; + end if; + + wait for 0.1*CLK_PERIOD; + + end loop; + + wait_clk_cycles(0); + -- disable the multiplier + enable <= '0'; + + end procedure run_encoder_profile_1; + + ----------------------------------------------------------------------------- + -- Encoder Profile #2: average frequency + noise + ----------------------------------------------------------------------------- + + procedure run_encoder_profile_2 ( + 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 step_pos : out std_logic; + signal step_neg : out std_logic; + init : in boolean := false) is + + variable step_cnt : natural := 0; + variable t_ref : time; + variable t_period : real; + variable rv : RandomPType; + variable delta_period : integer; + + begin + + if(error_flag = true) then + return; + end if; + + enable <= '0'; + step_pos <= '0'; + step_neg <= '0'; + + log("run_encoder_profile_2: Running " & to_string(max_steps) & " steps in direction " & to_string(dir) & ", at " & to_string(freq/1000.0) & " kHz ...", VMEDIUM); + + -- normalize to us + t_period := 1.0e6/freq; + + wait_clk_cycles(5); + + -- enable the multiplier + enable <= '1'; + wait_clk_cycles(5); + -- issue the first step + t_ref := now; + if(dir = '0') then + step_pos <= '1'; + else + step_neg <= '1'; + end if; + step_cnt := step_cnt + 1; + wait_clk_cycles(1); + step_pos <= '0'; + step_neg <= '0'; + + delta_period := 0; + while step_cnt < max_steps loop + + if(now-t_ref > (1.0 us)*((real(step_cnt-1)+((100.0+real(delta_period))/100.0))*t_period)) then + wait until clk = '1' and clk'event; + -- issue the next step + if(dir = '0') then + step_pos <= '1'; + else + step_neg <= '1'; + end if; + step_cnt := step_cnt + 1; + wait_clk_cycles(1); + step_pos <= '0'; + step_neg <= '0'; + delta_period := rv.RandInt(-period_noise, period_noise); + end if; + + wait for 0.1*CLK_PERIOD; + + end loop; + + wait_clk_cycles(0); + -- disable the multiplier + enable <= '0'; + + end procedure run_encoder_profile_2; + +begin -- architecture behav + + clk <= not clk after 0.5*CLK_PERIOD; + + ----------------------------------------------------------------------------- + -- UUTs + ----------------------------------------------------------------------------- + + iUUT: 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, + step_neg => step_neg, + delta_t => delta_t, + step_pos_out => step_pos_out, + step_neg_out => step_neg_out, + time_out_flag => time_out_flag); + + ----------------------------------------------------------------------------- + -- Support Logic + ----------------------------------------------------------------------------- + + pGEN_POS : process(clk) + begin + if(clk = '1' and clk'event) then + if(init = '1') then + abs_pos <= (others => '0'); + elsif(step_pos_out = '1') then + abs_pos <= std_logic_vector(unsigned(abs_pos)+1); + elsif(step_neg_out = '1') then + abs_pos <= std_logic_vector(unsigned(abs_pos)-1); + end if; + end if; + end process pGEN_POS; + + delta_t_norm <= to_integer(unsigned(delta_t(38 downto 8))) when delta_t(39) = '0' else -1*to_integer(unsigned(delta_t(38 downto 8))); + + ----------------------------------------------------------------------------- + -- Testbench Logic + ----------------------------------------------------------------------------- + + pTEST_PROC : process + + variable period_variance : integer range 0 to 100; + + alias loc_time is <>; + + begin + + --------------------------------------------------------------------------- + -- Initialize & Configure + --------------------------------------------------------------------------- + + reset_n <= '0'; + init <= '0'; + enable <= '0'; + + avg_steps <= std_logic_vector(to_unsigned(FILT_AVG,8)); + delta_init <= std_logic_vector(to_unsigned(DELTA_TMIN, delta_init'length)); + -- + time_out <= std_logic_vector(to_unsigned(6000, time_out'length)); + + step_pos <= '0'; + step_neg <= '0'; + + setup <= false; + running <= false; + + --Set the verbosity level for logging + set_log_verbosity(VERBOSITY_LEVEL); + -- + wait for 100 ns; + reset_n <= '1'; + + wait for 100 ns; + wait until clk = '1' and clk'event; + + -- Nothing really to do here + setup <= true; + + --------------------------------------------------------------------------- + -- Running + --------------------------------------------------------------------------- + + running <= true; + log_separator_line(VLOW); + log("Encoder-Speed-Detection verification:", VLOW); + log_separator_line(VLOW); + + wait_clk_cycles(10); + + wait until clk = '1' and clk'event; + -- assert init to provide a clean configuration + init <= '1'; + wait until clk = '1' and clk'event; + init <= '0'; + log("Average-Speed Filtering set to " & to_string(FILT_AVG) & "." , VLOW); + + wait_clk_cycles(10); + + if(RUN_TEST(0) = 1) then + log_separator_line(VLOW); + log("Tests at constant frequency:", VLOW); + log_separator_line(VLOW); + wait until clk = '1' and clk'event; + loc_time <= force std_logic_vector(28x"1"-to_unsigned(10000+1,28)); + wait until clk = '1' and clk'event; + loc_time <= release; + run_encoder_profile_1(100.0e3, '0', 50, enable, step_pos, step_neg, true); + wait for 65 us; + run_encoder_profile_1(100.0e3, '1', 50, enable, step_pos, step_neg, true); + wait for 65 us; + run_encoder_profile_1(100.0e3, '0', 25, enable, step_pos, step_neg); + wait for 50 us; + run_encoder_profile_1(100.0e3, '0', 25, enable, step_pos, step_neg); + wait for 50 us; + run_encoder_profile_1(100.0e3, '1', 25, enable, step_pos, step_neg); + wait for 50 us; + run_encoder_profile_1(100.0e3, '0', 1, enable, step_pos, step_neg); + wait for 20 us; + run_encoder_profile_1(100.0e3, '0', 1, enable, step_pos, step_neg); + wait for 20 us; + run_encoder_profile_1(100.0e3, '0', 1, enable, step_pos, step_neg); + wait for 20 us; + run_encoder_profile_1(100.0e3, '1', 1, enable, step_pos, step_neg); + wait for 20 us; + run_encoder_profile_1(100.0e3, '0', 1, enable, step_pos, step_neg); + wait for 20 us; + run_encoder_profile_1(100.0e3, '1', 1, enable, step_pos, step_neg); + wait for 20 us; + run_encoder_profile_1(100.0e3, '0', 1, enable, step_pos, step_neg); + wait for 20 us; + run_encoder_profile_1(100.0e3, '1', 3, enable, step_pos, step_neg); + wait for 20 us; + end if; + + period_variance := 45; + log_separator_line(VLOW); + + if(RUN_TEST(1) = 1) then + log("Tests at variable frequency (+/-" & to_string(period_variance) & "%):", VLOW); + log_separator_line(VLOW); + wait until clk = '1' and clk'event; + loc_time <= force std_logic_vector(28x"1"-to_unsigned(10000+1,28)); + wait until clk = '1' and clk'event; + loc_time <= release; + run_encoder_profile_2(100.0e3, '0', 50, period_variance, enable, step_pos, step_neg, true); + wait for 50 us; + run_encoder_profile_2(100.0e3, '0', 25, period_variance, enable, step_pos, step_neg); + wait for 50 us; + run_encoder_profile_2(100.0e3, '0', 25, period_variance, enable, step_pos, step_neg); + wait for 50 us; + run_encoder_profile_2(100.0e3, '1', 25, period_variance, enable, step_pos, step_neg); + wait for 50 us; + run_encoder_profile_2(100.0e3, '0', 1, period_variance, enable, step_pos, step_neg); + wait for 20 us; + run_encoder_profile_2(100.0e3, '0', 1, period_variance, enable, step_pos, step_neg); + wait for 20 us; + run_encoder_profile_2(100.0e3, '0', 1, period_variance, enable, step_pos, step_neg); + wait for 20 us; + run_encoder_profile_2(100.0e3, '1', 1, period_variance, enable, step_pos, step_neg); + wait for 20 us; + run_encoder_profile_2(100.0e3, '0', 1, period_variance, enable, step_pos, step_neg); + wait for 20 us; + run_encoder_profile_2(100.0e3, '1', 1, period_variance, enable, step_pos, step_neg); + wait for 20 us; + run_encoder_profile_2(100.0e3, '0', 1, period_variance, enable, step_pos, step_neg); + wait for 20 us; + run_encoder_profile_2(100.0e3, '1', 3, period_variance, enable, step_pos, step_neg); + wait for 20 us; + end if; + + --------------------------------------------------------------------------- + -- End + --------------------------------------------------------------------------- + + running <= false; + wait for 10 us; + if(error_flag = false) then + passed <= true; + end if; + wait; + + end process pTEST_PROC; + + 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)))+2.0) or (m_abs_pos_r < real(to_integer(signed(abs_pos)))-2.0)) then + error_flag := true; + end if; + */ + end if; + end process pERROR_DETECT; + + failed <= error_flag after 100 ns; + + CHECK_SIM_TIMEOUT: process + begin -- process CHECK_SIM_TIMEOUT + while now < MAX_SIM_TIME loop + wait for 100 us; + end loop; + test_timeout <= true; + wait; + end process CHECK_SIM_TIMEOUT; + + pREPORT_RESULT : process + begin + wait until failed = true or passed = true or test_timeout = 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); + elsif(test_timeout = true) then + log("FAILURE: test achieved max-sim-time without reaching ", VLOW); + log(" failed/passed condition.", VLOW); + end if; + log_separator_line(VLOW); + test_completed <= true; + end process pREPORT_RESULT; + +end architecture behav; From f3cf0fec4991f8d4714e8c7331f9e8d2673d8eb2 Mon Sep 17 00:00:00 2001 From: gianmarcogirau Date: Tue, 19 Mar 2019 15:01:54 +0000 Subject: [PATCH 4/9] SMB-87 - Encoder Multiplier block - WIP (5): Completed simulations with velocity estimation --- .../encoder_multiply/0/sim/sim_enc_mult.do | 4 + .../encoder_multiply/0/sim/wave_enc_mult.do | 131 +++++++++++------ .../0/sim/wave_enc_speed_detect.do | 82 +++++++++++ .../0/src/encoder_multiply_0.vhd | 34 ++--- .../0/src/encoder_speed_detect_0.vhd | 6 +- .../0/src/test/encoder_multiply_tb.vhd | 133 +++++++++--------- 6 files changed, 259 insertions(+), 131 deletions(-) create mode 100644 generic_ip/encoder_multiply/0/sim/wave_enc_speed_detect.do 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 215fd64..ae41735 100644 --- a/generic_ip/encoder_multiply/0/sim/sim_enc_mult.do +++ b/generic_ip/encoder_multiply/0/sim/sim_enc_mult.do @@ -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 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 d6c420c..6b54678 100644 --- a/generic_ip/encoder_multiply/0/sim/wave_enc_mult.do +++ b/generic_ip/encoder_multiply/0/sim/wave_enc_mult.do @@ -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} 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 new file mode 100644 index 0000000..4d52b6b --- /dev/null +++ b/generic_ip/encoder_multiply/0/sim/wave_enc_speed_detect.do @@ -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} 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 c799b77..36f0a9b 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-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); 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 7755a55..49a71e2 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 @@ -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 ( 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 cdf9687..7bfd16f 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-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 From fb1716a7bb8842f92b9ff96cdb0977c02de71bbb Mon Sep 17 00:00:00 2001 From: gianmarcogirau Date: Fri, 22 Mar 2019 14:49:01 +0000 Subject: [PATCH 5/9] SMB-87 - Encoder Multiplier block - WIP (6): Modify the logic to properly synthesize and meet timing constraints --- .../encoder_multiply/0/sim/sim_enc_mult.do | 2 +- .../0/sim/sim_speed_detect.do | 3 +- .../encoder_multiply/0/sim/wave_enc_mult.do | 9 +- .../0/sim/wave_enc_speed_detect.do | 7 +- .../0/src/encoder_multiply_0.vhd | 128 +++++++++++----- .../0/src/encoder_speed_detect_0.vhd | 47 ++++-- .../encoder_multiply/0/src/intel/divider.vhd | 140 ----------------- .../0/src/intel/divider_0.vhd | 141 ++++++++++++++++++ .../0/src/test/encoder_multiply_tb.vhd | 6 +- .../0/src/test/encoder_speed_detect_tb.vhd | 6 +- 10 files changed, 285 insertions(+), 204 deletions(-) delete mode 100644 generic_ip/encoder_multiply/0/src/intel/divider.vhd create mode 100644 generic_ip/encoder_multiply/0/src/intel/divider_0.vhd 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 ae41735..4a320e7 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.vhd +vcom -2008 -work $WORKLIB ./../src/intel/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 d4b0bbf..1ca696e 100644 --- a/generic_ip/encoder_multiply/0/sim/sim_speed_detect.do +++ b/generic_ip/encoder_multiply/0/sim/sim_speed_detect.do @@ -19,7 +19,8 @@ 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/intel/divider_0.vhd +#vcom -2008 -work $WORKLIB ./../src/serial_divide_uu.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 6b54678..d052f64 100644 --- a/generic_ip/encoder_multiply/0/sim/wave_enc_mult.do +++ b/generic_ip/encoder_multiply/0/sim/wave_enc_mult.do @@ -49,8 +49,13 @@ 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/delay_vect +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 +add wave -noupdate /encoder_multiply_tb/iMULT/realign_pos_d add wave -noupdate /encoder_multiply_tb/iMULT/realign_neg +add wave -noupdate /encoder_multiply_tb/iMULT/realign_neg_d 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 @@ -110,7 +115,7 @@ 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} {2725654906 ps} 0} +WaveRestoreCursors {{Cursor 1} {1702355000 ps} 0} quietly wave cursor active 1 configure wave -namecolwidth 260 configure wave -valuecolwidth 126 @@ -126,4 +131,4 @@ configure wave -griddelta 40 configure wave -timeline 0 configure wave -timelineunits ps update -WaveRestoreZoom {0 ps} {8161984512 ps} +WaveRestoreZoom {16300524428 ps} {32624493452 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 4d52b6b..bf78b9c 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 @@ -57,13 +57,16 @@ 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} {10535000 ps} 0} +WaveRestoreCursors {{Cursor 1} {20565000 ps} 0} quietly wave cursor active 1 configure wave -namecolwidth 330 configure wave -valuecolwidth 145 @@ -79,4 +82,4 @@ configure wave -griddelta 40 configure wave -timeline 0 configure wave -timelineunits ps update -WaveRestoreZoom {1695718995 ps} {2649693779 ps} +WaveRestoreZoom {0 ps} {1907949568 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 36f0a9b..3452c90 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-19 +-- Last update: 2019-03-20 -- SVN ID : Git -- Standard : VHDL'2008 ------------------------------------------------------------------------------- @@ -48,15 +48,6 @@ end encoder_multiply_0; architecture rtl of encoder_multiply_0 is - /* - function compute_mult(mult_sel : std_logic_vector(2 downto 0)) return std_logic_vector(7 downto 0) is - variable mult_value : std_logic_vector(7 downto 0); - begin - mult_value := (0 => '1', others => '0') sll(to_integer(unsigned(mult_sel))); - return mult_value; - end function compute_mult; - */ - -- number of bits to represent the maximum multiplication value (e.g. 8 => M = 128) constant MULT_W : natural := 8; -- Number of bits used to represent the encoder pulse count, before the multiplication @@ -66,38 +57,79 @@ architecture rtl of encoder_multiply_0 is -- To prevent counter saturation, subtract a fixed amount each time the -- counters exceed a given value - constant NORM_VALUE : natural := 2**(PULSE_CNT_W-3); - + constant NORM_VALUE : natural := 2**(PULSE_CNT_W-3); + subtype shft_left_vec_t is std_logic_vector(M_PULSE_CNT_W-1 downto 0); + subtype shft_right_vec_t is std_logic_vector(30 downto 0); + + function shift_left(operand : shft_left_vec_t; shf_val : natural range 0 to 7) return shft_left_vec_t 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'; + end if; + end loop; -- n + return result; + end function shift_left; + + function shift_right(operand : shft_right_vec_t; shf_val : natural range 0 to 7) return shft_right_vec_t 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); + end if; + end loop; -- n + return result; + end function shift_right; - signal init_d, step_pos, step_neg : std_logic; - 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 kickoff, pending_kickoff : std_logic; - 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 : 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); - signal delta_t_i : std_logic_vector(30 downto 0); + signal init_d, step_pos, step_neg : std_logic; + 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 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 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); + signal time_cnt : std_logic_vector(27 downto 0); + signal m_delta_t : std_logic_vector(30 downto 0); + signal delta_t_i : std_logic_vector(30 downto 0); 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)) sll(to_integer(unsigned(mult_sel))); + --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); @@ -136,18 +168,43 @@ begin elsif(time_cnt_tc = '0') then time_cnt <= std_logic_vector(unsigned(time_cnt)-1); end if; - m_delta_t <= delta_t_i srl to_integer(unsigned(mult_sel)); + --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)) sll to_integer(signed('0' & mult_sel)); + --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 + 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 + 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 + realign_neg <= '1'; + else + realign_neg <= '0'; + end if; + realign_pos_d <= realign_pos; + 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)) sll (to_integer(unsigned(mult_sel))); + --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))); end if; end process pSEQ_LOGIC; + realign_pos_i <= realign_pos and not realign_pos_d; + realign_neg_i <= realign_neg and not realign_neg_d; + step_pos <= step_pos_in and enable; step_neg <= step_neg_in and enable; @@ -156,13 +213,8 @@ begin time_cnt_tc <= '1' when unsigned(time_cnt) = 1 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'; + 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'; kickoff <= pending_kickoff and (step_pos or step_neg); 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 49a71e2..8d8f9db 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-19 +-- Last update: 2019-03-22 -- SVN ID : Git -- Standard : VHDL'2008 ------------------------------------------------------------------------------- @@ -53,6 +53,20 @@ 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"""; + signal step_type, step_pos_i, step_neg_i : std_logic; signal inc_last, inc_first, avg_transient_on : std_logic; signal init_i, time_out_flag_i, new_step : std_logic; @@ -60,14 +74,14 @@ architecture rtl of encoder_speed_detect_0 is 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( 5 downto 0); + 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 div_remain : std_logic_vector( 7 downto 0); signal step_balance, step_bal_m1 : std_logic_vector( 9 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 : std_logic_vector(30 downto 0); + signal time_diff_i, delta_t_i, delta_t_ii : 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); @@ -133,10 +147,13 @@ begin if(data_valid(0) = '1') then tag_last_i <= tag_last; end if; - if(step_balance(step_balance'left) = '0') then - step_bal_m1 <= std_logic_vector(signed(step_balance)-1); - else - step_bal_m1 <= std_logic_vector(-signed(step_balance)-1); + if(data_valid(2) = '1') then + if(step_balance(step_balance'left) = '0') then + step_bal_m1 <= std_logic_vector(signed(step_balance)-1); + else + step_bal_m1 <= std_logic_vector(-signed(step_balance)-1); + end if; + time_diff_i <= std_logic_vector(resize(unsigned(time_diff),31)); end if; if(init = '1' or new_step = '1') then time_out_cnt <= time_out; @@ -164,6 +181,8 @@ 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; @@ -204,14 +223,14 @@ begin time_diff <= std_logic_vector(resize(unsigned(tag_last_i(loc_time'range))-unsigned(tag_first(loc_time'range)),30)); - time_diff_i <= std_logic_vector(resize(unsigned(time_diff),31)); - - iDIVIDE: entity work.divider + iDIVIDE: entity work.divider_0 + generic map( + PIPELINE_STAGES => 1) port map ( clock => clk, - denom => step_bal_m1(7 downto 0), + denom => step_bal_m1(5 downto 0), numer => time_diff_i, - quotient => delta_t_i, - remain => div_remain); + quotient => delta_t_ii, + remain => open); end architecture rtl; diff --git a/generic_ip/encoder_multiply/0/src/intel/divider.vhd b/generic_ip/encoder_multiply/0/src/intel/divider.vhd deleted file mode 100644 index 25d4d68..0000000 --- a/generic_ip/encoder_multiply/0/src/intel/divider.vhd +++ /dev/null @@ -1,140 +0,0 @@ --- megafunction wizard: %LPM_DIVIDE% --- GENERATION: STANDARD --- VERSION: WM1.0 --- MODULE: LPM_DIVIDE - --- ============================================================ --- File Name: divider.vhd --- Megafunction Name(s): --- LPM_DIVIDE --- --- Simulation Library Files(s): --- lpm --- ============================================================ --- ************************************************************ --- THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE! --- --- 16.0.2 Build 222 07/20/2016 SJ Lite Edition --- ************************************************************ - - ---Copyright (C) 1991-2016 Altera Corporation. All rights reserved. ---Your use of Altera 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 Altera Program License ---Subscription Agreement, the Altera Quartus Prime License Agreement, ---the Altera MegaCore Function License Agreement, or other ---applicable license agreement, including, without limitation, ---that your use is for the sole purpose of programming logic ---devices manufactured by Altera and sold by Altera 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 IS - PORT - ( - clock : IN STD_LOGIC ; - denom : IN STD_LOGIC_VECTOR (7 DOWNTO 0); - numer : IN STD_LOGIC_VECTOR (30 DOWNTO 0); - quotient : OUT STD_LOGIC_VECTOR (30 DOWNTO 0); - remain : OUT STD_LOGIC_VECTOR (7 DOWNTO 0) - ); -END divider; - - -ARCHITECTURE SYN OF divider IS - - SIGNAL sub_wire0 : STD_LOGIC_VECTOR (30 DOWNTO 0); - SIGNAL sub_wire1 : STD_LOGIC_VECTOR (7 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 (7 DOWNTO 0); - numer : IN STD_LOGIC_VECTOR (30 DOWNTO 0); - quotient : OUT STD_LOGIC_VECTOR (30 DOWNTO 0); - remain : OUT STD_LOGIC_VECTOR (7 DOWNTO 0) - ); - END COMPONENT; - -BEGIN - quotient <= sub_wire0(30 DOWNTO 0); - remain <= sub_wire1(7 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 => 3, - lpm_type => "LPM_DIVIDE", - lpm_widthd => 8, - 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 "8" --- 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 8 0 INPUT NODEFVAL "denom[7..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 8 0 OUTPUT NODEFVAL "remain[7..0]" --- Retrieval info: CONNECT: @clock 0 0 0 0 clock 0 0 0 0 --- Retrieval info: CONNECT: @denom 0 0 8 0 denom 0 0 8 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 8 0 @remain 0 0 8 0 --- Retrieval info: GEN_FILE: TYPE_NORMAL divider.vhd TRUE --- Retrieval info: GEN_FILE: TYPE_NORMAL divider.inc FALSE --- Retrieval info: GEN_FILE: TYPE_NORMAL divider.cmp FALSE --- Retrieval info: GEN_FILE: TYPE_NORMAL divider.bsf FALSE --- Retrieval info: GEN_FILE: TYPE_NORMAL divider_inst.vhd FALSE --- Retrieval info: LIB_FILE: lpm diff --git a/generic_ip/encoder_multiply/0/src/intel/divider_0.vhd b/generic_ip/encoder_multiply/0/src/intel/divider_0.vhd new file mode 100644 index 0000000..08f721a --- /dev/null +++ b/generic_ip/encoder_multiply/0/src/intel/divider_0.vhd @@ -0,0 +1,141 @@ +-- 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/test/encoder_multiply_tb.vhd b/generic_ip/encoder_multiply/0/src/test/encoder_multiply_tb.vhd index 7bfd16f..a170c7b 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-19 +-- Last update: 2019-03-20 -- SVN ID : Git -- Standard : VHDL'2008 ------------------------------------------------------------------------------- @@ -203,7 +203,7 @@ architecture behav of encoder_multiply_tb is end loop; - wait_clk_cycles(10); + wait_clk_cycles(15); -- disable the multiplier enable <= '0'; @@ -294,7 +294,7 @@ architecture behav of encoder_multiply_tb is end loop; - wait_clk_cycles(10); + wait_clk_cycles(15); -- disable the multiplier enable <= '0'; 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 04bd6c6..3b5f949 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-19 +-- Last update: 2019-03-22 -- SVN ID : Git -- Standard : VHDL'2008 ------------------------------------------------------------------------------- @@ -164,7 +164,7 @@ architecture behav of encoder_speed_detect_tb is end loop; - wait_clk_cycles(0); + wait_clk_cycles(15); -- disable the multiplier enable <= '0'; @@ -244,7 +244,7 @@ architecture behav of encoder_speed_detect_tb is end loop; - wait_clk_cycles(0); + wait_clk_cycles(15); -- disable the multiplier enable <= '0'; From 29cacb44e2ec0abb310bed016dc0db2225e72b25 Mon Sep 17 00:00:00 2001 From: gianmarcogirau Date: Fri, 22 Mar 2019 15:20:49 +0000 Subject: [PATCH 6/9] ELGIP-44 - Improved PD Queue timing (Pulse-Generator v1.3) --- .../pulse_generator/1/doc/pulse_generator_1.json | 2 +- generic_ip/pulse_generator/1/src/pulse_generator_1.vhd | 4 ++-- generic_ip/pulse_generator/1/src/queue_and_delay_1.vhd | 10 ++++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/generic_ip/pulse_generator/1/doc/pulse_generator_1.json b/generic_ip/pulse_generator/1/doc/pulse_generator_1.json index 0c78552..f51624c 100644 --- a/generic_ip/pulse_generator/1/doc/pulse_generator_1.json +++ b/generic_ip/pulse_generator/1/doc/pulse_generator_1.json @@ -50,7 +50,7 @@ "minor_number" : { "type" : "c", "bit_len" : "8", - "reset" : "0x02", + "reset" : "0x03", "description" : "Minor number" }, "major_number" : { diff --git a/generic_ip/pulse_generator/1/src/pulse_generator_1.vhd b/generic_ip/pulse_generator/1/src/pulse_generator_1.vhd index dab7f8a..c759019 100644 --- a/generic_ip/pulse_generator/1/src/pulse_generator_1.vhd +++ b/generic_ip/pulse_generator/1/src/pulse_generator_1.vhd @@ -6,7 +6,7 @@ -- Author : Gianmarco Girau -- Company : Global Inkjet Systems -- Created : 2016-10-24 --- Last update: 2019-01-17 +-- Last update: 2019-03-22 -- SVN ID : Git -- Standard : VHDL'93 ------------------------------------------------------------------------------- @@ -66,7 +66,7 @@ architecture rtl of pulse_generator_1 is -- constants constant CSR_IP_ID : std_logic_vector(31 downto 0) := x"0000FF13"; - constant CSR_IP_VER : std_logic_vector(31 downto 0) := x"00000102"; + constant CSR_IP_VER : std_logic_vector(31 downto 0) := x"00000103"; signal init_de, init_qd, enable, loc_pd, pd_queue_error : std_logic; diff --git a/generic_ip/pulse_generator/1/src/queue_and_delay_1.vhd b/generic_ip/pulse_generator/1/src/queue_and_delay_1.vhd index b50c17c..a160bcd 100644 --- a/generic_ip/pulse_generator/1/src/queue_and_delay_1.vhd +++ b/generic_ip/pulse_generator/1/src/queue_and_delay_1.vhd @@ -6,7 +6,7 @@ -- Author : Gianmarco Girau -- Company : Global Inkjet Systems -- Created : 2016-05-28 --- Last update: 2018-06-28 +-- Last update: 2019-03-22 -- SVN ID : Git -- Standard : VHDL'93 ------------------------------------------------------------------------------- @@ -118,7 +118,13 @@ begin -- RTL -- Time reference: either use the external one or generate it locally gTIME_REF0: if use_ext_time = true generate - local_time <= ext_time; + + pLATCH_LOCTIME : process(clk) + begin + if(clk = '1' and clk'event) then + local_time <= ext_time; + end if; + end process pLATCH_LOCTIME; shf_enable <= '1' when local_time /= local_time_d else '0'; From 88f4323270d713496bb147a25ccad076f21011bd Mon Sep 17 00:00:00 2001 From: gianmarcogirau Date: Mon, 25 Mar 2019 15:55:54 +0000 Subject: [PATCH 7/9] HMBXR5601-664 - Bug Fixed --- .../0/src/fire_pulse_manager_0.vhd | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/generic_ip/fire_pulse_manager/0/src/fire_pulse_manager_0.vhd b/generic_ip/fire_pulse_manager/0/src/fire_pulse_manager_0.vhd index f1c1ebb..6c3c78a 100644 --- a/generic_ip/fire_pulse_manager/0/src/fire_pulse_manager_0.vhd +++ b/generic_ip/fire_pulse_manager/0/src/fire_pulse_manager_0.vhd @@ -6,7 +6,7 @@ -- Author : Gianmarco Girau -- Company : Global Inkjet Systems -- Created : 2017-09-06 --- Last update: 2019-01-23 +-- Last update: 2019-03-22 -- SVN ID : Git -- Standard : VHDL'08 ------------------------------------------------------------------------------- @@ -424,7 +424,13 @@ begin ----------------------------------------------------------------------------- -- Not instantiated yet - cs_nsnk_read_valid <= '1'; + pNSNK_RD : process(clk) + begin + if(clk = '1' and clk'event) then + cs_nsnk_read_valid <= cs_nsnk_read_en; + end if; + end process pNSNK_RD; + cs_nsnk_read_data <= X"DEAD_BEEF"; ----------------------------------------------------------------------------- @@ -432,7 +438,13 @@ begin ----------------------------------------------------------------------------- -- Not instantiated yet - cs_log_read_valid <= '1'; + pLOGGER_RD : process(clk) + begin + if(clk = '1' and clk'event) then + cs_log_read_valid <= cs_log_read_en; + end if; + end process pLOGGER_RD; + cs_log_read_data <= X"DEAD_BEEF"; end architecture rtl; From 9fd42054b808a4b564cd1c21aedd73e4ab30d841 Mon Sep 17 00:00:00 2001 From: gianmarcogirau Date: Fri, 5 Apr 2019 13:46:00 +0100 Subject: [PATCH 8/9] ELGIP-48 - Pulse Generator version 1.04: Added support for Spit functionality. Added a new control bit to bypass the Pulse-Conditioning logic --- generic_ip/encoder_multiply/0/sim/sim_all.do | 14 +++++ .../1/doc/pulse_generator_1.json | 9 ++-- .../1/src/pulse_generator_1.vhd | 53 ++++++++++++++----- 3 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 generic_ip/encoder_multiply/0/sim/sim_all.do diff --git a/generic_ip/encoder_multiply/0/sim/sim_all.do b/generic_ip/encoder_multiply/0/sim/sim_all.do new file mode 100644 index 0000000..cf471b1 --- /dev/null +++ b/generic_ip/encoder_multiply/0/sim/sim_all.do @@ -0,0 +1,14 @@ +# Simulation macro + +.main clear + +do sim_speed_detect.do +do sim_enc_mult.do 0 +do sim_enc_mult.do 1 +do sim_enc_mult.do 2 +do sim_enc_mult.do 3 +do sim_enc_mult.do 4 +do sim_enc_mult.do 5 +do sim_enc_mult.do 6 +do sim_enc_mult.do 7 + diff --git a/generic_ip/pulse_generator/1/doc/pulse_generator_1.json b/generic_ip/pulse_generator/1/doc/pulse_generator_1.json index f51624c..fe31d79 100644 --- a/generic_ip/pulse_generator/1/doc/pulse_generator_1.json +++ b/generic_ip/pulse_generator/1/doc/pulse_generator_1.json @@ -50,7 +50,7 @@ "minor_number" : { "type" : "c", "bit_len" : "8", - "reset" : "0x03", + "reset" : "0x04", "description" : "Minor number" }, "major_number" : { @@ -84,10 +84,11 @@ "reset": "0x0", "description": "By-Pass Ch-Ctrl (=> Fractional Divider only)" }, - "reserved_0": { - "type": "rsv", + "bypass_pulse_conditioning": { + "type": "w", "bit_len": "1", - "description": "" + "reset": "0x0", + "description": "By-Pass Pulse-Conditioning block" }, "bypass_delay_equalizer": { "type": "w", diff --git a/generic_ip/pulse_generator/1/src/pulse_generator_1.vhd b/generic_ip/pulse_generator/1/src/pulse_generator_1.vhd index c759019..9d99143 100644 --- a/generic_ip/pulse_generator/1/src/pulse_generator_1.vhd +++ b/generic_ip/pulse_generator/1/src/pulse_generator_1.vhd @@ -6,7 +6,7 @@ -- Author : Gianmarco Girau -- Company : Global Inkjet Systems -- Created : 2016-10-24 --- Last update: 2019-03-22 +-- Last update: 2019-04-04 -- SVN ID : Git -- Standard : VHDL'93 ------------------------------------------------------------------------------- @@ -66,7 +66,7 @@ architecture rtl of pulse_generator_1 is -- constants constant CSR_IP_ID : std_logic_vector(31 downto 0) := x"0000FF13"; - constant CSR_IP_VER : std_logic_vector(31 downto 0) := x"00000103"; + constant CSR_IP_VER : std_logic_vector(31 downto 0) := x"00000104"; signal init_de, init_qd, enable, loc_pd, pd_queue_error : std_logic; @@ -90,7 +90,9 @@ architecture rtl of pulse_generator_1 is signal prevent_div_restart, rst_jitter, rst_diag_regs : std_logic; signal fire_req, fire_req_d, fire_req_p : std_logic; signal mid_cross, mid_crossed, zero_cross : std_logic; - signal close_to_zero, close_to_mid : std_logic; + signal close_to_zero, close_to_mid, bypass_pulse_cond : std_logic; + signal div_pulse_i, spitting_enable, spit_pulse : std_logic; + signal seq_bus_valid, spit_nco_msb : std_logic; -- signal abs_pos_msb_old : std_logic_vector( 1 downto 0); signal ch_ctrl_csr_addr, ch_ctrl_trigger_in : std_logic_vector( 3 downto 0); @@ -111,6 +113,7 @@ architecture rtl of pulse_generator_1 is signal abs_pos_max, abs_pos_min : std_logic_vector(31 downto 0); signal last_pd_pos : std_logic_vector(31 downto 0); signal pd_in_cnt, fire_req_cnt : std_logic_vector(31 downto 0); + signal seq_bus_data, spit_nco, spit_nco_inc : std_logic_vector(31 downto 0); signal div_offset, div_ratio : std_logic_vector(33 downto 0); begin @@ -253,12 +256,12 @@ begin generic map ( TRIGGER_WIDTH => 4, VECTOR_WIDTH => 24, - BUS_WIDTH => 1, + BUS_WIDTH => 32, POS_WIDTH => 24, SEQ_DEPTH => 256, ADD_VEC_PIPE => false, VECT_RAMP_EN => false, - BUS_BURST_EN => false, + BUS_BURST_EN => true, POS_BUS_EN => true, ALU_EN => false, QUEUE_EN => true) @@ -281,9 +284,9 @@ begin pos_in => abs_position(23 downto 0), busy => ch_ctrl_busy, vector_out => ch_ctrl_vector_out, - bus_data => open, - bus_valid => open, - bus_ack => '0'); + bus_data => seq_bus_data, + bus_valid => seq_bus_valid, + bus_ack => '1'); ch_ctrl_trigger_in <= (0 => loc_pd, 1 => fire_enable, 2 => gated_pulse, 3 => (not fire_enable)); @@ -358,9 +361,12 @@ begin ratio => div_ratio, abs_pos => abs_position, enc_pulse => enc_pulse, - fire => div_pulse, + fire => div_pulse_i, fire_cnt => open); + -- to be replaced with a mux once the spitting logic is in place + div_pulse <= div_pulse_i when spitting_enable = '0' else spit_pulse; + -- In case upd_min_pos/upd_max_pos are asserted as a consequence of init, you -- need to guarantee a sufficient delay to make sure abs_pos get reset before -- updating min/max pos @@ -378,6 +384,27 @@ begin -- output to the monitoring point/event-logger raw_pulse_out <= div_pulse; + ----------------------------------------------------------------------------- + -- Spitting logic + ----------------------------------------------------------------------------- + + pSPITTING_LOGIC : process(clk) + begin + if(clk = '1' and clk'event) then + spitting_enable <= ch_ctrl_vector_out(6); + if(seq_bus_valid = '1') then + spit_nco_inc <= seq_bus_data; + end if; + if(spitting_enable = '0') then + spit_nco <= (others => '0'); + else + spit_nco <= std_logic_vector(unsigned(spit_nco)+unsigned(spit_nco_inc)); + end if; + spit_nco_msb <= spit_nco(spit_nco'left); + spit_pulse <= spit_nco(spit_nco'left) and not spit_nco_msb; + end if; + end process pSPITTING_LOGIC; + ----------------------------------------------------------------------------- -- Pulse Gating ----------------------------------------------------------------------------- @@ -479,8 +506,8 @@ begin pulse_width_ext => pulse_width_ext, pulse_out => pulse_out_ii); - pulse_out <= pulse_out_ii; - fire_req <= pulse_out_ii; + pulse_out <= pulse_out_ii when bypass_pulse_cond = '0' else pulse_out_i; + fire_req <= pulse_out_ii when bypass_pulse_cond = '0' else pulse_out_i; end generate gOUT_COND; @@ -560,6 +587,7 @@ begin -- enable_i <= '0'; bypass_ch_ctrl <= '0'; + bypass_pulse_cond <= '0'; bypass_delay_equal <= '0'; sw_ctrl_dp_dir <= '0'; enable_out <= '0'; @@ -591,6 +619,7 @@ begin when PULSE_GEN_CTRL_REG => enable_i <= avs_writedata(0); bypass_ch_ctrl <= avs_writedata(1); + bypass_pulse_cond <= avs_writedata(2); bypass_delay_equal <= avs_writedata(3); sw_ctrl_dp_dir <= avs_writedata(4); enable_out <= avs_writedata(16); @@ -639,7 +668,7 @@ begin when PULSE_GEN_CTRL_REG => avs_readdata_i(31 downto 8) <= (8 => ch_mask_i, 9 => fire_enable, 10 => dp_dir, 16 => enable_out, 17 => abort_fire, 18 => rst_diag_regs, others => '0'); avs_readdata_i( 7 downto 4) <= b"0" & de_queue_error & pd_queue_error & sw_ctrl_dp_dir; - avs_readdata_i( 3 downto 0) <= bypass_delay_equal & '0' & bypass_ch_ctrl & enable_i; + avs_readdata_i( 3 downto 0) <= bypass_delay_equal & bypass_pulse_cond & bypass_ch_ctrl & enable_i; when CH_OFFSET_D0_REG => avs_readdata_i <= ch_offset_dir0; when CH_OFFSET_D1_REG => From 10a13dd61ad59f89d01df13314a030ebc5f3fcff Mon Sep 17 00:00:00 2001 From: gianmarcogirau Date: Wed, 10 Apr 2019 13:16:26 +0100 Subject: [PATCH 9/9] ELGIP-48 - Updated Out-of-date comment --- generic_ip/pulse_generator/1/src/pulse_generator_1.vhd | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/generic_ip/pulse_generator/1/src/pulse_generator_1.vhd b/generic_ip/pulse_generator/1/src/pulse_generator_1.vhd index 20f6636..fae6365 100644 --- a/generic_ip/pulse_generator/1/src/pulse_generator_1.vhd +++ b/generic_ip/pulse_generator/1/src/pulse_generator_1.vhd @@ -6,7 +6,7 @@ -- Author : Gianmarco Girau -- Company : Global Inkjet Systems -- Created : 2016-10-24 --- Last update: 2019-04-04 +-- Last update: 2019-04-10 -- SVN ID : Git -- Standard : VHDL'93 ------------------------------------------------------------------------------- @@ -365,7 +365,6 @@ begin fire => div_pulse_i, fire_cnt => open); - -- to be replaced with a mux once the spitting logic is in place div_pulse <= div_pulse_i when spitting_enable = '0' else spit_pulse; -- In case upd_min_pos/upd_max_pos are asserted as a consequence of init, you