산업 제조
산업용 사물 인터넷 | 산업자재 | 장비 유지 보수 및 수리 | 산업 프로그래밍 |
home  MfgRobots >> 산업 제조 >  >> Industrial programming >> verilog

Verilog Mod-N 카운터 설계: 파라미터화 모듈 및 테스트벤치

설계

module modN_ctr #(
  parameter N = 10,
  parameter WIDTH = 4
) (
  input clk,
  input rstn,
  output reg[WIDTH-1:0] out
);
  always @ (posedge clk) begin
    if (!rstn) begin
      out <= 0;
    end else begin
      if (out == N-1) out <= 0;
      else out <= out + 1;
    end
  end
endmodule

테스트벤치

module tb;
  parameter N = 10;
  parameter WIDTH = 4;
  reg clk;
  reg rstn;
  wire [WIDTH-1:0] out;
  
  modN_ctr u0 (
    .clk(clk),
    .rstn(rstn),
    .out(out)
  );
  
  always #10 clk = ~clk;
  
  initial begin
    {clk, rstn} <= 0;
    $monitor ("T=%0t rstn=%0b out=0x%0h", $time, rstn, out);
    repeat(2) @ (posedge clk);
    rstn <= 1;
    repeat(20) @ (posedge clk);
    $finish;
  end
endmodule

시뮬레이션 로그

ncsim> run
T=0 rstn=0 out=0xx
T=10 rstn=0 out=0x0
T=30 rstn=1 out=0x0
T=50 rstn=1 out=0x1
T=70 rstn=1 out=0x2
T=90 rstn=1 out=0x3
T=110 rstn=1 out=0x4
T=130 rstn=1 out=0x5
T=150 rstn=1 out=0x6
T=170 rstn=1 out=0x7
T=190 rstn=1 out=0x8
T=210 rstn=1 out=0x9
T=230 rstn=1 out=0xa
T=250 rstn=1 out=0x0
T=270 rstn=1 out=0x1
T=290 rstn=1 out=0x2
T=310 rstn=1 out=0x3
T=330 rstn=1 out=0x4
T=350 rstn=1 out=0x5
T=370 rstn=1 out=0x6
T=390 rstn=1 out=0x7
T=410 rstn=1 out=0x8
Simulation complete via $finish(1) at time 430 NS + 0

verilog

  1. 버릴로그(Verilog) 입문: 디지털 회로 설계를 위한 하드웨어 기술 언어
  2. Verilog 결합(Concatenation) & 복제(Replication) 연산자 실전 가이드
  3. Verilog 할당문 이해: 유형, 문법, 모범 사례
  4. Verilog 차단 vs 비차단 할당: 핵심 차이점 완벽 이해
  5. Verilog 함수 마스터하기: 효율적인 RTL 설계를 위한 활용법
  6. Verilog 태스크 이해: 함수와의 차이점, 문법, 활용법
  7. Verilog 클럭 생성기: 설계 및 구현 가이드
  8. Verilog 수학 함수 마스터하기: 효율적인 하드웨어 설계를 위한 활용
  9. Verilog $timeformat 마스터하기: 정밀도 및 표시 제어
  10. Verilog T 플립플롭 설계: RTL 구현 및 테스트벤치