在写滤波程序的时候在网上看了好几篇大佬的笔记,都有提到使用3*3窗口,由于小白一个,看到复杂的理论就惧怕的不行。但是现在不得不上,自己调用移位寄存器ip核然后做了个3*3窗口出来,自己动手作出来忽然感觉到也不难嘛。
先贴一张ip核模块的接口参数图
生成3*3窗口需要两个寄存器,参数设置为数据宽度8,深度一个为4,另一个为3,选sclr端口
然后把两个移位寄存器串联起来就可以了
仿真的时候写好激励就行
放上最后仿真图
两条线那会是不是3*3矩阵呀,然后往右推就行。
顶层模块
1 module shift3by3( 2 clk, 3 rst_n, 4 datain, 5 dataout 6 ); 7 input clk; 8 input rst_n; 9 input [7:0] datain; 10 output [7:0] dataout; 11 12 wire [7:0] d_in; 13 wire sclr; 14 15 16 shiftip shift2( 17 .clk(clk), 18 .sclr(~rst_n), 19 .d(datain), 20 .q(d_in) 21 ); 22 23 shift3 shift3( 24 .clk(clk), 25 .sclr(~rst_n), 26 .d(d_in), 27 .q(dataout) 28 ); 29 30 endmodule
tesrbench
1 module shiftiptb; 2 3 // Inputs 4 reg clk; 5 reg [7:0] d; 6 7 // Outputs 8 wire [7:0] q; 9 10 // Instantiate the Unit Under Test (UUT) 11 shiftip uut ( 12 .clk(clk), 13 .d(d), 14 .q(q) 15 ); 16 initial clk=1; 17 always #10 clk=!clk; 18 initial begin 19 // Initialize Inputs 20 #20 d=11; 21 #20 d=22; 22 #20 d=33; 23 #20 d=44; 24 #20 d=55; 25 #20 d=66; 26 #20 d=77; 27 #20 d=88; 28 #20 d=99; 29 30 31 32 // Wait 100 ns for global reset to finish 33 #100; 34 35 // Add stimulus here 36 37 end 38 39 endmodule