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

Subversion Repositories generic_fifos

[/] [generic_fifos/] [trunk/] [rtl/] [verilog/] [lfsr.v] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 rherveille
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  Linear Feedback Shift Register                             ////
4
////                                                             ////
5
////  Author: Richard Herveille                                  ////
6
////          richard@asics.ws                                   ////
7
////          www.asics.ws                                       ////
8
////                                                             ////
9
/////////////////////////////////////////////////////////////////////
10
////                                                             ////
11
//// Copyright (C) 2001, 2002 Richard Herveille                  ////
12
////                          richard@asics.ws                   ////
13
////                                                             ////
14
//// This source file may be used and distributed without        ////
15
//// restriction provided that this copyright statement is not   ////
16
//// removed from the file and that any derivative work contains ////
17
//// the original copyright notice and the associated disclaimer.////
18
////                                                             ////
19
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
20
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
21
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
22
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
23
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
24
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
25
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
26
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
27
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
28
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
29
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
30
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
31
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
32
////                                                             ////
33
/////////////////////////////////////////////////////////////////////
34
 
35
//
36
//  CVS Log
37
//
38
//  $Id: lfsr.v,v 1.1 2002-10-29 19:45:07 rherveille Exp $
39
//
40
//  $Date: 2002-10-29 19:45:07 $
41
//  $Revision: 1.1 $
42
//  $Author: rherveille $
43
//  $Locker:  $
44
//  $State: Exp $
45
//
46
// Change History:
47
//               $Log: not supported by cvs2svn $
48
 
49
`include "timescale.v"
50
 
51
module lfsr (clk, ena, nReset, rst, q);
52
 
53
        //
54
        // parameters
55
        //
56
        parameter [3:0] TAPS   = 8;                // number of flip-flops in LFSR
57
 
58
        //
59
        // inputs & outputs
60
        //
61
        input clk;                                 // master clock
62
        input ena;                                 // clock enable
63
        input nReset;                              // asynchronous active low reset
64
        input rst;                                 // synchronous active high reset
65
 
66
        output [TAPS:1] q;                         // LFSR output
67
        reg [TAPS:1] q;
68
 
69
        //
70
        // Module body
71
        //
72
        function lsb;
73
           input [TAPS-1:0] q;
74
 
75
           case (TAPS)
76
               2: lsb = ~q[0];
77
               3: lsb = q[3] ^ q[2];
78
               4: lsb = q[4] ^ q[3];
79
               5: lsb = q[5] ^ q[3];
80
               6: lsb = q[6] ^ q[5];
81
               7: lsb = q[7] ^ q[6];
82
               8: lsb = q[8] ^ q[6] ^ q[5] ^ q[4];
83
               9: lsb = q[9] ^ q[5];
84
              10: lsb = q[10] ^ q[7];
85
              11: lsb = q[11] ^ q[9];
86
              12: lsb = q[12] ^ q[6] ^ q[4] ^ q[1];
87
              13: lsb = q[13] ^ q[4] ^ q[3] ^ q[1];
88
              14: lsb = q[14] ^ q[5] ^ q[3] ^ q[1];
89
              15: lsb = q[15] ^ q[14];
90
              16: lsb = q[16] ^ q[15] ^ q[13] ^ q[4];
91
           endcase
92
        endfunction
93
 
94
        always @(posedge clk or negedge nReset)
95
          if (~nReset)  q <= #1 0;
96
          else if (rst) q <= #1 0;
97
          else if (ena) q <= #1 {q[TAPS-1:1], lsb(q)};
98
endmodule
99
 

powered by: WebSVN 2.1.0

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