各位好:
又开始新一期的更新了,移植说做个有意思的项目,奈何是在加班严重,没有办法,只能带来点小玩意了,本期就在官方提供的教程基础上改一个吧;
官方提供的教程是让显示屏上显示彩条,如图所示:
我在这个实验的基础上,增加一个移动的方块,碰到屏端自动改变方向;
视频上传B站,链接:https://www.bilibili.com/video/BV1ft4y1i7Tw。
改动内容为:
1、将video_define.v中的分辨率更改为:`define VIDEO_1024_768,显示输出分辨率为1024_768,默认的1280_720的分辨率会出现严重的时序违例,无法正常显示;
2、根据分辨率将PLL的输出两路输出clkout0和clkout1分别调整为60Mhz和300MHz;
3、修改color_bar.v代码,将源代码中的最后一个always块修改如下:
reg [11:0] x;
reg flag_x;
reg [11:0] y;
reg flag_y;
always @(posedge clk or posedge rst) begin
if (rst == 1'b1) begin
x <='d0;
end
else if (flag_x == 1'b0 && (v_cnt == V_FP + V_SYNC + V_BP - 1) && (h_cnt == H_FP - 1)) begin
x<= x+ 1'b1;
end
else if(flag_x == 1'b1 && (v_cnt == V_FP + V_SYNC + V_BP - 1) && (h_cnt == H_FP - 1)) begin
x <= x -1'b1;
end
end
always @(posedge clk or posedge rst) begin
if (rst == 1'b1) begin
flag_x <= 1'b0;
end
else if (flag_x == 1'b0 && (v_cnt == V_FP + V_SYNC + V_BP - 1) && (h_cnt == H_FP - 1) && x == (H_ACTIVE - 201)) begin
flag_x <= 1'b1;
end
else if (flag_x == 1'b1 && (v_cnt == V_FP + V_SYNC + V_BP - 1) && (h_cnt == H_FP - 1) && x=='d1) begin
flag_x <= 1'b0;
end
end
always @(posedge clk or posedge rst) begin
if (rst == 1'b1) begin
y <= 'd0;
end
else if (flag_y == 1'b0 && (v_cnt == V_FP + V_SYNC + V_BP - 1) && (h_cnt == H_FP - 1)) begin
y <= y + 1'b1;
end
else if (flag_y == 1'b1 && (v_cnt == V_FP + V_SYNC + V_BP - 1) && (h_cnt == H_FP - 1)) begin
y <= y - 1'b1;
end
end
always @(posedge clk or posedge rst) begin
if (rst == 1'b1) begin
flag_y <= 1'b0;
end
else if (flag_y == 1'b0 && (v_cnt == V_FP + V_SYNC + V_BP - 1) && (h_cnt == H_FP - 1) && y==(V_ACTIVE - 201) ) begin
flag_y <= 1'b1;
end
else if (flag_y == 1'b1 && (v_cnt == V_FP + V_SYNC + V_BP - 1) && (h_cnt == H_FP - 1) && y=='d1 ) begin
flag_y <= 1'b0;
end
end
always@(posedge clk or posedge rst)
begin
if(rst == 1'b1)
begin
rgb_r_reg <= 8'h00;
rgb_g_reg <= 8'h00;
rgb_b_reg <= 8'h00;
end
else if(video_active)
if((h_cnt >= H_FP[11:0] + H_SYNC[11:0] + H_BP[11:0] -1 + x) && (h_cnt <=H_FP[11:0] + H_SYNC[11:0] + H_BP[11:0] -1 + 200 + x) && (v_cnt >=( V_FP + V_SYNC + V_BP - 1 + y)) && (v_cnt <=( 200 + V_FP + V_SYNC + V_BP - 1 + y)))
begin
rgb_r_reg <= WHITE_R;
rgb_g_reg <= WHITE_G;
rgb_b_reg <= WHITE_B;
end
else if((active_x >= 12'd0)&(active_x < {H_ACTIVE[14:3]}))//0-1
begin
rgb_r_reg <= WHITE_R;
rgb_g_reg <= WHITE_G;
rgb_b_reg <= 8'B01111111;//WHITE_B;
end
else if((active_x >= {H_ACTIVE[14:3]})&(active_x < {H_ACTIVE[13:3],1'b0}))//1-2
begin
rgb_r_reg <= YELLOW_R;
rgb_g_reg <= YELLOW_G;
rgb_b_reg <= YELLOW_B;
end
else if((active_x >= {H_ACTIVE[13:3],1'b0})&(active_x < {H_ACTIVE[13:3],1'b0} + {H_ACTIVE[14:3]}))//2-3
begin
rgb_r_reg <= CYAN_R;
rgb_g_reg <= CYAN_G;
rgb_b_reg <= CYAN_B;
end
else if((active_x >= {H_ACTIVE[13:3],1'b0} + {H_ACTIVE[14:3]})&(active_x < {H_ACTIVE[12:3],2'b0}))//3-4
begin
rgb_r_reg <= GREEN_R;
rgb_g_reg <= GREEN_G;
rgb_b_reg <= GREEN_B;
end
else if((active_x >= {H_ACTIVE[12:3],2'b0})&(active_x < {H_ACTIVE[12:3],2'b0} + {H_ACTIVE[14:3]}))//4-5
begin
rgb_r_reg <= MAGENTA_R;
rgb_g_reg <= MAGENTA_G;
rgb_b_reg <= MAGENTA_B;
end
else if((active_x >= ({H_ACTIVE[12:3],2'b0} + {H_ACTIVE[14:3]}))&(active_x < ({H_ACTIVE[12:3],2'b0} + {H_ACTIVE[13:3],1'b0})))//5-6
begin
rgb_r_reg <= RED_R;
rgb_g_reg <= RED_G;
rgb_b_reg <= RED_B;
end
else if((active_x >= {H_ACTIVE[12:3],2'b0} + {H_ACTIVE[13:3],1'b0})&(active_x < {H_ACTIVE[11:3],3'b0} - {H_ACTIVE[14:3]}))//6-7
begin
rgb_r_reg <= BLUE_R;
rgb_g_reg <= BLUE_G;
rgb_b_reg <= BLUE_B;
end
else if((active_x >= {H_ACTIVE[11:3],3'b0} - {H_ACTIVE[14:3]}))
begin
rgb_r_reg <= BLACK_R;
rgb_g_reg <= BLACK_G;
rgb_b_reg <= BLACK_B;
end
else
begin
rgb_r_reg <= rgb_r_reg;
rgb_g_reg <= rgb_g_reg;
rgb_b_reg <= rgb_b_reg;
end
else
begin
rgb_r_reg <= 8'h00;
rgb_g_reg <= 8'h00;
rgb_b_reg <= 8'h00;
end
end
增加了一个移动方块的控制逻辑,方块大小为200*200,碰到显示范围的边缘自动向反方向移动;
同时为了尽可能的优化时序,将原有代码中的乘法和除法运算均更改为移位操作。