HDLbits---Circuits---Sequential Logic---Counters

这篇具有很好参考价值的文章主要介绍了HDLbits---Circuits---Sequential Logic---Counters。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1.count15

module top_module (
    input clk,
    input reset,      // Synchronous active-high reset
    output [3:0] q);
    always@(posedge clk) begin
        if(reset)
            q<=0; 
        else 
            if(q==4'b1111)
                q<=0;
        else 
            q<=q+1;
    end
endmodule

2.Count10

module top_module (
    input clk,
    input reset,        // Synchronous active-high reset
    output [3:0] q);
    always@(posedge clk) begin
        if(reset)
            q<=0; 
        else if(q=='d9) begin
            q<=0; end
        else  begin
            q<=q+1; end
    end
endmodule

3.Count1to10

module top_module (
    input clk,
    input reset,
    output [3:0] q);
    always@(posedge clk) begin
        if(reset)
            q<='d1;
        else if(q=='d10)
            q<='d1;
        else 
            q<=q+1;
    end
endmodule

4.countslow

module top_module (
    input clk,
    input slowena,
    input reset,
    output [3:0] q);
    always@(posedge clk) begin
        if(reset)
            q<=0;
        else  begin
            if(slowena) begin
                if(q=='d9)
                    q<=0;
                else 
                    q<=q+1;
            end
        else
            q<=q;
        end
    end
    
endmodule

5.exams/ece241_2014_q7a

module top_module (
    input clk,
    input reset,
    input enable,
    output [3:0] Q,
    output c_enable,
    output c_load,
    output [3:0] c_d
); 
//其实我觉得我这里的上面提示是有一点问题的这里的c_其实是用在我整个模块化里面的
   assign c_d=c_load?4'd1:4'd0;
    assign c_load=reset|((Q=='d12)&&(c_enable=='d1));
    assign c_enable=enable;
    count4 U1(clk,c_enable,c_load,c_d,Q);  
endmodule

6.exams/ece241_2014_q7b

module top_module (
    input clk,
    input reset,
    output OneHertz,
    output [2:0] c_enable
); //
    wire [3:0] a,b,c;
    assign c_enable[0]=1;
    assign c_enable[1]=(a=='d9)?1:0;
    assign c_enable[2]=(a=='d9&&b=='d9)?1:0;
    assign OneHertz={a=='d9&&b=='d9&&c=='d9};
    bcdcount U1(clk,reset,c_enable[0],a);
    bcdcount U2(clk,reset,c_enable[1],b);
    bcdcount U3(clk,reset,c_enable[2],c);
endmodule

7.countbcd

module top_module (
    input clk,
    input reset,   // Synchronous active-high reset
    output [3:1] ena,
    output [15:0] q);
    wire[3:0] q0,q1,q2,q3;
    assign q[3:0]=q0;
    assign q[7:4]=q1;
    assign q[11:8]=q2;
    assign q[15:12]=q3;
    assign ena[1]={q0=='d9};
    assign ena[2]={q0=='d9&&q1=='d9};
    assign ena[3]={q0=='d9&&q1=='d9&&q2=='d9};
    always@(posedge clk) begin
        if(reset)
            q0<=0;
        else if(q0=='d9)
            q0<=0;
        else
            q0<=q0+1;
    end
    always@(posedge clk) begin
        if(reset)
            q1<=0;
        else if(q1=='d9&&q0=='d9)
            q1<=0;
        else if(ena[1]) 
            q1<=q1+1;
        else
            q1<=q1;
    end
     always@(posedge clk) begin
        if(reset)
            q2<=0;
         else if(q2=='d9&&q1=='d9&&q0=='d9)
            q2<=0;
         else if(ena[2]) 
            q2<=q2+1;
        else
            q2<=q2;
    end
     always@(posedge clk) begin
        if(reset)
            q3<=0;
         else if(q3=='d9&&q2=='d9&&q1=='d9&&q0=='d9)
            q3<=0;
         else if(ena[3]) 
            q3<=q3+1;
        else
            q3<=q3;
    end

       
endmodule

8.count_clock

module top_module(
    input clk,
    input reset,
    input ena,
    output reg pm,
    output [7:0] hh,
    output [7:0] mm,
    output [7:0] ss); 

wire ss_en,ss_60_en;       
reg [3:0] ss_one,ss_ten;   

wire mm_en,mm_60_en;
reg [3:0] mm_one,mm_ten; 

wire hh_en,pm_en;            
reg [3:0] hh_one,hh_ten; 

assign ss = {ss_ten,ss_one};
assign mm = {mm_ten,mm_one};
assign hh = {hh_ten,hh_one};
always @(posedge clk) begin
    if (reset) begin
        ss_one <= 4'b0;
    end
    else if(ena) begin
        if (ss_one == 4'd9) begin
            ss_one <= 4'b0;
        end
        else
            ss_one <= ss_one + 1'b1;
    end
end
assign ss_en = ((ss_one == 4'd9) && ena) ? 1'b1 : 1'b0;

always @(posedge clk) begin
    if (reset) begin
        ss_ten <= 4'b0;
    end
    else if(ss_en) begin
        if ((ss_one == 4'd9) && (ss_ten == 4'd5) && ena) begin
            ss_ten <= 4'b0;
        end
        else
            ss_ten <= ss_ten + 1'b1;
    end
end
assign ss_60_en = ((ss_one == 4'd9) && (ss_ten == 4'd5) && ena) ? 1'b1 : 1'b0;


always @(posedge clk) begin
    if (reset) begin
        mm_one <= 4'b0;
    end
    else if(ss_60_en) begin
        if (mm_one == 4'd9) begin
            mm_one <= 4'b0;
        end
        else
            mm_one <= mm_one + 1'b1;
    end
end
assign mm_en = ((mm_one == 4'd9) && (ss_one == 4'd9) && (ss_ten == 4'd5) && ena) ? 1'b1 : 1'b0;

always @(posedge clk) begin
    if (reset) begin
        mm_ten <= 4'b0;
    end
    else if(mm_en) begin
        if ((mm_one == 4'd9) && (mm_ten == 4'd5) && ena && (ss_one == 4'd9) && (ss_ten == 4'd5)) begin
            mm_ten <= 4'b0;
        end
        else
            mm_ten <= mm_ten + 1'b1;
    end
end
assign mm_60_en = ((mm_one == 4'd9) && (mm_ten == 4'd5) && ena && (ss_one == 4'd9) && (ss_ten == 4'd5)) ? 1'b1 : 1'b0;




always @(posedge clk) begin
    if (reset) begin
        hh_one <= 4'd2;
    end
    else if(mm_60_en) begin
        if ((hh_one == 4'd2) && (hh_ten == 4'd1) && (mm_one == 4'd9) && (mm_ten == 4'd5) && ena && (ss_one == 4'd9) && (ss_ten == 4'd5)) begin
            hh_one <= 4'd1;
        end
        else if ((hh_one == 4'd9) && (hh_ten == 4'd0) && (mm_one == 4'd9) && (mm_ten == 4'd5) && ena && (ss_one == 4'd9) && (ss_ten == 4'd5)) begin
            hh_one <= 4'd0;
        end
        else
            hh_one <= hh_one + 1'b1;
    end
end
assign hh_en = ((hh_one == 4'd9) && (hh_ten == 4'd0) && (mm_one == 4'd9) && (mm_ten == 4'd5) && ena && (ss_one == 4'd9) && (ss_ten == 4'd5)) ? 1'b1 : 1'b0;

always @(posedge clk) begin
    if (reset) begin
        hh_ten <= 4'b1;
    end
    else if ((hh_one == 4'd2) && (hh_ten == 4'd1) && (mm_one == 4'd9) && (mm_ten == 4'd5) && ena && (ss_one == 4'd9) && (ss_ten == 4'd5)) begin
        hh_ten <= 4'd0;
    end   
    else if(hh_en) begin
        hh_ten <= 4'd1;
    end
end

assign pm_en = ((hh_one == 4'd1) && (hh_ten == 4'd1) && (mm_one == 4'd9) && (mm_ten == 4'd5)&& (ss_one == 4'd9) && (ss_ten == 4'd5) && ena) ? 1'b1 : 1'b0;
always @(posedge clk) begin
    if (reset) begin
        pm <= 1'b0;
    end
    else    if (pm_en) begin
        pm <= ~pm;
    end
        
end
endmodule

文章来源地址https://www.toymoban.com/news/detail-548353.html

到了这里,关于HDLbits---Circuits---Sequential Logic---Counters的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【HDLBits 刷题 5】Circuits(1)Combinational Logic

    目录 写在前面 Combinational Logic Basic Gates Wire GND NOR Another gate Two gates More logic gates 7420 chips Truth table Two bit equality Simple circuit A Simple circuit B Combine circuits A and B Ring or vibrate Thermostat 3 bit population count Gates and vectors Even longer vectors Multiplexers 2 to 1 mux 2 to 1 bus mux 9 to 1 mux 256 to 1 mux 256 t

    2024年02月02日
    浏览(40)
  • HDLBits刷题笔记7:Circuits.Combinational Logic.Karnaugh Map to Circuit

    3-variable 实现如下卡诺图,用sop和pos两种方式 化简: 4-variable 实现如下卡诺图,用sop和pos两种方式 化简: 4-variable 实现如下卡诺图 化简: 4-variable 实现如下卡诺图 此卡诺图不管是sop还是pos都没法化简,但不难看出,输入有奇数个1时,输出为1,所以是异或 minimum SOP and POS 一

    2024年02月11日
    浏览(37)
  • 「HDLBits题解」Counters

    本专栏的目的是分享可以通过HDLBits仿真的Verilog代码 以提供参考 各位可同时参考我的代码和官方题解代码 或许会有所收益 题目链接:Count15 - HDLBits 题目链接:Count10 - HDLBits 题目链接:Count1to10 - HDLBits 题目链接:Countslow - HDLBits 题目链接:Exams/ece241 2014 q7a - HDLBits 题目链接:

    2024年01月23日
    浏览(46)
  • HDLbits counters 12 hour clock

    目前在HDLbits网站上比较难的一道题,记录和分享一下

    2024年02月21日
    浏览(41)
  • Circuits--Sequential--Registers_1

    1.4-bit shift register 2.Left/right rotator 3.Left / right arithmetic  4.5-bit LFSR

    2024年04月17日
    浏览(30)
  • [HDLBits] Alwaysblock2

    Build an XOR gate three ways, using an assign statement, a combinational always block, and a clocked always block. Note that the clocked always block produces a different circuit from the other two: There is a flip-flop so the output is delayed.  

    2024年02月13日
    浏览(33)
  • [HDLBits] Lemmings4

    See also: Lemmings1, Lemmings2, and Lemmings3. Although Lemmings can walk, fall, and dig, Lemmings aren\\\'t invulnerable. If a Lemming falls for too long then hits the ground, it can splatter. In particular, if a Lemming falls for more than 20 clock cycles then hits the ground, it will splatter and cease walking, falling, or digging (all 4 outputs become 0)

    2024年02月07日
    浏览(28)
  • [HDLBits] Dualedge

    You\\\'re familiar with flip-flops that are triggered on the positive edge of the clock, or negative edge of the clock. A dual-edge triggered flip-flop is triggered on both edges of the clock. However, FPGAs don\\\'t have dual-edge triggered flip-flops, and always @(posedge clk or negedge clk) is not accepted as a legal sensitivity list. Build a circuit that fun

    2024年02月09日
    浏览(26)
  • [HDLBits] Dff16e

    Create 16 D flip-flops. It\\\'s sometimes useful to only modify parts of a group of flip-flops. The byte-enable inputs control whether each byte of the 16 registers should be written to on that cycle. byteena[1] controls the upper byte d[15:8], while byteena[0] controls the lower byte d[7:0]. resetn is a synchronous, active-low reset. All DFFs should be

    2024年02月12日
    浏览(32)
  • [HDLBits] Edgecapture

    For each bit in a 32-bit vector, capture when the input signal changes from 1 in one clock cycle to 0 the next. \\\"Capture\\\" means that the output will remain 1 until the register is reset (synchronous reset). Each output bit behaves like a SR flip-flop: The output bit should be set (to 1) the cycle after a 1 to 0 transition occurs. The output bit should be res

    2024年02月09日
    浏览(22)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包