Line 1... |
Line 1... |
`timescale 1ns / 1ps
|
`timescale 1ns / 1ps
|
//////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
// Company:
|
|
// Engineer: Yann Vernier
|
// Engineer: Yann Vernier
|
//
|
//
|
// Create Date: 21:37:32 02/19/2011
|
// Create Date: 21:37:32 02/19/2011
|
// Design Name:
|
// Design Name:
|
// Module Name: vector2scanline
|
// Module Name: vector2scanline
|
Line 11... |
Line 10... |
// Tool versions:
|
// Tool versions:
|
// Description: Converts vector data (exposed points) into raster video
|
// Description: Converts vector data (exposed points) into raster video
|
//
|
//
|
// Dependencies:
|
// Dependencies:
|
//
|
//
|
|
// Revision: $Id$
|
|
// $Log$
|
|
// Additional Comments:
|
|
//
|
//////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
module vector2scanline(
|
module vector2scanline(
|
input clk, // clock
|
clk_i, // clock
|
|
|
input strobe, // new exposed pixel trigger
|
strobe_i, // new exposed pixel trigger
|
input [9:0] x, // column of exposed pixel
|
x_i, // column of exposed pixel
|
input [9:0] y, // row of exposed pixel
|
y_i, // row of exposed pixel
|
|
|
// Video output interface
|
// Video output interface
|
input [9:0] xout, // current pixel column
|
xout_i, // current pixel column
|
input [9:0] yout, // current pixel row
|
yout_i, // current pixel row
|
input newline, // line buffer swap signal
|
newline_i, // line buffer swap signal
|
input newframe, // new frame signal
|
newframe_i, // new frame signal
|
output [7:0] pixel // output pixel intensity
|
pixel_o // output pixel intensity
|
);
|
/*AUTOARG*/);
|
|
|
|
|
// TODO: figure out how to apply parameters to the port sizes above
|
|
parameter X_WIDTH = 10; // bit width of column coordinate
|
parameter X_WIDTH = 10; // bit width of column coordinate
|
parameter Y_WIDTH = 10; // bit width of row coordinate
|
parameter Y_WIDTH = 10; // bit width of row coordinate
|
parameter HIST_WIDTH = 10; // log2 of maximum lit pixels (exposure buffer)
|
parameter HIST_WIDTH = 10; // log2 of maximum lit pixels (exposure buffer)
|
parameter AGE_WIDTH = 8; // width of exposure age counter
|
parameter AGE_WIDTH = 8; // width of exposure age counter
|
|
|
|
input clk_i;
|
|
|
|
input strobe_i;
|
|
input [X_WIDTH-1:0] x_i;
|
|
input [Y_WIDTH-1:0] y_i;
|
|
|
|
input [X_WIDTH-1:0] xout_i;
|
|
input [Y_WIDTH-1:0] yout_i;
|
|
input newline_i, newframe_i;
|
|
output [AGE_WIDTH-1:0] pixel_o;
|
|
|
// positions and age of lit pixels
|
// positions and age of lit pixels
|
reg [X_WIDTH+Y_WIDTH+AGE_WIDTH-1:0] exposures [(2**HIST_WIDTH)-1:0];
|
reg [X_WIDTH+Y_WIDTH+AGE_WIDTH-1:0] exposures [(2**HIST_WIDTH)-1:0];
|
// output register of exposed pixels buffer
|
// output register of exposed pixels buffer
|
reg [X_WIDTH+Y_WIDTH+AGE_WIDTH-1:0] expr;
|
reg [X_WIDTH+Y_WIDTH+AGE_WIDTH-1:0] expr;
|
// data for next pixel to store in exposure buffer
|
// data for next pixel to store in exposure buffer
|
wire [X_WIDTH-1:0] expx;
|
wire [X_WIDTH-1:0] expx;
|
wire [Y_WIDTH-1:0] expy;
|
wire [Y_WIDTH-1:0] expy;
|
wire [7:0] expi;
|
wire [AGE_WIDTH-1:0] expi;
|
// whether this pixel needs to be stored back in exposure buffer
|
// whether this pixel needs to be stored back in exposure buffer
|
wire exposed;
|
wire exposed;
|
|
// whether this pixel belongs to the next (backbuffer) scanline
|
|
wire rowmatch;
|
// addresses for exposure buffer read and write ports
|
// addresses for exposure buffer read and write ports
|
reg [HIST_WIDTH-1:0] exprptr=0, expwptr=0;
|
reg [HIST_WIDTH-1:0] exprptr=0, expwptr=0;
|
|
|
// scanline pixel buffers, store intensity
|
// scanline pixel buffers, store intensity
|
// double-buffered; one gets wiped as it is displayed
|
// double-buffered; one gets wiped as it is displayed
|
Line 60... |
Line 76... |
reg bufsel = 0;
|
reg bufsel = 0;
|
// address lines for scanline buffers
|
// address lines for scanline buffers
|
wire [X_WIDTH-1:0] sl0w, sl1w;
|
wire [X_WIDTH-1:0] sl0w, sl1w;
|
|
|
// RAM read out of exposure buffer
|
// RAM read out of exposure buffer
|
always @(posedge clk) begin
|
always @(posedge clk_i) begin
|
expr<=exposures[exprptr];
|
expr<=exposures[exprptr];
|
if (!strobe) begin
|
if (!strobe) begin
|
// do not skip current read position if strobe inserts a new pixel
|
// do not skip current read position if strobe inserts a new pixel
|
exprptr<=exprptr+1;
|
exprptr<=exprptr+1;
|
end
|
end
|
end
|
end
|
|
|
// decode and mux: split fields from exposure buffer, or collect new at strobe
|
// decode and mux: split fields from exposure buffer, or collect new at strobe
|
assign expx = strobe?x:expr[X_WIDTH+Y_WIDTH+AGE_WIDTH-1:Y_WIDTH+AGE_WIDTH];
|
assign expx = strobe_i?x_i:expr[X_WIDTH+Y_WIDTH+AGE_WIDTH-1:Y_WIDTH+AGE_WIDTH];
|
assign expy = strobe?y:expr[Y_WIDTH+AGE_WIDTH-1:AGE_WIDTH];
|
assign expy = strobe_i?y_i:expr[Y_WIDTH+AGE_WIDTH-1:AGE_WIDTH];
|
assign expi = strobe?(2**AGE_WIDTH)-1:expr[AGE_WIDTH-1:0];
|
assign expi = strobe_i?(2**AGE_WIDTH)-1:expr[AGE_WIDTH-1:0];
|
// detect whether pixel even needs to be stored back
|
// detect whether pixel even needs to be stored back
|
assign exposed = expi!=0;
|
assign exposed = expi!=0;
|
|
// detect whether pixel applies to current backbuffer
|
|
// TODO: use a next line input port, this incrementer won't work for
|
|
// line 0 (which is unused in display.vhd) and could be shared.
|
|
assign rowmatch=(expy==y_i+1);
|
|
|
always @(posedge clk) begin
|
always @(posedge clk_i) begin
|
// Feed incoming exposures into exposure buffer
|
// Feed incoming exposures into exposure buffer
|
if (exposed) begin
|
if (exposed) begin
|
exposures[expwptr] <= {expx, expy, expy==yout?expi-1:expi};
|
exposures[expwptr] <= {expx, expy, expy==yout_i?expi-1:expi};
|
expwptr <= expwptr+1;
|
expwptr <= expwptr+1;
|
end
|
end
|
end
|
end
|
|
|
// scanline buffers switch output or expose roles based on bufsel
|
// scanline buffers switch output or expose roles based on bufsel
|
assign sl0w=bufsel?expx:xout;
|
assign sl0w=bufsel?expx:xout_i;
|
assign sl1w=bufsel?xout:expx;
|
assign sl1w=bufsel?xout_i:expx;
|
always @(posedge clk) begin
|
|
|
always @(posedge clk_i) begin
|
// Read out front buffer
|
// Read out front buffer
|
pixelout <= bufsel?scanline1[sl1w]:scanline0[sl0w];
|
pixelout <= bufsel?scanline1[xout_i]:scanline0[xout_i];
|
// TODO: use a next line input port, this incrementer won't work for
|
|
// line 0 (which is unused in display.vhd) and could be shared.
|
// Store exposures for next scanline and wipe front buffer
|
if (expy==(y+1)) begin
|
if (bufsel) begin
|
// Store exposures for current scanline and wipe front buffer
|
if (rowmatch)
|
scanline0[sl0w] <= bufsel?expi:0;
|
scanline0[sl0w] <= expi;
|
scanline1[sl1w] <= bufsel?0:expi;
|
scanline1[sl1w] <= 0;
|
|
end else begin
|
|
if (rowmatch)
|
|
scanline1[sl1w] <= expi;
|
|
scanline0[sl0w] <= 0;
|
end
|
end
|
|
|
// swap buffers when signaled
|
// swap buffers when signaled
|
if (newline) begin
|
if (newline_i) begin
|
bufsel <= ~bufsel;
|
bufsel <= ~bufsel;
|
end
|
end
|
end
|
end
|
|
|
// output pixel intensity
|
// output pixel intensity
|
assign pixel = pixelout;
|
assign pixel_o = pixelout;
|
|
|
endmodule
|
endmodule
|
|
|
No newline at end of file
|
No newline at end of file
|