Hello,
I am new with CPLD and Verilog. I have made some code and posted on comp.lang.verilog but nobody responded.
I need help. I don't know if this code works. I don't know how to make a test module. (I am using ISE Webpack 4.2 and MXE).
Thanks.
---
Here goes: ====================================================================== /* * VGA 800x600 @ 60 Hz Signal Generator using Verilog * ================================================== * * Date: 25 November 2004 * * Intended CPLD: Xilinx XC9536XL (or XC9572XL) * Clock source: 40 Mhz (25 nanoseconds per pixel) * Posted on comp.lang.verilog and es.ciencia.electronica *
Timing diagrams: ================
(For more detailed information on timing, see:
A) Horizontal Line: =================== A1 ---> 800 pixels (20 us) Horizontal active display A2 ---> 40 pixels ( 1 us) Horizontal front porch A3 ---> 128 pixels ( 3.2 us) Horizontal Sync. A4 ---> 88 pixels ( 2.2 us) Horizontal back porch ================================================== 1056 pixels (26.4 us) Total Horizontal line (about 37.879 KHz)
B) Vertical timing: ===================
(A1+A2+A3+A4) * 600 lines --> (15840 us) Vertical active display B (1 line) ----------------> ( 26.4 us) Vertical front porch C (4 lines) ---------------> ( 105.6 us) Vertical Sync. D (23 lines) ---------------> ( 607.2 us) Vertical back porch ===================================== 16579.2 us Total VGA Frame (about 60.31 Hz)
*/module VGAsignal (clock, reset, RGB, Hsync, Vsync);
input clock; input reset; output RGB, Hsync, Vsync; reg RGB, Hsync, Vsync;
reg [10:0] Xcounter; // 2^11 = 2048 reg [9:0] Ycounter; // 2^10 = 1024
parameter A1=0, A2=1, A3=2, A4=3, B=4, C=5, D=6;
reg [2:0] CurrentState, NextState;
always @(Xcounter or Ycounter or CurrentState) // Next state logic begin NextState = A1; case (CurrentState) A1 : begin if (Xcounter == 800) NextState = A2; else NextState = A1; end A2 : begin if (Xcounter == 840) NextState = A3; else NextState = A2; end A3 : begin if (Xcounter == 968) NextState = A4; else NextState = A3; end A4 : begin if ((Xcounter == 1056) & (Ycounter == 600)) NextState = B; else NextState = A4; end B : begin if (Ycounter == 602) NextState = C; else NextState = B; end C : begin if (Ycounter == 606) NextState = D; else NextState = C; end D : begin if (Ycounter == 628) NextState = A1; else NextState = D; end endcase end
always @(posedge clock or posedge reset) // Current state logic begin if (reset) begin CurrentState = A1; Xcounter = 0; Xcounter = 0; end else begin CurrentState = NextState; if (Xcounter == 1057) Xcounter = 0; else Xcounter = Xcounter + 1; if (Ycounter == 629) Ycounter = 0; else Ycounter = Ycounter + 1; end end
always @(CurrentState) // Output logic begin case (CurrentState) A1 : begin RGB = 1; Hsync = 0; Vsync = 0; // Active RGB end A2 : begin RGB = 0; Hsync = 0; Vsync = 0; // Horizontal Front Porch end A3 : begin RGB = 0; Hsync = 1; Vsync = 0; // Horizontal Sync. end A4 : begin RGB = 0; Hsync = 0; Vsync = 0; // Horizontal Back Porch end B : begin RGB = 0; Hsync = 0; Vsync = 0; // Vertical Front Porch end C : begin RGB = 0; Hsync = 0; Vsync = 1; // Vertical Sync. end D : begin RGB = 0; Hsync = 0; Vsync = 0; // Vertical Back Porch end default: begin RGB = 0; Hsync = 0; Vsync = 0; // Is this needed? end endcase end
endmodule