001 `timescale 1ns / 1ps
002 //////////////////////////////////////////////////////////////////////////////////
003 // Create Date: 17:31:54 10/22/2015
004 // Module Name: counter24
005 //////////////////////////////////////////////////////////////////////////////////
006 module counter24(
007 input wire clk0,
008 output wire [7:0] seg7,
009 output wire [3:0] line,
010 output wire [6:0] led
011 );
012 assign line = 4'b0001<<ab;
013 assign led = { 2'b00, count3, count10 };
014 assign seg7 = { 1'b0, disp };
015
016 parameter [6:0] seg7_data[0:9]={
017 7'h3f, 7'h06, 7'h5b, 7'h4f, 7'h66, // 0 1 2 3 4
018 7'h6d, 7'h7d, 7'h27, 7'h7f, 7'h6f // 5 6 7 8 9
019 };
020
021 // ダイナミック表示
022 reg[6:0] disp=7'b0;
023 reg[3:0] x;
024 reg ab=0;
025 always @( posedge clk0 )begin
026 if(c[19:0]==0)begin
027 x <= ab?count3:count10;
028 if(x<=4'd9)
029 disp <= seg7_data[x];
030 else
031 disp <= 7'b0000000;
032 ab <= ab + 1'b1;
033 end
034 end
035
036 // 1秒生成
037 reg[26:0] c=27'b0;
038 reg sec_enable=1'b0;
039 always @( posedge clk0 )begin
040 if( c==27'd99999999 )begin // 100,000,000-1
041 c <= 0;
042 sec_enable <= 1'b1;
043 end
044 else begin
045 c <= c + 1'b1;
046 sec_enable <= 1'b0;
047 end
048 end
049
050 // 10進カウンタ
051 reg[3:0] count10=4'b0;
052 reg sec10_enable = 1'b0;
053 always @( posedge clk0 )begin
054 if( sec_enable )begin
055 if( count10==4'd9 )begin
056 count10<=1'b0;
057 sec10_enable <= 1'b1;
058 end
059 else if( count10==4'd3 && count3==2'd2 )begin // <--追加
060 count10<=1'b0; // <--追加
061 sec10_enable <= 1'b1; // <--追加
062 end // <--追加
063 else begin
064 count10 <= count10 + 1'b1;
065 sec10_enable <= 1'b0;
066 end
067 end
068 else begin
069 sec10_enable <= 1'b0;
070 end
071 end
072
073 // 3進カウンタ
074 reg[1:0] count3=2'b0;
075 always @( posedge clk0 )begin
076 if( sec10_enable )
077 count3 <= (count3==2'd2)?1'b0:(count3+1'b1);
078 end
079
080 endmodule
081
ssatoh@
足立工科大学 工学部 情報通信工学科