【3】Verilog练习-时序逻辑与伪随机码发生器设计和仿真
我的学记|刘航宇的博客

【3】Verilog练习-时序逻辑与伪随机码发生器设计和仿真

刘航宇
3年前发布 /正在检测是否收录...
温馨提示:
本文最后更新于2022年05月23日,已超过1040天没有更新,若内容或图片失效,请留言反馈。

时序逻辑代码与仿真

图片[1] - 【3】Verilog练习-时序逻辑与伪随机码发生器设计和仿真 - 我的学记|刘航宇的博客
代码

//计数器
`timescale 1ns/10ps
module counter(
                clk,
                res,
                y
                );
input            clk;
input            res;
output[7:0]        y;
reg[7:0]        y;
wire[7:0]        sum;//+1运算的结果;
assign            sum=y+1;//组合逻辑部分;
always@(posedge clk or negedge res)
if(~res)begin
                y<=0;
end
else begin
                y<=sum;
end
endmodule
//----testbench of counter----
module counter_tb;
reg                clk,res;
wire[7:0]        y;
counter counter(
                .clk(clk),
                .res(res),
                .y(y)
                );
initial begin
                clk<=0;res<=0;
        #17        res<=1;
        #6000    $stop;
end
always #5 clk<=~clk;

endmodule

现象
图片[2] - 【3】Verilog练习-时序逻辑与伪随机码发生器设计和仿真 - 我的学记|刘航宇的博客
模拟显示
图片[3] - 【3】Verilog练习-时序逻辑与伪随机码发生器设计和仿真 - 我的学记|刘航宇的博客

伪随机码发生器

图片[4] - 【3】Verilog练习-时序逻辑与伪随机码发生器设计和仿真 - 我的学记|刘航宇的博客
代码

//四级伪随机码发生器;
`timescale 1ns/10ps
module m_gen(
                clk,
                res,
                y
                );
input            clk;
input            res;
output            y;
reg[3:0]        d;
assign            y=d[0];
always@(posedge clk or negedge res)
if(~res)begin
   d<=4'b1111;
end
else begin
   d[2:0]<=d[3:1];//右移一位;
   d[3]<=d[3]+d[0];//模二加;
end
endmodule
//----testbench of m_gen----
module m_gen_tb;
reg                clk,res;
wire            y;
m_gen m_gen(
                .clk(clk),
                .res(res),
                .y(y)
                );
initial begin
                clk<=0;res<=0;
        #17        res<=1;
        #600    $stop;
end
always #5 clk<=~clk;            
endmodule

现象

图片[5] - 【3】Verilog练习-时序逻辑与伪随机码发生器设计和仿真 - 我的学记|刘航宇的博客

© 版权声明
THE END
喜欢就支持一下吧
点赞 1 分享 赞赏
评论 抢沙发
取消