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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [rtl/] [common/] [FT64_pit.v] - Blame information for rev 51

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//        __
4
//   \\__/ o\    (C) 2017-2018  Robert Finch, Waterloo
5
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch<remove>@finitron.ca
7
//       ||
8
//
9
//      FT64_pit.v
10
//      - programmable interval timer
11
//              
12
//
13
// This source file is free software: you can redistribute it and/or modify 
14
// it under the terms of the GNU Lesser General Public License as published 
15
// by the Free Software Foundation, either version 3 of the License, or     
16
// (at your option) any later version.                                      
17
//                                                                          
18
// This source file is distributed in the hope that it will be useful,      
19
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
20
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
21
// GNU General Public License for more details.                             
22
//                                                                          
23
// You should have received a copy of the GNU General Public License        
24
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
25
//                                                                          
26
//
27
//      Reg     Description
28
//      00      current count   (read only)
29
//      04      max count           (read-write)
30
//  08  on time                 (read-write)
31
//      0C      control
32
//              byte 0 for counter 0, byte 1 for counter 1, byte 2 for counter 2
33
//              bit in byte
34
//              0 = 1 = load, automatically clears
35
//          1 = 1 = enable counting, 0 = disable counting
36
//              2 = 1 = auto-reload on terminal count, 0 = no reload
37
//              3 = 1 = use external clock, 0 = internal clk_i
38
//      4 = 1 = use gate to enable count, 0 = ignore gate
39
//      10      current count 1
40
//      14  max count 1
41
//      18  on time 1
42
//      20      current count 2
43
//      24      max count 2
44
//      28      on time 2
45
//
46
//      - all three counter controls can be written at the same time with a
47
//    single instruction allowing synchronization of the counters.
48
// ============================================================================
49
//
50
module FT64_pit(rst_i, clk_i, cs_i, cyc_i, stb_i, ack_o, sel_i, we_i, adr_i, dat_i, dat_o,
51
        clk0, gate0, out0, clk1, gate1, out1, clk2, gate2, out2
52
        );
53
input rst_i;
54
input clk_i;
55
input cs_i;
56
input cyc_i;
57
input stb_i;
58
output ack_o;
59
input [3:0] sel_i;
60
input we_i;
61
input [5:0] adr_i;
62
input [31:0] dat_i;
63
output reg [31:0] dat_o;
64
input clk0;
65
input gate0;
66
output out0;
67
input clk1;
68
input gate1;
69
output out1;
70
input clk2;
71
input gate2;
72
output out2;
73
 
74
integer n;
75
reg [31:0] maxcount [0:2];
76
reg [31:0] count [0:2];
77
reg [31:0] ont [0:2];
78
wire [2:0] gate;
79
wire [2:0] pulse;
80
reg ld [0:2];
81
reg ce [0:2];
82
reg ar [0:2];
83
reg ge [0:2];
84
reg xc [0:2];
85
reg out [0:2];
86
 
87
wire cs = cyc_i & stb_i & cs_i;
88
reg rdy;
89
always @(posedge clk_i)
90
        rdy <= cs;
91
assign ack_o = cs ? (we_i ? 1'b1 : rdy) : 1'b0;
92
 
93
assign out0 = out[0];
94
assign out1 = out[1];
95
assign out2 = out[2];
96
assign gate[0] = gate0;
97
assign gate[1] = gate1;
98
assign gate[2] = gate2;
99
 
100
edge_det ued0 (.rst(rst_i), .clk(clk_i), .ce(1'b1), .i(clk0), .pe(pulse[0]), .ne());
101
edge_det ued1 (.rst(rst_i), .clk(clk_i), .ce(1'b1), .i(clk1), .pe(pulse[1]), .ne());
102
edge_det ued2 (.rst(rst_i), .clk(clk_i), .ce(1'b1), .i(clk2), .pe(pulse[2]), .ne());
103
 
104 51 robfinch
initial begin
105
        for (n = 0; n < 3; n = n + 1) begin
106
                maxcount[n] <= 32'd0;
107
                count[n] <= 32'd0;
108
                ont[n] <= 32'd0;
109
                ld[n] <= 1'b0;
110
                ce[n] <= 1'b0;
111
                ar[n] <= 1'b0;
112
                ge[n] <= 1'b0;
113
                xc[n] <= 1'b0;
114
                out[n] <= 1'b0;
115
        end
116
end
117
 
118 48 robfinch
always @(posedge clk_i)
119
if (rst_i) begin
120
        for (n = 0; n < 3; n = n + 1) begin
121
                ld[n] <= 1'b0;
122
                ce[n] <= 1'b0;
123
                ar[n] <= 1'b1;
124
                ge[n] <= 1'b0;
125
                out[n] <= 1'b0;
126
        end
127
end
128
else begin
129
        for (n = 0; n < 3; n = n + 1) begin
130
                ld[n] <= 1'b0;
131
                if (cs && we_i && adr_i[5:4]==n)
132
                case(adr_i[3:2])
133
                2'd1:   maxcount[n] <= dat_i;
134
                2'd2:   ont[n] <= dat_i;
135
                2'd3:   begin
136
                                        if (sel_i[0]) begin
137
                                                ld[0] <= dat_i[0];
138
                                                ce[0] <= dat_i[1];
139
                                                ar[0] <= dat_i[2];
140
                                                xc[0] <= dat_i[3];
141
                                                ge[0] <= dat_i[4];
142
                                        end
143
                                        if (sel_i[1]) begin
144
                                                ld[1] <= dat_i[8];
145
                                                ce[1] <= dat_i[9];
146
                                                ar[1] <= dat_i[10];
147
                                                xc[1] <= dat_i[11];
148
                                                ge[1] <= dat_i[12];
149
                                        end
150
                                        if (sel_i[2]) begin
151
                                                ld[2] <= dat_i[16];
152
                                                ce[2] <= dat_i[17];
153
                                                ar[2] <= dat_i[18];
154
                                                xc[2] <= dat_i[19];
155
                                                ge[2] <= dat_i[20];
156
                                        end
157
                                end
158
                endcase
159
                if (adr_i[5:4]==n)
160
                        case(adr_i[3:2])
161
                        2'd0:   dat_o <= count[n];
162
                        2'd1:   dat_o <= maxcount[n];
163
                        2'd2:   dat_o <= ont[n];
164
                        2'd3:   dat_o <= {ge[2],xc[2],ar[2],ce[2],4'b0,ge[1],xc[1],ar[1],ce[1],4'b0,ge[0],xc[0],ar[0],ce[0],1'b0};
165
                        endcase
166
 
167
                if (ld[n])
168
                        count[n] <= maxcount[n];
169
                else if ((xc[n] ? pulse[n] & ce[n] : ce[n]) & (ge[n] ? gate[n] : 1'b1)) begin
170
                        count[n] <= count[n] - 32'd1;
171
                        if (count[n]==ont[n])
172
                                out[n] <= 1'b1;
173
                        else if (count[n]==32'd0) begin
174
                                out[n] <= 1'b0;
175
                                if (ar[n])
176
                                        count[n] <= maxcount[n];
177
                                else
178
                                        ce[n] <= 1'b0;
179
                        end
180
                end
181
        end
182
end
183
 
184
endmodule

powered by: WebSVN 2.1.0

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