diff --git a/Nexys4Game/src/hdl/SC_buffer_serializer.v b/Nexys4Game/src/hdl/SC_buffer_serializer.v index ff0cce1..bbe1151 100644 --- a/Nexys4Game/src/hdl/SC_buffer_serializer.v +++ b/Nexys4Game/src/hdl/SC_buffer_serializer.v @@ -1,17 +1,19 @@ module SC_buffer_serializer( input clk, - input song_time, + input [15:0] song_time, input [36:0] match_trigger, input [37*16-1:0] match_time, output reg match_en, - output reg [15:0] match_dt - + output reg [15:0] match_dt, + output [15:0] queue ); reg [17*6-1:0] match_queue; //represents a shift register with 6 shifts of 17 bits each, where the MSB means a valid match needs to be scored, and the next 16 bits are the dt initial match_queue = 0; + + assign queue = match_queue[15:0]; always @(posedge clk) begin @@ -97,7 +99,10 @@ module SC_buffer_serializer( match_queue[17*5-1:0] <= match_queue[17*6-1:17]; //Shift the queue match_en <= match_queue[16]; //shift out a match - match_dt <= song_time - match_queue[15:0]; //SIGNED ISSUES : NEED FIXING - + if(song_time >= match_queue[15:0]) + match_dt <= song_time - match_queue[15:0]; + else + match_dt <= match_queue[15:0] - song_time; + end endmodule \ No newline at end of file diff --git a/Nexys4Game/src/test/SC_buffer_serializer_tb.v b/Nexys4Game/src/test/SC_buffer_serializer_tb.v index 794d136..bfc3c9c 100644 --- a/Nexys4Game/src/test/SC_buffer_serializer_tb.v +++ b/Nexys4Game/src/test/SC_buffer_serializer_tb.v @@ -11,6 +11,7 @@ module SC_buffer_serializer_tb; // Outputs wire match_en; wire [15:0] match_dt; + wire [15:0] queue; // Instantiate the Unit Under Test (UUT) SC_buffer_serializer uut ( @@ -19,11 +20,12 @@ module SC_buffer_serializer_tb; .match_trigger(match_trigger), .match_time(match_time), .match_en(match_en), - .match_dt(match_dt) + .match_dt(match_dt), + .queue(queue) ); always #5 clk = !clk; - always #10 song_time = song_time + 1; + always #100 song_time = song_time + 1; initial begin // Initialize Inputs clk = 0; @@ -34,7 +36,7 @@ module SC_buffer_serializer_tb; #100; //Stimulus - + #1000 match_trigger = 1; //match e2 match_time[15:0] = 7; #10