首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

SystemVerilog学习一 —— 计数器

SystemVerilog学习一 —— 计数器

SystemVerilog给予Verilog、VHDL和C/C++优点为一身的硬件描述语言,很值得学一学。


18-bit up counter


***********************************************************


module up_counter(
output reg [7:0] out     ,  // Output of the counter
input  wire      enable  ,  // enable for counter
input  wire      clk     ,  // clock Input
input  wire      reset      // reset Input
);
//-------------Code Starts Here-------
always_ff @(posedge clk)
   if (reset)  out <= 8'b0 ;
   else if (enable) out ++;
      
endmodule
***********************************************************


RTL Riewer




28-bit up counter with load


*********************************************************


module up_counter_load    (
output  reg  [7:0]  out      ,  // Output of the counter
input   wire [7:0]  data     ,  // Parallel load for the counter
input   wire        load     ,  // Parallel load enable
input   wire        enable   ,  // Enable counting
input   wire        clk      ,  // clock input
input   wire        reset       // reset input
);
//-------------Code Starts Here-------
always_ff @ (posedge clk)
if (reset) begin
  out <= 8'b0 ;
end else if (load) begin
  out <= data;
end else if (enable) begin
  out++;
end
   
endmodule


*********************************************************


RTL Viewer




38-bit up-down counter


*****************************************************************************


module up_down_counter    (
output reg  [7:0] out      ,  // Output of the counter
input  wire       up_down  ,  // up_down control for counter
input  wire       clk      ,  // clock input
input  wire       reset       // reset input
);


//-------------Code Starts Here-------
always_ff @(posedge clk)
if (reset) begin // active high reset
  out <= 8'b0 ;
end else if (up_down) begin
  out ++;
end else begin
  out --;
end


endmodule


********************************************************************************


RTL Viewer




4、lfsr counter


****************************************************************************************


module lfsr (
output  reg  [7:0] out     ,  // Output of the counter
input   wire       enable  ,  // Enable  for counter
input   wire       clk     ,  // clock input
input   wire       reset      // reset input
);
//------------Internal Variables--------
wire        linear_feedback;
//-------------Code Starts Here-------
assign linear_feedback = !(out[7] ^ out[3]);


always_ff @(posedge clk)
if (reset) begin // active high reset
  out <= 8'b0 ;
end else if (enable) begin
  out <= {out[6],out[5],
          out[4],out[3],
          out[2],out[1],
          out[0], linear_feedback};
end


endmodule // End Of Module counter


***********************************************************************************


RTL Viewer


继承事业,薪火相传
返回列表