我不确定嵌套的 for 循环是否会像您认为的那样运行,至少对于综合设计而言。
我的建议是不要根据它的参数方程生成圆,这是我认为你想要做的。相反,如果圆始终是相同的(即它的半径始终为 100 像素或更小),请预先生成圆的位图并将其作为大精灵存储在 FPGA(块 RAM)内存中。它不会占用你太多空间。精灵中的 0 位将转换为“透明”,而 1 位表示使用与精灵相关的颜色(圆形)绘制此点。
这样,您绘制屏幕的代码(实际上是屏幕的活动部分)将是这样的:
`define SPRLEN 256 // how many pixels in width and heigh the sprite will have.
`define SPRITECOLOR 3'b100; // RED ball. (RGB, 1-bit per channel)
`define BGCOLOR 3'010; // GREEN background
reg ballsprite[0:`SPRLEN*`SPRLEN-1]; // A matrix to hold your sprite.
reg [9:0] hcont, vcont; // horizontal and vertical counters for scanning a VGA picture
reg [8:0] ballx, bally; //coordinates of the left-top corner of the ball sprite
reg [7:0] coorx,coory; //X,Y coordinates of the current sprite position to draw
initial begin // read your sprite definition into memory. FPGA synthetizable.
$readmemb ("mysprite.bin", ballsprite);
end
// process to obtain relative coordinates of the current screen position within the sprite
always @* begin
coorx = hcont+1-ballx;
coory = vcont+1-bally;
end
// process to get the next dot from the sprite. We begin at ballx-1,bally-1 because
// there's one clock delay in getting the current sprite dot value.
always @(posedge clk) begin
if (hcont>=ballx-1 && hcont<=ballx-1+`SPRLEN && vcont>=bally-1 && vcont<=bally-1+`SPRLEN)
dot_from_ball <= ballsprite[{coory,coorx}]; // i.e. coory*256+coorx
else
dot_from_ball <= 1'b0; // if scan trace is not under the boundaries of the sprite,
// then it's transparent color
end
// multiplexer to actually put an RGB value on screen
always @* begin
if (hcont>=0 && hcont<640 && vcont>=0 && vcont<480) begin
if (dot_from_ball)
{R,G,B} = `SPRITECOLOR;
else
{R,G,B} = `BGCOLOR;
end
else
{R,G,B} = 3'b000; //if not into active area, mute RGB
end
您可以为 hcont 和 vcont 生成适当的值,并根据这些计数器何时达到某些值来推断同步信号。
前段时间,我做过类似的事情:在 VGA 屏幕上绘制一个移动的精灵。我是用 Handel C 做的,但逻辑是一样的。你可以在这里看到它:
http ://www.youtube.com/watch?v=wgDSzC-vGZ0