2017-11-18 19:51:25 +00:00
|
|
|
`ifndef HVSYNC_GENERATOR_H
|
|
|
|
`define HVSYNC_GENERATOR_H
|
2017-11-11 19:45:32 +00:00
|
|
|
|
2017-11-15 00:12:52 +00:00
|
|
|
module hvsync_generator(
|
2017-11-29 01:48:27 +00:00
|
|
|
clk, reset, hsync, vsync, display_on, hpos, vpos);
|
2017-11-11 19:45:32 +00:00
|
|
|
|
|
|
|
input clk;
|
2017-11-29 01:48:27 +00:00
|
|
|
input reset;
|
|
|
|
output reg hsync, vsync;
|
2017-11-17 21:01:07 +00:00
|
|
|
output reg display_on;
|
|
|
|
output reg [8:0] hpos;
|
|
|
|
output reg [8:0] vpos;
|
2017-11-11 19:45:32 +00:00
|
|
|
|
2017-11-29 01:48:27 +00:00
|
|
|
// constant declarations for TV-simulator sync parameters
|
2017-11-11 19:45:32 +00:00
|
|
|
localparam H_DISPLAY = 256; // horizontal display area
|
2018-01-07 22:57:17 +00:00
|
|
|
localparam H_L_BORDER = 23; // horizontal left border (back porch)
|
|
|
|
localparam H_R_BORDER = 7; // horizontal right border (front porch)
|
|
|
|
localparam H_RETRACE = 23; // horizontal retrace (sync)
|
2017-11-11 19:45:32 +00:00
|
|
|
localparam H_MAX = H_DISPLAY + H_L_BORDER + H_R_BORDER + H_RETRACE - 1;
|
|
|
|
localparam START_H_RETRACE = H_DISPLAY + H_R_BORDER;
|
|
|
|
localparam END_H_RETRACE = H_DISPLAY + H_R_BORDER + H_RETRACE - 1;
|
|
|
|
|
|
|
|
localparam V_DISPLAY = 240; // vertical display area
|
2017-11-20 01:32:58 +00:00
|
|
|
localparam V_T_BORDER = 4; // vertical top border
|
|
|
|
localparam V_B_BORDER = 14; // vertical bottom border
|
2018-01-07 22:57:17 +00:00
|
|
|
localparam V_RETRACE = 4; // vertical retrace (sync)
|
2017-11-11 19:45:32 +00:00
|
|
|
localparam V_MAX = V_DISPLAY + V_T_BORDER + V_B_BORDER + V_RETRACE - 1;
|
|
|
|
localparam START_V_RETRACE = V_DISPLAY + V_B_BORDER;
|
|
|
|
localparam END_V_RETRACE = V_DISPLAY + V_B_BORDER + V_RETRACE - 1;
|
|
|
|
|
2017-11-29 01:48:27 +00:00
|
|
|
wire hmaxxed = (hpos == H_MAX) || reset;
|
|
|
|
wire vmaxxed = (vpos == V_MAX) || reset;
|
|
|
|
|
|
|
|
// increment horizontal position counter
|
|
|
|
always @(posedge clk)
|
2017-11-17 21:01:07 +00:00
|
|
|
if(hmaxxed)
|
|
|
|
hpos <= 0;
|
2017-11-11 19:45:32 +00:00
|
|
|
else
|
2017-11-17 21:01:07 +00:00
|
|
|
hpos <= hpos + 1;
|
2017-11-11 19:45:32 +00:00
|
|
|
|
2017-11-29 01:48:27 +00:00
|
|
|
// increment vertical position counter
|
2017-11-11 19:45:32 +00:00
|
|
|
always @(posedge clk)
|
2017-11-17 21:01:07 +00:00
|
|
|
if(hmaxxed)
|
|
|
|
if (!vmaxxed)
|
|
|
|
vpos <= vpos + 1;
|
2017-11-11 19:45:32 +00:00
|
|
|
else
|
2017-11-17 21:01:07 +00:00
|
|
|
vpos <= 0;
|
2017-11-11 19:45:32 +00:00
|
|
|
|
2017-11-29 01:48:27 +00:00
|
|
|
// compute hsync + vsync + display_on signals
|
2017-11-11 19:45:32 +00:00
|
|
|
always @(posedge clk)
|
|
|
|
begin
|
2017-11-21 16:15:08 +00:00
|
|
|
hsync <= (hpos>=START_H_RETRACE && hpos<=END_H_RETRACE);
|
|
|
|
vsync <= (vpos==START_V_RETRACE);
|
2017-11-17 21:01:07 +00:00
|
|
|
display_on <= (hpos<H_DISPLAY) && (vpos<V_DISPLAY);
|
2017-11-11 19:45:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
endmodule
|
2017-11-18 19:51:25 +00:00
|
|
|
|
|
|
|
`endif
|