SE-VGA/vgashiftout.sv

57 lines
1.7 KiB
Systemverilog
Raw Normal View History

2021-04-18 17:07:42 +00:00
/******************************************************************************
* SE-VGA
* VGA Shift Out
* techav
* 2021-04-06
******************************************************************************
* 2-stage shift register for storing & shifting out pixel data
*****************************************************************************/
`ifndef VGASHIFTOUT
`define VGASHIFTOUT
module vgaShiftOut (
input wire nReset,
input wire clk,
2021-04-18 18:19:16 +00:00
input wire shiftEn,
input wire nLoad1,
input wire nLoad2,
2021-04-18 17:07:42 +00:00
input logic [7:0] parIn,
output wire out
);
2021-04-18 18:19:16 +00:00
2021-04-18 17:07:42 +00:00
reg [7:0] inReg;
reg [7:0] outReg;
2021-04-18 19:31:05 +00:00
// load data into first stage register on rising edge of pixel clock
// if nLoad1 is asserted
2021-04-18 17:07:42 +00:00
always @(posedge clk or negedge nReset) begin
2021-04-18 18:19:16 +00:00
if(!nReset) inReg <= 0;
else if(!nLoad1) inReg <= parIn;
2021-04-18 17:07:42 +00:00
end
2021-04-18 19:31:05 +00:00
// load data into second stage register on falling edge of pixel clock
// if nLoad2 is asserted, otherwise if shiftEn is asserted, then shift
// video data out. Shift in 0 to fill empty registers
2021-04-18 17:07:42 +00:00
always @(negedge clk or negedge nReset) begin
2021-04-18 18:19:16 +00:00
if(!nReset) outReg <= 0;
else begin
if(!nLoad2) outReg <= inReg;
else if(shiftEn) begin
outReg[7] <= outReg[6];
outReg[6] <= outReg[5];
outReg[5] <= outReg[4];
outReg[4] <= outReg[3];
outReg[3] <= outReg[2];
outReg[2] <= outReg[1];
outReg[1] <= outReg[0];
outReg[0] <= 0;
2021-04-18 17:07:42 +00:00
end
end
end
2021-04-18 18:19:16 +00:00
2021-04-18 19:31:05 +00:00
// high-order bit of the shift register (second stage) is the serial output
2021-04-18 17:07:42 +00:00
assign out = outReg[7];
endmodule
`endif