Forum Discussion
Help needed in VHDL Testbench
Hi all,
I have written the testbench file in such a manner that I need to perform updowncounting and downcounting based on the value of dir_s. But the problem is, when I execute the code, the dir_s is incremented only for one value ie. when fmcw_ramp_o >= fmcw_bw_i and for all other values its zero. Because of this, Ì am getting this error "wrong output: addition should take place". I don't know how to solve this problem. I know for sure that dir_s should be 1 till it reaches the condition. I need to know how dir_s will be 1 continuously till fmcw_ramp_o< fstep_i or = "0000". The code looks like this:p_check_step: process(delayed_rst_s, clk_128meg_i)
begin
if (delayed_rst_s = '0') then
dir_s <= '0';
old_fmcw_ramp_s <= (others => '0');
elsif (clk_128meg_i'event and clk_128meg_i = '0') then
if (enable_i = '1' and fmcw_trig_i = '1') then
if( dir_s = '0') then
assert fmcw_ramp_o = std_logic_vector(unsigned(old_fmcw_ramp_s) + unsigned(fstep_i)) report " wrong output: addition should take place" severity error;
else
assert fmcw_ramp_o = std_logic_vector(unsigned(old_fmcw_ramp_s) - unsigned(fstep_i)) report " wrong output: subtraction should take place" severity error;
end if;
if (fmcw_ramp_o >= fmcw_bw_i) then
dir_s <= '1';
elsif (fmcw_ramp_o < fstep_i) then
dir_s <= '0';
elsif (fmcw_ramp_o = "000000000000000000000000") then
dir_s <= '0';
end if;
old_fmcw_ramp_s <= fmcw_ramp_o;
else
dir_s <= '0';
old_fmcw_ramp_s <= (others => '0');
end if;
end if;
end process; Also the VHDL code looks like this: begin
if (reset_n_i = '0') then
temp_s <= 0;
cnt_s <= '0';
elsif (clk_128meg_i'event and clk_128meg_i = '1') then
if (enable_i = '1' and fmcw_trig_i = '1') then
if (temp_s <= to_integer(unsigned(fstep_i))) then
temp_s <= temp_s + to_integer(unsigned(fstep_i)); -- Accumulated values of temp_s and fstep_i
cnt_s <= '0';
elsif (temp_s = 0) then
temp_s <= temp_s - to_integer(unsigned(fstep_i));
cnt_s <= '0';
elsif (temp_s >= (to_integer(unsigned(fmcw_bw_i)))) then
temp_s <= temp_s - to_integer(unsigned(fstep_i));
cnt_s <= '1';
elsif (cnt_s = '0') then
temp_s <= temp_s + to_integer(unsigned(fstep_i)); -- Up counter
else
temp_s <= temp_s - to_integer(unsigned(fstep_i)); -- Down counter
end if;
else
temp_s <= 0;
cnt_s <= '0';
end if;
end if;
end process;36 Replies
- Altera_Forum
Honored Contributor
This will be because you have the same assertion error if sel_s is '0' or '1' - so I assume it's going to happen on every clock cycle that enable_i is set.
- Altera_Forum
Honored Contributor
@tricky,
but I need to use this condition to check for the output: is there any other way to solve this. - Altera_Forum
Honored Contributor
Sorry, I missread the code - But you still have the same error reported for two different assertions. maybe you should change the text so that it is clearer which one is firing then you can use the wave window to debug the problem..
- Altera_Forum
Honored Contributor
@tricky,
I have tried all possibilities and I find that the old_phi_e_s is not pushed to phi_e_gr_o as well as phi_e_i is not pushed to phi_e_gr_o. This is the waveform I obtain when I run the simulation. https://www.alteraforum.com/forum/attachment.php?attachmentid=12710 Also I have changed my testbench because there was a kind of mistake in the design. This is my testbench code:
. Please help me to solve this issue. I am really fed up of why I am not getting the outputwait for 10 ns; reset_n_i <= '1'; wait for 15 ns; enable_i <= '1'; phi_e_i <= "101010101111010101101010101101010101"; thresh_i <= "10000000"; wait for 10 ns; phi_e_i <= "111010101101010101010101010101010101"; thresh_i <= "00010110"; wait for 10 ns; phi_e_i <= "100000000000000000010101010101010101"; thresh_i <= "00010101"; wait for 20 ns; phi_e_i <= "110101010101010101010101111110101010"; thresh_i <= "01110000"; wait for 15 ns; phi_e_i <= "000000000000000000000000001010110101"; thresh_i <= "01111111"; wait for 1 ms; reset_n_i <= '0'; wait for 1 ms; reset_n_i <= '1'; wait for 1 ms; enable_i <= '0'; wait for 1 ms; enable_i <= '1'; wait for 1 ms; assert False report "End simulation!" severity Failure; end process; delay_rst_s <= reset_n_i after 1 ns; new_thresh_s <= std_logic_vector(thresh_i & "0000000000000000000000000000"); p_check_outp: process(delay_rst_s, clk_128meg_i) begin if (delay_rst_s = '0') then old_phi_e_s <= (others => '0'); assert phi_e_gr_o = "000000000000000000000000000000000000" report "Output not set to default value when reset_n_i= 0" severity error; elsif (clk_128meg_i'event and clk_128meg_i = '0')then if (enable_i = '1') then old_phi_e_s <= phi_e_i; if (abs(signed(phi_e_i) - signed(old_phi_e_s)) >= to_integer(unsigned(new_thresh_s))) then assert phi_e_gr_o = old_phi_e_s report "Wrong output: phi_e_gr_o should be equal to old phi_e_i" severity error; elsif (abs(signed(phi_e_i) - signed(old_phi_e_s)) < to_integer(unsigned(new_thresh_s))) then assert phi_e_gr_o = phi_e_i report "Wrong output: phi_e_gr_o should be equal to phi_e_i" severity error; end if; else old_phi_e_s <= (others => '0'); assert phi_e_gr_o = "000000000000000000000000000000000000" report " Output not set to default value when enable_i= 0" severity error; end if; end if; end process; - Altera_Forum
Honored Contributor
This is debugging.
I have no knowledge of your deisgn and you are the best person to fix it. Use the testbench and internal wave forms to trace a known input through the design, and ensure it is the correct values at all stages through the design. - Altera_Forum
Honored Contributor
Hello all,
Once again I have a small clarification to be done regarding testbench. I have written a testbench in which I have used a signal say "XXX_s". Now I use the same signal XXX_s in another source code say "YYY.vhd" by port mapping it. However, I need to again use the same signal, XXX_s for the testbench file that I have written for the source file YYY.vhd. How can I do so?? Thanks in advance - Altera_Forum
Honored Contributor
I dont understand your question? Is it about naming scope in VHDL? Names can be re-used in as many files as long as you dont manage to put the same name twice in the same scope.
Why not post an example with the problem you're having? - Altera_Forum
Honored Contributor
Ok, i will post an example , I am just writing the entity and the portmap. I hope so this would be enough for you to have an idea of what I trying to ask.
Consider this as the first source code , Consider the output port rise_o
The testbench (port mapping section) for this source code is as follows:entity tdc_decode is port (reset_n_i : in std_logic; --asynch reset clk_128meg_i : in std_logic; --128 meg system clock enable_i : in std_logic; -- enable signal tdc_i : in std_logic_vector(63 downto 0); -- tdc data rise_o : out std_logic_vector(5 downto 0); -- value for rise rise_fall_o : out std_logic_vector(6 downto 0)); -- rise - fall value end tdc_decode;
This is the second source code tdc_readoutuut: tdc_decode port map (reset_n_i => reset_n_i, clk_128meg_i => clk_128meg_i, enable_i => enable_i, tdc_i => tdc_i, rise_o => rise_o, rise_fall_o => rise_fall_o );
However,I am going to port map the inputs of tdc_decode in tdc_readout:entity tdc_readout is port (reset_n_i : in std_logic; enable_i : in std_logic; clk_128meg_i : in std_logic; tdc_i : in std_logic_vector(63 downto 0); --tdc data scale_i : in std_logic_vector(7 downto 0); --scaling value from spi reg rise_fall_o : out std_logic_vector(6 downto 0); --calculated rise fall value to spi phi_frac_o : out std_logic_vector(13 downto 0)); --phi fractional value to add3 end tdc_readout;
Now, what I need is to use the output port "rise_o values " which I calculated in tdc_decode in my next testbench that I have written for tdc_readout (i.e. tb_tdc_readout). How can I do that. Was I clear?i_tdc_decode : tdc_decode port map (reset_n_i => reset_n_i, -- reset from pad clk_128meg_i => clk_128meg_i, -- system clock enable_i => enable_i, tdc_i => tdc_reg_s, rise_o => rise_s, rise_fall_o => rise_fall_o); - Altera_Forum
Honored Contributor
To your information, I have added the source files tdc_readout, tdc_decode and only the testbench tb_tdc_readout to my simulation
- Altera_Forum
Honored Contributor
Your question is still not clear, can you please post some code that shows an error?
You can map anything to anything, you just have to connect things through ports...