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公 ...
随机推荐
- CsvReader,CsvWriter的使用以及解决中文乱码
public void Csv(){ try { String[] stringList; String sourceFilePath = "D:\\111\\前海自身.csv"; ...
- BeanUtil体会
把字符串(非纯数字组成的字符串,带有字符的那种)拷贝到int属性中,int属性值设为0 把字符串(纯数字组成的),赋值给double类型,可以直接转换,int类型也可以直接转换成double类型 但是 ...
- surface实例-小球弹起事例
ball.java package com.example.sufacedemo; import android.graphics.Bitmap; import android.graphics.Bi ...
- 浏览器兼容 copyToClipboard("拷贝内容")
function copyToClipboard(txt) { if (window.clipboardData) { window.clipboardData.clearData(); clipbo ...
- 设置ASP.NET页面的运行超时时间详细到单个页面及站点
这篇文章主要介绍了如何设置ASP.NET页面的运行超时时间,包括全局超时时间.单个站点超时时间.单个页面请求超时时间,需要的朋友可以参考下 全局超时时间 服务器上如果有多个网站,希望统一设置一 ...
- 第三个Sprint冲刺第二天
讨论地点:宿舍 讨论成员:邵家文.李新.朱浩龙.陈俊金 讨论问题:强化答案讲解功能
- 限制文本框只能输入数字或浮点数的JS脚步
1.oninput,onpropertychange,onchange的用法 l onchange触发事件必须满足两个条件: a)当前对象属性改变,并且是由键盘或鼠标事件激发的(脚本 ...
- TCP/IP 协议:链路层概述
我们以一个常见的查看IP指令为出发点(ifconfig -a): 1.链路层是什么 链路层是指硬件层协议.也即网络所使用的硬件,比如:以太网(后文主要讨论对象),令牌环网,FDDI已经RS-232 ...
- 2015GitWebRTC编译实录14
libvpx 尝试用脚本编译了下,发现有问题,就偃旗息鼓,改用他自己的configure了,在网上找了下,Git上有个现成的,直接用,更好些. https://github.com/brion/VPX ...
- iOS的URL处理
前两天处理iOSapp过程中(我是用swift语言写的,资料较少),被一个“字符串”搞了一晚上的时间到第二天才处理好,在此记下,望见过此文的学生有一天遇到该情况能三分钟搞定不浪费时间: 先看如下代码 ...