FPGA-3X3矩阵的生成
生成 矩阵 FPGA
2023-09-14 09:13:03 时间
这里的话我用的是vivado的开发工具
配置shift ram可以实现两行数据的移位,
那再串上一行就可以实现说行数据的移位功能
配置下图:
其他的默认就行,这里我因为是对200*200 *8bit图片数据的进行处理,所以就主要把 位宽和深度定义为自己想要的就好了
module Shift_RAM_3X3(
//global signals
input clk,
input rst_n,
//Image data prepred to be processd
input per_clken,//Prepared Image data output/capture enable clock
input [7:0] per_img_Y,//Prepared Image brightness input
//Image data has been processd
output matrix_clken, //Prepared Image data output/capture enable clock
output reg [7:0] matrix_p11,
output reg [7:0] matrix_p12,
output reg [7:0] matrix_p13, //3X3 Matrix output
output reg [7:0] matrix_p21,
output reg [7:0] matrix_p22,
output reg [7:0] matrix_p23,
output reg [7:0] matrix_p31,
output reg [7:0] matrix_p32,
output reg [7:0] matrix_p33
);
//----------------------------------------------
//consume 1clk
wire [7:0] row1_data;//frame data of the 1th row
wire [7:0] row2_data;//frame data of the 2th row
reg [7:0] row3_data;//frame data of the 3th row
always @(posedge clk or negedge rst_n)begin
if(!rst_n)
row3_data <= 8'b0;
else begin
if(per_clken)
row3_data <= per_img_Y;
else
row3_data <= row3_data;
end
end
//----------------------------------------------------------
//module of shift ram for row data
wire shift_clk_en = per_clken;
//Shift_RAM_3X3_8bit1
Shift_RAM_3X3_8bit u1_Shift_RAM_3X3_8bit (
.D(row3_data), // input wire [7 : 0] D
.CLK(shift_clk_en), // input wire CLK
.SCLR(~rst_n), // input wire SCLR
.Q(row2_data) // output wire [7 : 0] Q
);
//Shift_RAM_3X3_8bit2
Shift_RAM_3X3_8bit u2_Shift_RAM_3X3_8bit (
.D(row2_data), // input wire [7 : 0] D
.CLK(shift_clk_en), // input wire CLK
.SCLR(~rst_n), // input wire SCLR
.Q(row1_data) // output wire [7 : 0] Q
);
//-------------------------------------------
//per_clken delay 3clk
reg [1:0] per_clken_r;
always @(posedge clk or negedge rst_n)begin
if(!rst_n)
per_clken_r <= 2'b0;
else
per_clken_r <= {per_clken_r[0], per_clken};
end
wire read_clken = per_clken_r[0];
assign matrix_clken = per_clken_r[1];
//---------------------------------------------------------------------
/****************************************
(1)read data from shift_RAM
(2)caulate the sobel
(3)steady data after sobel generate
******************************************/
//wire [23:0] matrix_row1 = {matrix_p11, matrix_p12,matrix_p13};//just for test
//wire [23:0] matrix_row2 = {matrix_p21, matrix_p22,matrix_p23};
//wire [23:0] matrix_row3 = {matrix_p31, matrix_p32,matrix_p33};
always @(posedge clk or negedge rst_n)begin
if(!rst_n)begin
{matrix_p11, matrix_p12, matrix_p13} <= 24'h0;
{matrix_p21, matrix_p22, matrix_p23} <= 24'h0;
{matrix_p31, matrix_p32, matrix_p33} <= 24'h0;
end
// else if(read_frame_href)begin
else if(read_clken)begin//shift_RAM data read clock enbale
{matrix_p11, matrix_p12, matrix_p13} <= {matrix_p12, matrix_p13, row1_data};//1th shift input
{matrix_p21, matrix_p22, matrix_p23} <= {matrix_p22, matrix_p23, row2_data};//2th shift input
{matrix_p31, matrix_p32, matrix_p33} <= {matrix_p32, matrix_p33, row3_data};//3th shift input
end
else begin
{matrix_p11, matrix_p12, matrix_p13} <= {matrix_p11, matrix_p12, matrix_p13};
{matrix_p21, matrix_p22, matrix_p23} <= {matrix_p21, matrix_p22, matrix_p23};
{matrix_p31, matrix_p32, matrix_p33} <= {matrix_p31, matrix_p32, matrix_p33};
end
// end
/* else begin
{matrix_p11, matrix_p12, matrix_p13} <= 24'h0;
{matrix_p21, matrix_p22, matrix_p23} <= 24'h0;
{matrix_p31, matrix_p32, matrix_p33} <= 24'h0;
end */
end
endmodule
相关文章
- acme.sh 生成证书一直卡在Getting domain auth token for each domain
- 使用generator自动生成mybatis model、mapper.xml、mapper等(转)
- 执行RF测试只生成output.xml文件,不生成log和report文件
- 基于zxing生成与解析二维码、条形码
- C#放缩、截取、合并图片并生成高质量新图的类
- [C#]二维码(QR Code)生成与解析
- Qt编写地图综合应用34-生成区域轮廓图
- 如何用ABAP生成一个三乘三的矩阵
- 【风场景生成与削减】【m-ISODATA、kmean、HAC】无监督聚类算法,用于捕获电力系统中风场景生成与削减研究(Matlab代码实现)
- 【MATLAB】数据类型 ( 矩阵 | 随机数函数 | 生成矩阵 )
- FastAdmin 在线命令生成时出错的分析
- 【.Net Core】编译时禁止自动生成netcoreapp文件夹
- 【Spring Boot】SpringBoot 优雅整合Swagger Api 自动生成文档
- 生成的SMILES以及对应的图像的评价指标【2】