SE-VGA/old/vgacount.sv

74 lines
2.2 KiB
Systemverilog
Raw Normal View History

2021-04-07 04:15:48 +00:00
/******************************************************************************
* SE-VGA
* VGA signal counter
* techav
* 2021-04-06
******************************************************************************
* Low-level VGA signal counter
*****************************************************************************/
2021-04-12 04:46:29 +00:00
`ifndef VGACOUNT
`define VGACOUNT
2021-04-07 04:15:48 +00:00
module vgacount (
input wire nReset, // system reset signal
input wire clock, // counter increment clock
2021-04-12 04:46:29 +00:00
output logic [9:0] count, // count output
2021-04-07 04:15:48 +00:00
output wire nSync, // sync pulse
output wire activeVid, // active video signal
output wire activeSE // secondary active video signal (SE)
);
2021-04-18 19:31:05 +00:00
parameter COUNTMAX=800, // Total dot count per line or line count per frame
SYNCBEGIN=592, // Dot/Line count where sync pulse begins
SYNCEND=688, // Dot/Line count +1 where sync pulse ends
ACTBEGIN=576, // Dot/Line count where VGA active video begins
ACTEND=736, // Dot/Line count +1 where VGA active video ends
SEACTBEGIN=512; // Dot/Line count +1 where SE video window ends
2021-04-07 04:15:48 +00:00
logic [9:0] counter;
// primary counter
always @(negedge clock or negedge nReset) begin
if(nReset == 1'b0) begin
counter <= 10'h0;
end else begin
if (counter < COUNTMAX) begin
counter <= counter + 10'h1;
end else begin
counter <= 10'h0;
end
end
end
// combinatorial logic derived from the counters
always_comb begin
// output the count signals
count <= counter;
// Sync pulse
2021-04-12 04:46:29 +00:00
if(count >= SYNCBEGIN && count < SYNCEND) begin
nSync <= 1'b0;
2021-04-07 04:15:48 +00:00
end else begin
2021-04-12 04:46:29 +00:00
nSync <= 1'b1;
2021-04-07 04:15:48 +00:00
end
2021-04-18 17:50:43 +00:00
// VGA active video range
2021-04-12 04:46:29 +00:00
if(count >= ACTBEGIN && count < ACTEND) begin
activeVid <= 1'b0;
2021-04-07 04:15:48 +00:00
end else begin
2021-04-12 04:46:29 +00:00
activeVid <= 1'b1;
2021-04-07 04:15:48 +00:00
end
2021-04-18 17:50:43 +00:00
// SE active video window within VGA active video range
2021-04-12 04:46:29 +00:00
if(count >= SEACTBEGIN) begin
activeSE <= 1'b0;
2021-04-07 04:15:48 +00:00
end else begin
2021-04-12 04:46:29 +00:00
activeSE <= 1'b1;
2021-04-07 04:15:48 +00:00
end
end
2021-04-12 04:46:29 +00:00
endmodule
`endif