Question: You were telling me to make it so one button if I press once in mode 1 and if I press twice in mode 2
You were telling me to make it so one button if I press once in mode and if I press twice in mode The thing you are mentioning is what we discussed about how to encode your operation once you are within that mode. The way you had it in your code was to use switches, however you'd then have to figure out how to then still utilize all bits for your inputs.
The other method would be to encode your selection with more button presses. So one press you are in mode then say press again for add, press again for subtract, and then once you have a selection a separate button press goes to execute stage.
#setproperty PACKAGEPIN Ugetports btnC
#setproperty IOSTANDARD LVCMOSgetports btnC
#setproperty PACKAGEPIN Tgetports btnU
#setproperty IOSTANDARD LVCMOSgetports btnU
#setproperty PACKAGEPIN Wgetports btnL
#setproperty IOSTANDARD LVCMOSgetports btnL
#setproperty PACKAGEPIN Tgetports btnR
#setproperty IOSTANDARD LVCMOSgetports btnR
#setproperty PACKAGEPIN Ugetports btnD
#setproperty IOSTANDARD LVCMOSgetports btnD
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
