Embedded Systems
Spring 2024
Lab 6 2's complement adder/subtractor.
Name: Mason
Brady Email:
mrbrady1@fortlewis.edu
2's Complement Adder / Subtractor
Introduction:
This lab was to learn how to implement more complex circuits with all
the techniques we've learned Materials
GVIM, Vivado, Basys 3 Methods / Results:
For this lab I have coppied the entire code for each part and
highlighted the main changes in Bold
to indicate what I added / changed for each part.
always @(posedge clk25) begin
cnt = cnt + 1;
if (cnt >= cntmax) begin
cnt <= 0;
end else cnt <= cnt + 1;
if (hcount < HLIM - 1) begin
hcount <= hcount + 1;
if (32 < hcount && hcount < 35) begin
red_reg <= 3'b000;
green_reg <= 3'b111;
blue_reg <= 3'b000;
end else begin
red_reg <= 3'b111;
green_reg <= 3'b111;
blue_reg <= 3'b111;
end
end else begin
hcount <= 0;
if (vcount < VLIM - 1) vcount <= vcount + 1;
else vcount <= 0;
end
if (vcount > sy) begin
pixel_addr <= -1;
enable <= 0;
end else begin
if (hcount < sx) begin
enable <= 1;
pixel_addr <= pixel_addr + 1;
end else enable <= 0;
end
if (enable == 1) begin
red <= red_reg;
green <= green_reg;
blue <= blue_reg;
end
else begin
red <= 3'b000;
green <= 3'b000;
blue <= 3'b000;
end
always @(posedge clk25) begin
cnt = cnt + 1;
if (cnt >= cntmax) begin
cnt <= 0;
end else cnt <= cnt + 1;
if (hcount < HLIM - 1) begin
hcount <= hcount + 1;
if (32 < hcount && hcount < 35) begin
red_reg <= 3'b000;
green_reg <= 3'b111;
blue_reg <= 3'b000;
end else if (x0 < hcount && hcount < x0 +
width && y0 < vcount && vcount
< y0 + height) begin
red_reg <= 3'b111;
green_reg <= 3'b000;
blue_reg <= 3'b000;
end else begin
red_reg <= 3'b111;
green_reg <= 3'b111;
blue_reg <= 3'b111;
end
end else begin
hcount <= 0;
if (vcount < VLIM - 1) vcount <= vcount + 1;
else vcount <= 0;
end
if (vcount > sy) begin
pixel_addr <= -1;
enable <= 0;
end else begin
if (hcount < sx) begin
enable <= 1;
pixel_addr <= pixel_addr + 1;
end else enable <= 0;
end
if (enable == 1) begin
red <= red_reg;
green <= green_reg;
blue <= blue_reg;
end
else begin
red <= 3'b000;
green <= 3'b000;
blue <= 3'b000;
end
always @(posedge clk25) begin
cnt = cnt + 1;
if (cnt >= cntmax) begin
if(x0 < 600) x0 <= x0 + 1;
cnt <= 0;
end else cnt <= cnt + 1;
if (hcount < HLIM - 1) begin
hcount <= hcount + 1;
if (32 < hcount && hcount < 35) begin
red_reg <= 3'b000;
green_reg <= 3'b111;
blue_reg <= 3'b000;
end else if (x0 < hcount && hcount < x0 +
width && y0 < vcount && vcount
< y0 + height) begin
red_reg <= 3'b111;
green_reg <= 3'b000;
blue_reg <= 3'b000;
end else begin
red_reg <= 3'b111;
green_reg <= 3'b111;
blue_reg <= 3'b111;
end
end else begin
hcount <= 0;
if (vcount < VLIM - 1) vcount <= vcount + 1;
else vcount <= 0;
end
if (vcount > sy) begin
pixel_addr <= -1;
enable <= 0;
end else begin
if (hcount < sx) begin
enable <= 1;
pixel_addr <= pixel_addr + 1;
end else enable <= 0;
end
if (enable == 1) begin
red <= red_reg;
green <= green_reg;
blue <= blue_reg;
end
else begin
red <= 3'b000;
green <= 3'b000;
blue <= 3'b000;
end
always @(posedge clk25) begin
cnt = cnt + 1; if
(x0 >= 600) dir <= 1'b1;
else if(x0 <= 30) dir <= 1'b0;
if (cnt >= cntmax) begin if(dir) x0 <= x0 - 1;
else x0 <= x0 + 1;
cnt <= 0;
end else cnt <= cnt + 1;
if (hcount < HLIM - 1) begin
hcount <= hcount + 1;
if (32 < hcount && hcount < 35) begin
red_reg <= 3'b000;
green_reg <= 3'b111;
blue_reg <= 3'b000;
end else if (x0 < hcount && hcount < x0 +
width && y0 < vcount && vcount
< y0 + height) begin
red_reg <= 3'b111;
green_reg <= 3'b000;
blue_reg <= 3'b000;
end else begin
red_reg <= 3'b111;
green_reg <= 3'b111;
blue_reg <= 3'b111;
end
end else begin
hcount <= 0;
if (vcount < VLIM - 1) vcount <= vcount + 1;
else vcount <= 0;
end
if (vcount > sy) begin
pixel_addr <= -1;
enable <= 0;
end else begin
if (hcount < sx) begin
enable <= 1;
pixel_addr <= pixel_addr + 1;
end else enable <= 0;
end
if (enable == 1) begin
red <= red_reg;
green <= green_reg;
blue <= blue_reg;
end
else begin
red <= 3'b000;
green <= 3'b000;
blue <= 3'b000;
end
Discussion: This
lab was super easy once I figured out my syntax issue... apparently
verilog doesn't like the formatting if (x0 < v < x1) but
it doesn't report a syntax error the logic just breaks....