1
0

TimingGenerator.v 3.3 KB

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