Day 4 - 7-seg BCD Counter

2025. 3. 7. 15:54·IDEC 교육/Verilog HDL
// BCD Counter with modulo K

module alu_ex3 #(
    parameter N = 32,
    parameter K = 10,
    parameter M = 3
)(
    input   wire clk,
    input   wire rstn,
    output  wire [6:0]   bcd0,
    output  wire [6:0]   bcd1,
    output  wire [6:0]   bcd2
);

wire        roll0, roll1, roll2;
wire [ 3:0] led[0:2];

modulo_cnt #(.K(50000000))  u_cnt_base (.clk(clk), .rstn(rstn), .ena(1'b1 ), .led(      ), .roll(roll0));
modulo_cnt #(.K(10))        u_cnt_0    (.clk(clk), .rstn(rstn), .ena(roll0), .led(led[0]), .roll(roll1));
modulo_cnt #(.K(10))        u_cnt_1    (.clk(clk), .rstn(rstn), .ena(roll1), .led(led[1]), .roll(roll2));
modulo_cnt #(.K(10))        u_cnt_2    (.clk(clk), .rstn(rstn), .ena(roll2), .led(led[2]), .roll(     ));

SEG7_LUT u_seg7_0 (.iDIG(led[0]), .oSEG(bcd0));
SEG7_LUT u_seg7_1 (.iDIG(led[1]), .oSEG(bcd1));
SEG7_LUT u_seg7_2 (.iDIG(led[2]), .oSEG(bcd2));

endmodule

module modulo_cnt #(
    parameter K = 10,
    parameter N = 32
)(
    input wire clk,
    input wire rstn,
    input wire ena,
    output wire [4:0] led,
    output wire       roll
);

reg [N-1:0] cnt;

always @ (posedge clk or negedge rstn) begin
    if (~rstn)      cnt <= {N{1'b0}};
    else if (roll)  cnt <= {N{1'b0}};
    else if (ena)   cnt <= cnt + 1'b1;
end

assign roll = (cnt == K - 1) ? 1 : 0;

assign led = cnt[3:0];

endmodule

module SEG7_LUT (oSEG, iDIG);
input   [3:0]   iDIG;
output  [6:0]   oSEG;
reg     [6:0]   oSEG;

always @(iDIG)
begin
    case(iDIG)
        4'h1: oSEG = 7'b1111001;    // ---t---
        4'h2: oSEG = 7'b0100100;    // |     |
        4'h3: oSEG = 7'b0110000;    // lt   rt
        4'h4: oSEG = 7'b0011001;    // |     |
        4'h5: oSEG = 7'b0010010;    // ---m---
        4'h6: oSEG = 7'b0000010;    // |     |
        4'h7: oSEG = 7'b1111000;    // lb   rb
        4'h8: oSEG = 7'b0000000;    // |     |
        4'h9: oSEG = 7'b0011000;    // ---b---
        4'ha: oSEG = 7'b0001000;
        4'hb: oSEG = 7'b0000011;
        4'hc: oSEG = 7'b1000110;
        4'hd: oSEG = 7'b0100001;
        4'he: oSEG = 7'b0000110;
        4'hf: oSEG = 7'b0001110;
        4'h0: oSEG = 7'b1000000;
    endcase
end

endmodule

설명 적을 시간은 없었다

저작자표시 비영리 변경금지 (새창열림)
'IDEC 교육/Verilog HDL' 카테고리의 다른 글
  • Day 4 - 7-Segment Decoder
  • Day 4 - FPGA Example (with DE2-115)
  • Day 2 - Case / Casez / Casex
  • Day 2 - Latch
Zi_Yoon
Zi_Yoon
머리 속에 정리하는 곳 <전자공학>
  • Zi_Yoon
    ZY_repo
    Zi_Yoon
  • 전체
    오늘
    어제
    • 분류 전체보기 (70)
      • HDLBits (25)
        • Verilog (19)
        • Circuits (4)
        • Verification (0)
      • IDEC 교육 (1)
        • Embedded C (13)
        • Verilog HDL (8)
      • Hardware (8)
        • RISC-V Project (1)
        • Computer Architecture (0)
        • AMBA (2)
        • FPGA (0)
        • 논문 읽기 (1)
        • ETC. (4)
      • 42서울 (13)
        • 리눅스 (12)
        • 네트워크 (1)
      • 생각 (1)
      • 취업 (1)
  • 블로그 메뉴

    • 홈
    • 태그
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    research rabbit
    pointer
    QUARTUS
    embedded
    verilog
    verilator
    bit-wise and
    보안 쉘
    fpga
    hdlbits
    세션 키
    AppArmor
    RISC-V
    c
    ARM
    AXI4
    centos
    vm
    APT
    charater
    ssh
    비대칭 키
    lsblk
    debian
    axi
    fucntion
    Keil
    IDEC
    signal trap
    AMBA
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.1
Zi_Yoon
Day 4 - 7-seg BCD Counter
상단으로

티스토리툴바