ステートマシン
CoddyのVerilogジャーニー「基礎」セクションの一部。レッスン 88/90。
チャレンジ
ステートマシンは、複数の state のいずれかになれる回路です。UART では、各 bit に対して異なる state があります:idle、start、data bits 0-7、stop です。bit カウンター(cnt)によって、現在どの state にいるかがわかります。cnt に基づいて、tx line に送信する値を決定します。
前のレッスンで使用した bit カウンターがあります。これを UART transmitter として動作するように変更する必要があります。
送信する Bit の値(文字 'A' の場合)
| cnt | tx の値 |
|---|---|
| 0 | 1 |
| 1 | 0 |
| 2 | 1 |
| 3 | 0 |
| 4 | 0 |
| 5 | 0 |
| 6 | 0 |
| 7 | 0 |
| 8 | 1 |
| 9 | 0 |
| 10 | 1 |
実行すること
startという input を追加するtxという output reg を追加するinitialblock で、tx = 1(idle HIGH)を設定する- カウンターの logic を変更する:
cnt == 0かつstart == 1の場合、cnt <= 1を設定する(transmitting を開始)cntが 1 から 9 の間の場合、インクリメントする:cnt <= cnt + 1cnt == 10の場合、0に reset する
自分で試してみよう
module uart_tx (
input clk,
output reg [3:0] cnt
);
initial begin
cnt = 0;
end
always @(posedge clk) begin
cnt <= cnt + 1;
end
endmodule基礎のすべてのレッスン
自分で練習してみよう: Verilogオンラインコンパイラ