TinyAdder: Add docs, organise things, updated EAGLE files.

This commit is contained in:
Kyle Isom 2018-12-29 10:49:04 -08:00
parent 4770a2bd9c
commit b4d0799516
5 changed files with 4082 additions and 102 deletions

View File

@ -0,0 +1,37 @@
TinyAdder
========
TinyAdder is a 4-bit adder built on the TinyFPGA BX. It connects four
slide switches (I wanted actual toggle switches, but that's how it goes)
to a pair of 7-segment LCD displays.
Code organisation
-----------------
Currently there are two modules:
+ SegmentLCD: a little awkwardly named due to the naming constraints,
but this takes a 4-bit input number and outputs a 7-bit output. The
hookup requirements are described in the module comments.
+ TinyAdder: This is the top-level adder.
Hardware revisions
------------------
+ rev1 (2018-12-22)
+ rev2 (2018-12-22): realised that the LCDs were missing resistors;
I had been looking at a tutorial that used a shift register; the shift
register apparently had an internal current limiter so I assumed the
LCDs didn't need them. This was wrong. Fortunately I was able to cancel
the rev1 order before it went out.
+ rev3 (2018-12-28): after breadboarding the push button, I realised
I'd messed up the schematic (and accordingly, the board) by wiring
both ends of the push buttons to Vcc, which... isn't very useful at
all. I fixed it, but not before the rev2 was sent to the fab.
TODO
----
+ I'd like to have the two displays show the two numbers before adding
them. The 'hi' display could show the first addend, and the 'low' could
show the second addend, with live updating.

View File

@ -0,0 +1,41 @@
/// SegmentLCD represents a 7-segment display that takes as input a 4-bit
/// number and outputs the correct pin configuration. The pins need to be
/// wired as {G, F, E, D, C, B, A} for this to work.
///
/// For example,
///
/// wire [7:0] sum = 8'b00000000;
/// segment7 low (
/// .number(sum[3:0]),
/// .out({PIN_15, PIN_14, PIN_13, PIN_12, PIN_11, PIN_10, PIN_9})
/// );
module SegmentLCD (
input [3:0] number,
output [6:0] out = 7'b0000000
);
always @(*)
begin
case (number)
4'b0000: out <= 7'b0111111; // 0
4'b0001: out <= 7'b0000110; // 1
4'b0010: out <= 7'b1011011; // 2
4'b0011: out <= 7'b1001111; // 3
4'b0100: out <= 7'b1100110; // 4
4'b0101: out <= 7'b1101101; // 5
4'b0110: out <= 7'b1111101; // 6
4'b0111: out <= 7'b0000111; // 7
4'b1000: out <= 7'b1111111; // 8
4'b1001: out <= 7'b1100111; // 9
4'b1010: out <= 7'b1110111; // A
4'b1011: out <= 7'b1111100; // B
4'b1100: out <= 7'b0111001; // C
4'b1101: out <= 7'b1011110; // D
4'b1110: out <= 7'b1111001; // E
4'b1111: out <= 7'b1110001; // F
endcase
end
endmodule

View File

@ -1,102 +1,99 @@
module segment7 ( `include "SegmentLCD.v"
input [3:0] number,
output [6:0] out = 7'b0000000 /////////////////////////////////////////////////////////////////////////
); /// TinyAdder.v
/// Author: K. Isom
always @(*) /// Created: 2018-12-27
begin /////////////////////////////////////////////////////////////////////////
case (number) /// TinyAdder is a 4-bit adder that displays calculations on a pair of
4'b0000: out <= 7'b0111111; // 0 /// 7-segment LCDs. The EXEC button doubles as a plus and equals button:
4'b0001: out <= 7'b0000110; // 1 /// the first time it is pressed, entry begins with the second number. The
4'b0010: out <= 7'b1011011; // 2 /// second time it is pressed, the sum of the two numbers is shown on the
4'b0011: out <= 7'b1001111; // 3 /// display.
4'b0100: out <= 7'b1100110; // 4 module TinyAdder (
4'b0101: out <= 7'b1101101; // 5 input PIN_1, // A[0]
4'b0110: out <= 7'b1111101; // 6 input PIN_2, // A[1]
4'b0111: out <= 7'b0000111; // 7 input PIN_3, // A[2]
4'b1000: out <= 7'b1111111; // 8 input PIN_4, // A[3]
4'b1001: out <= 7'b1100111; // 9 input PIN_5, // EXEC
4'b1010: out <= 7'b1110111; // A input PIN_6, // CLR
4'b1011: out <= 7'b1111100; // B
4'b1100: out <= 7'b0111001; // C // There are two 7-segment displays: 'low' shows the 4 LSBs, and 'hi'
4'b1101: out <= 7'b1011110; // D // shows the 4 MSBs. That is, given 0x12, 'low' would display '2' and
4'b1110: out <= 7'b1111001; // E // 'hi' would show '1'.
4'b1111: out <= 7'b1110001; // F output PIN_9, // LOW/A
endcase output PIN_10, // LOW/B
end output PIN_11, // LOW/C
output PIN_12, // LOW/D
endmodule output PIN_13, // LOW/E
output PIN_14, // LOW/F
// look in pins.pcf for all the pin names on the TinyFPGA BX board output PIN_15, // LOW/G
module TinyAdder ( output PIN_16, // HI/A
input CLK, // 16MHz clock output PIN_17, // HI/B
input PIN_1, // A[0] output PIN_18, // HI/C
input PIN_2, // A[1] output PIN_19, // HI/D
input PIN_3, // A[2] output PIN_20, // HI/E
input PIN_4, // A[3] output PIN_21, // HI/F
input PIN_5, // EXEC output PIN_22, // HI/G
input PIN_6, // CLR
output LED, // User/boot LED next to power LED
// 7-segment LCD displays output USBPU // USB pull-up resistor
output PIN_9, // LOW/A );
output PIN_10, // LOW/B
output PIN_11, // LOW/C // Drive USB pull-up resistor to '0' to disable USB. This prevents us
output PIN_12, // LOW/D // from falling back into the bootloader, I think.
output PIN_13, // LOW/E assign USBPU = 0;
output PIN_14, // LOW/F
output PIN_15, // LOW/G wire [7:0] sum = 8'b00000000;
output PIN_16, // HI/A wire [3:0] switches;
output PIN_17, // HI/B
output PIN_18, // HI/C assign switches = {PIN_4, PIN_3, PIN_2, PIN_1};
output PIN_19, // HI/D
output PIN_20, // HI/E // state determines what happens when the button is pressed.
output PIN_21, // HI/F reg [1:0] state = 2'b00;
output PIN_22, // HI/G
segment7 low (
output LED, // User/boot LED next to power LED .number(sum[3:0]),
output USBPU // USB pull-up resistor .out({PIN_15, PIN_14, PIN_13, PIN_12, PIN_11, PIN_10, PIN_9})
); );
// drive USB pull-up resistor to '0' to disable USB segment7 hi (
assign USBPU = 0; .number(sum[7:4]),
.out({PIN_22, PIN_21, PIN_20, PIN_19, PIN_18, PIN_17, PIN_16})
wire [7:0] sum = 8'b00000000; );
wire [3:0] switches;
// When EXEC is pressed, the adder's state is advanced. There are
assign switches = {PIN_4, PIN_3, PIN_2, PIN_1}; // three states:
// state determines what happens when the button is pressed. // + state 00: entry of the first number.
reg [1:0] state = 2'b00; // + state 01: entry of the second number.
// + state 10: the sum of the two numbers is displayed. Pressing
assign LED = state[0]; // exec again resets the display.
always @(negedge PIN_5)
segment7 low ( begin
.number(sum[3:0]), case (state)
.out({PIN_15, PIN_14, PIN_13, PIN_12, PIN_11, PIN_10, PIN_9}) 2'b00: begin
); sum = switches;
state <= 2'b01;
segment7 hi ( end
.number(sum[7:4]), 2'b01: begin
.out({PIN_22, PIN_21, PIN_20, PIN_19, PIN_18, PIN_17, PIN_16}) sum = sum + switches;
); state = 2'b10;
LED <= 1;
always @(PIN_5) end
begin 2'b10: begin
case (state) sum = 8'b00000000;
2'b00: begin state = 2'b00;
sum = switches; LED <= 0;
state <= 2'b01; end
end endcase
2'b01: begin end
sum = sum + switches;
state = 2'b10; // When CLEAR is pressed, the adder should go back to its initial
end // state.
endcase always @(negedge PIN_6)
end begin
state <= 2'b00;
always @(PIN_6) sum = 8'b0000000;
begin LED <= 0;
state <= 2'b00; end
sum = 7'b0000000; endmodule
end
endmodule

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff