Hi guys, I'm really stuck and have been trying to figure this out for hours. I can't seem to understand what I'm doing wrong.
I need to build a 3-bit Gray counter with an input x that controls the counting order as follows:
The tricky part is that I need to implement an asynchronous memory controlled by two signals, a and b, that follows the following transitions on the positive edge of the clock:
i already did this much:
4 states
P=00 Q=01 R=11 S=10
y1)
y2)
I noticed that y2= y1^clk
and
y1 = (y1&~clk) | (y1&!y2f) | (y1&y2&!a&!b) | (a&(y1^y2)&clk);
Then I wrote the moddule of this memory:
module ab_mem(
input wire clk, // Segnale di clock
input wire reset, // Segnale di reset asincrono
input wire a, // Ingresso a
input wire b, // Ingresso b
output reg Q // Uscita Q
);
wire y1,y2,y1f,y2f;
assign y1 = (y1f&~clk) | (y1f&!y2f) | (y1f&y2f&!a&!b) | (a&(y1f^y2f)&clk);
assign y2= (y1^clk);
assign y1f = y1 & ~reset;
assign y2f = y2 & ~reset;
assign Q = y1f;
endmodule
I made a simulation andd all the states work in the right combos.
then I had to write the gray counter so I introduced the 0'= 1->0 and 1'= 0->1 states.
and wrote this table:
Now from the previous transaction table I wrote the excitation diagram for ab_mem:
and I searched the right function for every a_n,b_n:
y1:
a1:
b1:
y2:
a2:
b2:
y3:
a3:
b3:
I found the value of all a and b and put them in this module:
module gray2(
input wire clk, // Segnale di clock
input wire reset, // Segnale di reset
input wire x, // Segnale di input
output [2:0] z // Segnali di output
);
wire y1,y2,y3;
wire a1,b1,a2,b2,a3,b3;
assign a1 = (!y2&!y3&x) |(y2&!y3&!x);
assign b1 = (!y2&!y3&!x) |(y2&!y3&x);
assign a2 = (y3&!x&!y1)|(y3&x&y1);
assign b2 = (y3&!x&y1)| (y3&x&!y1);
assign a3= (!y1&y2&x) | (y1&!y2&x) | (!y1&!y2&!x) | (y1&y2&!x);
assign b3 = (y1&y2&x) | (!y1&y2&!x) | (!y1&!y2&x) | (y1&!y2&!x);
assign z[2]=y1;
assign z[1]=y2;
assign z[0]=y3;
ab_mem FF3(.clk(clk), .reset(reset), .a(a3), .b(b3), .Q(y3));
ab_mem FF2(.clk(clk), .reset(reset), .a(a2), .b(b2), .Q(y2));
ab_mem FF1(.clk(clk), .reset(reset), .a(a1), .b(b1), .Q(y1));
endmodule
but when I did the simulation, thisd was the result:

It doesn t work and i can't understand what am I doing wrong. pls help.
PS sorry for the bad english. Not my first language
I need to build a 3-bit Gray counter with an input x that controls the counting order as follows:
- When x = 0, the counter works in descending order (e.g., 000 → 001 → 011 → 010 → 110 → ...).
- When x = 1, the counter works in ascending order (e.g., 000 → 100 → 101 → 111 → ...).
The tricky part is that I need to implement an asynchronous memory controlled by two signals, a and b, that follows the following transitions on the positive edge of the clock:
out/a,b | 00 | 01 | 11 | 10 |
0 | - | 0 | - | 1 |
1 | 1 | 0 | 1 | 1 |
i already did this much:
4 states
P=00 Q=01 R=11 S=10
| c=0 | c=0 | c=0 | c=0 | c=1 | c=1 | c=1 | c=1 | |
st/ab | 00 | 01 | 11 | 10 | 00 | 01 | 11 | 10 | OUT |
P | P | P | P | P | - | Q | - | S | 0 |
Q | P | P | P | P | Q | Q | Q | Q | 0 |
R | R | R | R | R | 1 | 0 | 1 | 1 | 1 |
S | R | R | R | R | S | S | S | S | 1 |
| c=0 | c=0 | c=0 | c=0 | c=1 | c=1 | c=1 | c=1 | |
y1y2/ab | 00 | 01 | 11 | 10 | 00 | 01 | 11 | 10 | OUT |
00 | 00 | 00 | 00 | 00 | - | 01 | - | 10 | 0 |
01 | 00 | 00 | 00 | 00 | 01 | 01 | 01 | 01 | 0 |
11 | 11 | 11 | 11 | 11 | 10 | 01 | 10 | 10 | 1 |
10 | 11 | 11 | 11 | 11 | 10 | 10 | 10 | 10 | 1 |
y1)
| c=0 | c=0 | c=0 | c=0 | c=1 | c=1 | c=1 | c=1 | |
y1y2/ab | 00 | 01 | 11 | 10 | 00 | 01 | 11 | 10 | OUT |
00 | 0 | 0 | 0 | 0 | - | 0 | - | 1 | 0 |
01 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
11 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 |
10 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
y2)
| c=0 | c=0 | c=0 | c=0 | c=1 | c=1 | c=1 | c=1 | |
y1y2/ab | 00 | 01 | 11 | 10 | 00 | 01 | 11 | 10 | OUT |
00 | 0 | 0 | 0 | 0 | - | 1 | - | 0 | 0 |
01 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 |
11 | 1 | 1 | 1 | 1 | 0 | 1 | 0 | 0 | 1 |
10 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 1 |
I noticed that y2= y1^clk
and
y1 = (y1&~clk) | (y1&!y2f) | (y1&y2&!a&!b) | (a&(y1^y2)&clk);
Then I wrote the moddule of this memory:
module ab_mem(
input wire clk, // Segnale di clock
input wire reset, // Segnale di reset asincrono
input wire a, // Ingresso a
input wire b, // Ingresso b
output reg Q // Uscita Q
);
wire y1,y2,y1f,y2f;
assign y1 = (y1f&~clk) | (y1f&!y2f) | (y1f&y2f&!a&!b) | (a&(y1f^y2f)&clk);
assign y2= (y1^clk);
assign y1f = y1 & ~reset;
assign y2f = y2 & ~reset;
assign Q = y1f;
endmodule
I made a simulation andd all the states work in the right combos.
then I had to write the gray counter so I introduced the 0'= 1->0 and 1'= 0->1 states.
and wrote this table:
| x=0 | x=0 | x=1 | x=1 |
Q(t) | Q(t+1) | y1y2y3 | Q(t+1) | y1y2y3 |
000 | 001 | 001’ | 100 | 1’00 |
001 | 011 | 01’1 | 000 | 000’ |
011 | 010 | 010’ | 001 | 00’1 |
010 | 110 | 1’10 | 011 | 011’ |
110 | 111 | 111’ | 010 | 0’10 |
111 | 101 | 10’1 | 110 | 110’ |
101 | 100 | 100’ | 111 | 11’1 |
100 | 000 | 0’00 | 101 | 101’ |
Now from the previous transaction table I wrote the excitation diagram for ab_mem:
| a | b |
0 | 0 | - |
1 | -/1 | 0/- |
0’ | 0 | 1 |
1’ | 1 | - |
and I searched the right function for every a_n,b_n:
y1:
y1y2/y3x | 00 | 01 | 11 | 10 |
00 | 0 | 1’ | 0 | 0 |
01 | 1’ | 0 | 0 | 0 |
11 | 1 | 0’ | 1 | 1 |
10 | 0’ | 1 | 1 | 1 |
a1:
y1y2/y3x | 00 | 01 | 11 | 10 |
00 | 0 | 1 | 0 | 0 |
01 | 1 | 0 | 0 | 0 |
11 | -/1 | 0 | -/1 | -/1 |
10 | 0 | -/1 | -/1 | -/1 |
b1:
y1y2/y3x | 00 | 01 | 11 | 10 |
00 | - | - | - | - |
01 | - | - | - | - |
11 | 0/- | 1 | 0/- | 0/- |
10 | 1 | 0/- | 0/- | 0/- |
y2:
y1y2/y3x | 00 | 01 | 11 | 10 |
00 | 0 | 0 | 0 | 1’ |
01 | 1 | 1 | 0’ | 1 |
11 | 1 | 1 | 1 | 0’ |
10 | 0 | 0 | 1’ | 0 |
a2:
y1y2/y3x | 00 | 01 | 11 | 10 |
00 | 0 | 0 | 0 | 1 |
01 | -/1 | -/1 | 0 | -/1 |
11 | -/1 | -/1 | -/1 | 0 |
10 | 0 | 0 | 1 | 0 |
b2:
y1y2/y3x | 00 | 01 | 11 | 10 |
00 | - | - | - | - |
01 | 0/- | 0/- | 1 | 0/- |
11 | 0/- | 0/- | 0/- | 1 |
10 | - | - | - | - |
y3:
y1y2/y3x | 00 | 01 | 11 | 10 |
00 | 1’ | 0 | 0’ | 1 |
01 | 0 | 1’ | 1 | 0’ |
11 | 1’ | 0 | 0’ | 1 |
10 | 0 | 1’ | 1 | 0’ |
a3:
y1y2/y3x | 00 | 01 | 11 | 10 |
00 | 1 | 0 | 0 | -/1 |
01 | 0 | 1 | -/1 | 0 |
11 | 1 | 0 | 0 | -/1 |
10 | 0 | 1 | -/1 | 0 |
b3:
y1y2/y3x | 00 | 01 | 11 | 10 |
00 | - | - | 1 | 0/- |
01 | - | - | 0/- | 1 |
11 | - | - | 1 | 0/- |
10 | - | - | 0/- | 1 |
I found the value of all a and b and put them in this module:
module gray2(
input wire clk, // Segnale di clock
input wire reset, // Segnale di reset
input wire x, // Segnale di input
output [2:0] z // Segnali di output
);
wire y1,y2,y3;
wire a1,b1,a2,b2,a3,b3;
assign a1 = (!y2&!y3&x) |(y2&!y3&!x);
assign b1 = (!y2&!y3&!x) |(y2&!y3&x);
assign a2 = (y3&!x&!y1)|(y3&x&y1);
assign b2 = (y3&!x&y1)| (y3&x&!y1);
assign a3= (!y1&y2&x) | (y1&!y2&x) | (!y1&!y2&!x) | (y1&y2&!x);
assign b3 = (y1&y2&x) | (!y1&y2&!x) | (!y1&!y2&x) | (y1&!y2&!x);
assign z[2]=y1;
assign z[1]=y2;
assign z[0]=y3;
ab_mem FF3(.clk(clk), .reset(reset), .a(a3), .b(b3), .Q(y3));
ab_mem FF2(.clk(clk), .reset(reset), .a(a2), .b(b2), .Q(y2));
ab_mem FF1(.clk(clk), .reset(reset), .a(a1), .b(b1), .Q(y1));
endmodule
but when I did the simulation, thisd was the result:

It doesn t work and i can't understand what am I doing wrong. pls help.
PS sorry for the bad english. Not my first language


