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 calculatorfsm
input clk
input btnmode, Single button for toggling modes
input : btnsel, Operation selection input
output reg : opcode,
output reg mode, Arithmetic, Bitwise
output reg aluenable
;
localparam MODEb; Arithmetic operations
localparam MODEb; Bitwise operations
reg mode MODE; Initialize mode
reg btnmodesync; Synchronized button signal
reg btnmodedebounced; Debounced button signal
Synchronize and debounce btnmode
always @posedge clk begin
btnmodesync btnmode; Synchronize input to clock domain
if btnmodesync btnmodedebounced begin
debouncecnt ; Reset counter
end else if debouncecnt d begin
debouncecnt debouncecnt ; Increment counter
end
if debouncecnt d begin
btnmodedebounced btnmodesync; Update debounced signal
end
end
Toggle mode on falling edge of debounced button
always @posedge clk begin
if btnmodedebounced && btnmodesync begin
mode ~mode; Toggle mode
end
end
Determine opcode based on mode and button inputs
always @ begin
aluenable ; Default disable ALU
case mode
MODE: begin
Arithmetic Mode
case btnsel
b: opcode b; Addition
b: opcode b; Subtraction
b: opcode b; Multiplication
b: opcode b; Division
default: opcode b; Default to Addition
endcase
aluenable ;
end
MODE: begin
Bitwise Mode
case btnsel
b: opcode b; AND
b: opcode b; OR
b: opcode b; Shift Left
b: opcode b; Shift Right
default: opcode b; Default to AND
endcase
aluenable ;
end
default: begin
opcode b;
aluenable ;
end
endcase
end
endmodule
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
