Merge pull request #66 from lekcyjna123/dev/sar-logic

Remove modulo operator from sar logic
This commit is contained in:
PhillipRambo 2026-06-15 15:09:25 +02:00 committed by GitHub
commit 133ecf6575
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 90 additions and 26 deletions

View File

@ -4,30 +4,23 @@ module sar_logic (
input wire En, input wire En,
input wire Om, input wire Om,
input wire rst, input wire rst,
output reg [6:0] B, // 7-bit output wire [7:0] B, // 8-bit
output reg [6:0] BN, // 7-bit output reg [7:0] BN, // 8-bit
output reg [7:0] D // 8-bit output reg [7:0] D // 8-bit
); );
reg [3:0] counter = 4'b0000; // 4-bit counter reg [3:0] counter; // 3-bit counter
assign B = D;
always @(posedge clk) begin always @(posedge clk) begin
if (rst) begin if (rst) begin
B <= 7'b0000000; BN <= 8'b0000000;
BN <= 7'b0000000; D <= 8'b00000000;
D <= 8'b00000000; counter <= 4'b0000;
counter <= 4'b0000; end else if (En && (Op ^ Om) && ~(counter==8)) begin
end else if (En && (Op ^ Om)) begin D[counter[2:0]] <= Op;
if (counter < 7) begin BN[counter[2:0]] <= Om;
D <= D | ({7'b0, Op} << counter); counter <= counter + 1'b1;
B[counter % 7] <= (Op) ? 1'b1 : 1'b0;
BN[counter % 7] <= (Om) ? 1'b1 : 1'b0;
counter <= counter + 1'b1;
end
end end
end end
endmodule endmodule

View File

@ -10,8 +10,8 @@ module sar_logic_tb();
reg En; reg En;
// Outputs // Outputs
wire [6:0] B; wire [7:0] B;
wire [6:0] BN; wire [7:0] BN;
wire [7:0] D; wire [7:0] D;
// Instantiate the SAR Logic module // Instantiate the SAR Logic module
@ -48,12 +48,83 @@ module sar_logic_tb();
Om = 1'b0; Om = 1'b0;
// Apply reset again // Apply reset again
#80 rst = 1'b1; #100 rst = 1'b1;
#10 rst = 1'b0; #10 rst = 1'b0;
Op = 1'b0; Op = 1'b0;
Om = 1'b1; Om = 1'b1;
#70 rst = 1'b1; #50 rst = 1'b1;
#10 rst = 1'b0;
En = 1'b1;
Op = 1'b1;
Om = 1'b0;
#10 Op = 1'b0;
Om = 1'b0;
#10 Op = 1'b0;
Om = 1'b1;
#10 Op = 1'b1;
Om = 1'b0;
#10 Op = 1'b0;
Om = 1'b1;
#10 Op = 1'b1;
Om = 1'b0;
#10 Op = 1'b0;
Om = 1'b1;
#10 Op = 1'b1;
Om = 1'b0;
#10 Op = 1'b0;
Om = 1'b1;
#10 Op = 1'b1;
Om = 1'b0;
#10 Op = 1'b0;
Om = 1'b1;
#50 rst = 1'b1;
#10 rst = 1'b0;
En = 1'b1;
Op = 1'b0;
Om = 1'b1;
#10 Op = 1'b1;
Om = 1'b0;
#10 Op = 1'b0;
Om = 1'b1;
#10 Op = 1'b1;
Om = 1'b0;
#10 Op = 1'b0;
Om = 1'b1;
#10 Op = 1'b1;
Om = 1'b0;
#10 Op = 1'b0;
Om = 1'b1;
#10 Op = 1'b1;
Om = 1'b0;
#10 Op = 1'b0;
Om = 1'b1;
#10 Op = 1'b1;
Om = 1'b0;
#10 Op = 1'b0;
Om = 1'b1;
// End of simulation // End of simulation
#100 $finish; #100 $finish;