Advertisement
Guest User

LCD Sync Gen Attempt

a guest
Feb 14th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Width of counters
  2.     parameter WIDTH = 11;
  3.    
  4.     // Horizontal timing parameters
  5.     parameter H_VISIBLE = 800;
  6.     parameter H_FRONT_PORCH = 210;
  7.     parameter H_SYNC = 30;
  8.     parameter H_BACK_PORCH = 16;
  9.  
  10.     // Vertical timing parameters
  11.     parameter V_VISIBLE = 480;
  12.     parameter V_FRONT_PORCH = 22;
  13.     parameter V_SYNC = 13;
  14.     parameter V_BACK_PORCH = 10;
  15.      
  16.      wire hblank;
  17.      wire vblank;
  18.  
  19.     // Instantiate the synchronize generator
  20.     sync_gen #(
  21.         .WIDTH(WIDTH),
  22.         .H_VISIBLE(H_VISIBLE),
  23.         .H_FRONT_PORCH(H_FRONT_PORCH),
  24.         .H_SYNC(H_SYNC),
  25.         .H_BACK_PORCH(H_BACK_PORCH),
  26.         .V_VISIBLE(V_VISIBLE),
  27.         .V_FRONT_PORCH(V_FRONT_PORCH),
  28.         .V_SYNC(V_SYNC),
  29.         .V_BACK_PORCH(V_BACK_PORCH)
  30.     ) sync_gen_0 (
  31.         .clk(clock_to_lcd),
  32.         .rst(~KEY[0]),
  33.         .hsync(hsync),
  34.         .vsync(vsync),
  35.         .hblank(hblank),
  36.         .vblank(vblank),
  37.     );
  38.  
  39. And then separately
  40.  
  41. module sync_gen
  42. #(
  43.     // Width of counters
  44.     parameter WIDTH,
  45.    
  46.     // Horizontal timing parameters
  47.     parameter H_VISIBLE,
  48.     parameter H_FRONT_PORCH,
  49.     parameter H_SYNC,
  50.     parameter H_BACK_PORCH,
  51.  
  52.     // Vertical timing parameters
  53.     parameter V_VISIBLE,
  54.     parameter V_FRONT_PORCH,
  55.     parameter V_SYNC,
  56.     parameter V_BACK_PORCH
  57. )
  58. (
  59.     input logic clk, rst,
  60.     output logic hsync, vsync,
  61.     output logic hblank, vblank
  62.  
  63. );
  64.  
  65.     // The counters used to determine when to pulse the sync signals
  66.     logic [WIDTH-1:0] pix_x, pix_y;
  67.  
  68.      
  69.     // Parameters that determine the maximum line and frame sizes
  70.     localparam [WIDTH-1:0] H_WHOLE_LINE = H_VISIBLE + H_FRONT_PORCH + H_SYNC + H_BACK_PORCH;
  71.     localparam [WIDTH-1:0] V_WHOLE_FRAME = V_VISIBLE + V_FRONT_PORCH + V_SYNC + V_BACK_PORCH;
  72.  
  73.     // Determines when to turn on sync (active low) and blank signals
  74.     assign hsync = !(pix_x >= (H_VISIBLE + H_FRONT_PORCH) && pix_x < (H_VISIBLE + H_FRONT_PORCH + H_SYNC));
  75.     assign vsync = !(pix_y >= (V_VISIBLE + V_FRONT_PORCH) && pix_y < (V_VISIBLE + V_FRONT_PORCH + V_SYNC));
  76.    
  77.     assign hblank = (pix_x >= (H_VISIBLE) && pix_x < (H_WHOLE_LINE));
  78.     assign vblank = (pix_y >= (V_VISIBLE) && pix_y < (V_WHOLE_FRAME));
  79.  
  80.     // Increment the counters
  81.     always_ff @(posedge clk) begin
  82.         begin
  83.             if(rst) begin
  84.                 pix_x <= '0;
  85.                 pix_y <= '0;
  86.             end else if (pix_x < H_WHOLE_LINE - 1) begin   // End of pixel, go to next pixel
  87.                 pix_x <= pix_x + 1'b1;
  88.                 pix_y <= pix_y;          
  89.             end else begin  // End of line, go to next line
  90.                 pix_x <= '0;
  91.                 if(pix_y < V_WHOLE_FRAME - 1)
  92.                     pix_y <= pix_y + 1'b1;
  93.                 else    // End of frame, go back to top
  94.                     pix_y <= '0;
  95.             end
  96.         end
  97.     end
  98.  
  99.     endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement