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

Subversion Repositories 8051

[/] [8051/] [trunk/] [rtl/] [verilog/] [oc8051_tc.v] - Blame information for rev 116

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 82 simont
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  8051 cores timer/counter control                            ////
4
////                                                              ////
5
////  This file is part of the 8051 cores project                 ////
6
////  http://www.opencores.org/cores/8051/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////   timers and counters handling for 8051 core                 ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////   Nothing                                                    ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Simon Teran, simont@opencores.org                     ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE.  See the GNU Lesser General Public License for more ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
//
44
// CVS Revision History
45
//
46
// $Log: not supported by cvs2svn $
47 116 simont
// Revision 1.6  2003/04/04 10:34:13  simont
48
// change timers to meet timing specifications (add divider with 12)
49
//
50 112 simont
// Revision 1.5  2003/01/13 14:14:41  simont
51
// replace some modules
52
//
53 82 simont
// Revision 1.4  2002/09/30 17:33:59  simont
54
// prepared header
55
//
56
//
57
 
58
`include "oc8051_defines.v"
59
 
60
//synopsys translate_off
61
`include "oc8051_timescale.v"
62
//synopsys translate_on
63
 
64
 
65
 
66 112 simont
module oc8051_tc (clk, rst,
67 116 simont
            data_in,
68
            wr_addr,
69 112 simont
            wr, wr_bit,
70 116 simont
            ie0, ie1,
71
            tr0, tr1,
72 112 simont
            t0, t1,
73
            tf0, tf1,
74 116 simont
            pres_ow,
75
//registers
76
            tmod, tl0, th0, tl1, th1);
77 82 simont
 
78 112 simont
input [7:0]  wr_addr,
79 116 simont
             data_in;
80 112 simont
input        clk,
81
             rst,
82
             wr,
83
             wr_bit,
84
             ie0,
85
             ie1,
86
             tr0,
87
             tr1,
88
             t0,
89
             t1;
90 116 simont
output [7:0] tmod,
91
             tl0,
92
             th0,
93
             tl1,
94
             th1;
95 112 simont
output       tf0,
96
             tf1,
97
             pres_ow;
98 82 simont
 
99 112 simont
 
100 116 simont
reg [7:0] tmod, tl0, th0, tl1, th1;
101 82 simont
reg tf0, tf1_0, tf1_1, t0_buff, t1_buff;
102
 
103 112 simont
reg pres_ow;
104
reg [3:0] prescaler;
105
 
106 82 simont
wire tc0_add, tc1_add;
107
 
108 112 simont
assign tc0_add = (tr0 & (!tmod[3] | !ie0) & ((!tmod[2] & pres_ow) | (tmod[2] & !t0 & t0_buff)));
109
assign tc1_add = (tr1 & (!tmod[7] | !ie1) & ((!tmod[6] & pres_ow) | (tmod[6] & !t1 & t1_buff)));
110 82 simont
assign tf1= tf1_0 | tf1_1;
111
 
112
//
113
// read or write from one of the addresses in tmod
114
//
115
always @(posedge clk or posedge rst)
116
begin
117
 if (rst) begin
118
   tmod <=#1 `OC8051_RST_TMOD;
119
 end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TMOD))
120
    tmod <= #1 data_in;
121
end
122
 
123
//
124
// TIMER COUNTER 0
125
//
126
always @(posedge clk or posedge rst)
127
begin
128
 if (rst) begin
129
   tl0 <=#1 `OC8051_RST_TL0;
130
   th0 <=#1 `OC8051_RST_TH0;
131
   tf0 <= #1 1'b0;
132
   tf1_0 <= #1 1'b0;
133
 end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TL0)) begin
134
   tl0 <= #1 data_in;
135
   tf0 <= #1 1'b0;
136
   tf1_0 <= #1 1'b0;
137
 end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TH0)) begin
138
   th0 <= #1 data_in;
139
   tf0 <= #1 1'b0;
140
   tf1_0 <= #1 1'b0;
141
 end else begin
142
     case (tmod[1:0])
143
      `OC8051_MODE0: begin                       // mode 0
144
        tf1_0 <= #1 1'b0;
145
        if (tc0_add)
146
          {tf0, th0,tl0[4:0]} <= #1 {1'b0, th0, tl0[4:0]}+ 1'b1;
147
      end
148
      `OC8051_MODE1: begin                       // mode 1
149
        tf1_0 <= #1 1'b0;
150
        if (tc0_add)
151
          {tf0, th0,tl0} <= #1 {1'b0, th0, tl0}+ 1'b1;
152
      end
153
 
154
      `OC8051_MODE2: begin                       // mode 2
155
        tf1_0 <= #1 1'b0;
156
        if (tc0_add) begin
157
          if (tl0 == 8'b1111_1111) begin
158
            tf0 <=#1 1'b1;
159
            tl0 <=#1 th0;
160
           end
161
          else begin
162
            tl0 <=#1 tl0 + 8'h1;
163
            tf0 <= #1 1'b0;
164
          end
165
        end
166
      end
167
      `OC8051_MODE3: begin                       // mode 3
168
 
169
         if (tc0_add)
170
           {tf0, tl0} <= #1 {1'b0, tl0} +1'b1;
171
 
172 112 simont
         if (tr1 & pres_ow)
173 82 simont
           {tf1_0, th0} <= #1 {1'b0, th0} +1'b1;
174
 
175
      end
176
      default:begin
177
        tf0 <= #1 1'b0;
178
        tf1_0 <= #1 1'b0;
179
      end
180
    endcase
181
 end
182
end
183
 
184
//
185
// TIMER COUNTER 1
186
//
187
always @(posedge clk or posedge rst)
188
begin
189
 if (rst) begin
190
   tl1 <=#1 `OC8051_RST_TL1;
191
   th1 <=#1 `OC8051_RST_TH1;
192
   tf1_1 <= #1 1'b0;
193
 end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TL1)) begin
194
   tl1 <= #1 data_in;
195
   tf1_1 <= #1 1'b0;
196
 end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TH1)) begin
197
   th1 <= #1 data_in;
198
   tf1_1 <= #1 1'b0;
199
 end else begin
200
     case (tmod[5:4])
201
      `OC8051_MODE0: begin                       // mode 0
202
        if (tc1_add)
203
          {tf1_1, th1,tl1[4:0]} <= #1 {1'b0, th1, tl1[4:0]}+ 1'b1;
204
      end
205
      `OC8051_MODE1: begin                       // mode 1
206
        if (tc1_add)
207
          {tf1_1, th1,tl1} <= #1 {1'b0, th1, tl1}+ 1'b1;
208
      end
209
 
210
      `OC8051_MODE2: begin                       // mode 2
211
        if (tc1_add) begin
212
          if (tl1 == 8'b1111_1111) begin
213
            tf1_1 <=#1 1'b1;
214
            tl1 <=#1 th1;
215
           end
216
          else begin
217
            tl1 <=#1 tl1 + 8'h1;
218
            tf1_1 <= #1 1'b0;
219
          end
220
        end
221
      end
222
      default:begin
223
        tf1_1 <= #1 1'b0;
224
      end
225
    endcase
226
 end
227
end
228
 
229
 
230 112 simont
always @(posedge clk or posedge rst)
231
begin
232
  if (rst) begin
233
    prescaler <= #1 4'h0;
234
    pres_ow <= #1 1'b0;
235
  end else if (prescaler==4'b1011) begin
236
    prescaler <= #1 4'h0;
237
    pres_ow <= #1 1'b1;
238
  end else begin
239
    prescaler <= #1 prescaler + 4'h1;
240
    pres_ow <= #1 1'b0;
241
  end
242
end
243 82 simont
 
244
always @(posedge clk or posedge rst)
245
  if (rst) begin
246
    t0_buff <= #1 1'b0;
247
    t1_buff <= #1 1'b0;
248
  end else begin
249
    t0_buff <= #1 t0;
250
    t1_buff <= #1 t1;
251
  end
252
endmodule

powered by: WebSVN 2.1.0

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