Defining The States
Coddy Verilog 여정의 기초 섹션에 포함된 레슨. 90개 중 79번째.
챌린지
교통 신호 제어기는 특정한 시간 간격에 따라 서로 다른 신호 상태(빨간색, 노란색, 초록색)를 순환하는 유한 상태 머신입니다. 유한 상태 머신(FSM)은 제한된 수의 state 중 하나에 있을 수 있는 회로입니다. 입력 또는 타이밍에 따라 한 state에서 다른 state로 변경됩니다.
이 프로젝트에서는 간단한 교차로를 위한 교통 신호 제어기를 만듭니다. 교통 신호에는 세 개의 output이 있습니다:
| 신호 | Output | 의미 |
|---|---|---|
| 빨간색 | red = 1 | 정지 |
| 노란색 | yellow = 1 | 주의 |
| 초록색 | green = 1 | 진행 |
신호는 다음 순서로 순환합니다:
Green → Yellow → Red → Green → …
타이밍 순서
| State | 지속 시간 | 다음 State |
|---|---|---|
| Green | 30초 | Yellow |
| Yellow | 10초 | Red |
| Red | 40초 | Green |
이 레슨에서는 교통 신호 제어기의 state를 정의합니다.
교통 신호에는 세 가지 가능한 state가 있습니다:
| State | 신호 | 코드 |
|---|---|---|
| Green | 초록색 신호 켜짐 | 2'b00 |
| Yellow | 노란색 신호 켜짐 | 2'b01 |
| Red | 빨간색 신호 켜짐 | 2'b10 |
누락된 부분을 추가하여 module을 완성하세요.
할 일:
state 인코딩 정의: 0=Green, 1=Yellow, 2=Red
- 2비트 register를
state라는 이름으로 Declare하세요. - 6비트 register를
counter라는 이름으로 Declare하세요(최대 40초까지 타이밍을 측정하기 위함). - 조합형 always block 안에 output assignments를 추가하세요.
always @(*) begin ... end을 사용하고, 그 안에case (state)를 포함하세요.red,yellow,green은output reg으로 Declare되어 있으며,reg는 이러한 block 내부에서만 할당할 수 있습니다.@(*)는 이 block이 읽는 값이 변경될 때마다 block이 다시 실행된다는 의미이며, 여기서는state가 해당합니다:- state가 0일 때:
green = 1,yellow = 0,red = 0 - state가 1일 때:
green = 0,yellow = 1,red = 0 - state가 2일 때:
green = 0,yellow = 0,red = 1
- state가 0일 때:
직접 해보기
module traffic_light (
input clk,
input reset,
output reg red,
output reg yellow,
output reg green
);
// TODO: Task 1 - 상태 레지스터 선언 (2비트)
// TODO: Task 2 - 카운터 레지스터 선언 (6비트)
// TODO: Task 3 - case (state)를 사용한 출력 할당
// 상태 0: green=1, yellow=0, red=0
// 상태 1: green=0, yellow=1, red=0
// 상태 2: green=0, yellow=0, red=1
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 컴파일러