新闻  |   论坛  |   博客  |   在线研讨会
可综合风格的计数器设计
zhchxgh | 2009-07-15 00:14:26    阅读:969   发布文章

可综合风格的计数器设计 
   
  写一个既紧凑又能满足定时要求的定时器可能会有一点棘手。根据你在面积和速度方面的要求,以及你所使用的具体器件的不同,你可能需要尝试完全不同的设计方法。
  如果你需要设计一个计数速度很快的计数器,你最好先查找一下你所使用的FPGA设计工具中是否有厂家提供的现成的计数器单元。因为厂家提供的设计单元库针对特定的器件进行了优化,所以使用这些器件可以达到最快的速度。如果你的设计需要应用到几种不同的FPGA中,因而要求独立于特定的设计单元库,那么你就只能自己设计计数器了。当然,最容易的计数器设计就是count = count + 1,但是你可能得不到最好的结果。如果是计数值较小的计数器,使用序列器方法会得到较好的结果。 
例如:

always @(count)
   case (count) 
   2'h0: next_count = 2'h1;
   2'h1: next_count = 2'h2;
   2'h2: next_count = 2'h3;
   2'h3: next_count = 2'h0;
   endcase
end

always @ (posedge clk or posedge reset)
begin
  if (reset) begin
    count = 0;
  end
  else if (enable) begin
    count = next_count;
  end
end

另一种方法是异步产生计数使能,条件是使能信号必须没有毛刺并且与时钟信号有恰当的定时关系。

例如:

wire gate_clk = clk & enable;

always @ (posedge gate_clk or posedge reset)
begin
  if (reset) begin
    count = 0;
  end
  else begin
    count = count + 1;
  end
end

另一种类型的计数器是波纹计数器。这种计数器适合速度较慢、要求低功耗的场合,可以用Verilog很容易地实现。

例如:

always @(count) begin
   count0 = count[0] ;
   count1 = count[1] ;
   count2 = count[2] ;
end

always @(posedge clk or posedge reset) begin
  if (reset) begin
    count[0] = 0 ;
  end
  else begin
    count[0] = ~count[0];
  end
end

always @(posedge count0 or posedge reset)
begin
  if (reset) begin
    count[1] = 0 ;
  end
  else begin
    count[1] = ~count[1];
  end
end

always @(posedge count1 or posedge reset)
begin
  if (reset) begin
    count[2] = 0 ;
  end
  else begin
    count[2] = ~count[2];
  end
end

always @(posedge count2 or posedge reset)
begin
  if (reset) begin
    count[3] = 0 ;
  end
  else begin
    count[3] = ~count[3];
  end
end

*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
推荐文章
最近访客