1
0

TimingGenerator.v 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Generates video timings and counters
  3. */
  4. module TimingGenerator
  5. #(
  6. parameter H_RES = 640, // horizontal resolution (pixels)
  7. parameter V_RES = 480, // vertical resolution (lines)
  8. parameter H_FP = 16, // horizontal front porch
  9. parameter H_SYNC = 96, // horizontal sync
  10. parameter H_BP = 48, // horizontal back porch
  11. parameter V_FP = 10, // vertical front porch
  12. parameter V_SYNC = 2, // vertical sync
  13. parameter V_BP = 33, // vertical back porch
  14. parameter H_POL = 0, // horizontal sync polarity (0:neg, 1:pos)
  15. parameter V_POL = 0, // vertical sync polarity
  16. parameter INTERRUPT_TICKS = 32 // number of cycles the interrupt should be high
  17. )
  18. /* 4xWide 320x240
  19. #(
  20. parameter H_RES = 1706, // horizontal resolution (pixels)
  21. parameter V_RES = 240, // vertical resolution (lines)
  22. parameter H_FP = 40, // horizontal front porch
  23. parameter H_SYNC = 168, // horizontal sync
  24. parameter H_BP = 208, // horizontal back porch
  25. parameter V_FP = 3, // vertical front porch
  26. parameter V_SYNC = 10, // vertical sync
  27. parameter V_BP = 6, // vertical back porch
  28. parameter H_POL = 0, // horizontal sync polarity (0:neg, 1:pos)
  29. parameter V_POL = 0, // vertical sync polarity
  30. parameter INTERRUPT_TICKS = 32 // number of cycles the interrupt should be high
  31. )*/
  32. (
  33. input clkPixel,
  34. // Position counters
  35. output reg [11:0] h_count = 12'd0, // line position in pixels including blanking
  36. output reg [11:0] v_count = 12'd0, // frame position in lines including blanking
  37. output wire hsync,
  38. output wire vsync,
  39. output wire csync,
  40. output wire blank,
  41. //Interrupt signal
  42. output frameDrawn
  43. );
  44. // Horizontal: sync, active, and pixels
  45. localparam HS_STA = H_FP - 1; // sync start (first pixel is 0) 15
  46. localparam HS_END = HS_STA + H_SYNC; // sync end 111
  47. localparam HA_STA = HS_END + H_BP; // active start 149
  48. localparam HA_END = HA_STA + H_RES; // active end 789
  49. localparam LINE = HA_END; // line pixels
  50. // Vertical: sync, active, and pixels
  51. localparam VS_STA = V_FP - 1; // sync start (first line is 0) 9
  52. localparam VS_END = VS_STA + V_SYNC; // sync end 11
  53. localparam VA_STA = VS_END + V_BP; // active start 44
  54. localparam VA_END = VA_STA + V_RES; // active end 524
  55. localparam FRAME = VA_END; // frame lines
  56. always @ (posedge clkPixel)
  57. begin
  58. if (h_count == LINE) // end of line
  59. begin
  60. h_count <= 12'd0;
  61. v_count <= (v_count == FRAME) ? 12'd0 : v_count + 12'd1;
  62. end
  63. else
  64. h_count <= h_count + 12'd1;
  65. end
  66. assign hsync = H_POL ? (h_count > HS_STA && h_count <= HS_END):
  67. ~(h_count > HS_STA && h_count <= HS_END);
  68. assign vsync = V_POL ? (v_count > VS_STA && v_count <= VS_END):
  69. ~(v_count > VS_STA && v_count <= VS_END);
  70. assign csync = ~(hsync ^ vsync);
  71. assign blank = ~(h_count > HA_STA && h_count <= HA_END && v_count > VA_STA && v_count <= VA_END);
  72. // Interrupt signal for CPU, high for some ticks when last frame is drawn
  73. assign frameDrawn = (v_count == 0 && h_count < INTERRUPT_TICKS);
  74. endmodule