コンテキスト:
私はコンピュータ工学の男です。私は学校に通っており、これは私の上級プロジェクトの一部です。私は、私のグループによって作成された電子ボードゲームで使用するためにFPGAをプログラムしようとしています。 FPGAは、すべてのロジックを制御するRaspberry PiのIOエクステンダです。下記のVerilogコードは、アルテラのMax V 570 devkit上で実行され、本番用ユニットのMax V 40に移行する予定です。各FPGAは4つのゲームタイルのグループを制御し、最終製品には4つのタイルグループが存在します。コンプライアントSCIの主要な予期しない出力でFPGAをプログラミングする際の問題
問題:
は、私は我々のシステムでは(今のLED)MOSFETを制御するためにラズベリーパイとのインタフェースになるFPGAを作成しています。私が午前の問題は関係なく、私がタイルに送って、どのコマンド、LEDは、いつものようにトグルされていない、ということです:
tile0のために、唯一の0番目のLEDは第一LEDが切り替わります、tile1ため
を切り替えます(
https://drive.google.com/open?id=0B7P773tnBnRybHhGRmZMX3hScGFrNXpKUDN2c0tBbkFZaTVJ
それぞれのLED決勝を無視:
tile2のために、唯一の第二LEDはtile3のために、唯一の第三LEDがここ
を切り替えます容量性センサから入力される)、
これは、LEDトグルコマンド(下のコードでは2'b11)とソレノイドのトグル(下のコードでは2'b01)に該当します。
アルテラModelSimでのシミュレーションでは、すべてが完全に機能します!しかし、すべてがブレッドボードに接続されて、私は上記の状況を参照してください。
は、私が最初に問題を考え、問題に
私の考えは、私はから読んでいた同じレジスタに割り当てるとあったが、私はそれから割り当て、レジスタを読み取るために(...無計画に)別のステップを追加しましたが、私は悪い動作を見た(LEDはトグルしない)。助けて! :)ここで
は私のverilogコードです:誰もが私に正確に40のLE以下にこれを削減する方法についての指針を与えることができれば
module comm_protocol(clock, bus, t0, t1, t2, t3, t0cap, t1cap, t2cap, t3cap, capOut);
parameter [1:0] my_address = 2'b11;
input clock;
input [3:0] bus;
output reg [4:0] t0;
output reg [4:0] t1;
output reg [4:0] t2;
output reg [4:0] t3;
input wire t0cap, t1cap, t2cap, t3cap;
output reg capOut;
reg start;
reg [1:0] tickCounter;
reg gotFpgaAddress;
reg [1:0] fpgaAddress;
reg[1:0] tileAddress;
reg gotCommand;
reg [3:0] command;
initial begin
start <= 0;
t0 <= 5'b11111;
t1 <= 5'b11111;
t2 <= 5'b11111;
t3 <= 5'b11111;
end
always @ (posedge clock) begin
// check if we have recieved the start condition, which is just a positive edge on the clock
if (~start) begin
start <= 1;
tickCounter <= 0;
gotFpgaAddress <= 0;
gotCommand <= 0;
end
else begin // we have received the start condition, so continue into the logic
// increment the counter
// this counter controls when a reset of the logic is performed
// the entire protocol should take place in 4 cycles, so when our counter hits 3 we are done
tickCounter <= tickCounter + 1;
if (tickCounter == 3) begin
start <= 0;
end
else begin // no reset, continue into logic
// here, we will read the address of the fpga the pi is talking to
// first check if we have recieved the address or not
if (~gotFpgaAddress) begin
fpgaAddress <= bus[3:2]; //[3:0];
tileAddress <= bus[1:0];
gotFpgaAddress <= 1;
//gotTileAddress <= 1;
end
else begin // we got the address, now compare it to see if it matches our address
if (fpgaAddress == my_address) begin
// the message is intended for us, so next we check if the command has been received
if (~gotCommand) begin
//tileAddress <= bus[3:0];
command <= bus;
gotCommand <= 1;
end
else begin // we have received the command, now decode it and perform the action
// decode the command that has been sent
// leading 11xx : toggle an led specified by the 2 least significant bits
// leading 00xx : read from the capactive sensor and write it onto the bus
// leading 01xx : toggle the solenoid for the popup
// implement logic to toggle leds
if (command[3:2] == 2'b11) begin
// route to appropriate tile
case (tileAddress)
// tile 0
2'b00: begin
case (command[1:0])
2'b00: t0[0] <= ~t0[0];
2'b01: t0[1] <= ~t0[1];
2'b10: t0[2] <= ~t0[2];
2'b11: t0[3] <= ~t0[3];
endcase
end
// tile 1
2'b01: begin
case (command[1:0])
2'b00: t1[0] <= ~t1[0];
2'b01: t1[1] <= ~t1[1];
2'b10: t1[2] <= ~t1[2];
2'b11: t1[3] <= ~t1[3];
endcase
end
// tile 2
2'b10: begin
case (command[1:0])
2'b00: t2[0] <= ~t2[0];
2'b01: t2[1] <= ~t2[1];
2'b10: t2[2] <= ~t2[2];
2'b11: t2[3] <= ~t2[3];
endcase
end
// tile 3
2'b11: begin
case (command[1:0])
2'b00: t3[0] <= ~t3[0];
2'b01: t3[1] <= ~t3[1];
2'b10: t3[2] <= ~t3[2];
2'b11: t3[3] <= ~t3[3];
endcase
end
endcase
end
// implement logic to read from the capacitive sensor and write it onto the bus
else if (command[3:2] == 2'b00) begin
case (tileAddress)
2'b00: capOut <= t0cap;
2'b01: capOut <= t1cap;
2'b10: capOut <= t2cap;
2'b11: capOut <= t3cap;
endcase
end
// implement logic to toggle the solenoid
else if (command[3:2] == 2'b01) begin
case (tileAddress)
2'b00: t0[4] <= ~t0[4];
2'b01: t1[4] <= ~t1[4];
2'b10: t2[4] <= ~t2[4];
2'b11: t3[4] <= ~t3[4];
endcase
end
end
end
end
end
end
end
endmodule
BONUS
は現在、私は、42個のロジック・エレメントを消費しています、私は永遠に感謝します!ではない大したことは、80の要素マックスVは、問題を発見MaxV40
fpgaのコンパイル中に警告が表示されましたか?私には疑わしい場所はほとんどありません。 1)正しいリセットがない。初期ブロックがFPGAで動作していない可能性があります。 2)ポートを 'reg'として宣言してください。必ずしも正しく動作する概念ではありません。より高いレベルの階層では接続の問題があり、シミュレーション/ FPGAの動作の違いがあるかもしれません。 – Serge
これは、2分間のコーヒーブレークで読み込むコードがたくさんあります。 1つの明白なことは 'コマンド'です - あなたはそれをいつ割り当てるのですか、それをいつ読むのですか? 2つの異なるクロックサイクルに入っていますか?それがうまくいくと思いますか?もしそうなら、なぜですか?タイミングダイアグラムを描き、ダイアグラムからコードを作成します。あなたのコントロールの流れは間違っています。また、非ブロッキング代入( '<=')が何をするのかを理解してください。 – EML
@ Serge私は警告を受け取りますが、なぜこれが正しく機能していないのかの手掛かりはありません。ちょうどタイミングファイルが欠けているなどです。 – user1152415