State Machine
Coddy Verilog 여정의 기초 섹션에 포함된 레슨. 90개 중 88번째.
챌린지
상태 머신은 여러 상태 중 하나에 있을 수 있는 회로입니다. UART에서는 각 bit에 대해 서로 다른 상태를 사용합니다: idle, start, data bits 0-7, 그리고 stop입니다. bit 카운터(cnt)는 현재 어떤 state에 있는지 알려 줍니다. cnt를 기반으로 tx line에 보낼 값을 결정합니다.
이전 lesson에서 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기초의 모든 레슨
4Operators Part 1
Arithmetic OperatorsModulo OperatorComparison OperatorsRecap - Simple MathBitwise Operators7Assign And Gates
Continuous AssignmentAssign With OperatorsBuilt In Gate PrimitivesAND OR NOT GatesXOR XNOR GatesRecap - Logic Gate Circuit10Decision Making
If StatementIf - ElseRecap - Simple ComparatorCase StatementCasex And CasezRecap - ALU Design5Operators Part 2
Logical OperatorsReduction OperatorsShift OperatorsConcatenation OperatorConditional OperatorRecap - Operator Challenge3Number System
Binary RepresentationSized NumbersUnsized NumbersNegative NumbersSpecial Values X And ZRecap - Number Formats6Modules
Module StructureInput And Output PortsInout PortsModule InstantiationPort Mapping By NamePort Mapping By OrderRecap - Build A Module9Procedural Blocks
Always BlockInitial BlockSensitivity ListBlocking AssignmentNon Blocking AssignmentRecap - Always vs Initial15Traffic Light Controller
Defining The StatesState Machine Logic직접 연습해 보세요: 온라인 Verilog 컴파일러