使用 T 触发器设计 3 位计数器
Designing a 3-bit counter using T-flipflop
module tff(t,i,qbprev,q,qb);
input t,i,qbprev;
output q,qb;
wire q,qb,w1;
begin
assign w1=qbprev;
if(w1==1)begin
not n1(i,i);
end
assign q=i;
not n2(qb,i);
end
endmodule
module counter(a,b,c,cin,x0,x1,x2);
input a,b,c,cin;
output x0,x1,x2;
reg a,b,c,x0,x1,x2,temp,q,qb;
always@(posedge cin)
begin
tff t1(.t(1) ,.i(a),.qbprev(1),.q(),.qb());
x0=q;
temp=qb;
tff t2(.t(1) ,.i(b),.qbprev(temp),.q(),.qb());
x1=q;
temp=qb;
tff t3(.t(1) ,.i(c),.qbprev(temp),.q(),.qb());
x2=q;
a=x0;
b=x1;
c=x2;
end
endmodule
这是我在 verilog 中的代码。我的输入是 - 初始状态 - a、b、c 和 cin
我遇到很多错误,其中第一个是 "w1 is not a constant" 这是什么意思?
我也收到错误 "Non-net port a cannot be of mode input" 但我想输入一个!
谢谢。
模块被实例化为硬件。它们不是软件调用,因此您不能即时创建和销毁硬件:
if(w1==1)begin
not n1(i,i);
end
考虑到这一点,我希望您能明白,除非 w1 是常量参数,而这是 'generate if' 您的描述没有意义。
实例n1未按要求调用或创建,必须一直存在。
您还可以将输入和输出连接到 i
。 i
代表一根物理线它不能是i和not i。这些需要不同的名称来表示不同的物理线。
在你的第二个模块中你有:
input a,b,c,cin;
// ...
reg a,b,c; //...
如警告所述,输入不能是 regs,只是不要将它们声明为 regs。
input a,b,c,cin;
output x0,x1,x2;
reg x0,x1,x2,temp,q,qb;
module tff(t,i,qbprev,q,qb);
input t,i,qbprev;
output q,qb;
wire q,qb,w1;
begin
assign w1=qbprev;
if(w1==1)begin
not n1(i,i);
end
assign q=i;
not n2(qb,i);
end
endmodule
module counter(a,b,c,cin,x0,x1,x2);
input a,b,c,cin;
output x0,x1,x2;
reg a,b,c,x0,x1,x2,temp,q,qb;
always@(posedge cin)
begin
tff t1(.t(1) ,.i(a),.qbprev(1),.q(),.qb());
x0=q;
temp=qb;
tff t2(.t(1) ,.i(b),.qbprev(temp),.q(),.qb());
x1=q;
temp=qb;
tff t3(.t(1) ,.i(c),.qbprev(temp),.q(),.qb());
x2=q;
a=x0;
b=x1;
c=x2;
end
endmodule
这是我在 verilog 中的代码。我的输入是 - 初始状态 - a、b、c 和 cin
我遇到很多错误,其中第一个是 "w1 is not a constant" 这是什么意思?
我也收到错误 "Non-net port a cannot be of mode input" 但我想输入一个!
谢谢。
模块被实例化为硬件。它们不是软件调用,因此您不能即时创建和销毁硬件:
if(w1==1)begin
not n1(i,i);
end
考虑到这一点,我希望您能明白,除非 w1 是常量参数,而这是 'generate if' 您的描述没有意义。
实例n1未按要求调用或创建,必须一直存在。
您还可以将输入和输出连接到 i
。 i
代表一根物理线它不能是i和not i。这些需要不同的名称来表示不同的物理线。
在你的第二个模块中你有:
input a,b,c,cin;
// ...
reg a,b,c; //...
如警告所述,输入不能是 regs,只是不要将它们声明为 regs。
input a,b,c,cin;
output x0,x1,x2;
reg x0,x1,x2,temp,q,qb;