1 /////////////////////////////////////////////////////////////////////
3 //// Simple Baud Rate Generator ////
6 //// Author: Rudolf Usselmann ////
7 //// rudi@asics.ws ////
10 //// Downloaded from: http://www.opencores.org/cores/sasc/ ////
12 /////////////////////////////////////////////////////////////////////
14 //// Copyright (C) 2000-2002 Rudolf Usselmann ////
15 //// www.asics.ws ////
16 //// rudi@asics.ws ////
18 //// This source file may be used and distributed without ////
19 //// restriction provided that this copyright statement is not ////
20 //// removed from the file and that any derivative work contains ////
21 //// the original copyright notice and the associated disclaimer.////
23 //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ////
24 //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
25 //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
26 //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
27 //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ////
28 //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ////
29 //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ////
30 //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ////
31 //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ////
32 //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ////
33 //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ////
34 //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ////
35 //// POSSIBILITY OF SUCH DAMAGE. ////
37 /////////////////////////////////////////////////////////////////////
41 // $Id: sasc_brg.v,v 1.2 2002/11/08 15:22:49 rudi Exp $
43 // $Date: 2002/11/08 15:22:49 $
50 // $Log: sasc_brg.v,v $
51 // Revision 1.2 2002/11/08 15:22:49 rudi
53 // Fixed a typo in brg
55 // Revision 1.1.1.1 2002/09/16 16:16:40 rudi
66 `include "timescale.v"
72 div0 - is the first stage divider
73 Set this to the desired number of cycles less two
74 div1 - is the second stage divider
75 Set this to the actual number of cycles
77 Remember you have to generate a baud rate that is 4 higher than what
78 you really want. This is because of the DPLL in the RX section ...
81 If your system clock is 50MHz and you want to generate a 9.6 Kbps baud rate:
83 50MHz/38400KHz=1302 or 6*217
84 set div0=4 (6-2) and set div1=217
86 100MHz/38400KHz=2604 or 12*217
87 set div0=10 (12-2) and set div1=217
91 module sasc_brg(clk, rst, div0, div1, sio_ce, sio_ce_x4);
94 input [7:0] div0, div1;
95 output sio_ce, sio_ce_x4;
97 ///////////////////////////////////////////////////////////////////
99 // Local Wires and Registers
108 reg sio_ce, sio_ce_x4;
112 ///////////////////////////////////////////////////////////////////
114 // Boud Rate Generator
117 // -----------------------------------------------------
119 always @(posedge clk)
120 if(!rst) ps <= #1 8'h0;
122 if(ps_clr) ps <= #1 8'h0;
123 else ps <= #1 ps + 8'h1;
125 always @(posedge clk)
126 ps_clr <= #1 (ps == div0); // Desired number of cycles less 2
128 // -----------------------------------------------------
129 // Oversampled Boud Rate (x4)
130 always @(posedge clk)
131 if(!rst) br_cnt <= #1 8'h0;
133 if(br_clr) br_cnt <= #1 8'h0;
135 if(ps_clr) br_cnt <= #1 br_cnt + 8'h1;
137 always @(posedge clk)
138 br_clr <= #1 (br_cnt == div1); // Prciese number of PS cycles
140 always @(posedge clk)
141 sio_ce_x4_r <= #1 br_clr;
143 always @(posedge clk)
144 sio_ce_x4_t <= #1 !sio_ce_x4_r & br_clr;
146 always @(posedge clk)
147 sio_ce_x4 <= #1 sio_ce_x4_t;
149 // -----------------------------------------------------
151 always @(posedge clk)
152 if(!rst) cnt <= #1 2'h0;
154 if(!sio_ce_x4_r & br_clr) cnt <= #1 cnt + 2'h1;
156 always @(posedge clk)
157 sio_ce_r <= #1 (cnt == 2'h0);
159 always @(posedge clk)
160 sio_ce <= #1 !sio_ce_r & (cnt == 2'h0);