2017-11-18 19:51:25 +00:00
|
|
|
`ifndef HVSYNC_GENERATOR_H
|
|
|
|
`define HVSYNC_GENERATOR_H
|
2017-11-11 19:45:32 +00:00
|
|
|
|
2018-02-03 20:20:56 +00:00
|
|
|
// constant declarations for TV-simulator sync parameters
|
|
|
|
localparam H_DISPLAY = 256; // horizontal display width
|
|
|
|
localparam H_BACK = 23; // horizontal left border (back porch)
|
|
|
|
localparam H_FRONT = 7; // horizontal right border (front porch)
|
|
|
|
localparam H_SYNC = 23; // horizontal sync width
|
|
|
|
localparam H_SYNC_START = H_DISPLAY + H_FRONT;
|
|
|
|
localparam H_SYNC_END = H_DISPLAY + H_FRONT + H_SYNC - 1;
|
|
|
|
localparam H_MAX = H_DISPLAY + H_BACK + H_FRONT + H_SYNC - 1;
|
|
|
|
|
|
|
|
localparam V_DISPLAY = 240; // vertical display height
|
|
|
|
localparam V_TOP = 5; // vertical top border
|
|
|
|
localparam V_BOTTOM = 14; // vertical bottom border
|
|
|
|
localparam V_SYNC = 3; // vertical sync # lines
|
|
|
|
localparam V_SYNC_START = V_DISPLAY + V_BOTTOM;
|
|
|
|
localparam V_SYNC_END = V_DISPLAY + V_BOTTOM + V_SYNC - 1;
|
|
|
|
localparam V_MAX = V_DISPLAY + V_TOP + V_BOTTOM + V_SYNC - 1;
|
|
|
|
|
2017-11-15 00:12:52 +00:00
|
|
|
module hvsync_generator(
|
2018-01-13 20:48:58 +00:00
|
|
|
input clk,
|
|
|
|
input reset,
|
|
|
|
output hsync, vsync,
|
|
|
|
output display_on,
|
|
|
|
output [8:0] hpos,
|
|
|
|
output [8:0] vpos
|
|
|
|
);
|
2017-11-11 19:45:32 +00:00
|
|
|
|
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)
|
2018-01-13 20:48:58 +00:00
|
|
|
begin
|
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;
|
2018-02-03 20:20:56 +00:00
|
|
|
end
|
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)
|
2018-01-13 20:48:58 +00:00
|
|
|
begin
|
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;
|
2018-02-03 20:20:56 +00:00
|
|
|
end
|
2018-01-13 20:48:58 +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
|
2018-01-13 20:48:58 +00:00
|
|
|
hsync <= (hpos>=H_SYNC_START && hpos<=H_SYNC_END);
|
|
|
|
vsync <= (vpos>=V_SYNC_START && vpos<=V_SYNC_END);
|
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
|