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

Subversion Repositories thor

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

Go to most recent revision | 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
always @(posedge clk_i)
105
if (rst_i) begin
106
        for (n = 0; n < 3; n = n + 1) begin
107
                ld[n] <= 1'b0;
108
                ce[n] <= 1'b0;
109
                ar[n] <= 1'b1;
110
                ge[n] <= 1'b0;
111
                out[n] <= 1'b0;
112
        end
113
end
114
else begin
115
        for (n = 0; n < 3; n = n + 1) begin
116
                ld[n] <= 1'b0;
117
                if (cs && we_i && adr_i[5:4]==n)
118
                case(adr_i[3:2])
119
                2'd1:   maxcount[n] <= dat_i;
120
                2'd2:   ont[n] <= dat_i;
121
                2'd3:   begin
122
                                        if (sel_i[0]) begin
123
                                                ld[0] <= dat_i[0];
124
                                                ce[0] <= dat_i[1];
125
                                                ar[0] <= dat_i[2];
126
                                                xc[0] <= dat_i[3];
127
                                                ge[0] <= dat_i[4];
128
                                        end
129
                                        if (sel_i[1]) begin
130
                                                ld[1] <= dat_i[8];
131
                                                ce[1] <= dat_i[9];
132
                                                ar[1] <= dat_i[10];
133
                                                xc[1] <= dat_i[11];
134
                                                ge[1] <= dat_i[12];
135
                                        end
136
                                        if (sel_i[2]) begin
137
                                                ld[2] <= dat_i[16];
138
                                                ce[2] <= dat_i[17];
139
                                                ar[2] <= dat_i[18];
140
                                                xc[2] <= dat_i[19];
141
                                                ge[2] <= dat_i[20];
142
                                        end
143
                                end
144
                endcase
145
                if (adr_i[5:4]==n)
146
                        case(adr_i[3:2])
147
                        2'd0:   dat_o <= count[n];
148
                        2'd1:   dat_o <= maxcount[n];
149
                        2'd2:   dat_o <= ont[n];
150
                        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};
151
                        endcase
152
 
153
                if (ld[n])
154
                        count[n] <= maxcount[n];
155
                else if ((xc[n] ? pulse[n] & ce[n] : ce[n]) & (ge[n] ? gate[n] : 1'b1)) begin
156
                        count[n] <= count[n] - 32'd1;
157
                        if (count[n]==ont[n])
158
                                out[n] <= 1'b1;
159
                        else if (count[n]==32'd0) begin
160
                                out[n] <= 1'b0;
161
                                if (ar[n])
162
                                        count[n] <= maxcount[n];
163
                                else
164
                                        ce[n] <= 1'b0;
165
                        end
166
                end
167
        end
168
end
169
 
170
endmodule

powered by: WebSVN 2.1.0

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