Calculation (SCI baud rate)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Calculation (SCI baud rate)

9,105 Views
CCandido
Contributor V
Hi,
I always used in the GP32 9600baud.  but I want to use others baud_rate and in agreement the calculation of datasheet I am not obtaining to make formulates it for all baud_rate.
 
init_sci( baud );
----------------------------------------------
my_Fbus = 8000000mhz
SCC1 = 0x40;    
SCC2 = 0x2C;
SCBR = 0x30; = 9600baud
----------------------------------------------
calculation no run !!
SCBR = (unsigned char)((8000000UL /2 )  /baud / 64 *1 *4);
 
-------------------------------------------------
datasheet :

          Fbus = XTAL/4 2.4576 MHz *

 Baud Rate = -------------------- = ---------- = 9600 bps *

               64 x SCP1:0 x SCR2:0 64 x 1 x 4 *

SCBR = 0x02; /* Select a baud rate of 9600 bps with Fbus = 2.4576 MHz */

 

 

thanks

 

Labels (1)
0 Kudos
12 Replies

1,085 Views
peg
Senior Contributor IV

Hi CCandido,

Not real sure I understand your question, but I will throw this at you.

With the GP, to select the baudrate you have two things to adjust, the Prescaler and the BR Divisor.

What type of bus frequency you have determines the prescaler i.e.

if you have an even high frequency xtal, like 32MHz for 8MHz then you use 11 for the prescaler to give you a standard baudrate. Then you can use the divisor to get lower stadard baudrates than that.

If you use the PLL to get frequencies like 7.3728MHz then you use 01 or 00 for 4.9MHz.

So its no good trying to do a calculation in one go.

Just lock in a Prescaler based on your buss frequency then allow selection of the allowable range of standard baudrates using the baudrate divisor.

hope this helps

Peg

 

0 Kudos

1,085 Views
CCandido
Contributor V
my Fbus = 8mhz ( xtal=32768kh -> PLL up 8mhz)
 
thanks.
0 Kudos

1,085 Views
peg
Senior Contributor IV

Yes, so 8M / 64 / 13 = 9615baud

then you can only go down from here to 4800, 2400, 1200 etc

If you want a better range use 7.3728MHz from PLL

Then 7.3728M / 3 / 1 = 38,400baud.

Now you can use the divisor to get 19,200, 9600, 4800 etc

BR Peg

 

0 Kudos

1,085 Views
rocco
Senior Contributor II
. . . and are you sure your baudrate generator is running from the PLL?

On the GP32, bit-0 of the CONFIG2 register, "SCIBDSRC", selects which clock is the source for the baud rate generator. If it is zero (default), your external oscillator frequency is used, instead of your bus clock. That will give you a really low baud rate.

I use this feature to get 500 KBaud from the GP32 SCI.

Message Edited by rocco on 04-14-200610:18 PM

0 Kudos

1,085 Views
CCandido
Contributor V
my 9600 baud =OK
my_Fbus 8mhz
CONFIG2= 0x01;
SCC1 = 0x40;    
SCC2 = 0x2C;
SCBR = 0x30;  9600baud
------------------------------------------
my problem is, to create one funçao that it configures others baud_rate.
ex:
 
Init_sci ( 57600 );
 
void Init_sci ( ulong baud ){
 
????????
 
}

 
0 Kudos

1,085 Views
rocco
Senior Contributor II
I'm sorry, I misunderstood the question. I thought you were having trouble getting the baud rate you calculated.

As Peg pointed out, you can't get baud rates like 57600 with a 8 MHz bus clock. But you can may be able to vary the bus clock with the PLL, as long as the rest of your firmware can tolerate it.

I do auto-baud detect through a table. It only modifies the SCBR register, but I saw code on the Freescale site that selects bus frequencies by loading the PLL from a table. You can get any baud rate by combining the two.

Calculating the values for both the PLL and SCBR directly from a baudrate value would be possible, but it may be rather tedious.
0 Kudos

1,085 Views
CCandido
Contributor V
HI,
I only cited PLL to esplcar that I use 8mhz of buss.  oque I want I am to make one funçâo I to change mine baud_rate as mine I to need yes the calculation I go to be based on 8mhz.
 
init_sci( baud );
 
translated language: Portuguese for English.
Edit by Carlos Candido from Brasil. 
0 Kudos

1,085 Views
peg
Senior Contributor IV

Hi Carlos,

If you stay with a fixed buss frequency there is only so many baudrates you can achieve and many of these will be non-standard.

I have created a table that lists all of the possible baudrates for buss frequencies of 8MHz and for 7.3728MHz

 ,   ,8000000,7372800
64,   , 125000, 115200
 1,  1, 125000, 115200
 1,  2,  62500,  57600
 1,  4,  31250,  28800
 1,  8,  15625,  14400
 1, 16,   7813,   7200
 1, 32,   3906,   3600
 1, 64,   1953,   1800
 1,128,    977,    900
 3,  1,  41667,  38400
 3,  2,  20833,  19200
 3,  4,  10417,   9600
 3,  8,   5208,   4800
 3, 16,   2604,   2400
 3, 32,   1302,   1200
 3, 64,    651,    600
 3,128,    326,    300
 4,  1,  31250,  28800
 4,  2,  15625,  14400
 4,  4,   7813,   7200
 4,  8,   3906,   3600
 4, 16,   1953,   1800
 4, 32,    977,    900
 4, 64,    488,    450
 4,128,    244,    225
13,  1,   9615,   8862
13,  2,   4808,   4431
13,  4,   2404,   2215
13,  8,   1202,   1108
13, 16,    601,    554
13, 32,    300,    277
13, 64,    150,    138
13,128,     75,     69

I have highlighted all the standard baudrates

As I said before you can try and calculate it if you like but by the time you round it off and indicate the ones you can't acheive etc you will be better off with a simple switch statement.

int init_sci(baud){

switch (baud){

case 115200:

SCBR = 0x00;

break;

case 57600;

SCBR = 0x01;

etc

default:

return -1;

}

return 0;

}

BR Peg

 

Message Edited by peg on 04-16-200610:57 AM

0 Kudos

1,085 Views
CCandido
Contributor V
Hi,
Thanks peg and to the others for having helped me. 
 with fbuss_8mhz really ai does not function I moved of 8 for 7372800 functioned perfect.
 now I do not know because he does not function with 8mhz I I tried but, I gave many errors.  but, important that now he functions.  e khz that I lost does not go to make lack.
 
Thanks==Obrigado.
 
Edit by Carlos.
 
soccer worldcup brasil 06. 
0 Kudos

1,085 Views
peg
Senior Contributor IV

Hi Carlos,

Are you trimming the ICG?

At 8MHz there is already a baudrate error and lack of trim could make it worse.

At 7.3MHz you have exact baudrate and the lack of trim may not be enough to stop it working.

In the future could you include the original text Portuguese because I am struggling with the translated versions.

Go the socceroos!

Adeus

Peg

 

0 Kudos

1,085 Views
peg
Senior Contributor IV

Hi all,

Just today I flashed a board (GT16) and my serial comms didn't work.

After some fiddling I found I forgot to trim the ICG. Once trimmed it worked.

Then I did some experimenting and found that inside about +/- 7% a PC terminal can communicate with virtually no errors and just outside 7% you get about 1 garbled char in 5.

The greater majority of trims required that I have seen fall over a slightly larger spread than this.

Just something to keep in mind!

BR Peg

I guess I should add this was at 9600 baud.

Message Edited by peg on 04-19-200608:55 PM

0 Kudos

1,085 Views
peg
Senior Contributor IV

Hi,

Like I said before the maximum standard baudrate you can achieve with a 32k xtal and a 8M buss is 9600 baud.

You could use a switch statement to set the divisor for the std baudrates below this I guess.

BR Peg

 

0 Kudos