Advertisement
Guest User

Untitled

a guest
Feb 27th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // File: vga_timing.v
  2. // This is the vga timing design for EE178 Lab #4.
  3.  
  4. // The `timescale directive specifies what the
  5. // simulation time units are (1 ns here) and what
  6. // the simulator time step should be (1 ps here).
  7.  
  8. //https://timetoexplore.net/blog/video-timings-vga-720p-1080p
  9. //https://learn.digilentinc.com/Documents/269
  10. //https://timetoexplore.net/blog/arty-fpga-vga-verilog-01
  11.  
  12. `timescale 1 ns / 1 ps
  13.  
  14. // Declare the module and its ports. This is
  15. // using Verilog-2001 syntax.
  16.  
  17. module vga_timing (
  18.   output reg [10:0] vcount,
  19.   output reg vsync,
  20.   output reg vblnk,
  21.   output reg [10:0] hcount,
  22.   output reg hsync,
  23.   output reg hblnk,
  24.   input wire pclk,
  25.   input wire rst
  26.   );
  27.  
  28. // Describe the actual circuit for the assignment.
  29. // Video timing controller set for 800x600@60fps
  30. // using a 40 MHz pixel clock per VESA spec.
  31.  
  32. //Time in horizontal lines
  33.     parameter HorTimeWidth = 10'd128;
  34.     parameter HorFrontPorch = 10'd40;
  35.     parameter HorBackPorch = 10'd88;
  36.     parameter HorTimeToDisplay = 10'd800;
  37.     parameter HorTotalTime = 12'd1056;
  38.     parameter HorSyncStart = 10'd840;
  39.      
  40. //Time in Vertincal lines
  41.     parameter VerTimeWidth = 10'd4;
  42.     parameter VerFrontPorch = 10'd1;      
  43.     parameter VerBackPorch = 10'd23;
  44.     parameter VerTimeToDisplay = 10'd600;
  45.     parameter VerTotalTime = 10'd628;
  46.     parameter VerSyncStart = 10'd601;
  47.    
  48.     parameter initial_borders = 10'b0;
  49.    
  50. //Horizontal counter
  51. always @(posedge pclk or posedge rst)
  52.     if (rst)
  53.         hcount <= initial_borders;
  54.     else
  55.         begin
  56.             if (hcount == HorTotalTime)
  57.                 hcount <= initial_borders;
  58.             else
  59.                 hcount <= hcount + 1;
  60.         end
  61.  
  62. //Vertical counter
  63. always @(posedge pclk or posedge rst)
  64.     if (rst)
  65.         vcount <= initial_borders;
  66.     else begin
  67.         if (hcount == HorTotalTime)
  68.             begin
  69.                 if (vcount == VerTotalTime)
  70.                     vcount <= initial_borders;
  71.                 else
  72.                     vcount <= vcount +1;
  73.             end
  74.     end
  75.  
  76. always @* begin
  77.  
  78.     if (hcount >= HorSyncStart && hcount <= (HorSyncStart + HorTimeWidth)) begin
  79.         hsync = 1;
  80.     end
  81.     else begin
  82.         hsync = 0;
  83.     end
  84.    
  85.     if (vcount >= VerSyncStart && vcount <= (VerSyncStart + VerTimeWidth)) begin
  86.         vsync = 1;
  87.     end
  88.     else begin
  89.         vsync = 0;
  90.     end
  91.    
  92.     if (hcount >= HorTimeToDisplay) begin
  93.         hblnk = 1;
  94.     end
  95.     else begin
  96.         hblnk = 0;
  97.     end
  98.    
  99.     if (vcount >= VerTimeToDisplay) begin
  100.         vblnk = 1;
  101.     end
  102.     else begin
  103.         vblnk = 0;
  104.     end
  105.    
  106. end
  107. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement