集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 1194|回复: 0

求助,时序仿真结果正确,连上fpga后出问题(nios软核只提供一个输入)

[复制链接]
wwzjlx 发表于 2012-5-7 22:04:33 | 显示全部楼层 |阅读模式
程序的主要功能是给两个输入,将其分别乘查找表中数据,然后输出。下面是我的ip核和接口程序,问题:我将ip核和接口程序连在一起进行时序仿真时输出结果正确(乘法用的是并行乘法器,时钟周期是20ns)但集成到sopc,de2开发板实现,用嵌入式逻辑分析仪观察时(nios2软核就一句话,实现给定两个输入的功能),输出是恒定值。请大神指导一下,万分感谢


ip核

`define toni 20 //toni4/m+1
`define tonu 25 //tonu4/m+1
`define toffi 35 //toffi3/m+1
`define toffu 35 //toffu4/m+1





module switching(clk,switches,U0,I0,reset,I,U);

input clk;
input switches;//0:on;1:off;
input wire [15:0] U0;
input wire [15:0] I0;
input wire reset;
output reg[31:0]U,I;

wire[31:0]I1,U1;

reg[11:0]t1=0;
reg[11:0]t2=0;
reg[11:0]t3=0;
reg[11:0]t4=0;
reg[15:0]KI,KU;

reg[15:0] KIon [0:`toni];
reg[15:0] KUon [0:`tonu];
reg[15:0] KIoff[0:`toffi];
reg[15:0] KUoff[0:`toffu];
initial
  begin
KIon[1]=16'b0000000000000000;
KIon[2]=16'b0000000000000000;
KIon[3]=16'b0000001010101010;
KIon[4]=16'b0000100000000000;
KIon[5]=16'b0000110101010101;
KIon[6]=16'b0001001010101010;
KIon[7]=16'b0001100000000000;
..........//这是数据表
  end



always@(posedge clk)
begin
  if(reset==0)
    begin
     t1=0;
     t3=0;
    end
  if (switches==0)
   begin
     if (t1<`toni)t1=t1+1;
     KI=KIon[t1];
     t3=0;
   end
else if(switches==1)
   begin  
     if (t3<`toffi)t3=t3+1;
     KI=KIoff[t3];
     t1=0;
   end

end  

mul_16 mulI(I0,KI,I1);

always@(posedge clk)
begin
  if(reset==0)
    begin
     t2=0;
     t4=0;
    end
  if (switches==0)
   begin
    if (t2<`tonu)t2=t2+1;
     KU=KUon[t2];
     t4=0;
   end
  else if(switches==1)
    begin
     if (t4<`toffu)t4=t4+1;
     KU=KUoff[t4];
     t2=0;
     end
end
mul_16 mulU(U0,KU,U1);
  
  
always@(posedge clk)
  begin
     I[31:0]<={13'b0000000000000,I1[31:13]};
     U[31:0]<={13'b0000000000000,U1[31:13]};
  end  
  
endmodule



这是接口程序
module                Avalon_interface(
                                                clk,
                                                reset_n,
                                                U,
                                                I,
                                                  chipselect,
                                                address,
                                                read,
                                                readdata,
                                                write,
                                                writedata,
                        U0,
                        I0,
                        switches,
                        reset
                                                );
                                               
input                                        clk;
input                                        reset_n;
input                                        chipselect;
input                                     address;
input                                        read;
input                                        write;
input                        [31:0]        writedata;
input           [31:0]  U,I;
output  reg             reset;
output        reg         [31:0]        readdata;
output        reg         [15:0]        U0;
output        reg         [15:0]        I0;                       
output  reg                    switches;//0:on;1:off
reg                     ui_select,switch_select;

/*
always@(address)
  begin
    ui_select<=0;
    switch_select<=0;
   case(address)
    1'b0:ui_select<=1;
    1'b1:switch_select<=1;
   endcase   
  end
*/

always @ (posedge clk or negedge reset_n)
begin
if(reset_n==1'b0)
  begin
     U0<=16'b0000000000000000;
     I0<=16'b0000000000000000;
     switches<=1'b0;
  end
else
  if(write & chipselect)
    begin
     U0[15:0]<=writedata[15:0];
     I0[15:0]<={1'b0,writedata[30:16]};
     switches<=writedata[31];
    end
end
/*
always @ (posedge clk or negedge reset_n)
begin
  if(reset_n==1'b0)
   switches=1'b0;
  else
   if(write & chipselect & switch_select)
    begin
          switches<=writedata[0];
    end
end  
*/

always @ (read or address or chipselect)
begin
  if(read & chipselect)
    case(address)
      1'b0:readdata<=U;
      1'b1:readdata<=I;   
     default:
      begin
       readdata<=0;
      end
    endcase  
end

always @ (reset_n)
begin
   reset<=reset_n;
end


endmodule
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2025-6-25 21:16 , Processed in 0.063532 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表