The Godfather talking
You can run, but you can't hide.
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 29, 2024, 06:35:57 18:35


Login with username, password and session length


Pages: [1]
Print
Author Topic: UART BaudRate drift calculation on PC side?  (Read 4413 times)
0 Members and 1 Guest are viewing this topic.
xpress_embedo
Active Member
***
Offline Offline

Posts: 173

Thank You
-Given: 122
-Receive: 254


« on: February 13, 2015, 12:41:11 12:41 »

Hello!! all, i am having a device, which sends data to PC using UART, is there any way to calculate the drift in the Baud Rate of the received data.

Lets say, i had written a program in a micro-controller to send some characters to PC using UART communication, but this micro-controller has to face different ranges of temperature and due to which the clock can change and due to this, the Baud Rate can also change.
Is there any software for this purpose or, any other way to to calculate the drift in Baud Rate as compared to actual Baud Rate.
Logged
h0nk
Senior Member
****
Offline Offline

Posts: 257

Thank You
-Given: 226
-Receive: 231



« Reply #1 on: February 13, 2015, 02:20:41 14:20 »

Hello xpress_embedo,

the change of baudrate is direct proportional to the change of oscillator frequency.
You should check the data sheet for You PIC it there are any figures about the depencancy to temperature.
Attached a figure for the internal oscillator of a PIC 12F675.
RS-232 works well if the error is below approx. 4%.
From the figure the error at 0 grad celsius should 2% compared to 25 grad celsius.
For testing send the character 'U' back-to-back in a loop and measure the frequency.
It should be equal to Your baudrate.

To avoid any trouble i would simply use a quartz.

Best Regards
« Last Edit: February 13, 2015, 02:38:48 14:38 by h0nk » Logged
xpress_embedo
Active Member
***
Offline Offline

Posts: 173

Thank You
-Given: 122
-Receive: 254


« Reply #2 on: February 13, 2015, 02:59:14 14:59 »

Actually i am not using PIC micro-controller, one can use any micro-controller, i just want to make a simple Drift Rate Calculator or one can say Error Calculator.
It doesn't matter whether by using any type of crystal i get proper baud rate.
Sending 'U' means sending 0x55 and in Binary 0b01010101.
By Padding Start and Stop Bit the signal will look like the following (LSB is transmitted First)
0(Start) 1(LSB) 0 1 0 1 0 1 0(MSB) 1(Stop)
Suppose the device under test is continuously transmitted 'U' character, and then by measuring the frequency i can calculate the baud rate.
I will use PIC16F877A for frequency measurement.
Is that okay, or i have to do something else also.
Logged
h0nk
Senior Member
****
Offline Offline

Posts: 257

Thank You
-Given: 226
-Receive: 231



« Reply #3 on: February 13, 2015, 03:23:19 15:23 »

Hello xpress_embedo,

most controller derive the baudrate directly from their oscillators either with direct or sometimes fractional dividers.
So no extra calculation for the error should be necessary.

To get the error of Your RS-232 below 2%, the error of the oscillator has the same margins.

A 16F877A with a quartz would be fine to measure this. Also some multimeters and digital scopes offer frequency measurement.

I would recommend to check with a scope, that the frames are really send back-to-back.


Best Regards
Logged
titi
Active Member
***
Offline Offline

Posts: 230

Thank You
-Given: 3807
-Receive: 834



« Reply #4 on: February 13, 2015, 03:33:39 15:33 »

Hi xpress_embedo,

it should be more precise to measure the period or the duration of the pulse high by using the CCP/TIMER1.
Frequency=1/Period

This can helps you:
"PIC­ MCU CCP and ECCP Tips n Tricks" at http://ww1.microchip.com/downloads/en/DeviceDoc/41214a.pdf
Best regards.
Logged
kreutz
Active Member
***
Offline Offline

Posts: 183

Thank You
-Given: 994
-Receive: 125


« Reply #5 on: February 13, 2015, 04:09:29 16:09 »

Also be aware that, due to the baud-rate being generated by means of main clock frequency division, some baud-rates will have less deviation than others at the same temperature. Use one of those and you will have less probability of communication problems. The optimum solution is to have a good quartz crystal/oscillator for the uController clock as per h0nk's suggestion.
Logged
flo0319
Junior Member
**
Offline Offline

Posts: 81

Thank You
-Given: 7
-Receive: 17


« Reply #6 on: February 15, 2015, 01:50:28 13:50 »

In general internal clocks of uC are RC calibrated oscillators and the frequency is 8,12,16 MHz. Unfortunately for UART Baudrate those freq. generate errors.
For example pic16f877 has only external clock and in datasheet can be found a table with different clock configuration and the error generated to each standard baudrate http://ww1.microchip.com/downloads/en/DeviceDoc/39582C.pdf page 114. To avoid this error, can be used the special quartz (designed for serial communication ) like :
    1,8432 MHz (das ist die klassische Frequenz des PC-Baudratengenerators)
    3,6864 MHz
    4,9152 MHz
    6,1440 MHz
    7,3728 MHz
    9,8304 MHz
    11,0592 MHz
    12,2880 MHz
    14,7456 MHz
    18,4320 MHz
    19,6608 MHz
    22,1184 MHz

but this will not solve your BR drift  during temperature variation
Logged
solutions
Hero Member
*****
Offline Offline

Posts: 1826

Thank You
-Given: 656
-Receive: 905



« Reply #7 on: February 15, 2015, 05:45:18 17:45 »

UARTs work by OVERSAMPLING, around 8x, 10X, or 16x, depending on device, if I remember it right...the second letter in the acronym is ASYNCHRONOUS. That means clock drift DOES NOT MATTER because each start of packet resets the sampling point.

So, unless you are using slang for a USART, which does require synchronization, in most UART protocols the clock errors on the send or receive side are irrelevant if the clocks are kept within a few percent of the ideal baud rate. It is left to the reader to do the math.

If you are sending a continuous data stream and not packets or single characters, over a UART you are abusing the protocol, particularly since there is no clock encoding or line balancing, just bit banging.

But you said you are sending characters. That implies a bracketing of start/stop bits and a minimalist set of bits between them. Should be NO PROBLEM.
« Last Edit: February 15, 2015, 05:50:44 17:50 by solutions » Logged
h0nk
Senior Member
****
Offline Offline

Posts: 257

Thank You
-Given: 226
-Receive: 231



« Reply #8 on: February 16, 2015, 10:11:05 22:11 »

It should be equal to Your baudrate.

should be:
It should be half of Your baudrate.

Best Regards


PIC16F819 running on internal Oscillator at 4 MHz with a baudrate of approx 38400:



Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC