Advertisement
Guest User

VGA_Test_Patterns_Top.v

a guest
Jan 27th, 2021
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module VGA_Test_Patterns_Top
  2. (input i_Clk,
  3.  input i_UART_RX,
  4.  output o_UART_TX,
  5.  
  6.  // VGA Stuff
  7.  output o_VGA_HSync,
  8.  output o_VGA_VSync,
  9.  output o_VGA_Red_0,
  10.  output o_VGA_Red_1,
  11.  output o_VGA_Red_2,
  12.  output o_VGA_Grn_0,
  13.  output o_VGA_Grn_1,
  14.  output o_VGA_Grn_2,
  15.  output o_VGA_Blu_0,
  16.  output o_VGA_Blu_1,
  17.  output o_VGA_Blu_2
  18.     );
  19.  
  20. // VGA Constants to set frame size
  21. parameter c_VIDEO_WIDTH  = 3;
  22. parameter c_TOTAL_COLS   = 800;
  23. parameter c_TOTAL_ROWS   = 525;
  24. parameter c_ACTIVE_COLS  = 640;
  25. parameter c_ACTIVE_ROWS  = 480;
  26.  
  27. wire w_RX_DV;
  28. wire [7:0] w_RX_Byte;
  29. wire w_TX_Active, w_TX_Serial;
  30.  
  31. reg [3:0] r_TP_Index = 0;  
  32.  
  33. // Common VGA Signals
  34. wire [c_VIDEO_WIDTH-1:0] w_Red_Video_TP, w_Red_Video_Porch;
  35. wire [c_VIDEO_WIDTH-1:0] w_Grn_Video_TP, w_Grn_Video_Porch;
  36. wire [c_VIDEO_WIDTH-1:0] w_Blu_Video_TP, w_Blu_Video_Porch;
  37.  
  38.  
  39. // Formula for 115,200 baud rate
  40. // 25mhz / 115,200 = 217
  41. // But I have a 100mhz clock
  42.  
  43. UART_RX #(.CLKS_PER_BIT(868)) UART_RX_Inst
  44. (.i_Clock(i_Clk),
  45.  .i_RX_Serial(I_UART_RX),
  46.  .o_RX_DV(w_RX_DV),
  47.  .o_RX_Byte(w_RX_Byte));
  48.  
  49. UART_TX #(.CLKS_PER_BIT(868)) UART_TX_Inst
  50. (.i_Clock(I_Clk),
  51.  .i_TX_DV(w_RX_DV),
  52.  .i_TX_Byte(w_RX_Byte),
  53.  .o_TX_Active(w_TX_Active),
  54.  .o_TX_Serial(w_TX_Serial),
  55.  .o_TX_Done());
  56.  
  57.  assign o_UART_TX = w_TX_Active ? w_TX_Serial : 1'b1;
  58.  
  59.  
  60. //////////////////////////////////////////////////////////////////
  61. // VGA Test Patterns
  62. //////////////////////////////////////////////////////////////////
  63. // Purpose: Register test pattern from UART when DV pulse is seen
  64. // Only least significant 4 bits are needed from whole byte.
  65.  
  66.  
  67. //Clock Division
  68. reg half;
  69. reg quarter;
  70.  
  71. always @(posedge i_Clk)
  72.   begin
  73.     half <= ~half;
  74.   end
  75. always @(posedge half)
  76.   begin
  77.     quarter <= ~quarter;
  78.   end
  79.  
  80.  
  81. always @(posedge quarter)
  82.  begin
  83.   if (w_RX_DV == 1'b1)
  84.     r_TP_Index <= w_RX_Byte[3:0];
  85.  end
  86.    
  87. // Generates Sync Pulses to run VGA
  88. VGA_Sync_Pulses #(.TOTAL_COLS(c_TOTAL_COLS),
  89.                   .TOTAL_ROWS(c_TOTAL_ROWS),
  90.                   .ACTIVE_COLS(c_ACTIVE_COLS),
  91.                   .ACTIVE_ROWS(c_ACTIVE_ROWS))
  92. VGA_Sync_Pulses_Inst
  93.     (.i_Clk(quarter),
  94.     .o_HSync(w_HSync_Start),
  95.     .o_VSync(w_VSync_Start),
  96.     .o_Col_Count(),
  97.     .o_Row_Count()
  98. );
  99.    
  100.    
  101. // Drives Red/Grn/Blue video - Test Pattern 5 (Color Bars)
  102. Test_Pattern_Gen  #(.VIDEO_WIDTH(c_VIDEO_WIDTH),
  103.                     .TOTAL_COLS(c_TOTAL_COLS),
  104.                     .TOTAL_ROWS(c_TOTAL_ROWS),
  105.                     .ACTIVE_COLS(c_ACTIVE_COLS),
  106.                     .ACTIVE_ROWS(c_ACTIVE_ROWS))
  107. Test_Pattern_Gen_Inst
  108.     (.i_Clk(quarter),
  109.     .i_Pattern(r_TP_Index),
  110.     .i_HSync(w_HSync_Start),
  111.     .i_VSync(w_VSync_Start),
  112.     .o_HSync(w_HSync_TP),
  113.     .o_VSync(w_VSync_TP),
  114.     .o_Red_Video(w_Red_Video_TP),
  115.     .o_Grn_Video(w_Grn_Video_TP),
  116.     .o_Blu_Video(w_Blu_Video_TP));
  117.      
  118. VGA_Sync_Porch  #(.VIDEO_WIDTH(c_VIDEO_WIDTH),
  119.                   .TOTAL_COLS(c_TOTAL_COLS),
  120.                   .TOTAL_ROWS(c_TOTAL_ROWS),
  121.                   .ACTIVE_COLS(c_ACTIVE_COLS),
  122.                   .ACTIVE_ROWS(c_ACTIVE_ROWS))
  123. VGA_Sync_Porch_Inst
  124.     (.i_Clk(quarter),
  125.      .i_HSync(w_HSync_TP),
  126.     .i_VSync(w_VSync_TP),
  127.     .i_Red_Video(w_Red_Video_TP),
  128.     .i_Grn_Video(w_Grn_Video_TP),
  129.     .i_Blu_Video(w_Blu_Video_TP),
  130.     .o_HSync(w_HSync_Porch),
  131.     .o_VSync(w_VSync_Porch),
  132.     .o_Red_Video(w_Red_Video_Porch),
  133.     .o_Grn_Video(w_Grn_Video_Porch),
  134.     .o_Blu_Video(w_Blu_Video_Porch));
  135.        
  136. assign o_VGA_HSync = w_HSync_Porch;
  137. assign o_VGA_VSync = w_VSync_Porch;
  138.        
  139. assign o_VGA_Red_0 = w_Red_Video_Porch[0];
  140. assign o_VGA_Red_1 = w_Red_Video_Porch[1];
  141. assign o_VGA_Red_2 = w_Red_Video_Porch[2];
  142.    
  143. assign o_VGA_Grn_0 = w_Grn_Video_Porch[0];
  144. assign o_VGA_Grn_1 = w_Grn_Video_Porch[1];
  145. assign o_VGA_Grn_2 = w_Grn_Video_Porch[2];
  146.  
  147. assign o_VGA_Blu_0 = w_Blu_Video_Porch[0];
  148. assign o_VGA_Blu_1 = w_Blu_Video_Porch[1];
  149. assign o_VGA_Blu_2 = w_Blu_Video_Porch[2];
  150.    
  151. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement