FPGA project : uart232_ram_vga

news/2025/3/29 0:27:33/

重点学习:

本实验重点学习了双口ram解决多bit跨时钟域同步处理的问题。

其实signal port ram,它的输入口和输出口分别用不同的时钟,也可以解决这个问题。

让我意识到的比较重要的事情:

1,代码设计中,一些大于10的数字,尽量用parameter设定一些可以重传的参数来代替。因为这样方便仿真修改。我就是之前写uart_rx模块,数字啥的没用参数替代。这个实验中仿真时需要修改参数,然后重新修改了uart_rx代码。使得仿真时间大大缩短,很方便。

2,在vga_pic模块中模拟产生的ram,读完数据后,ram里面的数据并没有消失,还在。

写数据:在时钟上升沿,写使能拉高,与此同时要有对应的地址与数据。然后数据就写进对应的地址里面了。

读数据:在时钟上升沿,读使能拉高,与此同时给出地址,然后数据就都出来了。值得一提的是,数据会滞后一个时钟周期(相对于读使能与地址),说明ram内部用的时序逻辑嘛。

3, task input ...如果写在task内部了。那么在task name 后面就不要加括号了。否则modulism会报错。

 

module vga_pic (input       wire            clk_25  , // ram 的输出时钟,也是vga图像的时钟。input       wire            clk_50  , // ram 的输入时钟input       wire            rst_n   , // 经过系统复位和pll的locked相与后的复位。input       wire    [9:0]   pix_x   ,input       wire    [9:0]   pix_y   ,input       wire    [7:0]   po_data , // 写入的数据的数据input       wire            po_flag , // 用作ram的读使能。output      wire    [7:0]   pix_data
);// parameter parameter   H_VALID = 10'd640    ,V_VALID = 10'd480    ;parameter   PIC_SIZE= 14'd1_0000 ,H_PIC   = 10'd100    ,V_PIC   = 10'd100    ;parameter   RED     = 8'b1110_0000 ,GREEN   = 8'b0001_1100 ,BLUE    = 8'b0000_0011 ,WHITE   = 8'b1111_1111 ,BLACK   = 8'b0000_0000 ;// reg signal definereg     [13:0]  wr_addr  ;  // ram 的写地址。reg     [ 7:0]  data_pix ;  // 彩条像素reg             pic_valid; // 图片有效wire    [ 7:0]  pic_data ; // 图片像素reg             rd_en    ; // ram读使能reg     [13:0]  rd_addr  ;/************************************************************************/// reg     [13:0]  wr_addr  ;  // ram 的写地址。    always @(posedge clk_50 or negedge rst_n) beginif(~rst_n) beginwr_addr <= 14'd0 ;end else beginif(po_flag) beginif(wr_addr == 9999) begin // 记到最大的地址后归零。wr_addr <= 14'd0 ;end else beginwr_addr <= wr_addr + 1'b1 ;endend else beginwr_addr <= wr_addr ;endendend// reg     [ 7:0]  data_pix ;  // 彩条像素always @(posedge clk_25 or negedge rst_n) begin if(~rst_n) begindata_pix <= BLACK ;end else beginif(pix_y >= 0 && pix_y <= (V_VALID / 5 - 1))data_pix <= RED ;else if((pix_y >= V_VALID / 5) && pix_y <= ((V_VALID / 5 ) * 2) - 1)data_pix <= GREEN ;else if((pix_y >= (V_VALID / 5) * 2) && pix_y <= ((V_VALID / 5 ) * 3) - 1)data_pix <= BLUE ;else if((pix_y >= (V_VALID / 5) * 3) && pix_y <= ((V_VALID / 5 ) * 4) - 1)data_pix <= WHITE ;else if((pix_y >= (V_VALID / 5) * 4) && pix_y <= (V_VALID  - 1))data_pix <= BLACK ;else data_pix <= BLACK ;end // 先不写else 一会看编译是否会通过。end// reg             pic_valid; // 图片有效always @(posedge clk_25 or negedge rst_n) beginif(~rst_n) beginpic_valid <= 1'b0 ;end else beginif(pix_x >= 269 && pix_x <= 368 && pix_y >= 190 && pix_y <= 289) beginpic_valid <= 1'b1 ;end else beginpic_valid <= 1'b0 ;endendend// wire    [ 7:0]  pic_data ; // 图片像素// 图片像素存在了ram中,所以只需要取出来就是图片像素了。// reg             rd_en    ; // ram读使能always @(posedge clk_25 or negedge rst_n) beginif(~rst_n) beginrd_en <= 1'b0 ;end else beginif(pix_x >= 268 && pix_x <= 367 && pix_y >= 190 && pix_y <= 289) beginrd_en <= 1'b1 ;end else beginrd_en <= 1'b0 ;endendend// reg     [13:0]  rd_addr  ;always @(posedge clk_25 or negedge rst_n) beginif(~rst_n) beginrd_addr <= 14'd0 ;end else beginif(rd_en) beginif(rd_addr == 9999) beginrd_addr <= 14'd0 ;end else beginrd_addr <= rd_addr + 1'b1 ;endend else beginrd_addr <= rd_addr ;endendend/**********************output signal define**************************************/// wire    [7:0]   pix_data ;assign pix_data = (pic_valid == 1'b1) ? pic_data : data_pix ;
/******************例化双口ram*******************/
ram_10000_double ram_10000_double_insert(.data                   ( po_data ) ,.inclock                ( clk_50  ) ,.outclock               ( clk_25  ) ,.rdaddress              ( rd_addr ) ,.wraddress              ( wr_addr ) ,.wren                   ( po_flag ) ,.q                      ( pic_data)
);endmodule

 

module top(input       wire            sys_clk     ,input       wire            sys_rst_n   ,input       wire            rx          ,output      wire    [7:0]   rgb         ,output      wire            hsync       ,output      wire            vsync   
);// 例化间连线wire            rst_n       ;wire    [7:0]   po_data     ;wire            po_flag     ;wire    [7:0]   pix_data    ;wire    [9:0]   pix_x       ;wire    [9:0]   pix_y       ;wire            clk_25      ;wire            clk_50      ;pll	pll_inst (.sys_rst_n              ( sys_rst_n     ) ,.areset                 ( ~sys_rst_n    ) ,.inclk0                 ( sys_clk       ) ,.c0                     ( clk_25        ) ,.c1                     ( clk_50        ) ,.locked                 ( rst_n         )
);uart_rx uart_rx_inst(.sys_clk                ( clk_50        ) ,.sys_rst_n              ( rst_n         ) ,.rx                     ( rx            ) ,.po_data                ( po_data       ) ,.po_flag                ( po_flag       ) 
);vga_ctrl vga_ctrl_inst(.vga_clk                ( clk_25        ) ,.vga_rst_n              ( rst_n         ) ,.pix_data               ( pix_data      ) ,.hsync                  ( hsync         ) ,.vsync                  ( vsync         ) ,.pix_x                  ( pix_x         ) ,.pix_y                  ( pix_y         ) ,.rgb                    ( rgb           )         
);vga_pic vga_pic_inst(.clk_25                 ( clk_25        ) ,.clk_50                 ( clk_50        ) ,.rst_n                  ( rst_n         ) ,.pix_x                  ( pix_x         ) ,.pix_y                  ( pix_y         ) ,.po_data                ( po_data       ) ,.po_flag                ( po_flag       ) ,.pix_data               ( pix_data      )
);endmodule
`timescale 1ns/1ns
module test_top();reg             sys_clk     ;reg             sys_rst_n   ;reg             rx          ;wire    [7:0]   rgb         ;wire            hsync       ;wire            vsync       ;reg     [7:0]   data_mem    [9999:0];top top_insert(.sys_clk                ( sys_clk    ) ,.sys_rst_n              ( sys_rst_n  ) ,.rx                     ( rx         ) ,.rgb                    ( rgb        ) ,.hsync                  ( hsync      ) ,.vsync                  ( vsync      )   
);defparam    top_insert.uart_rx_inst.CLK_FREQ = 5 ;defparam    top_insert.uart_rx_inst.UART_BPS = 1  ;parameter   CYCLE = 20 ;initial beginsys_clk     = 1'b1 ;sys_rst_n   <=1'b0 ;#(CYCLE)           ;sys_rst_n   <=1'b1 ; endalways #(CYCLE / 2) sys_clk = ~sys_clk ;initial begin$readmemh ("D:/intel_FPGA/VScodedocument/EmbedFire/31 rs232_vga/matlab/data_test.txt",data_mem);endinitial beginrx <= 1'b1 ;#(CYCLE * 10) ;rx_byte ;endtask    rx_byte;integer j ; // j 是存储器的地址。for (j = 0;j < 10000 ;j = j + 1 ) beginrx_bit(data_mem[j]) ; // 没有输入端口,自然不需要输入参数。endendtasktask    rx_bit;input [7:0]data ;integer i ;for (i = 0;i < 10 ;i = i + 1 ) begincase (i)0:rx    <= 1'b0;1:rx    <= data[0];2:rx    <= data[1];3:rx    <= data[2];4:rx    <= data[3];5:rx    <= data[4];6:rx    <= data[5];7:rx    <= data[6];8:rx    <= data[7];9:rx    <= 1'b1;default: rx    <= 1'b1;endcase#(5 * CYCLE) ;endendtask
endmodule

 

文章来源:https://blog.csdn.net/Meng_long2022/article/details/133319679
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.ppmy.cn/news/1126034.html

相关文章

图像的读写与保存

图像是由众多的像素值构成的&#xff0c;我们如何去操作图像呢&#xff1f; 答案就是将图像转化为数组。 OpenCV提供了这样的方法。 我们使用cv2.imread()方法读取图片&#xff0c;返回数组格式。 对于cv2.imread(filename, flags)函数参数如下&#xff1a; 参数filename&a…

【计算机网络】IP协议

目录 前言 IP协议 基本概念 IP协议格式 分片 16位标识 3位标志与13位片偏移 分片流程 网段划分 网络号和主机号 DHCP协议 CIDR划分方案 特殊的ip地址 ip地址数量限制 私有ip地址与公网ip地址 路由转发 前言 我们前面讲了HTTP/HTTPS协议和TCP/…

软件测试BUG都修复了就结束了吗?

一般来说&#xff0c;当 Bug 跟踪系统上所有的 bug 都被关闭了以后&#xff0c;你会感到如释重负&#xff0c;终于可以松一口气了。 当项目成功交付后&#xff0c;你是否感到大脑进入了疲惫期&#xff0c;上网&#xff0c;聊天&#xff0c;写自己感兴趣的小程序&#xff0c;项…

JDK21更新内容:增强模式匹配

“ 有的时候博客内容会有变动&#xff0c;首发博客是最新的&#xff0c;其他博客地址可能会未同步,认准https://blog.zysicyj.top ” 首发博客地址 文章更新计划 文章更新计划 “ | 441: | Pattern Matching for switch | ” 1. 什么是 Pattern Matching for switch? Pattern …

最新版小说泛站群系统源码 小说泛目录站群源码系统程序/PHP语言(源码+教程)

源码简介&#xff1a; 新版小说泛目录站群系统网站源码&#xff08;小说站群源码&#xff09;&#xff0c;PHP小说泛站群系统程序&#xff0c;网站优化泛目录站群源码&#xff0c;新版小说泛站群系统源码&#xff0c;小说站群源码&#xff0c;小说泛目录站群源码PHP语言操作简…

构建智能客服知识库,优化客户体验不是难题!

在当今快节奏的商业环境中&#xff0c;客户都希望得到及时个性化的支持&#xff0c;拥有一个智能客服知识库对于现代企业至关重要。智能客服知识库是一个集中存储、组织和访问与客户服务互动相关的信息的综合性知识库。它为企业提供了全面的知识来源&#xff0c;使他们能够为客…

golang学习笔记(一):基础入门

基础入门 菜鸟教程Go语言环境安装 GoLand开发工具下载 Gin web开发框架 Go 语言流行 ORM 框架 GORM 使用介绍 如何使用Go语言连接分布式MySQL数据库 Go语言依赖搜索网站&#xff0c;类似Maven 添加依赖&#xff1a; 基础知识 1.关键字 go 开启协程执行调用语句/方法。 def…

科技成果鉴定测试有多重要?可出具专业测试报告的软件测评机构推荐

科技成果鉴定测试在现代社会中具有重要意义&#xff0c;它不仅可以评估科技成果的价值和可行性&#xff0c;还可以为科技创新提供决策依据&#xff0c;推动科技进步和社会发展&#xff0c;那么科技成果鉴定测试究竟重要在哪呢? 1、对于科技项目的投资决策至关重要。鉴定测试可…