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

Subversion Repositories turbo8051

[/] [turbo8051/] [trunk/] [rtl/] [8051/] [oc8051_tc2.v] - Blame information for rev 68

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

Line No. Rev Author Line
1 2 dinesha
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  8051 cores timer/counter2 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 2 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
// Revision 1.2  2003/04/04 10:34:13  simont
48
// change timers to meet timing specifications (add divider with 12)
49
//
50
// Revision 1.1  2003/01/13 14:13:12  simont
51
// initial import
52
//
53
//
54
//
55
 
56
`include "oc8051_defines.v"
57
 
58
//synopsys translate_off
59
`include "oc8051_timescale.v"
60
//synopsys translate_on
61
 
62
 
63
 
64
module oc8051_tc2 (clk, rst,
65
            wr_addr,
66
            data_in, bit_in,
67
            wr, wr_bit,
68
            t2, t2ex,
69
            rclk, tclk,
70
            brate2, tc2_int,
71
            pres_ow,
72
//registers
73
            t2con, tl2, th2, rcap2l, rcap2h);
74
 
75
input [7:0]  wr_addr,
76
             data_in;
77
input        clk,
78
             rst,
79
             wr,
80
             wr_bit,
81
             t2,
82
             t2ex,
83
             bit_in,
84
             pres_ow;   //prescalre owerflov
85
output [7:0] t2con,
86
             tl2,
87
             th2,
88
             rcap2l,
89
             rcap2h;
90
output       tc2_int,
91
             rclk,
92
             tclk,
93
             brate2;
94
 
95
 
96
reg brate2;
97
reg [7:0] t2con, tl2, th2, rcap2l, rcap2h;
98
 
99
reg neg_trans, t2ex_r, t2_r, tc2_event, tf2_set;
100
 
101
wire run;
102
 
103
//
104
// t2con
105
wire tf2, exf2, exen2, tr2, ct2, cprl2;
106
 
107
assign tc2_int = tf2 | exf2;
108
assign tf2   = t2con[7];
109
assign exf2  = t2con[6];
110
assign rclk  = t2con[5];
111
assign tclk  = t2con[4];
112
assign exen2 = t2con[3];
113
assign tr2   = t2con[2];
114
assign ct2   = t2con[1];
115
assign cprl2 = t2con[0];
116
 
117
always @(posedge clk or posedge rst)
118
begin
119
  if (rst) begin
120
    t2con <= #1 `OC8051_RST_T2CON;
121
  end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_T2CON)) begin
122
    t2con <= #1 data_in;
123
  end else if ((wr) & (wr_bit) & (wr_addr[7:3]==`OC8051_SFR_B_T2CON)) begin
124
    t2con[wr_addr[2:0]] <= #1 bit_in;
125
  end else if (tf2_set) begin
126
    t2con[7] <= #1 1'b1;
127
  end else if (exen2 & neg_trans) begin
128
    t2con[6] <= #1 1'b1;
129
  end
130
end
131
 
132
 
133
//
134
//th2, tl2
135
assign run = tr2 & ((!ct2 & pres_ow) | (ct2 & tc2_event));
136
 
137
always @(posedge clk or posedge rst)
138
begin
139
  if (rst) begin
140
//
141
// reset
142
//
143
    tl2 <= #1 `OC8051_RST_TL2;
144
    th2 <= #1 `OC8051_RST_TH2;
145
    brate2 <= #1 1'b0;
146
    tf2_set <= #1 1'b0;
147
  end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TH2)) begin
148
//
149
// write to timer 2 high
150
//
151
    th2 <= #1 data_in;
152
  end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TL2)) begin
153
//
154
// write to timer 2 low
155
//
156
    tl2 <= #1 data_in;
157
  end else if (!(rclk | tclk) & !cprl2 & exen2 & neg_trans) begin
158
//
159
// avto reload mode, exen2=1, 0-1 transition on t2ex pin
160
//
161
    th2 <= #1 rcap2h;
162
    tl2 <= #1 rcap2l;
163
    tf2_set <= #1 1'b0;
164
  end else if (run) begin
165
    if (rclk | tclk) begin
166
//
167
// boud rate generator mode
168
//
169
      if (&{th2, tl2}) begin
170
        th2 <= #1 rcap2h;
171
        tl2 <= #1 rcap2l;
172
        brate2 <= #1 1'b1;
173
      end else begin
174
        {brate2, th2, tl2}  <= #1 {1'b0, th2, tl2} + 17'h1;
175
      end
176
      tf2_set <= #1 1'b0;
177
    end else if (cprl2) begin
178
//
179
// capture mode
180
//
181
      {tf2_set, th2, tl2}  <= #1 {1'b0, th2, tl2} + 17'h1;
182
    end else begin
183
//
184
// auto reload mode
185
//
186
      if (&{th2, tl2}) begin
187
        th2 <= #1 rcap2h;
188
        tl2 <= #1 rcap2l;
189
        tf2_set <= #1 1'b1;
190
      end else begin
191
        {tf2_set, th2, tl2} <= #1 {1'b0, th2, tl2} + 17'h1;
192
      end
193
    end
194
  end else tf2_set <= #1 1'b0;
195
end
196
 
197
 
198
//
199
// rcap2l, rcap2h
200
always @(posedge clk or posedge rst)
201
begin
202
  if (rst) begin
203
    rcap2l <= #1 `OC8051_RST_RCAP2L;
204
    rcap2h <= #1 `OC8051_RST_RCAP2H;
205
  end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_RCAP2H)) begin
206
    rcap2h <= #1 data_in;
207
  end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_RCAP2L)) begin
208
    rcap2l <= #1 data_in;
209
  end else if (!(rclk | tclk) & exen2 & cprl2 & neg_trans) begin
210
    rcap2l <= #1 tl2;
211
    rcap2h <= #1 th2;
212
  end
213
end
214
 
215
 
216
//
217
//
218
always @(posedge clk or posedge rst)
219
begin
220
  if (rst) begin
221
    neg_trans <= #1 1'b0;
222
    t2ex_r <= #1 1'b0;
223
  end else if (t2ex) begin
224
    neg_trans <= #1 1'b0;
225
    t2ex_r <= #1 1'b1;
226
  end else if (t2ex_r) begin
227
    neg_trans <= #1 1'b1;
228
    t2ex_r <= #1 1'b0;
229
  end else begin
230
    neg_trans <= #1 1'b0;
231
    t2ex_r <= #1 t2ex_r;
232
  end
233
end
234
 
235
//
236
//
237
always @(posedge clk or posedge rst)
238
begin
239
  if (rst) begin
240
    tc2_event <= #1 1'b0;
241
    t2_r <= #1 1'b0;
242
  end else if (t2) begin
243
    tc2_event <= #1 1'b0;
244
    t2_r <= #1 1'b1;
245
  end else if (!t2 & t2_r) begin
246
    tc2_event <= #1 1'b1;
247
    t2_r <= #1 1'b0;
248
  end else begin
249
    tc2_event <= #1 1'b0;
250
  end
251
end
252
 
253
endmodule

powered by: WebSVN 2.1.0

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