Advertisement
Guest User

Test_Pattern_Gen.v

a guest
Jan 27th, 2021
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // This module is designed for 640x480 with a 25 MHz input clock.
  3. // All test patterns are being generated all the time.  This makes use of one
  4. // of the benefits of FPGAs, they are highly parallelizable.  Many different
  5. // things can all be happening at the same time.  In this case, there are several
  6. // test patterns that are being generated simulatenously.  The actual choice of
  7. // which test pattern gets displayed is done via the i_Pattern signal, which is
  8. // an input to a case statement.
  9.  
  10. // Available Patterns:
  11. // Pattern 0: Disables the Test Pattern Generator
  12. // Pattern 1: All Red
  13. // Pattern 2: All Green
  14. // Pattern 3: All Blue
  15. // Pattern 4: Checkerboard white/black
  16. // Pattern 5: Color Bars
  17. // Pattern 6: White Box with Border (2 pixels)
  18.  
  19. // Note: Comment out this line when building in iCEcube2:
  20. //`include "Sync_To_Count.v"
  21.  
  22.  
  23. module Test_Pattern_Gen
  24.   #(parameter VIDEO_WIDTH = 3,
  25.    parameter TOTAL_COLS  = 800,
  26.    parameter TOTAL_ROWS  = 525,
  27.    parameter ACTIVE_COLS = 640,
  28.    parameter ACTIVE_ROWS = 480)
  29.   (input       i_Clk,
  30.    input [3:0] i_Pattern,
  31.    input       i_HSync,
  32.    input       i_VSync,
  33.    output reg  o_HSync = 0,
  34.    output reg  o_VSync = 0,
  35.    output reg [VIDEO_WIDTH-1:0] o_Red_Video,
  36.    output reg [VIDEO_WIDTH-1:0] o_Grn_Video,
  37.    output reg [VIDEO_WIDTH-1:0] o_Blu_Video);
  38.  
  39.   wire w_VSync;
  40.   wire w_HSync;
  41.  
  42.  
  43.   // Patterns have 16 indexes (0 to 15) and can be g_Video_Width bits wide
  44.   wire [VIDEO_WIDTH-1:0] Pattern_Red[0:15];
  45.   wire [VIDEO_WIDTH-1:0] Pattern_Grn[0:15];
  46.   wire [VIDEO_WIDTH-1:0] Pattern_Blu[0:15];
  47.  
  48.   // Make these unsigned counters (always positive)
  49.   wire [9:0] w_Col_Count;
  50.   wire [9:0] w_Row_Count;
  51.  
  52.   wire [6:0] w_Bar_Width;
  53.   wire [2:0] w_Bar_Select;
  54.  
  55.   Sync_To_Count #(.TOTAL_COLS(TOTAL_COLS),
  56.                   .TOTAL_ROWS(TOTAL_ROWS))
  57.  
  58.   UUT (.i_Clk      (i_Clk),
  59.        .i_HSync    (i_HSync),
  60.        .i_VSync    (i_VSync),
  61.        .o_HSync    (w_HSync),
  62.        .o_VSync    (w_VSync),
  63.        .o_Col_Count(w_Col_Count),
  64.        .o_Row_Count(w_Row_Count)
  65.       );
  66.      
  67.  
  68.   // Register syncs to align with output data.
  69.   always @(posedge i_Clk)
  70.   begin
  71.     o_VSync <= w_VSync;
  72.     o_HSync <= w_HSync;
  73.   end
  74.  
  75.   /////////////////////////////////////////////////////////////////////////////
  76.   // Pattern 0: Disables the Test Pattern Generator
  77.   /////////////////////////////////////////////////////////////////////////////
  78.   assign Pattern_Red[0] = 0;
  79.   assign Pattern_Grn[0] = 0;
  80.   assign Pattern_Blu[0] = 0;
  81.  
  82.   /////////////////////////////////////////////////////////////////////////////
  83.   // Pattern 1: All Red
  84.   /////////////////////////////////////////////////////////////////////////////
  85.   assign Pattern_Red[1] = (w_Col_Count < ACTIVE_COLS && w_Row_Count < ACTIVE_ROWS) ? {VIDEO_WIDTH{1'b1}} : 0;
  86.   assign Pattern_Grn[1] = 0;
  87.   assign Pattern_Blu[1] = 0;
  88.  
  89.   /////////////////////////////////////////////////////////////////////////////
  90.   // Pattern 2: All Green
  91.   /////////////////////////////////////////////////////////////////////////////
  92.   assign Pattern_Red[2] = 0;
  93.   assign Pattern_Grn[2] = (w_Col_Count < ACTIVE_COLS && w_Row_Count < ACTIVE_ROWS) ? {VIDEO_WIDTH{1'b1}} : 0;
  94.   assign Pattern_Blu[2] = 0;
  95.  
  96.   /////////////////////////////////////////////////////////////////////////////
  97.   // Pattern 3: All Blue
  98.   /////////////////////////////////////////////////////////////////////////////
  99.   assign Pattern_Red[3] = 0;
  100.   assign Pattern_Grn[3] = 0;
  101.   assign Pattern_Blu[3] = (w_Col_Count < ACTIVE_COLS && w_Row_Count < ACTIVE_ROWS) ? {VIDEO_WIDTH{1'b1}} : 0;
  102.  
  103.   /////////////////////////////////////////////////////////////////////////////
  104.   // Pattern 4: Checkerboard white/black
  105.   /////////////////////////////////////////////////////////////////////////////
  106.   assign Pattern_Red[4] = w_Col_Count[5] ^ w_Row_Count[5] ? {VIDEO_WIDTH{1'b1}} : 0;
  107.   assign Pattern_Grn[4] = Pattern_Red[4];
  108.   assign Pattern_Blu[4] = Pattern_Red[4];
  109.  
  110.  
  111.   /////////////////////////////////////////////////////////////////////////////
  112.   // Pattern 5: Color Bars
  113.   // Divides active area into 8 Equal Bars and colors them accordingly
  114.   // Colors Each According to this Truth Table:
  115.   // R G B  w_Bar_Select  Ouput Color
  116.   // 0 0 0       0        Black
  117.   // 0 0 1       1        Blue
  118.   // 0 1 0       2        Green
  119.   // 0 1 1       3        Turquoise
  120.   // 1 0 0       4        Red
  121.   // 1 0 1       5        Purple
  122.   // 1 1 0       6        Yellow
  123.   // 1 1 1       7        White
  124.   /////////////////////////////////////////////////////////////////////////////
  125.   assign w_Bar_Width = ACTIVE_COLS/8;
  126.  
  127.   assign w_Bar_Select = w_Col_Count < w_Bar_Width*1 ? 0 :
  128.                         w_Col_Count < w_Bar_Width*2 ? 1 :
  129.                         w_Col_Count < w_Bar_Width*3 ? 2 :
  130.                         w_Col_Count < w_Bar_Width*4 ? 3 :
  131.                         w_Col_Count < w_Bar_Width*5 ? 4 :
  132.                         w_Col_Count < w_Bar_Width*6 ? 5 :
  133.                         w_Col_Count < w_Bar_Width*7 ? 6 : 7;
  134.                  
  135.   // Implement Truth Table above with Conditional Assignments
  136.   assign Pattern_Red[5] = (w_Bar_Select == 4 || w_Bar_Select == 5 ||
  137.                            w_Bar_Select == 6 || w_Bar_Select == 7) ?
  138.                           {VIDEO_WIDTH{1'b1}} : 0;
  139.                      
  140.   assign Pattern_Grn[5] = (w_Bar_Select == 2 || w_Bar_Select == 3 ||
  141.                            w_Bar_Select == 6 || w_Bar_Select == 7) ?
  142.                           {VIDEO_WIDTH{1'b1}} : 0;
  143.                                          
  144.   assign Pattern_Blu[5] = (w_Bar_Select == 1 || w_Bar_Select == 3 ||
  145.                            w_Bar_Select == 5 || w_Bar_Select == 7) ?
  146.                           {VIDEO_WIDTH{1'b1}} : 0;
  147.  
  148.  
  149.   /////////////////////////////////////////////////////////////////////////////
  150.   // Pattern 6: Black With White Border
  151.   // Creates a black screen with a white border 2 pixels wide around outside.
  152.   /////////////////////////////////////////////////////////////////////////////
  153.   assign Pattern_Red[6] = (w_Row_Count <= 1 || w_Row_Count >= ACTIVE_ROWS-1-1 ||
  154.                            w_Col_Count <= 1 || w_Col_Count >= ACTIVE_COLS-1-1) ?
  155.                           {VIDEO_WIDTH{1'b1}} : 0;
  156.   assign Pattern_Grn[6] = Pattern_Red[6];
  157.   assign Pattern_Blu[6] = Pattern_Red[6];
  158.  
  159.  
  160.   /////////////////////////////////////////////////////////////////////////////
  161.   // Select between different test patterns
  162.   /////////////////////////////////////////////////////////////////////////////
  163.   always @(posedge i_Clk)
  164.   begin
  165.     case (i_Pattern)
  166.       4'h0 :
  167.       begin
  168.         o_Red_Video <= Pattern_Red[0];
  169.         o_Grn_Video <= Pattern_Grn[0];
  170.         o_Blu_Video <= Pattern_Blu[0];
  171.       end
  172.       4'h1 :
  173.       begin
  174.         o_Red_Video <= Pattern_Red[1];
  175.         o_Grn_Video <= Pattern_Grn[1];
  176.         o_Blu_Video <= Pattern_Blu[1];
  177.       end
  178.       4'h2 :
  179.       begin
  180.         o_Red_Video <= Pattern_Red[2];
  181.         o_Grn_Video <= Pattern_Grn[2];
  182.         o_Blu_Video <= Pattern_Blu[2];
  183.       end
  184.       4'h3 :
  185.       begin
  186.         o_Red_Video <= Pattern_Red[3];
  187.         o_Grn_Video <= Pattern_Grn[3];
  188.         o_Blu_Video <= Pattern_Blu[3];
  189.       end
  190.       4'h4 :
  191.       begin
  192.         o_Red_Video <= Pattern_Red[4];
  193.         o_Grn_Video <= Pattern_Grn[4];
  194.         o_Blu_Video <= Pattern_Blu[4];
  195.       end
  196.       4'h5 :
  197.       begin
  198.         o_Red_Video <= Pattern_Red[5];
  199.         o_Grn_Video <= Pattern_Grn[5];
  200.         o_Blu_Video <= Pattern_Blu[5];
  201.       end
  202.       4'h6 :
  203.       begin
  204.         o_Red_Video <= Pattern_Red[6];
  205.         o_Grn_Video <= Pattern_Grn[6];
  206.         o_Blu_Video <= Pattern_Blu[6];
  207.       end
  208.       default:
  209.       begin
  210.         o_Red_Video <= Pattern_Red[0];
  211.         o_Grn_Video <= Pattern_Grn[0];
  212.         o_Blu_Video <= Pattern_Blu[0];
  213.       end
  214.     endcase
  215.   end
  216. endmodule
  217.  
  218.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement