EmbeddedRelated.com
Forums

Exact 115200 bps baud rate generation in LPC 2378

Started by pravin falcao March 12, 2009
Hi,

I need to generate exact 115200 bps baud rate for LPC 2378. Is it possible to generate? If yes then please provide the details.

BR,
Pravin Falcao



An Engineer's Guide to the LPC2100 Series

> Hi,
>
> I need to generate exact 115200 bps baud rate for LPC 2378. Is it possible
> to generate? If yes then please provide the details.

Have a look in the user manual, in the chapter about the UART. There's a set
of registers to configure a fractional baud rate divider in case an integer
divider is not accurate enough. Some people seem to have problems with this
though (I never tried it).

Probably the easiest way is to use a crystal that is an integer multiple
of (16 * baud rate), like 14.746 MHz.

Kind regards,
Bertrik

----Original Message----
From: l...
[mailto:l...] On Behalf Of pravin falcao
Sent: 12 March 2009 07:17 To: l...
Subject: [lpc2000] Exact 115200 bps baud rate generation in
LPC 2378

> Hi,
>
> I need to generate exact 115200 bps baud rate for LPC
> 2378. Is it possible to generate? If yes then please
> provide the details.

There's a nice page here to work out the settings for the fractional
baud rate generator:
http://prototalk.net/forums/showthread.php?t

--
Tim Mitchell

Hi,

I have slightly improved the search algorithm I posted some time ago to
allow for smaller resulting baud rate. It can be used in run-time. I think
it finds the best possible value, whereas the algorithm on the page seems to
only get very close, e.g. for 12'000'000Hz and 9600 the page gives resulting
baud-rate 9603 whereas my algorithm finds settings for 9601.

u32 findDivisorAndPrescale(u32 frequency, u32 baudRate, bool
allowSmallerBaudRate, u32& mulVal, u32& divAddVal)
{
// The FDR is set to prescale the UART_CLK with factor M/(M+D),
// where both M and D are in <0, 15>. This is to achieve smaller
// error when calculating the divisor (the UnDL).
// UART_CLK M
// UARTbaudrate = --------- x -----
// 16 x UnDL (M+D)

u32 divisor = frequency / (16 * baudRate);
u32 baudRateError = (frequency / (16 * divisor)) - baudRate;
if (allowSmallerBaudRate)
{
u32 otherDivisor = divisor + 1;
u32 otherBaudRateError = baudRate - (frequency / (16 *
otherDivisor));
if (baudRateError > otherBaudRateError)
{
divisor = otherDivisor;
baudRateError = otherBaudRateError;
}
}
mulVal = 1;
divAddVal = 0;
for (u32 mv = 0; ++mv < 16;)
{
for (u32 dav = 0; ++dav < 16;)
{
u32 prescaledClock = (frequency * mv) / (16 * (mv + dav));
u32 newDivisor = prescaledClock / baudRate;
if (newDivisor != 0)
{
u32 newBaudRateError = (prescaledClock / newDivisor) -
baudRate;
if (baudRateError > newBaudRateError)
{
divisor = newDivisor;
mulVal = mv;
divAddVal = dav;
baudRateError = newBaudRateError;
}
}
if (allowSmallerBaudRate)
{
++newDivisor;
u32 newBaudRateError = baudRate - (prescaledClock /
newDivisor);
if (baudRateError > newBaudRateError)
{
divisor = newDivisor;
mulVal = mv;
divAddVal = dav;
baudRateError = newBaudRateError;
}
}
}
}
// u32 calculatedBaudRate = (frequency * mulVal) / ((16 * divisor) *
(mulVal + divAddVal));
return divisor;
}

With regards,
Jan

...Curious whether I'll receive my own post this time...

----- Original Message -----
From: "Tim Mitchell"
To:
Sent: Thursday, March 12, 2009 10:11 AM
Subject: RE: [lpc2000] Exact 115200 bps baud rate generation in LPC 2378
----Original Message----
From: l...
[mailto:l...] On Behalf Of pravin falcao
Sent: 12 March 2009 07:17 To: l...
Subject: [lpc2000] Exact 115200 bps baud rate generation in
LPC 2378

> Hi,
>
> I need to generate exact 115200 bps baud rate for LPC
> 2378. Is it possible to generate? If yes then please
> provide the details.

There's a nice page here to work out the settings for the fractional
baud rate generator:
http://prototalk.net/forums/showthread.php?t

--
Tim Mitchell

--- In l..., "Jan Vanek" wrote:
>
> Hi,
>
> I have slightly improved the search algorithm I posted some time ago to
> allow for smaller resulting baud rate. It can be used in run-time. I think
> it finds the best possible value, whereas the algorithm on the page seems to
> only get very close, e.g. for 12'000'000Hz and 9600 the page gives resulting
> baud-rate 9603 whereas my algorithm finds settings for 9601.
>
> u32 findDivisorAndPrescale(u32 frequency, u32 baudRate, bool
> allowSmallerBaudRate, u32& mulVal, u32& divAddVal)
> {
> // The FDR is set to prescale the UART_CLK with factor M/(M+D),
> // where both M and D are in <0, 15>. This is to achieve smaller
> // error when calculating the divisor (the UnDL).
> // UART_CLK M
> // UARTbaudrate = --------- x -----
> // 16 x UnDL (M+D)
>
> u32 divisor = frequency / (16 * baudRate);
> u32 baudRateError = (frequency / (16 * divisor)) - baudRate;
> if (allowSmallerBaudRate)
> {
> u32 otherDivisor = divisor + 1;
> u32 otherBaudRateError = baudRate - (frequency / (16 *
> otherDivisor));
> if (baudRateError > otherBaudRateError)
> {
> divisor = otherDivisor;
> baudRateError = otherBaudRateError;
> }
> }
> mulVal = 1;
> divAddVal = 0;
> for (u32 mv = 0; ++mv < 16;)
> {
> for (u32 dav = 0; ++dav < 16;)
> {
> u32 prescaledClock = (frequency * mv) / (16 * (mv + dav));
> u32 newDivisor = prescaledClock / baudRate;
> if (newDivisor != 0)
> {
> u32 newBaudRateError = (prescaledClock / newDivisor) -
> baudRate;
> if (baudRateError > newBaudRateError)
> {
> divisor = newDivisor;
> mulVal = mv;
> divAddVal = dav;
> baudRateError = newBaudRateError;
> }
> }
> if (allowSmallerBaudRate)
> {
> ++newDivisor;
> u32 newBaudRateError = baudRate - (prescaledClock /
> newDivisor);
> if (baudRateError > newBaudRateError)
> {
> divisor = newDivisor;
> mulVal = mv;
> divAddVal = dav;
> baudRateError = newBaudRateError;
> }
> }
> }
> }
> // u32 calculatedBaudRate = (frequency * mulVal) / ((16 * divisor) *
> (mulVal + divAddVal));
> return divisor;
> }
>
> With regards,
> Jan
>
> ...Curious whether I'll receive my own post this time...
>
> ----- Original Message -----
> From: "Tim Mitchell"
> To:
> Sent: Thursday, March 12, 2009 10:11 AM
> Subject: RE: [lpc2000] Exact 115200 bps baud rate generation in LPC 2378
> ----Original Message----
> From: l...
> [mailto:l...] On Behalf Of pravin falcao
> Sent: 12 March 2009 07:17 To: l...
> Subject: [lpc2000] Exact 115200 bps baud rate generation in
> LPC 2378
>
> > Hi,
> >
> > I need to generate exact 115200 bps baud rate for LPC
> > 2378. Is it possible to generate? If yes then please
> > provide the details.
>
> There's a nice page here to work out the settings for the fractional
> baud rate generator:
> http://prototalk.net/forums/showthread.php?t
>
> --
> Tim Mitchell
>
Hi to all
I've used this file for calculating the right baud rate for my uarts :

http://www.standardics.nxp.com/support/documents/microcontrollers/xls/lpc2000.uart.baudrate.calculator.xls

Franco

On Thu, 12 Mar 2009, Tim Mitchell wrote:

> There's a nice page here to work out the settings for the fractional
> baud rate generator:

> http://prototalk.net/forums/showthread.php?t

Thanks for this! The only other thing I'd seen before was a Win executable.

-Kenny

--
Kenneth R. Crudup Sr. SW Engineer, Scott County Consulting, Los Angeles
O: 3630 S. Sepulveda Blvd. #138, L.A., CA 90034-6809 (888) 454-8181
NXP also has an Excel spreadsheet for calculating baud rates on the LPC2000 family. Tt supports calculating with or without franctional mode. See the link below.

http://www.standardics.nxp.com/support/documents/microcontrollers/xls/lpc2000.uart.baudrate.calculator.xls

Frank
--- In l..., Kenneth Crudup wrote:
> On Thu, 12 Mar 2009, Tim Mitchell wrote:
>
> > There's a nice page here to work out the settings for the fractional
> > baud rate generator:
>
> > http://prototalk.net/forums/showthread.php?t
>
> Thanks for this! The only other thing I'd seen before was a Win executable.
>
> -Kenny
>
> --
> Kenneth R. Crudup Sr. SW Engineer, Scott County Consulting, Los Angeles
> O: 3630 S. Sepulveda Blvd. #138, L.A., CA 90034-6809 (888) 454-8181
>