- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was designing a stop watch this week,but get some troubles.
There are four keys---reset,stop,minset(minute set),and secset(second set) in the watch.The reset and stop fuctions are right,but the minset and the secset won't make the minute or the second +1 successfully,and show some error numbers.I don't know why. This is my code: module SECLOCK(clk,sclk,rundir,key); input clk,sclk;//clk--system clk,sclk---percentage second input rundir;//run direction input[3:0] key;// 4 keys reg[32:0] j;//the total percentage seconds,to generate min,sec,percentage second reg run;//stop mark reg keyclk; reg ssclk; always @(posedge clk)//scan the keys' value,when key!=0,keyclk set high begin if(key!=0) keyclk<=1; else keyclk<=0; end always @(sclk)//avoid the conflict between keyclk and ssclk begin if(keyclk!=0) ssclk=0; else ssclk=sclk; end always @(posedge keyclk or posedge ssclk) begin if(keyclk) begin case(key0) 4'b0001://reset begin j<=0; run<=0; end 4'b0010://stop begin run<=~run; end 4'b0100://set second + 1 begin j<=j+33'd100; end 4'b1000://set min + 1 begin j<=j+33'd6000; end endcase end else begin if(run==1 && rundir==1 ) //forward count j<=j+1; else if(run==1 && rundir==0 && j>0) //reward count j<=j-1; end end endmoduleLink Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I hope somebody can help solve it.Thanks.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page