Skip to content
This repository was archived by the owner on Aug 21, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
79becf4
Finished the Work Plan
bwerth Oct 24, 2017
b7b6ed4
Finished Input Conditioner First Pass
bwerth Oct 24, 2017
389fe5a
conditioner typo
wiltang Oct 24, 2017
004d432
Finished shiftregister.v
JosephLee19 Oct 25, 2017
3091e5c
Finished shiftregister.v for real now
JosephLee19 Oct 25, 2017
ea32329
midpt.v
wilttang Oct 25, 2017
8db2dac
Merge branch 'master' of https://github.com/bwerth/Lab2
wilttang Oct 25, 2017
bb577e3
Added Test Benches
bwerth Oct 25, 2017
b6575c4
Fixed Test Benches
bwerth Oct 25, 2017
ca1d5c3
Merge branch 'master' of https://github.com/bwerth/Lab2
bwerth Oct 25, 2017
dd3f8b6
Fixed Test Benches
bwerth Oct 25, 2017
6ee1a5a
Fixed inputconditioner
bwerth Oct 25, 2017
a48dbbb
Test Sequence
wilttang Oct 25, 2017
0350750
Test Sequence
wilttang Oct 25, 2017
70fec8c
Finite State Machine First Pass is Working
bwerth Oct 30, 2017
b4cf5d8
Merge branch 'master' of https://github.com/bwerth/Lab2
bwerth Oct 30, 2017
387a1e6
first version of spi
wiltang Oct 31, 2017
f980c18
Finished first pass implementation
bwerth Nov 1, 2017
eac0358
added timing conditions
JosephLee19 Nov 1, 2017
f90df21
spi memory compiles now!
bwerth Nov 2, 2017
2020254
spimemory compiles and is correct
bwerth Nov 2, 2017
33610b6
fpga
wiltang Nov 2, 2017
4a8c8b9
fpga
wiltang Nov 2, 2017
0391cab
Fixed the fsm
bwerth Nov 2, 2017
db517af
Merge branch 'master' of https://github.com/bwerth/Lab2
bwerth Nov 2, 2017
c7b97ff
Fixed some things with spi memory
bwerth Nov 2, 2017
1cf7056
fpga edits 1
wiltang Nov 2, 2017
711b170
merge
wiltang Nov 2, 2017
fc8ea63
Fixed spi memory
bwerth Nov 2, 2017
0ae250e
Merge branch 'master' of https://github.com/bwerth/Lab2
bwerth Nov 2, 2017
f231e30
Fixed spi memory
bwerth Nov 2, 2017
e63207d
updated spimemory
wiltang Nov 2, 2017
95517bd
Fixed spi memory organizationally
bwerth Nov 2, 2017
91a55a3
Merge branch 'master' of https://github.com/bwerth/Lab2
bwerth Nov 2, 2017
5fee377
Updated fsm within spimemory_fpga.v
bwerth Nov 2, 2017
c5eba8d
Finished readding everything to spimemory_fpga.v
bwerth Nov 2, 2017
2365796
Fixed the outputs of spimemory_fpga.v
bwerth Nov 2, 2017
1c73271
spi merge
wiltang Nov 2, 2017
bb372b0
spi merge
wiltang Nov 2, 2017
f9ea9a6
added filler wire
wiltang Nov 2, 2017
dfc240c
Made a first pass at the function required for the test bench. I only…
bwerth Nov 2, 2017
ffebf97
Merge branch 'master' of https://github.com/bwerth/Lab2
bwerth Nov 2, 2017
16717c8
spimemory.t.v
wiltang Nov 2, 2017
d3ba0ac
spimemory.t.v
wiltang Nov 2, 2017
0432833
test case 3
wiltang Nov 3, 2017
0d9e4b6
commit
bwerth Nov 3, 2017
51b52ae
updated fsm
bwerth Nov 3, 2017
956bd8f
fixed error in fsm
bwerth Nov 3, 2017
2e5967e
merging
wiltang Nov 3, 2017
0315a60
merged no changes
wiltang Nov 3, 2017
5d0115e
Finished finally
bwerth Dec 13, 2017
a075740
Finished
bwerth Dec 13, 2017
f4b8fa9
Finished
bwerth Dec 13, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Test_Sequence.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Test Sequence

Controls:

Button0: Parallel Data In
Button1: Show Last 4 Bits
Button2: Show First 4 Bits

Switch0: Serial Data In
Switch1: Serial Data In CLk Edge

To begin testing first press Button0, then Button1.
You should see the following sequence in the 4 LEDS: 0011
Press Button2 to see the first 4 bits which should be: 1100

Now to test the serial data in functionality set switch0 to HIGH and toggle Switch1 to high
This should write a 1 bit to the back of the shift register and you should see the following:
Press Button1: 0111
Press Button2: 1000

Now set switch0 to low and toggle switch1 to high
This should write a 0 bit to the back of the shift register and you should see the following:
Press Button1: 1110
Press Button2: 0000


Now press Button0 again and the output should be 11000011 again.
2 changes: 1 addition & 1 deletion datamemory.v
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module datamemory
input [addresswidth-1:0] address,
input writeEnable,
input [width-1:0] dataIn
)
);


reg [width-1:0] memory [depth-1:0];
Expand Down
156 changes: 156 additions & 0 deletions fsm.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// MISO_BUFF DM_WE ADDR_WE SR_WE
//CS 0 0 0 0
//~CS 0 0 1 1
//shiftRegOutP[0] 1 0 0 1
//~shiftRegOutP[0]0 1 0 0
module fsm(MISO_BUFF,DM_WE,ADDR_WE,SR_WE,POS_EDGE,CS,shiftRegOutP0,clk,state,counter,relevant_shiftRegOutP0,clk_counter);
input POS_EDGE;
input CS;
input shiftRegOutP0;
input clk;
output MISO_BUFF;
output DM_WE;
output ADDR_WE;
output SR_WE;
output [1:0] state;
output [5:0] counter;
output [1:0] relevant_shiftRegOutP0;
output [5:0] clk_counter;

wire [1:0] state;
reg MISO_BUFF,DM_WE,ADDR_WE,SR_WE;
reg [1:0] next_state;
parameter counter_num_bits = 5;
reg[counter_num_bits-1:0] counter = 0;
reg start_counter;
wire [1:0] previous_state;
reg [1:0] counter_type;
reg [1:0] relevant_shiftRegOutP0;
reg already_counted;
reg [5:0] clk_counter;
reg [1:0] counter_flag;

assign state = next_state;

function [1:0] fsm_function;
input [1:0] state;
input CS;
input relevant_shiftRegOutP0;
case(state)
2'b00:if(!CS) begin
fsm_function = 2'b01;
end
2'b01:if(relevant_shiftRegOutP0 == 2'b10) begin
fsm_function = 2'b10;
end else if (relevant_shiftRegOutP0 == 2'b01) begin
fsm_function = 2'b11;
end else if (already_counted && counter == 0 && CS) begin
fsm_function = 2'b00;
end
2'b10:if(CS) begin
fsm_function = 2'b00;
end
2'b11:if(CS) begin
fsm_function = 2'b00;
end
default:fsm_function = 2'b00;
endcase
endfunction

always @ (posedge clk) begin
if(counter == 7) begin
clk_counter <= 1;
counter_flag <= 2'b01;
end else if (counter == 10 && relevant_shiftRegOutP0 == 2'b10) begin
clk_counter <= 1;
counter_flag <= 2'b10;
end else if (counter == 18 && relevant_shiftRegOutP0 == 2'b10) begin
clk_counter <= 1;
counter_flag <= 2'b11;
end else if (clk_counter == 3 && counter_flag == 2'b01) begin
relevant_shiftRegOutP0 <= shiftRegOutP0 ? 2'b10 : 2'b01;
clk_counter <= 0;
end else if (clk_counter == 6 && counter_flag == 2'b10) begin
MISO_BUFF <= 1;
clk_counter <= 0;
end else if (clk_counter == 6 && counter_flag == 2'b11) begin
MISO_BUFF <= 0;
clk_counter <= 0;
counter <= 0;
relevant_shiftRegOutP0 <= 2'b00;
end else if (clk_counter > 0) begin
clk_counter <= clk_counter + 1;
end
end

always @ (posedge POS_EDGE) begin
next_state <= fsm_function(state,CS,relevant_shiftRegOutP0);
if (next_state == 2'b00) begin
MISO_BUFF <= 0;
DM_WE <= 0;
SR_WE <= 0;
ADDR_WE <= 0;
already_counted <= 0;
end else if (next_state == 2'b01) begin
if(counter == 0 && !already_counted) begin
counter <= 1;
counter_type <= 2'b01;
already_counted <= 1;
end
end else if (next_state == 2'b10) begin
ADDR_WE <= 0;
DM_WE <= 0;
if(counter > 0) begin
SR_WE <= 1;
MISO_BUFF <= 1;
end
end else if (next_state == 2'b11) begin
DM_WE <= 0;
ADDR_WE <= 0;
SR_WE <= 0;
end
if (counter == 7) begin
ADDR_WE <= 1;
//relevant_shiftRegOutP0 <= shiftRegOutP0 ? 2'b10 : 2'b01;
counter <= counter + 1;
end else if (counter == 8) begin
ADDR_WE <= 0;
counter <= counter + 1;
end else if (counter == 9) begin
if (relevant_shiftRegOutP0 == 2'b10) begin
SR_WE <= 1;
end
counter <= counter + 1;
end else if (counter == 10) begin
SR_WE <= 0;
counter <= counter + 1;
//end else if (counter == ) begin
//if (next_state == 2'b10) begin
//MISO_BUFF <= 1;
//end
//counter <= counter + 1;
//end else if (counter == 10) begin
//if (relevant_shiftRegOutP0 == 2'b10) begin
// MISO_BUFF <= 1;
//end
end else if (counter == 15) begin
if (relevant_shiftRegOutP0 == 2'b01) begin
DM_WE <= 1;
end
counter <= counter + 1;
end else if (counter == 16) begin
DM_WE <= 0;
SR_WE <= 0;
//counter <= 0;
if (relevant_shiftRegOutP0 == 2'b01) begin
MISO_BUFF <= 0;
counter <= 0;
relevant_shiftRegOutP0 <= 2'b00;
end else if (relevant_shiftRegOutP0 == 2'b10) begin
counter <= counter + 1;
end
end else if (counter > 0) begin
counter <= counter + 1;
end
end
endmodule
24 changes: 16 additions & 8 deletions inputconditioner.t.v
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//------------------------------------------------------------------------
// Input Conditioner test bench
//------------------------------------------------------------------------
`include "inputconditioner.v"

module testConditioner();

reg clk;
reg clk = 0;
reg pin;
wire conditioned;
wire rising;
Expand All @@ -14,16 +15,23 @@ module testConditioner();
.noisysignal(pin),
.conditioned(conditioned),
.positiveedge(rising),
.negativeedge(falling))

.negativeedge(falling));

// Generate clock (50MHz)
initial clk=0;
always #10 clk=!clk; // 50MHz Clock
initial begin
forever begin
clk = !clk; #10;
end
end

initial begin
// Your Test Code
// Be sure to test each of the three conditioner functions:
// Synchronization, Debouncing, Edge Detection
pin = 0; #50;
pin = 1; #100;
pin = 0; #100;
pin = 1; #150;
pin = 0; #30;
pin = 1; #60;
pin = 0; #30;
end

endmodule
31 changes: 22 additions & 9 deletions inputconditioner.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,46 @@
//------------------------------------------------------------------------

module inputconditioner
(
input clk, // Clock domain to synchronize input to
input noisysignal, // (Potentially) noisy input signal
output reg conditioned, // Conditioned output signal
output reg positiveedge, // 1 clk pulse at rising edge of conditioned
output reg negativeedge // 1 clk pulse at falling edge of conditioned
);
(clk,noisysignal,conditioned,positiveedge,negativeedge);

parameter counterwidth = 3; // Counter size, in bits, >= log2(waittime)
parameter waittime = 3; // Debounce delay, in clock cycles

input clk;
input noisysignal;
output reg conditioned;
output reg positiveedge;
output reg negativeedge;

reg[counterwidth-1:0] counter = 0;
reg synchronizer0 = 0;
reg synchronizer1 = 0;
reg conditioned1 = 0;

always @(posedge clk ) begin
if(conditioned == synchronizer1)
if(conditioned1 == 0 && conditioned == 1) begin
negativeedge = 1;
end else if (conditioned1 == 1 && conditioned == 0) begin
positiveedge = 1;
end else if (positiveedge == 1 || negativeedge == 1) begin
positiveedge = 0;
negativeedge = 0;
end
if(conditioned1 == synchronizer1)
counter <= 0;
else begin
if( counter == waittime) begin
counter <= 0;
conditioned <= synchronizer1;
conditioned1 <= synchronizer1;
end
else
counter <= counter+1;
end
synchronizer0 <= noisysignal;
synchronizer1 <= synchronizer0;
conditioned <= conditioned1;
end
endmodule



Loading