// // File: vga_romdisp.v // Date: 14-Nov-05 // Author: I. Chuang // // Example demonstrating display of image from ROM on 640x480 VGA // // This module reads data from ROM and creates the proper 8-bit pixel // value for a pixel position defined by (hcount,vcount). Note that // there is a one cycle delay in reading from memory, so we may // have a single pixel offset error here, to be fixed. But the displayed // image looks respectable nevertheless. // // To create the image ROM, use the Xilinx IP tools to generate a // single port block memory, and load in an initial value file (*.coe) // for your image. This ROM should have width 8 (8-bit pixel output) // and depth 76800 (320x240). // // The COE file may be generated from an 8-bit PGM format image file // using pgm2coe.py, or using your own tool. Read the Xilinx documentation // for more about COE files. module vga_romdisp(clk,hcount,vcount,pix_clk,pixel); input clk; // video clock input [9:0] hcount; // current x,y location of pixel input [9:0] vcount; input pix_clk; // pixel clock output [7:0] pixel; // pixel value output // the memory address is hcount/2 + vcount/2 * 320 // (4 pixels per memory location, since image is 320x240, and // display is 640x480). reg [16:0] raddr; always @(posedge clk) raddr <= (hcount==0 & vcount==0) ? 0 : (hcount==0 & pix_clk & ~vcount[0]) ? raddr + 320 : raddr; wire [16:0] addr = {8'b0,hcount[9:1]} + raddr[16:0]; reg [16:0] addr_reg; always @(posedge clk) addr_reg <= addr; // instantiate the image rom flower2_bw_320_240 imgrom(addr_reg,clk,pixel); endmodule // vga_romdisp