zoukankan      html  css  js  c++  java
  • 计数器设计模板

    所需计数的个数:num

    计数器位宽:width

    开始计数:wire start_cnt;

    停止计数:wire end_cnt;

    计数器:reg  [width-1:0]   cnt;

    always @(posedge sclk or negedge rst_n)
    begin
      if(rst_n == 1'b0)begin
        cnt <= 'd0;
      end
      else if(start_cnt)begin
        if(end_cnt)begin
          cnt <= 'd0;
        end
        else begin
          cnt <= cnt + 1'b1;
        end
      end
    end

    assign start_cnt = 1;
    assign end_cnt = start_cnt && cnt==num-1;

    /////////////////////////////////////////////////////////////////////////////////////////

    例如:

    reg [3:0] cnt0,cnt1;

    wire start_cnt0,start_cnt1;

    wire end_cnt0,end_cnt1;

    always @(posedge sclk or negedge rst_n)
    begin
      if(rst_n == 1'b0)begin
        cnt0 <= 'd0;
      end
      else if(start_cnt0)begin
        if(end_cnt0)begin
          cnt0 <= 'd0;
        end
        else begin
          cnt0 <= cnt0 + 1'b1;
        end
      end
    end

    assign start_cnt0 = 1;
    assign end_cnt0 = start_cnt0 && cnt0==2-1;

    always @(posedge sclk or negedge rst_n)
    begin
       if(rst_n == 1'b0)begin
        cnt1 <= 'd0;
      end
      else if(start_cnt1)begin
        if(end_cnt1)begin
          cnt1 <= 'd0;
        end
        else begin
          cnt1 <= cnt1 + 1'b1;
        end
      end
    end

    assign start_cnt1 = end_cnt0;
    assign end_cnt1 = start_cnt1 && cnt1==4-1;

  • 相关阅读:
    行转列函数listagg() WITHIN GROUP ()
    位图索引
    windows 杀掉进程
    vue 实践(过滤器)
    vue 总结
    vue v-show v-if 的使用
    vue v-for 绑定数据
    vue v-model实现数据的双向绑定
    vue .stop .self .capture .prevent 阻止冒泡
    vue v-on v-text 的运用
  • 原文地址:https://www.cnblogs.com/MAQI/p/7693332.html
Copyright © 2011-2022 走看看