I'm trying to make a 2 digit BCD counter which would count from 0 to 99. The problem I'm facing is that both the 7-segment dispays on the board are changing digits at the same time. The scenairio is like this - 00, 11, 22...99.
Here's the main logic code:
module PartD(
output reg[0:6] lcd, //for one particular 7 segment LCD.
input clock,
output reg[0:7] sel // for selecting which LCD to be used
);
integer count=0;
//integer i=0, j=0;
reg[3:0] i, j; //4 bit reg for counting
always@(posedge clock)
begin
if(count==100000000) //(100MHz) count till 100M cycles...(1 sec delay)
begin
count = 0;
sel=00000001; //selecting the most significant digit
case (i)
0: lcd = 7'b0000001;
1: lcd = 7'b1001111;
2: lcd = 7'b0010010;
3: lcd = 7'b0000110;
4: lcd = 7'b1001100;
5: lcd = 7'b0100100;
6: lcd = 7'b0100000;
7: lcd = 7'b0001111;
8: lcd = 7'b0000000;
9: lcd = 7'b0000100;
endcase
sel=00000010; //selecting the least significant digit
case (j)
0: lcd = 7'b0000001;
1: lcd = 7'b1001111;
2: lcd = 7'b0010010;
3: lcd = 7'b0000110;
4: lcd = 7'b1001100;
5: lcd = 7'b0100100;
6: lcd = 7'b0100000;
7: lcd = 7'b0001111;
8: lcd = 7'b0000000;
9: lcd = 7'b0000100;
endcase
j = j+1;
if(j>9)
begin
j=0;
i = i+1; //increment i only when j overflows.
if(i>9)
i = 0;
end
end
else count = count + 1;
end
endmodule
Since both displays are changing at once, there seems to be some logical error. What could it be. Am I making the mistake of not thinking in terms of hardware?