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

Subversion Repositories bubblesortmodule

[/] [bubblesortmodule/] [trunk/] [rtl/] [verilog/] [intgenerator.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 avramionut
//////////////////////////////////////////////////////////////////////
2
////
3
//// Copyright (C) 2014 avram ionut, avramionut@opencores.org
4
////
5
//// This source file may be used and distributed without
6
//// restriction provided that this copyright statement is not
7
//// removed from the file and that any derivative work contains
8
//// the original copyright notice and the associated disclaimer.
9
////
10
//// This source file is free software; you can redistribute it
11
//// and/or modify it under the terms of the GNU Lesser General
12
//// Public License as published by the Free Software Foundation;
13
//// either version 2.1 of the License, or (at your option) any
14
//// later version.
15
////
16
//// This source is distributed in the hope that it will be
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19
//// PURPOSE. See the GNU Lesser General Public License for more
20
//// details.
21
////
22
//// You should have received a copy of the GNU Lesser General
23
//// Public License along with this source; if not, download it
24
//// from http://www.opencores.org/lgpl.shtml
25
////
26
//
27
// Revisions: 
28
// Revision 0.01 - File Created
29
// Additional Comments: 
30
//                     
31
//
32
//////////////////////////////////////////////////////////////////////////////////
33
module intgenerator #(parameter N_BITS=8, parameter K_NUMBERS=8)
34
    (
35
    input   clk,
36
    input   rst,
37
    input   run_i,
38
    input   swap_i,
39
    output  done_o,
40
    output  interrupt_o
41
    );
42
 
43
    parameter P_PULSES = (2*(K_NUMBERS+11))/(N_BITS+4);
44
    parameter P_WIDTH = $clog2(P_PULSES)+1;
45
 
46
    reg     r_run_delay;
47
    reg     r_swap_delay;
48
    reg [P_WIDTH:0]   r_pulses;
49
    reg     r_done;
50
 
51
    always @(posedge clk)
52
        begin
53
            if (rst) begin
54
                r_run_delay <= 1'b0;
55
                r_swap_delay <= 1'b0;    end
56
            else begin
57
                r_run_delay <= run_i;
58
                r_swap_delay <= swap_i;  end
59
        end
60
 
61
    always @(posedge clk)
62
        begin
63
            if (rst || (r_pulses[P_WIDTH])) begin
64
                r_pulses <= P_PULSES - 1;            end
65
            else if (w_falling_run) begin
66
                if (~r_swap_delay) begin
67
                    r_pulses <= r_pulses - 1;        end
68
                else begin
69
                    r_pulses <= P_PULSES - 1;        end
70
                end
71
        end
72
 
73
    always @(posedge clk)
74
        begin
75
            /*if (rst) begin
76
                r_done <= 1'b0;                      end
77
            else*/ if (w_falling_run & (~r_swap_delay)) begin
78
                r_done <= 1'b1;                      end
79
            else begin
80
                r_done <= 1'b0;                      end
81
        end
82
 
83
    assign w_falling_run = (~run_i) & r_run_delay;
84
 
85
    assign done_o = r_done;
86
    assign interrupt_o = r_pulses[P_WIDTH];
87
 
88
endmodule

powered by: WebSVN 2.1.0

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