原创 3级积分器的verilog实现

2016-1-29 15:48 6553 19 19 分类: FPGA/CPLD
module integrator( clk,rst,x_in,y_out
    );
input clk,rst;
input [7:0] x_in;
output  [7:0] y_out;
reg [7:0] intreg0;
reg  [7:0]  intreg1;
reg  [7:0] intreg2;
 
reg [7:0] x_reg;
 
 
 
 
always @(posedge clk) begin
if(!rst) begin
   x_reg  <= 0;
intreg0 <= 0;
intreg1 <= 0;
intreg2 <= 0;
end
else begin
  x_reg <= x_in;
intreg0 <= intreg0 + x_reg;
intreg1 <= intreg1 + intreg0;
intreg2 <= intreg2 + intreg1;
end
end 
 
 
 
 
 
assign y_out = intreg2;
 
 
 
 
endmodule
测试文件
module tb_integrator;
 
// Inputs
reg clk;
reg rst;
reg [7:0] x_in;
 
// Outputs
wire [7:0] y_out;
 
// Instantiate the Unit Under Test (UUT)
integrator uut (
.clk(clk), 
.rst(rst), 
.x_in(x_in), 
.y_out(y_out)
);
 
initial begin
// Initialize Inputs
clk = 0;
rst = 0;
x_in = 0;
 
// Wait 100 ns for global reset to finish
#100;
        rst =1;
// Add stimulus here
 
end
      always #10 clk =~clk;
always @(posedge clk) begin
if(!rst)
x_in <= 0;
else
x_in <= x_in +1;
end
endmodule
 
 
 
 
 
 
 
 
       
 
 
 

文章评论0条评论)

登录后参与讨论
我要评论
0
19
关闭 站长推荐上一条 /2 下一条