Altera Home Page
Literature Licensing
Buy On-Line Download

  Home   |   Products   |   Support   |   End Markets   |   Technology Center   |   Education & Events   |   Corporate   |   Buy On-Line  
  Knowledge Database   |   Devices   |   Design Software   |   Intellectual Property   |   Design Examples   |   mySupport   |   Reference Designs  

 Products
      MAX/MAX II
      Stratix/Stratix GX
      Nios II
  
 Functionality
      Arithmetic
      Memory
      Bus & I/O
      Logic
      Interfaces & Peripherals
      DSP
      Communications
      PLL & Clocking
  
 Design Entry
      Quartus II Project
      Tcl
      VHDL
      Verilog HDL
      C Code Examples
      DSP Builder
      TimeQuest
   On-Chip Debugging
  
 Simulation Tools
      Mentor Graphics ModelSim
      Cadence NCsim
      Synopsys VCS
  
 Legacy Examples
      Graphic Editor
      AHDL
  

Verilog HDL: Behavioral Counter

This example describes an 8-bit loadable counter with count enable. The always construct, highlighted in red text, describes how the counter should behave.

For more information on using this example in your project, go to:


behav_counter.v

module behav_counter( d, clk, clear, load, up_down, qd);

// Port Declaration

input   [7:0] d;
input   clk;
input   clear;
input   load;
input   up_down;
output  [7:0] qd;

reg     [7:0] cnt;


assign qd = cnt;


always @ (posedge clk)
begin
    if (!clear)
        cnt = 8'h00;
    else if (load)
        cnt = d;
    else if (up_down)
        cnt = cnt + 1;
    else
        cnt = cnt - 1;
end	

endmodule

Feedback

Did this information help you?

If not, please log onto mySupport to file a technical request or enhancement.


Altera does not warrant that this solution will work for the customer's intended purpose and disclaims all liability for use of or reliance on the solution.

  Please Give Us Feedback