FPGA|CPLD|ASICwilliam hill官网
直播中

Aomiz_fans

10年用户 12经验值
擅长:控制/MCU
私信 关注
[问答]

关于modelsim和matlab协仿真的问题,用的是verilog语言。。。。

问题:用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 is
signal add1 :  std_logic_vector(11 downto 0);
begin
process(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

  • VHDL.png
  • verilog.png

回帖(1)

Aomiz_fans

2015-4-28 09:15:44
这是我给的m文件,即输入的激励:
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
举报

更多回帖

发帖
×
20
完善资料,
赚取积分