State Machine Logic
Coddy'nin Verilog Journey'sinin Temeller bölümünün bir parçası. Ders 80 / 90.
Görev
Bu derste, trafik ışığı denetleyicisine state geçiş mantığını ekleyeceksin. state machine, bir state'ten bir sonrakine ne zaman geçileceğini belirler.
state machine mantığı, trafik ışığının state'leri ne zaman ve nasıl değiştireceğini kontrol eder.
state Sırası
Green → Yellow → Red → Green → …
Görevin, state machine mantığını module'e eklemektir.
Yapılacaklar:
- Bir
always @(posedge clk or posedge reset)bloğu Add et - reset durumunda
state'i Red (2) olarak ayarla next1 olduğunda bir sonraki state'e geç:- state Green (0) ise: Yellow olarak change et
- state Yellow (1) ise: Red olarak change et
- state Red (2) ise: Green olarak change et
Kendin dene
module traffic_light (
input clk,
input reset,
input next, // Durumu değiştirmek için tetikleyici
output reg red,
output reg yellow,
output reg green
);
reg [1:0] state;
// Çıkış atamaları
always @(*) begin
case (state)
0: begin green = 1; yellow = 0; red = 0; end
1: begin green = 0; yellow = 1; red = 0; end
2: begin green = 0; yellow = 0; red = 1; end
default: begin green = 0; yellow = 0; red = 1; end
endcase
end
// TODO: Durum makinesi mantığını ekle (zamanlama olmadan)
// always @(posedge clk or posedge reset) begin
// if (reset) begin
// state <= 2;
// end else if (next) begin
// case (state)
// 0: state <= 1;
// 1: state <= 2;
// 2: state <= 0;
// endcase
// end
// end
endmoduleTemeller bölümündeki tüm dersler
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 LogicKendi başına pratik yap: Online Verilog derleyicisi