Question: Hello, im trying to make a stopwatch program that resets / starts + stops with two buttons, has 4 modes based on s witches (
Hello, im trying to make a stopwatch program that resetsstartsstops with two buttons, has modes based on s witches mode counts up from : mode counts up from value, mode counts down from : mode counts down from value and inputs the value from switches. its almost working, i think it is a small problem i have, any help is appreciated thank you!
module stopwatchtimer
input clk
input reset,
input startstop,
input : modeselect, mode selection
input : presetvalue, modes and switches
output reg : seg, segments
output reg : an anode activation
;
reg : seconds ;
reg : milliseconds ;
reg running ; flag
reg : count ; clock divider counter
reg : displaycounter ; counter to cycle
Mode selection and Timer Logic
always @posedge clk or posedge reset begin
if reset begin
Reset logic, set initial values based on the mode
case modeselect
b: begin Mode : Count up from :
seconds ;
milliseconds ;
end
b: begin Mode : Count up from preset value
seconds presetvalue:;
milliseconds ;
end
b: begin Mode : Count down from :
seconds ;
milliseconds ;
end
b: begin Mode : Count down from preset value
seconds presetvalue:;
milliseconds presetvalue:;
end
default: begin
seconds ;
milliseconds ;
end
endcase
running ;
count ;
end else begin
Handle the startstop functionality
if startstop running ~running;
Increment or decrement logic based on the mode and running state
if running && count begin
count ;
case modeselect
bb: begin Modes and : Counting up
if milliseconds begin
milliseconds ;
if seconds
seconds ;
else
seconds seconds ;
end else begin
milliseconds milliseconds ;
end
end
bb: begin Modes and : Counting down
if milliseconds begin
if seconds begin
milliseconds ;
seconds seconds ;
end else if seconds && milliseconds begin
Optionally stop timer when it reaches :
running ;
end
end else begin
milliseconds milliseconds ;
end
end
endcase
end else if running begin
count count ;
end
end
end
Display Logic
always @posedge clk begin
if count begin update display
case displaycounter
b: begin
seg decodesevensegmentseconds ;
an b;
end
b: begin
seg decodesevensegmentseconds ;
an b;
end
b: begin
seg decodesevensegmentmilliseconds ;
an b;
end
b: begin
seg decodesevensegmentmilliseconds ;
an b;
end
endcase
displaycounter displaycounter ;
end
end
function : decodesevensegment;
input : digit;
begin
case digit
h: decodesevensegment b;
h: decodesevensegment b;
h: decodesevensegment b;
h: decodesevensegment b;
h: decodesevensegment b;
h: decodesevensegment b;
h: decodesevensegment b;
h: decodesevensegment b;
h: decodesevensegment b;
h: decodesevensegment b;
default: decodesevensegment b; blank
endcase
end
endfunction
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
