Timing The Transitions
Coddy'nin Verilog Journey'sinin Temeller bölümünün bir parçası. Ders 81 / 90.
Görev
Bu derste, her ışığın ne kadar süre açık kalacağını kontrol eden counter mantığını ekleyeceksin. counter, önceden ayarlanmış bir değerden sıfıra doğru geri sayar ve ardından bir sonraki State değişikliğini tetikler.
Timing Gereksinimleri
| State | Süre | Counter Değeri |
|---|---|---|
| Green | 30 seconds | 30 |
| Yellow | 10 seconds | 10 |
| Red | 40 seconds | 40 |
Counter Nasıl Çalışır
- Bir State başladığında counter, süre değeriyle yüklenir
- Her clock vuruşunda counter 1 azalır
- counter 0'a ulaştığında bir sonraki State'e geçme zamanı gelmiştir
Görevin, State makinesine eksik counter mantığını eklemektir.
Yapılacaklar:
reg [5:0] counterbildirimini ekle- reset sırasında
counterdeğerini 0 olarak ayarla counter == 0olduğunda:- Bir sonraki State'in süresini counter içine yükle
- Bir sonraki State'e geç
- Aksi durumda, her clock'ta counter değerini 1 azalt
Kendin dene
module traffic_light (
input clk,
input reset,
output reg red,
output reg yellow,
output reg green
);
reg [1:0] state;
// TODO: Sayaç kaydını bildir (6 bit)
// Çı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
// Zamanlamalı durum makinesi
always @(posedge clk or posedge reset) begin
if (reset) begin
state <= 2; // Kırmızıda başla
// TODO: Sayaçı 0'a ayarla
end else begin
if (counter == 0) begin
case (state)
0: begin
state <= 1;
// TODO: Sarı için sayacı yükle (10 saniye)
end
1: begin
state <= 2;
// TODO: Kırmızı için sayacı yükle (40 saniye)
end
2: begin
state <= 0;
// TODO: Yeşil için sayacı yükle (30 saniye)
end
endcase
end else begin
// TODO: Sayaçı 1 azalt
end
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