问题:用vhdl语言和Verilog语言和matlab协仿真同一个程序,在modelsim上跑出来的结果不一样。导致时序有问题。网上查了很多资料没有结果。(调用的.m函数一样即输入信号一样)。例子: 带使能信号和复位信号的加法器,由matlab给输入数据addin,en。错误: VHDL仿真结果貌似是正确的,但是verilog语言仿真的结果addout应该延时输入的addin一个clk,为什么没有延时呢。!!1. VHDL语言:
LIBRARY ieee;USE ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity test is port ( rst_n : in std_logic; clk : in std_logic; en : in std_logic; addin : in std_logic_vector(11 downto 0); addout : out std_logic_vector (11 downto 0) );END test;architecture rtl of test issignal add1 : std_logic_vector(11 downto 0);beginprocess(clk,rst_n)begin if rst_n ='0' then add1<=(others=>'0'); elsifclk'event and clk = '1' then if en = '1' then add1<=addin+'1'; else add1<=add1; endif; end if; end process;addout<=add1;
end architecture;
2. Verilog语言
module test (clk, rst_n, addin, en, addout );input clk;input rst_n;input en;input [11:0] addin; output [11:0] addout; reg [11:0] add1;assign addout=add1;always @ (posedge clk) begin if (!rst_n) begin add1=12'h0; end else if(en) begin add1=addin+1; end end
endmodule
-
-
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
function [iport,tnext] = test(oport, tnow, portinfo)
tnext=[];
iport=struct();
persistent inc;
persistent rst;
CLK_PERIOD = 1e-8;
RST_MUL_TIME = 5;
RST_TIME = RST_MUL_TIME * CLK_PERIOD;
if isempty(inc)
inc=0;
iport.addin=dec2bin(0,12);
iport.en=dec2bin(0,1);
end
inc =inc+1;
if tnow <= RST_TIME
rst = dec2bin(0, 1);
inc=[];
else
rst = dec2bin(1, 1);
end
if inc>=10
iport.addin=dec2bin(inc,12);
iport.en=dec2bin(1,1);
end
if 30==mvl2dec(oport.addout)
iport.en=dec2bin(0,1);
end
iport.rst_n=rst;
end
一周热门 更多>