The Godfather talking
This is god damn my place! Capisci?
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 07, 2016, 11:18:58 23:18


Login with username, password and session length


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

Posts: 153

Thank You
-Given: 103
-Receive: 188


WWW
« on: February 13, 2015, 01:41:11 13: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
Active Member
***
Offline Offline

Posts: 120

Thank You
-Given: 89
-Receive: 83



« Reply #1 on: February 13, 2015, 03:20:41 15: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, 03:38:48 15:38 by h0nk » Logged
xpress_embedo
Active Member
***
Offline Offline

Posts: 153

Thank You
-Given: 103
-Receive: 188


WWW
« Reply #2 on: February 13, 2015, 03:59:14 15: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
Active Member
***
Offline Offline

Posts: 120

Thank You
-Given: 89
-Receive: 83



« Reply #3 on: February 13, 2015, 04:23:19 16: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: 192

Thank You
-Given: 1434
-Receive: 705



« Reply #4 on: February 13, 2015, 04:33:39 16: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
Junior Member
**
Offline Offline

Posts: 68

Thank You
-Given: 179
-Receive: 25


« Reply #5 on: February 13, 2015, 05:09:29 17: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: 82

Thank You
-Given: 7
-Receive: 16


« Reply #6 on: February 15, 2015, 02:50:28 14: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: 1446

Thank You
-Given: 590
-Receive: 851



« Reply #7 on: February 15, 2015, 06:45:18 18: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, 06:50:44 18:50 by solutions » Logged
h0nk
Active Member
***
Offline Offline

Posts: 120

Thank You
-Given: 89
-Receive: 83



« Reply #8 on: February 16, 2015, 11:11:05 23: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