OpenCores
URL https://opencores.org/ocsvn/ata/ata/trunk

Subversion Repositories ata

[/] [ata/] [trunk/] [rtl/] [verilog/] [ocidec-1/] [ud_cnt.v] - Diff between revs 22 and 33

Only display areas with differences | Details | Blame | View Log

Rev 22 Rev 33
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
////                                                             ////
////                                                             ////
////  Generic Up/Down counter                                    ////
////  Generic Up/Down counter                                    ////
////                                                             ////
////                                                             ////
////  Author: Richard Herveille                                  ////
////  Author: Richard Herveille                                  ////
////          richard@asics.ws                                   ////
////          richard@asics.ws                                   ////
////          www.asics.ws                                       ////
////          www.asics.ws                                       ////
////                                                             ////
////                                                             ////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
////                                                             ////
////                                                             ////
//// Copyright (C) 2001, 2002 Richard Herveille                  ////
//// Copyright (C) 2001, 2002 Richard Herveille                  ////
////                          richard@asics.ws                   ////
////                          richard@asics.ws                   ////
////                                                             ////
////                                                             ////
//// This source file may be used and distributed without        ////
//// This source file may be used and distributed without        ////
//// restriction provided that this copyright statement is not   ////
//// restriction provided that this copyright statement is not   ////
//// removed from the file and that any derivative work contains ////
//// removed from the file and that any derivative work contains ////
//// the original copyright notice and the associated disclaimer.////
//// the original copyright notice and the associated disclaimer.////
////                                                             ////
////                                                             ////
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
////                                                             ////
////                                                             ////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
 
 
//  CVS Log
//  CVS Log
//
//
//  $Id: ud_cnt.v,v 1.2 2002-02-16 10:42:17 rherveille Exp $
//  $Id: ud_cnt.v,v 1.2 2002-02-16 10:42:17 rherveille Exp $
//
//
//  $Date: 2002-02-16 10:42:17 $
//  $Date: 2002-02-16 10:42:17 $
//  $Revision: 1.2 $
//  $Revision: 1.2 $
//  $Author: rherveille $
//  $Author: rherveille $
//  $Locker:  $
//  $Locker:  $
//  $State: Exp $
//  $State: Exp $
//
//
// Change History:
// Change History:
//               $Log: not supported by cvs2svn $
//               $Log: not supported by cvs2svn $
//
//
 
 
 
 
/////////////////////////////
/////////////////////////////
// general purpose counter //
// general purpose counter //
/////////////////////////////
/////////////////////////////
 
 
`include "timescale.v"
`include "timescale.v"
 
 
module ud_cnt (clk, nReset, rst, cnt_en, ud, nld, d, q, rci, rco);
module ud_cnt (clk, nReset, rst, cnt_en, ud, nld, d, q, rci, rco);
        // parameter declaration
        // parameter declaration
        parameter SIZE  = 8;
        parameter SIZE  = 8;
        parameter RESD  = {SIZE{1'b0}}; // data after reset
        parameter RESD  = {SIZE{1'b0}}; // data after reset
 
 
        // inputs & outputs
        // inputs & outputs
        input             clk;    // master clock
        input             clk;    // master clock
        input             nReset; // asynchronous active low reset
        input             nReset; // asynchronous active low reset
        input             rst;    // synchronous active high reset
        input             rst;    // synchronous active high reset
        input             cnt_en; // count enable
        input             cnt_en; // count enable
        input             ud;     // up/not down
        input             ud;     // up/not down
        input             nld;    // synchronous active low load
        input             nld;    // synchronous active low load
        input  [SIZE-1:0] d;      // load counter value
        input  [SIZE-1:0] d;      // load counter value
        output [SIZE-1:0] q;      // current counter value
        output [SIZE-1:0] q;      // current counter value
        input             rci;    // carry input
        input             rci;    // carry input
        output            rco;    // carry output
        output            rco;    // carry output
 
 
        // variable declarations
        // variable declarations
        reg  [SIZE-1:0] Qi;  // intermediate value
        reg  [SIZE-1:0] Qi;  // intermediate value
        wire [SIZE:0]   val; // carry+result
        wire [SIZE:0]   val; // carry+result
 
 
        //
        //
        // Module body
        // Module body
        //
        //
 
 
        assign val = ud ? ( {1'b0, Qi} + rci) : ( {1'b0, Qi} - rci);
        assign val = ud ? ( {1'b0, Qi} + rci) : ( {1'b0, Qi} - rci);
 
 
        always@(posedge clk or negedge nReset)
        always@(posedge clk or negedge nReset)
        begin
        begin
                if (~nReset)
                if (~nReset)
                        Qi <= #1 RESD;
                        Qi <= #1 RESD;
                else if (rst)
                else if (rst)
                        Qi <= #1 RESD;
                        Qi <= #1 RESD;
                else    if (~nld)
                else    if (~nld)
                        Qi <= #1 d;
                        Qi <= #1 d;
                else if (cnt_en)
                else if (cnt_en)
                        Qi <= #1 val[SIZE-1:0];
                        Qi <= #1 val[SIZE-1:0];
        end
        end
 
 
        // assign outputs
        // assign outputs
        assign q = Qi;
        assign q = Qi;
        assign rco = val[SIZE];
        assign rco = val[SIZE];
endmodule
endmodule
 
 
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.