2014-04-05 25 views
0

我在Altera DE0板上使用三個按鈕。Verilog Muliple如果沒有按預期工作

我宣佈它作爲

input [2:0] Button; 
    reg [2:0] y; 
    parameter [2:0] S0 = 3'b000, S1 = 3'b001, S2 = 3'b010, S3 = 3'b011, S4 = 3'b100, S5 = 3'b101; 

我有一個基於三個按鈕的值的嵌套的if-else語句

[email protected](negedge (&Button)) 
//if(&Button == 0) 
begin 
if(Button == 3'b011) // Button 2 is pressed 
begin 
if(y == S0) 
    begin 
    y = S1; 
    end 
end 
else if(Button == 3'b101) // Button 1 is pressed 
begin 
if (y == S1) 
    begin 
    y = S2; 
    end 
else if (y == S2) 
    begin 
    y = S3; 
    end 
end 
else if(Button == 3'b110) //This is the check on button 0, but this conditional statement does not work. 
begin 
if(y == S2) 
    begin 
    y = S3; 
    end 
end 
end 

assign z = (y == S0);  // z,z1,z2,z3 are LED's on the board 
assign z1 = (y == S1); 
assign z2 = (y == S2); 
assign z3 = (y == S3); 

當我使用的前兩個按鈕中的if-else在DE0板上標有BUTTON2和BUTTON1的語句(按鈕== 3'b011和按鈕== 3'b101),代碼工作,y按預期變爲適當的值。

但是當我嘗試if-else中的第三個按鈕時,按鈕== 3'b011,在DE0上標記爲BUTTON0,沒有任何反應,y沒有得到期望的值。我使用了2個不同的DE0板,並出現相同的問題。

我覺得它有什麼做的

[email protected](negedge (&button)) 
中,這只是沒有被發現的第三個按鈕按下

。但是當我使用代碼如

[email protected](negedge button[0] or negedge button[1] or negedge button[2]) 

其他問題出現,我一直無法解決。

回答

2

您需要考慮您嘗試建模的硬件。 always @(negedge或更一般的邊沿觸發的總是塊,用於暗示通常由時鐘和復位驅動的觸發器。

數據信號可以像在Frequency Divider中那樣用作時鐘。然而,如果使用組合簡化運算符的一元運算符&,將導致真實硬件中的時鐘出現故障。

我提到想着你是什麼暗示的硬件,因爲你有這樣的結構:

[email protected](negedge button[0] or negedge button[1] or negedge button[2]) 

已在硬件不等價的。

您可能會感興趣這個Altera FSM example有幫助。你可能想要什麼implement edge detection from this question,所以你只需按下一次按鈕即可改變狀態。