Clock Generation
Coddy Verilog 여정의 기초 섹션에 포함된 레슨. 90개 중 71번째.
클록은 일정한 간격으로 0과 1 사이를 계속 전환하는 신호입니다. 클록은 플립플롭 및 카운터와 같은 순차 논리에 필수적입니다.
클록을 생성하는 이유
테스트벤치에서는 순차 회로를 테스트하기 위해 클록이 필요합니다. 클록은 플립플롭, 레지스터 및 상태 머신의 동작을 구동합니다.
클록을 생성하는 방법
| 방법 | 설명 |
|---|---|
always와 # 지연 | 가장 일반적인 방법 |
forever 루프 | 대안 방법 |
repeat 루프 | 고정된 cycles 수에 사용 |
방법 1: 지연이 있는 always 블록
reg clk;
initial begin
clk = 0;
end
always #5 clk = ~clk;clk = 0시간 0에서every5timeunits마다clk가 toggle됩니다
- Period = 10 time units
- Frequency = 1/10 = 0.1 per time unit
방법 2: 무한 루프
reg clk;
initial begin
clk = 0;
forever begin
#5 clk = ~clk;
end
endalways 방법과 동일한 결과입니다.
방법 3: 고정된 cycles 동안 반복
reg clk;
initial begin
clk = 0;
repeat (10) begin
#5 clk = ~clk;
end
end정확히 10개의 클록 edges(완전한 5 cycles)를 생성한 후 중지합니다.
챌린지
Add 누락된 코드를 추가하여 4 time units마다 toggle되는 Clock을 생성하세요(period = 8 time units).
수행할 작업:
initialblock을 사용하여 time 0에서clk를 0으로 초기화하세요.- 지연 시간이 있는
alwaysblock을 사용하여 4 time units마다clk를 toggle하세요.
직접 해보기
module clock_challenge;
reg clk;
// TODO: Step 1 - clk = 0으로 설정하는 initial 블록 추가
// TODO: Step 2 - 4 시간 단위마다 clk을 토글하는 always 블록 추가
initial begin
$monitor("Time %0t: clk = %b", $time, clk);
#20;
$display("Clock generated for 20 time units");
$finish;
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 Design13Timing And Delays
What Are DelaysGate DelaysAssignment DelaysTimescale DirectiveClock GenerationRecap - Timing Control5Operators 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 컴파일러