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:
I am going to just copy my entire code for the two main modules for
this code below here since I did it all in one go and kind of forgot to
doccument how I was changing the code and I'm not really sure about
everything I changed at this point. Most of it was fairly straight
forward based off of the given instructions/what we've done in the
past/ and the book/PicoBlaze documentation so it was just a lot of bug
fixing.
// 2 MSBs of counter to control 4-to-1 multiplexing
// and to generate active-low enable signal
always @* begin
case (q_reg[N-1:N-2])
2'b00:
begin
an = 4'b1110;
sseg = in0;
case(in0)
192: begin led[3:0] = 0; digit0 = 48; end
249: begin led[3:0] = 1; digit0 = 49; end
164: begin led[3:0] = 2; digit0 = 50; end
176: begin led[3:0] = 3; digit0 = 51; end
153: begin led[3:0] = 4; digit0 = 52; end
146: begin led[3:0] = 5; digit0 = 53; end
130: begin led[3:0] = 6; digit0 = 54; end
248: begin led[3:0] = 7; digit0 = 55; end
128: begin led[3:0] = 8; digit0 = 56; end
132: begin led[3:0] = 9; digit0 = 57; end
144: begin led[3:0] = 10; digit0 = 65; end
131: begin led[3:0] = 11; digit0 = 66; end
198: begin led[3:0] = 12; digit0 = 67; end
261: begin led[3:0] = 13; digit0 = 68; end
134: begin led[3:0] = 14; digit0 = 69; end
142: begin led[3:0] = 15; digit0 = 70; end
endcase
end
2'b01:
begin
an = 4'b1101;
sseg = in1;
case(in1)
192: begin led[7:4] = 0; digit1 = 48; end
249: begin led[7:4] = 1; digit1 = 49; end
164: begin led[7:4] = 2; digit1 = 50; end
176: begin led[7:4] = 3; digit1 = 51; end
153: begin led[7:4] = 4; digit1 = 52; end
146: begin led[7:4] = 5; digit1 = 53; end
130: begin led[7:4] = 6; digit1 = 54; end
248: begin led[7:4] = 7; digit1 = 55; end
128: begin led[7:4] = 8; digit1 = 56; end
132: begin led[7:4] = 9; digit1 = 57; end
144: begin led[7:4] = 10; digit1 = 65; end
131: begin led[7:4] = 11; digit1 = 66; end
198: begin led[7:4] = 12; digit1 = 67; end
261: begin led[7:4] = 13; digit1 = 68; end
134: begin led[7:4] = 14; digit1 = 69; end
142: begin led[7:4] = 15; digit1 = 70; end
endcase
end
2'b10:
begin
an = 4'b1011;
sseg = in2;
case(in2)
192: begin led[11:8] = 0; digit2 = 48; end
249: begin led[11:8] = 1; digit2 = 49; end
164: begin led[11:8] = 2; digit2 = 50; end
176: begin led[11:8] = 3; digit2 = 51; end
153: begin led[11:8] = 4; digit2 = 52; end
146: begin led[11:8] = 5; digit2 = 53; end
130: begin led[11:8] = 6; digit2 = 54; end
248: begin led[11:8] = 7; digit2 = 55; end
128: begin led[11:8] = 8; digit2 = 56; end
132: begin led[11:8] = 9; digit2 = 57; end
144: begin led[11:8] = 10; digit2 = 65; end
131: begin led[11:8] = 11; digit2 = 66; end
198: begin led[11:8] = 12; digit2 = 67; end
261: begin led[11:8] = 13; digit2 = 68; end
134: begin led[11:8] = 14; digit2 = 69; end
142: begin led[11:8] = 15; digit2 = 70; end
endcase
end
default:
begin
an = 4'b0111;
sseg = in3;
case(in3)
192: begin led[15:12] = 0; digit3 = 48; end
249: begin led[15:12] = 1; digit3 = 49; end
164: begin led[15:12] = 2; digit3 = 50; end
176: begin led[15:12] = 3; digit3 = 51; end
153: begin led[15:12] = 4; digit3 = 52; end
146: begin led[15:12] = 5; digit3 = 53; end
130: begin led[15:12] = 6; digit3 = 54; end
248: begin led[15:12] = 7; digit3 = 55; end
128: begin led[15:12] = 8; digit3 = 56; end
132: begin led[15:12] = 9; digit3 = 57; end
144: begin led[15:12] = 10; digit3 = 65; end
131: begin led[15:12] = 11; digit3 = 66; end
198: begin led[15:12] = 12; digit3 = 67; end
261: begin led[15:12] = 13; digit3 = 68; end
134: begin led[15:12] = 14; digit3 = 69; end
142: begin led[15:12] = 15; digit3 = 70; end
endcase
end
endcase
end
always @ (posedge clk) begin
data[0]<=digit3; data [1] <=digit2; data [2]
<=digit1; data [3] <=digit0; data [4] <= " "; data
[5] <=" "; data [6]<=" "; data [7]<=" "; data
[8]<=" "; data [9]<=" "; data [10] <=" "; data
[11]<=" "; data [12] <=" "; data [13]<=" "; data
[14] <=" "; data [15] <=" ";
if (counter == clk_param) begin
counter <= 0;
wr_en <= 1'b1;
character <= data[index];
index <= index + 1'b1;
end else begin
wr_en <= 0;
counter <= counter + 1;
if (index > 15) index <= 0;
end
end
endmodule
1) Part 1 and 2
I implemented these parts at the same time to reduce the time it took
to compuile and upload youtube videos since that usually slows down the
process quite a bit. Implementing the LED display was fairly straight
forward and then I just used the third decimal point as the last LED.
The video can be seen below.
I was kinda stupid so I ended up inverting the entire binary string
instead of everything but the last bit and that took me too long to
realize.
2) Part 3
For part 3 I copied my code from the LCD display lab into the top of
the MUX module before integrating it by copying more of my code from
last time and then just adding the digits into the case statements from
the first part LEDs to change my digits. This worked out pretty good
but for some reason I had to invert my digits from what I thought they
would be.