网站首页
IC库存
IC展台
电子资讯
技术资料
PDF文档
我的博客
IC72论坛
ic72 logo
资料首页最新产品 技术参数 电路图 设计应用 解决方案 代理商查询 IC替换 IC厂商 电子辞典
关键字: 技术文章 PDF资料 IC价格 电路图 代理商查询 IC替换 IC厂商 电子辞典

Verilog HDL源程序库

 在熟悉了Verilog HDL语法之后,使用Verilog HDL设计FPGA遇到的最大困难可能就是不知如何用Verilog HDL的语句去描述想要实现的电路功能。要克服这一困难,除了提高数字电路设计功底之外,很重要的一点就是要学习他人的经验,多看有经验的设计者设计的源程序。
  我们提供Verilog HDL源程序库的目的就是想收集尽可能多的谈设计经验的文章和经典的Verilog HDL设计,供大家学习参考。同时也希望大家能提供一些相关资料,使这个程序库能不断得到充实!
状态机举例
你可以指定状态寄存器和状态机的状态。以下是一个有四种状态的普通状态机。   // These are the symbolic names for states // 定义状态的符号名称 parameter  [1:0]   S0 = 2'h0,   S1 = 2'h1,   S2 = 2'h2,   S3 = 2'h3;  // These are the current state and next state variables // 定义当前状态和下一状态变量 reg [1:0] state; reg [1:0] next_state;     // state_vector state // 状态向量的转移关系 always @ (state or y or x) begin    next_state = state;   case (state)                      S0: begin        if (x) begin          next_state = S1;       end       else begin          next_state = S2;       end     end     S1: begin        if (y) begin          next_state = S2;       end       else begin          next_state = S0;       end     end     S2: begin        if (x & y) begin          next_state = S3;       end       else begin          next_state = S0;       end     end     S3: begin        next_state = S0;     end   endcase end   always @ (posedge clk or posedge reset) begin    if (reset) begin      state <= S0;   end   else begin      state <= next_state;   end end      同样的状态机也可以用下面的代码以“One hot”编码方式实现。
// These are the symbolic names for states // 定义状态的符号名称 parameter  [1:0]   S0 = 2'h0,   S1 = 2'h1,   S2 = 2'h2,   S3 = 2'h3;   parameter  [3:0]    s0 = 4'h1,   s1 = 4'h2,   s2 = 4'h4,   s3 = 4'h8;    // These are the current state and next state variables // 定义当前状态和下一状态变量 reg [3:0] state; reg [3:0] next_state;     // state_vector state // 状态向量的转移关系 always @ (state or y or x) begin    next_state = state;   case (1)                      state[S0]: begin        if (x) begin          next_state = 1 << S1;       end       else begin          next_state = 1 << S2;       end     end     state[S1]: begin        if (y) begin          next_state = 1 << S2;       end       else begin          next_state = 1 << S0;       end     end     state[S2]: begin        if (x & y) begin          next_state = 1 << S3;       end       else begin          next_state = 1 << S0;       end     end     state[S3]: begin        next_state = 1 << S0;     end   endcase end   always @ (posedge clk or posedge reset) begin    if (reset) begin      state <= 1 << S0;   end   else begin      state <= next_state;   end end 
  
来源 译自Celia的Verilog网站
可综合风格的计数器设计
  写一个既紧凑又能满足定时要求的定时器可能会有一点棘手。根据你在面积和速度方面的要求,以及你所使用的具体器件的不同,你可能需要尝试完全不同的设计方法。
  如果你需要设计一个计数速度很快的计数器,你最好先查找一下你所使用的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

  


热门搜索:SBB2808-1 RBC11A 1553DBPCB SUPER6OMNI B ULTRABLOK TLP604 2320306 2856142 2320319 N060-004 01T5001JF BT151S-800R118 TRAVELER3USB CC2544RHBR PS240406 2838322 2320089 02C1001JF 2839211 2856087 SBB830 SBB1005-1 TLP712B SBB1002-1 PS120420
COPYRIGHT:(1998-2010) IC72 达普IC芯片交易网
客户服务:service@IC72.com 库存上载:IC72@IC72.com
(北京)联系方式: 在线QQ咨询:点击这里给我发消息 联系电话:010-82614113 传真:010-82614123
京ICP备06008810号-21 京公网安备 11010802032910 号 企业资质