2016-03-07 22 views
0
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; 
[email protected](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使用T-flipflop設計3位計數器

我得到許多錯誤,其中第一個錯誤是「w1不是常量」這是什麼意思?

我也收到錯誤「非網絡端口不能模式輸入」但我想要一個輸入!

謝謝。

回答

3

模塊被實例化爲硬件。他們不是軟件電話,你不能創建和因此飛破壞硬件:

if(w1==1)begin 
    not n1(i,i); 
end 

考慮到這一點,我希望你能看到,除非W1是恆定的參數,這是一個「生成如果'你的描述沒有意義。

實例n1未根據需要調用或創建,它必須始終存在。

此外,您的輸入和輸出連接到ii代表一個物理線,它不能是我而不是我。這些需要使用不同的名稱來表示不同的物理線路。

在你的第二個模塊,您有:

input a,b,c,cin; 
// ... 
reg a,b,c; //... 

輸入不能暫存器作爲警告說,只是不聲明爲暫存器這一點。

input a,b,c,cin; 
output x0,x1,x2; 
reg x0,x1,x2,temp,q,qb; 
+0

謝謝你,但我仍然沒有得到我能做的關於w1的事情。我想用它像鐘錶。那另一個錯誤呢? –

+1

對於w1問題更基礎的是,您使用'i'連接模塊的輸入和輸出的方式,我無法描述解決w1問題的方案,直到解決問題。 – Morgan

+0

我解決了使用另一個線temp1,然後使用if else部分。 –