1 //===============================================================================
 
   2 // FPGA VGA INTERFACE  FOR ALTERA CYCLONE & XILINX SPARTAN2E
 
   6 // Copyright(c) 2003 - 2004 Katsumi Degawa , All rights reserved
 
   8 // based on a design by Tatsuyuki Satoh
 
  12 // This program is freeware for non-commercial use. 
 
  13 // An author does no guarantee about this program.
 
  14 // You can use this under your own risk.
 
  16 // 2004- 9-18 added SPARTAN2E DEVIDE . K.DEGAWA
 
  17 //================================================================================
 
  18 `include "src/mc_conf.v"
 
  39 input I_CLK_1;        // 6.144MHz  input pixel clock
 
  40 input I_CLK_2;       // 12.288Mhz output pixel clock
 
  41 input [2:0]I_R;        // R in
 
  42 input [2:0]I_G;        // G in
 
  43 input [1:0]I_B;        // B in
 
  44 input I_H_SYNC;        // HSYNC input (16KHz)
 
  45 input I_V_SYNC;        // VSYNC input (60Hz)
 
  48 output [2:0]O_R;       // R out
 
  49 output [2:0]O_G;       // G out
 
  50 output [1:0]O_B;       // B out
 
  51 output O_H_SYNCn;      // HSYNC output
 
  52 output O_V_SYNCn;      // VSYNC output
 
  54 //---------------------------------------------------------------------------
 
  56 //---------------------------------------------------------------------------
 
  58 parameter H_COUNT  = 384;        // number of pixels in H-SCAN
 
  59 parameter HS_POS   = 16;         // HSYNC position 
 
  60 parameter HS_WIDTH = HS_POS+8;   // HSYNC width / pixel
 
  61 parameter VS_WIDTH = 8;          // VSYNC width / HSYNC_OUT
 
  63 //---------------------------------------------------------------------------
 
  65 //---------------------------------------------------------------------------
 
  66 reg    [8:0]Hpos_in;     // input capture postion
 
  68 wire   HP_in = ~L_Hsync_i & I_H_SYNC;
 
  69 always@(posedge I_CLK_1)
 
  71    Hpos_in   <= HP_in ? 0: Hpos_in + 1;
 
  72    L_Hsync_i <= I_H_SYNC;
 
  75 //---------------------------------------------------------------------------
 
  77 //---------------------------------------------------------------------------
 
  80 wire   HP_out = ~L_Hsync_o & I_H_SYNC;
 
  81 wire   HP_ret = HP_out | (Hpos_out == H_COUNT-1);
 
  83 always@(posedge I_CLK_2)
 
  85    Hpos_out  <= HP_ret ? 0:Hpos_out + 1;
 
  86    L_Hsync_o <= I_H_SYNC;
 
  90 always@(posedge I_CLK_2)
 
  93       HS_POS  :O_Hsync <= 1'b1;
 
  94       HS_WIDTH:O_Hsync <= 1'b0;
 
  99 //---------------------------------------------------------------------------
 
 100 // RGB capture(portA) & output(portB)
 
 101 //---------------------------------------------------------------------------
 
 102 wire   [7:0]rgb_in = {I_R,I_G,I_B};       // RGB input
 
 103 wire   [7:0]rgb_out;                      // RGB output
 
 105 `ifdef DEVICE_CYCLONE
 
 106 alt_ram_512_8_d double_scan_ram(
 
 117 .address_b(Hpos_out),
 
 126 `ifdef DEVICE_SPARTAN2E
 
 127 RAMB4_S8_S8 double_scan_ram (
 
 147 //---------------------------------------------------------------------------
 
 150 // 1 HSYNC_IN delay & HSYNC pulse width = 4xHSYNC(in)
 
 151 //---------------------------------------------------------------------------
 
 156 always @(posedge O_Hsync)
 
 159       vs_cnt  <= VS_WIDTH-1;
 
 162       if(vs_cnt==0) vs_cnt <= vs_cnt;
 
 163       else          vs_cnt <= vs_cnt-1;
 
 166 always @(posedge O_Hsync)
 
 169       VS_WIDTH-2 :O_Vsync <= 1;
 
 173 //---------------------------------------------------------------------------
 
 175 //---------------------------------------------------------------------------
 
 177 assign O_R = rgb_out[7:5]; 
 
 178 assign O_G = rgb_out[4:2];
 
 179 assign O_B = rgb_out[1:0]; 
 
 181 // converted  H V SYNC
 
 182 assign O_H_SYNCn = ~O_Hsync;
 
 183 assign O_V_SYNCn = ~O_Vsync;
 
 187 `ifdef DEVICE_CYCLONE
 
 188 module alt_ram_512_8_d (
 
 206         input   [8:0]  address_a;
 
 208         input   [8:0]  address_b;
 
 219         wire [7:0] sub_wire0;
 
 220         wire [7:0] sub_wire1;
 
 221         wire [7:0] q_a = sub_wire0[7:0];
 
 222         wire [7:0] q_b = sub_wire1[7:0];
 
 224         altsyncram      altsyncram_component (
 
 225                                 .clocken0 (enable_a),
 
 226                                 .clocken1 (enable_b),
 
 233                                 .address_a (address_a),
 
 234                                 .address_b (address_b),
 
 240                 altsyncram_component.operation_mode = "BIDIR_DUAL_PORT",
 
 241                 altsyncram_component.width_a = 8,
 
 242                 altsyncram_component.widthad_a = 9,
 
 243                 altsyncram_component.numwords_a = 512,
 
 244                 altsyncram_component.width_b = 8,
 
 245                 altsyncram_component.widthad_b = 9,
 
 246                 altsyncram_component.numwords_b = 512,
 
 247                 altsyncram_component.lpm_type = "altsyncram",
 
 248                 altsyncram_component.width_byteena_a = 1,
 
 249                 altsyncram_component.width_byteena_b = 1,
 
 250                 altsyncram_component.outdata_reg_a = "UNREGISTERED",
 
 251                 altsyncram_component.outdata_aclr_a = "NONE",
 
 252                 altsyncram_component.outdata_reg_b = "UNREGISTERED",
 
 253                 altsyncram_component.indata_aclr_a = "CLEAR0",
 
 254                 altsyncram_component.wrcontrol_aclr_a = "CLEAR0",
 
 255                 altsyncram_component.address_aclr_a = "CLEAR0",
 
 256                 altsyncram_component.indata_reg_b = "CLOCK1",
 
 257                 altsyncram_component.address_reg_b = "CLOCK1",
 
 258                 altsyncram_component.wrcontrol_wraddress_reg_b = "CLOCK1",
 
 259                 altsyncram_component.indata_aclr_b = "CLEAR1",
 
 260                 altsyncram_component.wrcontrol_aclr_b = "CLEAR1",
 
 261                 altsyncram_component.address_aclr_b = "CLEAR1",
 
 262                 altsyncram_component.outdata_aclr_b = "NONE",
 
 263                 altsyncram_component.ram_block_type = "M4K",
 
 264                 altsyncram_component.intended_device_family = "Stratix";