qq_58272240 2022-11-11 18:14 采纳率: 100%
浏览 66
已结题

Modelsim仿真不出来波形,不知道.v文件程序错在哪

课程实践,编写简单的模13奇数分频器
编写程序实在找不出来什么问题,但是仿真始终没有波形
这是分频器的代码

module fenpin13
(input clk,reset,
output wire cout);
reg [4:0]m,n;
reg cout1,cout2;
assign cout=cout1|cout2;
always @(posedge clk)
begin if(!reset) begin cout1<=0;m<=0;end
else
begin if(m==12) m<=0;else m<=m+1;
if(m<6) cout1<=1;else cout1<=0;
end
end
always @(posedge clk)
begin if(!reset) begin cout2<=0;n<=0;end
else begin
if(n==12) n<=0;else n<=n+1;
if(n<6) cout2<=1;else cout2<=0;end
end
endmodule

这是testbench文件的代码

`timescale 1ns/1ns
module fenpin13_tb;
reg clk,reset;
wire cout,cout1,cout2;
wire [4:0]m,n;
fenpin13 u1(clk,reset,cout);
parameter PERIOD=100;
initial
begin
reset=0;clk=0;
#40 reset=1;
forever
#(PERIOD/2) clk=~clk;
end
endmodule

最后运行modelsim始终无波形

img

本人是初学者,希望可以多指教,谢谢!

  • 写回答

1条回答 默认 最新

  • 老皮芽子 2022-11-12 08:57
    关注

    1:fenpin13 奇数分频,需要用上升沿和下降沿分别计数分频后再合成
    第二个分频改用 always @(negedge clk)
    2:仿真部分,复位信号时间太短
    3:仿真部分,复位信号有效时要有时钟触发

    
    module fenpin13
    (
        input clk,reset,
        output wire cout
    );
    reg [4:0]m,n;
    reg cout1,cout2;
    assign cout=cout1|cout2;
    
    always @(posedge clk)
    begin
        if(!reset)
        begin
            cout1<=0;
            m<=0;
        end
        else
        begin
            if(m==12)    m<=0;
            else            m<=m+1;
    
            if(m<6)    cout1<=1;
            else    cout1<=0;
        end
    end
    
    always @(negedge clk)
    begin
        if(!reset)
        begin
            cout2<=0;
            n<=0;
        end
        else
        begin
            if(n==12)    n<=0;
            else        n<=n+1;
            if(n<6)    cout2<=1;
            else    cout2<=0;
        end
    end
    endmodule
    
    `timescale 1ns/1ns
    module fenpin13_tb;
    reg clk,reset;
    wire cout,cout1,cout2;
    wire [4:0]m,n;
    fenpin13 u1(clk,reset,cout);
    parameter PERIOD=100;
    initial
    begin
        reset=0;
        clk=0;
        #200 reset=1;
    end
    always
        #(PERIOD/2) clk=~clk;
    
    endmodule  
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月21日
  • 已采纳回答 11月13日
  • 创建了问题 11月11日

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂