1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-18 18:07:35 +00:00
8bitworkshop/presets/verilog/hvsync_generator.v

64 lines
1.8 KiB
Coq
Raw Normal View History

`ifndef HVSYNC_GENERATOR_H
`define HVSYNC_GENERATOR_H
2017-11-11 19:45:32 +00:00
module hvsync_generator(
clk, hsync, vsync, display_on, hpos, vpos);
2017-11-11 19:45:32 +00:00
input clk;
output hsync, vsync;
output reg display_on;
output reg [8:0] hpos;
output reg [8:0] vpos;
2017-11-11 19:45:32 +00:00
// constant declarations for VGA sync parameters
localparam H_DISPLAY = 256; // horizontal display area
localparam H_L_BORDER = 12; // horizontal left border
localparam H_R_BORDER = 8; // horizontal right border
localparam H_RETRACE = 24; // horizontal retrace
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
localparam V_T_BORDER = 4; // vertical top border
localparam V_B_BORDER = 16; // vertical bottom border
localparam V_RETRACE = 2; // vertical retrace
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;
wire hmaxxed = (hpos==H_MAX);
wire vmaxxed = (vpos==V_MAX);
2017-11-11 19:45:32 +00:00
always @(posedge clk)
if(hmaxxed)
hpos <= 0;
2017-11-11 19:45:32 +00:00
else
hpos <= hpos + 1;
2017-11-11 19:45:32 +00:00
always @(posedge clk)
if(hmaxxed)
if (!vmaxxed)
vpos <= vpos + 1;
2017-11-11 19:45:32 +00:00
else
vpos <= 0;
2017-11-11 19:45:32 +00:00
reg vga_HS, vga_VS;
always @(posedge clk)
begin
vga_HS <= (hpos>=280 && hpos<288); // change this value to move the display horizontally
vga_VS <= (vpos==START_V_RETRACE); // change this value to move the display vertically
2017-11-11 19:45:32 +00:00
end
always @(posedge clk)
begin
display_on <= (hpos<H_DISPLAY) && (vpos<V_DISPLAY);
2017-11-11 19:45:32 +00:00
end
assign hsync = ~vga_HS;
assign vsync = ~vga_VS;
endmodule
`endif