Verilog: Why the "maxcount" cannot keep its max value but changes with the "count"? -


any appreciated!

i wrote module in order keep track of score (<= 99) game written in verilog , runs on led array. want able maintain max score. when current count greater maxcount, maxcount equal current count, else keeps value.

the problem is, not know why maxcount changes value whenever count changes (it cannot keep value when count less, instead become less along count)

is there logical error? or there verilog error missed?

thank much!

module score_keep(clock, reset, pt_0, pt_1, pt_2, pt_3, hex1, hex0, hex3, hex2);     input clock, reset;     input signed [3:0] pt_0, pt_1, pt_2, pt_3;     output [6:0] hex1, hex0, hex3, hex2;      wire signed [6:0] count;     wire signed [6:0] maxcount;     score_counter sc (clock, reset, pt_0, pt_1, pt_2, pt_3, count, maxcount);      display(count, maxcount, hex1, hex0, hex3, hex2);  endmodule   module display (count, maxcount, hex1, hex0, hex3, hex2);     input [6:0] count, maxcount;     output [6:0] hex1, hex0, hex3, hex2;      wire [4:0] unit, unit_m;     wire [4:0] tens, tens_m;      assign unit = count % 10;     assign tens = count / 10;      assign unit_m = count % 10;     assign tens_m = count / 10;      seg7 ud (unit, hex0);     seg7 td (tens, hex1);     seg7 umd (unit_m, hex2);     seg7 tmd (tens_m, hex3);   endmodule   module score_counter(clock, reset, pt_0, pt_1, pt_2, pt_3, count, maxcount);     input clock, reset;     //input signed [3:0] sum;     input [3:0] pt_0, pt_1, pt_2, pt_3;     parameter signed [3:0] no_point = 4'b0000, plus_one = 4'b0001, plus_two = 4'b0010, neg_two = 4'b1110;     //input zero, negative, carry, overflow;      output signed [6:0] count, maxcount;     reg signed [6:0] count, maxcount;      ////wire ps;     //reg ns;      @(posedge clock)         if (reset) begin             count <= 7'b0;             maxcount <= 7'b0;         end else begin             if (count > maxcount) begin                 maxcount <= count;             end              if (pt_0 == neg_two) begin                 if (count < 2) begin                     count <= 7'b0;                 end else begin                     count <= count - 2;                 end             end else begin                 count <= count + pt_0;                 if (count > 7'b100010) begin                     count <= 7'b0;                 end             end              if (pt_1 == neg_two) begin                 if (count < 2) begin                     count <= 7'b0;                 end else begin                     count <= count - 2;                 end             end else begin                 count <= count + pt_1;                 if (count > 7'b100010) begin                     count <= 7'b0;                 end             end              if (pt_2 == neg_two) begin                 if (count < 2) begin                     count <= 7'b0;                 end else begin                     count <= count - 2;                 end             end else begin                 count <= count + pt_2;                 if (count > 7'b100010) begin                     count <= 7'b0;                 end             end              if (pt_3 == neg_two) begin                 if (count < 2) begin                     count <= 7'b0;                 end else begin                     count <= count - 2;                 end             end else begin                 count <= count + pt_3;                 if (count > 7'b100010) begin                     count <= 7'b0;                 end             end         end endmodule 

your displaying count hex? positions.

assign unit_m = count % 10; assign tens_m = count / 10; 

should be:

assign unit_m = maxcount % 10; assign tens_m = maxcount / 10; 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -