VGA逐行扫描控制器的Verilog建模
前言:因为VGA是一种模拟图像传输数据接口,所要将数字信号用DAC转换成模拟量。本文用的一款ADI公司高精度的视频IC,实则一款高带宽的视频DAC。因为VGA时序较为简单,并且网上的VGA驱动基本大同小异。本文也没有什么特别创新之处。
注意点:(a)行扫描计数器和场扫描计数器需要与每个像素点、消隐数目想对应,这样才能得到正确的行列地址坐标。
参考资料:《VESA_VGA时序标准》、《ADV7123a》
源码1:逐行扫描的VGA控制器
`timescale ns / ps
`define RedWidth
`define GreenWidth
`define BlueWidth
`define VGA640x480x60Hz
module vga_pscan_ctrl(
sys_clk,
sys_rst_n,
vga_red_i,
vga_green_i,
vga_blue_i,
column_addr_o,
row_addr_o,
frame_flag_o,
video_valid_o,
//vga port
vga_red,
vga_green,
vga_blue,
vga_v_sync,
vga_h_sync,
//special port
vga_sync,
vga_blank,
vga_clk
);
//macro
`ifdef VGA640x480x60Hz
`define ColumnWidth
`define RowWidth
`define H_SYNC
`define H_BACK_PORCH
`define H_VIDEO
`define H_FRONT_PORCH
`define H_TOTAL
`define H_BIAS //`H_SYNC+`H_BACK_PORCH
`define V_SYNC
`define V_BACK_PORCH
`define V_VIDEO
`define V_FRONT_PORCH
`define V_TOTAL
`define V_BIAS //V_SYNC+V_BACK_PORCH
`endif
input sys_clk;
input sys_rst_n;
input [`RedWidth-:] vga_red_i;
input [`GreenWidth-:] vga_green_i;
input [`BlueWidth-:] vga_blue_i;
output [`ColumnWidth-:] column_addr_o; //像素当前列地址
output [`RowWidth-:] row_addr_o; //像素当前行地址
output frame_flag_o; //帧结束
output video_valid_o; //数据有效
//vga port
output [`RedWidth-:] vga_red;
output [`GreenWidth-:] vga_green;
output [`BlueWidth-:] vga_blue;
output vga_v_sync;
output vga_h_sync;
//special port
output vga_blank;
output vga_sync;
output vga_clk;
//pix clk divider
reg pix_clk=;
always @ (posedge sys_clk) begin
pix_clk <= ~pix_clk;
end //horizion counter
reg [`ColumnWidth-:] h_cnt = ;
always @ (posedge sys_clk) begin
if(sys_rst_n == 'b0) h_cnt <= 0;
else if((pix_clk == 'b1)&&(h_cnt < `H_TOTAL-1)) h_cnt <= h_cnt + 1'd1;
else if((pix_clk == 'b1)&&(h_cnt == `H_TOTAL-1)) h_cnt <= 0;
else h_cnt <= h_cnt;
end //vertical counter
reg [`RedWidth-:] v_cnt = ;
always @ (posedge sys_clk) begin
if('b0 == sys_rst_n) v_cnt <= 0;
else if((pix_clk)&&(h_cnt == `H_TOTAL-)&&(v_cnt < `V_TOTAL-)) v_cnt <= v_cnt + 'd1;
else if((pix_clk)&&(h_cnt == `H_TOTAL-)&&(v_cnt == `V_TOTAL-)) v_cnt <= ;
else v_cnt <= v_cnt;
end //generate the sync
assign vga_h_sync = (h_cnt > `H_SYNC-)?'b1:1'b0;
assign vga_v_sync = (v_cnt > `V_SYNC-)?'b1:1'b0; //generate data valid
wire h_video_valid = ((h_cnt > `H_SYNC+`H_BACK_PORCH-)&&(h_cnt < `H_TOTAL-`H_FRONT_PORCH))?'b1:1'b0;
wire v_video_valid = ((v_cnt > `V_SYNC+`V_BACK_PORCH-)&&(v_cnt < `V_TOTAL-`V_FRONT_PORCH))?'b1:1'b0;
assign video_valid_o = (h_video_valid && v_video_valid)?'b1:1'b0;
//generate frame_flag_o
assign frame_flag_o = ((v_cnt == `V_TOTAL-)&&(h_cnt == `H_TOTAL-))?'b1:1'b0; //generate vga_blank and vga_sync and vga_clk
assign vga_clk = pix_clk;
assign vga_sync = 'b0;
assign vga_blank = vga_h_sync & vga_v_sync; //generate column_addr_o and row_addr_o
reg [`ColumnWidth-:] column_addr_o=;
reg [`RowWidth-:] row_addr_o=;
always @ (posedge sys_clk) begin
if(sys_rst_n == 'b0) begin
column_addr_o <= ;
row_addr_o <= ;end
else if(video_valid_o) begin
column_addr_o <= h_cnt - `H_BIAS;
row_addr_o <= v_cnt - `V_BIAS;end
else begin
column_addr_o <= column_addr_o;
row_addr_o <= row_addr_o;end
end
//generate RGB
assign vga_red = (video_valid_o)?vga_red_i:`RedWidth'd0;
assign vga_green = (video_valid_o)?vga_green_i:`GreenWidth'd0;
assign vga_blue = (video_valid_o)?vga_blue_i:`BlueWidth'd0; endmodule
源码2:简单驱动
`timescale ns / ps
`define RedWidth
`define GreenWidth
`define BlueWidth
`define Offset1
`define Offset2
module vga_driver(
sys_clk,
sys_rst_n,
sys_en,
vga_red_o,
vga_green_o,
vga_blue_o
);
input sys_clk;
input sys_rst_n;
input sys_en;
output [`RedWidth-:] vga_red_o;
output [`GreenWidth-:] vga_green_o;
output [`BlueWidth-:] vga_blue_o;
reg [`RedWidth-:] vga_red_o=;
reg [`GreenWidth-:] vga_green_o=;
reg [`BlueWidth-:] vga_blue_o=; //generate red vector
always @ (posedge sys_clk) begin
if(sys_rst_n == 'b0) vga_red_o <= 0;
else if(sys_en) vga_red_o <= vga_red_o + 'd1;
else vga_red_o <= vga_red_o;
end //generate green vector
always @ (posedge sys_clk) begin
if(sys_rst_n == 'b0) vga_green_o <= `Offset1;
else if(sys_en) vga_green_o <= vga_green_o + 'd1;
else vga_green_o <= vga_green_o;
end //generate blue vector
always @ (posedge sys_clk) begin
if(sys_rst_n == 'b0) vga_blue_o <= `Offset2;
else if (sys_en) vga_blue_o <= vga_blue_o + 'd1;
else vga_blue_o <= vga_blue_o;
end endmodule
源码3:VGA相关模块的顶层例化
`timescale ns / ps
`define RedWidth
`define GreenWidth
`define BlueWidth
`define VGA640x480x60Hz
module vga(
sys_clk,
sys_rst_n,
//vga port
vga_red,
vga_blue,
vga_green,
vga_h_sync,
vga_v_sync,
//special port
vga_blank,
vga_sync,
vga_clk
);
`ifdef VGA640x480x60Hz
`define ColumnWidth
`define RowWidth
`endif
input sys_clk;
input sys_rst_n;
//vga port
output [`RedWidth-:] vga_red;
output [`GreenWidth-:] vga_green;
output [`BlueWidth-:] vga_blue;
output vga_v_sync;
output vga_h_sync;
//special io
output vga_blank;
output vga_sync;
output vga_clk;
//wires
wire [`RedWidth-:] vga_red_w;
wire [`GreenWidth-:] vga_green_w;
wire [`BlueWidth-:] vga_blue_w;
wire [`ColumnWidth-:] column_addr_w;
wire [`RowWidth-:] row_addr_w;
wire frame_flag_w;
wire video_valid_w;
vga_driver inst_vga_driver(
.sys_clk(sys_clk),
.sys_rst_n(sys_rst_n),
.sys_en(video_valid_w),
.vga_red_o(vga_red_w),
.vga_green_o(vga_green_w),
.vga_blue_o(vga_blue_w)
); vga_pscan_ctrl inst_vga_pscan_ctrl(
.sys_clk(sys_clk),
.sys_rst_n(sys_rst_n),
.vga_red_i(vga_red_w),
.vga_green_i(vga_green_w),
.vga_blue_i(vga_blue_w),
.column_addr_o(column_addr_w),
.row_addr_o(row_addr_w),
.frame_flag_o(frame_flag_w),
.video_valid_o(video_valid_w),
//vga port
.vga_red(vga_red),
.vga_green(vga_green),
.vga_blue(vga_blue),
.vga_v_sync(vga_v_sync),
.vga_h_sync(vga_h_sync),
//special port
.vga_sync(vga_sync),
.vga_blank(vga_blank),
.vga_clk(vga_clk)
); endmodule
仿真文件:
`timescale ns / ps
`define RedWidth
`define GreenWidth
`define BlueWidth
module vga_tsb;
reg sys_clk;
reg sys_rst_n;
initial begin
sys_clk=;
sys_rst_n=;
# sys_rst_n=;
end
always begin
# sys_clk=~sys_clk;
end wire [`RedWidth-:] vga_red;
wire [`GreenWidth-:] vga_green;
wire [`BlueWidth-:] vga_blue;
wire vga_h_sync;
wire vga_v_sync;
vga inst_vga(
.sys_clk(sys_clk),
.sys_rst_n(sys_rst_n),
//vga port
.vga_red(vga_red),
.vga_blue(vga_blue),
.vga_green(vga_green),
.vga_h_sync(vga_h_sync),
.vga_v_sync(vga_v_sync),
.vga_blank(vga_blank),
.vga_sync(vga_sync)
); endmodule
仿真脚本文件:
vlib work
vmap work work vlog -work work vga_pscan_ctrl.v
vlog -work work vga_driver.v
vlog -work work vga.v
vlog -work work vga_tsb.v vsim -novopt -lib work vga_tsb view wave
# signals in vga_driver
add wave -radix unsigned sim:/vga_tsb/inst_vga/inst_vga_driver/vga_red_o
add wave -radix unsigned sim:/vga_tsb/inst_vga/inst_vga_driver/vga_green_o
add wave -radix unsigned sim:/vga_tsb/inst_vga/inst_vga_driver/vga_blue_o
add wave sim:/vga_tsb/inst_vga/inst_vga_driver/sys_en # signals in vga_pscan_ctrl
add wave -radix unsigned sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/vga_red_i
add wave -radix unsigned sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/vga_green_i
add wave -radix unsigned sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/vga_blue_i
add wave -radix unsigned sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/column_addr_o
add wave -radix unsigned sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/row_addr_o
add wave sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/frame_flag_o
add wave sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/video_valid_o
add wave sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/vga_sync
add wave sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/vga_blank
add wave sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/pix_clk
add wave sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/v_video_valid
add wave sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/vga_v_sync
add wave -radix unsigned sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/v_cnt
add wave sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/vga_h_sync
add wave sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/h_video_valid
add wave -radix unsigned sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/h_cnt
add wave -radix unsigned sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/vga_red
add wave -radix unsigned sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/vga_green
add wave -radix unsigned sim:/vga_tsb/inst_vga/inst_vga_pscan_ctrl/vga_blue run 50ms
VGA逐行扫描控制器的Verilog建模的更多相关文章
- Norflash控制器的Verilog建模之一
摘要:今天驱动一款SPANSION公司生产的norflash——S29AL032D70,没有别的参考资料,大致了解一下norflash的内部cmos电路架构以及其用途之后,直接看手册吧. 如何看手册: ...
- SDRAM控制器的Verilog建模之一
前言:作为经典存储器的三剑客中的flash和sram已经建模测试过了,虽然现在都已经ddr2,ddr3,667MHZ.1333MHZ的天下了,但是接下这周来准备写一下sdram的controller. ...
- Norflash控制器的Verilog建模之二(仿真)
前言:经过几天修改,norflash控制器基本已经完成,通过仿真.完整的norflash包含2个模块:直接操作硬件的norflash_ctrl.v与控制ctrl模块的驱动norflash_driver ...
- 异步SRAM控制器的Verilog建模
前言:sram顾名思义静态随机存储器,分为asram异步型和ssram同步型.这里驱动DE2上一块ISSI公司的512KB的asram. 设计思路:因为实际应用中单字节读写效率不高,所以本设计中仿照s ...
- I2C控制器的Verilog建模之三(完结版)
前言:终于到了测试篇,不过悲剧了一下.按照之前<二>里面的思路,在顶层用一个复用器驱动读写独立模块的I2C总线确实失败.虽然综合过去了,不过警告里已经说明:底层的2个原本是inout三态口 ...
- Norflash控制器的Verilog建模之三(測試)
前言:回校了,辦好手續就著手寫測試篇.初步的norflash控制器已經完成,通過硬件測試.目前的norflash完成扇区块擦除.单字节写.单字节读3个功能.博文最后附上源码. 总结:和之前的博文一样, ...
- I2C控制器的Verilog建模之一
前言:之前申请了ADI公司的一款ADV7181CBSTZ的视频解码芯片,正好原装DE2板子安的是同系列的ADV7181BBSTZ.虽然都是ADV7181的宗出,但是寄存器配置等等还是有些诧异,引脚也不 ...
- I2C控制器的Verilog建模之二
前言:接着上一篇的I2C写操作,今天要实现一个I2C的读操作.虽然在ADV7181B配置内部寄存器时没有必要使用到读操作,但是为了进一步确认寄存器是否在I2C写模块下被正确配置,这一步是必不可少的. ...
- 【接口时序】7、VGA接口原理与Verilog实现
一. 软件平台与硬件平台 软件平台: 1.操作系统:Windows-8.1 2.开发套件:ISE14.7 3.仿真工具:ModelSim-10.4-SE 硬件平台: 1. FPGA型号:Xilinx公 ...
随机推荐
- [转]Android,Yocto,Meego构建系统的区别
http://m.blog.csdn.net/blog/sonach_tjsd/6647829
- O_NONBLOCK on regular file
It seems that writes/reads to regular files can't not be made non-blocking. I found the following re ...
- windows定时执行百度新闻爬虫
想要做个新闻文本识别分类的项目,就先写了个爬取百度新闻的爬虫. 环境:win7 32 bit python3.4 若干第三方库 可以实现的功能:定期按照百度新闻的分类抓取新闻的标题,所属类别及文本内容 ...
- javascript 封装(给自己看)
HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...
- Sublime Text 3安装插件指南
Sublime Text已经很用得很广泛,一般普通的功能已经够用,加入一些插件能些许加快开发. 安装 Package Control 有了插件控制器Package Control安装起来就很轻松了. ...
- (实用篇)php数组查找函数in_array()、array_search()、array_key_exists()使用
php在数组中查找指定值是否存在的方法有很多,记得很久以前我一直都是傻傻的用foreach循环来查找的,下面我主要分享一下用php内置的三个数组函数来查找指定值是否存在于数组中,这三个数组分别是 in ...
- Java初学者入门应该掌握的30个概念
1.OOP中唯一关系的是对象的接口是什么,就像计算机的销售商她不管电源内部结构 是怎样的,他只关系能否给你提供电就行了,也就是只要知道can or not而不是how and why.所有的程序是由一 ...
- javascript confirm()函数的用法
javascript confirm()函数的用法 confirm():确认消息对话框.用于允许用户做选择的动作.弹出的对话框中包含一确定按钮和一取消按钮. confirm(str) 参数说明: st ...
- maven的SNAPSHOT版本和正式版本不同
转载文章: http://www.huangbowen.net/blog/2016/01/29/understand-official-version-and-snapshot-version-in- ...
- centos6.4_安装Python3.5.2之问题
一.安装centos6.4虚拟机 这个就不用我详细介绍了,网上安装教程一大把了哈,自己百度安装应该没啥问题了 二.下载python安装包 官网下载python3.5.2安装包:https://www. ...