SE-VGA/vgacount.sv

72 lines
1.8 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)
);
parameter COUNTMAX=800,
SYNCBEGIN=592,
SYNCEND=688,
ACTBEGIN=576,
ACTEND=736,
SEACTBEGIN=512;
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-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-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