CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Possible Baud Rate Tolerance Issue
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MotoDan



Joined: 30 Dec 2011
Posts: 55

View user's profile Send private message

PostPosted: Wed Dec 03, 2014 10:05 pm     Reply with quote

Thanks PCM for the terrific detective work on finding a high tolerance internal osc part! It looks like the PIC16F1717 will drop right in. I was not aware that higher precision parts were offered by Microchip. Given the amount of trouble a wider tolerance oscillator can cause, I would think Microchip would make all of their parts using higher tolerance internal oscillators. What good is an MCU with built-in UART and 16 MHZ oscillator if it won't perform within it's specifications?

Well, lesson learned! Now I just need to figure out the best way to fix the 2,000 units that have been built and shipped! Replacing the PIC for these units (4,000 PICs) is not a very viable solution. Looks like the best I can do is come up with a way to compensate for the inaccuracies of the internal osc.

Thanks again to every one who offered their expertise!
newguy



Joined: 24 Jun 2004
Posts: 1913

View user's profile Send private message

PostPosted: Wed Dec 03, 2014 11:10 pm     Reply with quote

Our existing product line was designed starting in 1998. Over the years, needs were identified and things were added to address the issues that needed to be addressed.

One of the issues that was tagged as a shortcoming of our system was a way of measuring position (angle) as one of our components moved. My predecessor found a company that makes nothing but inclinometers and selected a model which he then "shoe-horned" (literally) into our system.

These particular inclinometers run $300 each and they do work well most of the time. However, they lack a crystal.

Once my predecessor was let go, it fell to me to figure out why we kept losing angles. And it didn't take long.

We have a generic processor board, with a crystal, getting serial data from this inclinometer module, which lacks a crystal. And our equipment runs at ambient temperatures that range from -40C to +120C (ish). Since the inclinometers lack a crystal, they don't have a reliable clock, particularly at the upper end of the temperature range. Temperatures change, the clock drifts, and we "lose" angles.

I designed a drop-in replacement with a crystal that we had manufactured for about $22 each delivered. We have no problem with missing/dropped angles with our version.

Long story short: when it comes to communication between distinct modules, do your best to demonstrate or iterate to your higher ups that it's well worth the extra $.50 per unit to assure reliable data links. Another thing I've learned is never to trust anyone that tells you that "don't worry about temperature, we're never going to run these outside." They will. They won't think of you when the product works. They will, however, think of you if it fails. ...Not favourably.
MotoDan



Joined: 30 Dec 2011
Posts: 55

View user's profile Send private message

PostPosted: Wed Dec 03, 2014 11:19 pm     Reply with quote

Well said newguy. Reminds me of that old adage: “One 'aw, sh*t' wipes out a thousand 'attaboys'!
Ttelmah



Joined: 11 Mar 2010
Posts: 19786

View user's profile Send private message

PostPosted: Thu Dec 04, 2014 1:35 am     Reply with quote

I think on the low accuracy internal oscillators the thought is that as a designer you make the decision to have the cheap oscillator and work with it's problems (you can in most cases for instance trim the master clock to synchronise to an incoming signal), or you add an external oscillator. Things like laser trimming add cost. It's noticeable though that the automated systems are getting so good, that this cost is getting ever lower. Smile
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Dec 04, 2014 4:58 am     Reply with quote

temtronic wrote:
Another possible thing to try is to reduce from 19k2 down to say 9600. Slower speeds are more 'forgiving'.
I've always wondered about this suggestion. When the error is caused by a large percentage clock error, then this percentage value will be the same for every baud rate, even extreme slow rates should suffer.
The only improvement I can see is for the signal edges being better defined on slower baudrates but that means you have a driver / wiring problem and not a pure clock problem.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Thu Dec 04, 2014 5:28 am     Reply with quote

ckielstra wrote:
temtronic wrote:
Another possible thing to try is to reduce from 19k2 down to say 9600. Slower speeds are more 'forgiving'.
I've always wondered about this suggestion. When the error is caused by a large percentage clock error, then this percentage value will be the same for every baud rate, even extreme slow rates should suffer.


With hardware UARTs there are two main sources of baud rate error. There is a fixed error due to to quantisation of the baudrates due to not using a baud rate related clock frequency. Most people use non-baud related clocks, such as 8MHz, 10Mhz, 64MHz, etc., most of the time. There is also the variable error related to clock drift/inaccuracy. This error changes (mainly) with temperature and supply voltage.

With software serial there are potentially more, and more unpredictable sources of error if interrupts are allowed when serial comms are active. Also the baudrate quantisation of software comms is significantly worse than hardware due to the much lower instruction clock rate. This can make the fixed error significantly higher than with a hardware UART clocked from the same source.

In practical use these sources can add up, so a +1.5% fixed quantisation error and a +2.5% clock drift give +4% overall error, which is no good, while individually both are acceptable.

In general - there are some anomalies - the fixed quantisation error is lower for lower baud rates from any given clock. So, a lower baud rate generally does have a lower overall baud rate error.

Also, it easy to forget that the error is not one end only, it's end to end. There will be some clock drift at both ends, so an error of +2% at one end will combine with say a -2% error at the other and the serial link won't work reliably, or even necessarily at all. Don't think that PCs are perfect either - they drift too - and many PCs now have to have USB to serial adaptors, which have their own clock issues, though I suspect they need to be pretty good (i.e. better than the needs of async serial) for the USB to work.

So, yes, its generally is easier to get lower baud rates to work.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Dec 04, 2014 2:40 pm     Reply with quote

To add to an earlier post by pcm_programmer:
specific to the UART based error independent of any master clock frequency error.

Quote:


Maxim says +/- 2% baud rate tolerance between transmitter and receiver:
http://pdfserv.maximintegrated.com/en/an/AN2141.pdf

Silicon labs says +/- 2% (or +/- 2.5%):
http://www.silabs.com/Support%20Documents/Software/Serial_Communications.pdf

ST says 5% (aka +/- 2.5%)
http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/CD00105092.pdf


the math behind it is based on a 16x baudrate master clock coupled with
"half rate bit slicing" to test for each ONE or ZERO in the stream.

Whatever the master baud - the PEAK to peak error implicit in a mismatched baud master clock is always 1/16 or 6.25%

so the average max error is then half of that or +/- 3.12% -rounded down to 3% plus or minus a skosh. the error band is implied by the bit-test oversample frequency ratio employed in the receiver bit shift circuitry , to the actual baud rate ( which will always be a constant such as 16 ).-- and nothing else.
You won't be bitten by allowing a 1.5% (absolute) baud error in crystal based systems.. Very Happy Very Happy Very Happy
SuperDave



Joined: 22 May 2008
Posts: 63
Location: Madison, TN

View user's profile Send private message Visit poster's website

PostPosted: Sun Dec 14, 2014 7:20 pm     Reply with quote

Here's a piece that I didn't see in the discussion.

I've learned the hard way to "wire it right". You talk about 1 wire but there must be two, one of which is obviously ground and so obvious we forget about it. Is ground ground everywhere? Current pulled thru a ground connection causes ground at one end to be a different potential from the other and can cause really crazy looking problems especially if the current drawn varies significantly over time. So that's one thing to check. Put your scope ground on the power supply output ground and probe all the other 'ground' connections.

Also I would suggest, again assuming you have only one supply that wired to both units, that the wire from one unit to the other be either a twisted pair or shielded single with the ground side connected on only one end. This should get rid of potential radiated interference. (It might work on your bench but not some other place with a clear channel AM station nearby.)
SuperDave



Joined: 22 May 2008
Posts: 63
Location: Madison, TN

View user's profile Send private message Visit poster's website

PostPosted: Sun Dec 14, 2014 7:28 pm     Reply with quote

Another thought. Fix it in firmware.

At start up have one unit output a "known" but perhaps inaccurate frequency on the line and have the other unit measure that frequency and adjust the use delay statement so the devices agree. Both baud rates might then be WAY out of tolerance but they would agree with each other quite closely.

Perhaps this happens at start up only if "switch A" is held or a temporary jumper is installed as part of the production test protocol with the new use delay value stored in eeprom.

Firmware updates on existing units are usually simpler than hardware updates.
MotoDan



Joined: 30 Dec 2011
Posts: 55

View user's profile Send private message

PostPosted: Sun Dec 14, 2014 7:47 pm     Reply with quote

Thanks for your reply Super Dave. I implemented an Autobaud procedure that is run every time the remote Slave device is plugged in. The Master is always sending the same size packet which is terminated with a LF. My routine sweeps across a range of baud rate settings until the valid packet is received. It then bumps the baud rate slightly to put it close to the center of that being transmitted by the Master. This only takes a couple of seconds and so far seems to be very reliable. Just as you suggest, the baud rates are no longer standard (19.2kb in my case) due to the wide tolerance of the int osc, but they are the same between Master and Slave.
Ttelmah



Joined: 11 Mar 2010
Posts: 19786

View user's profile Send private message

PostPosted: Mon Dec 15, 2014 4:38 am     Reply with quote

Well done.

This is actually a variation of the approach suggested by Microchip. They suggest modifying the OSCTUNE value, rather than the BRG, since this gives finer adjustments.
MotoDan



Joined: 30 Dec 2011
Posts: 55

View user's profile Send private message

PostPosted: Mon Dec 15, 2014 8:36 am     Reply with quote

I originally thought about trimming the int osc, but could not find a way to do it. The datasheet refers to using OSCTUNE for this, but there is no other mention of the register. It doesn't look like it exists in the PIC16F1517.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Dec 15, 2014 9:58 am     Reply with quote

caution: when sweeping,
the value you select may still be at or close to a marginal error point since in reality you could STILL be off by 3%
and with internal osc we have the chance of thermal frequency drift.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 15, 2014 11:37 am     Reply with quote

asmboy wrote:
caution: when sweeping,
the value you select may still be at or close to a marginal error point

He said that he adjusts for that:
MotoDan wrote:

My routine sweeps across a range of baud rate settings until the valid
packet is received. It then bumps the baud rate slightly to put it
close to the center of that being transmitted by the Master

Presumably his adjustment factor is about +2.5%.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group