Question: i need this the mode to toggle through mode and have it start off in airthmric mode and have the other button for the opcode

i need this the mode to toggle through mode and have it start off in airthmric mode and have the other button for the opcode in each mode as well as a testbench for it through all the opcode. this code run into problem like not showing any output.
module calculator_fsm (
input clk,
input btn_mode, // Single button for toggling modes
input [1:0] btn_sel, // Operation selection input
output reg [2:0] opcode,
output reg mode, //0= Arithmetic, 1= Bitwise
output reg alu_enable
);
localparam MODE_1=1'b0; // Arithmetic operations
localparam MODE_2=1'b1; // Bitwise operations
reg mode = MODE_1; // Initialize mode
reg btn_mode_sync; // Synchronized button signal
reg btn_mode_debounced; // Debounced button signal
// Synchronize and debounce btn_mode
always @(posedge clk) begin
btn_mode_sync = btn_mode; // Synchronize input to clock domain
if (btn_mode_sync != btn_mode_debounced) begin
debounce_cnt =0; // Reset counter
end else if (debounce_cnt 4'd15) begin
debounce_cnt = debounce_cnt +1; // Increment counter
end
if (debounce_cnt ==4'd15) begin
btn_mode_debounced = btn_mode_sync; // Update debounced signal
end
end
// Toggle mode on falling edge of debounced button
always @(posedge clk) begin
if (btn_mode_debounced && !btn_mode_sync) begin
mode = ~mode; // Toggle mode
end
end
// Determine opcode based on mode and button inputs
always @(*) begin
alu_enable =0; // Default disable ALU
case (mode)
MODE_1: begin
// Arithmetic Mode
case (btn_sel)
2'b00: opcode =3'b000; // Addition
2'b01: opcode =3'b001; // Subtraction
2'b10: opcode =3'b010; // Multiplication
2'b11: opcode =3'b011; // Division
default: opcode =3'b000; // Default to Addition
endcase
alu_enable =1;
end
MODE_2: begin
// Bitwise Mode
case (btn_sel)
2'b00: opcode =3'b100; // AND
2'b01: opcode =3'b101; // OR
2'b10: opcode =3'b110; // Shift Left
2'b11: opcode =3'b111; // Shift Right
default: opcode =3'b100; // Default to AND
endcase
alu_enable =1;
end
default: begin
opcode =3'b000;
alu_enable =0;
end
endcase
end
endmodule
i need this the mode to toggle through mode and

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!