Author Topic: smart auto-baud algorithm?  (Read 15554 times)

0 Members and 2 Guests are viewing this topic.

Offline ralphdTopic starter

  • Frequent Contributor
  • **
  • Posts: 445
  • Country: ca
    • Nerd Ralph
smart auto-baud algorithm?
« on: June 07, 2015, 06:59:12 pm »
Since the problem is >30 years old, I thought by now someone would have come up with the Holy Grail of autobaud algorithms.  Assuming 8N1 human readable ASCII, I think it is possible to detect the baud rate between 9600 and 115,200 after a single character.  None of the algorithms I have found take advantage of the fact that the 9th bit is always 0 and the 10th bit is always 1 for stop.  It also looks like the shortest run of ones or zeros is never more than 2 bit times, and there will always be an odd number of 0 or 1 bits, with the other count being even.
Unthinking respect for authority is the greatest enemy of truth. Einstein
 

Offline John_ITIC

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: us
  • ITIC Protocol Analyzers
    • International Test Instruments Corporation
Re: smart auto-baud algorithm?
« Reply #1 on: June 07, 2015, 10:43:19 pm »
I have worked on industrial serial communications auto-baud detection systems in the past. We sent a "spew" pattern of known data that was check-summed at the end. The receiver simply went through the available baud rates to see which baud rate resulted in valid data and check sum. If garbage was received, the receiver FIFO was flushed, the speed changed and the reception was attempted again. This was fairly simple so could also be implemented in an FPGA, up to several Mbit/second.

I think your actual implementation entirely depends on the protocol you are using on top of the basic serial protocol.

/John.
Pocket-Sized USB 2.0 LS/FS/HS Protocol Analyzer Model 1480A with OTG decoding.
Pocket-sized PCI Express 1.1 Protocol Analyzer Model 2500A. 2.5 Gbps with x1, x2 and x4 lane widths.
https://www.internationaltestinstruments.com
 

Offline ralphdTopic starter

  • Frequent Contributor
  • **
  • Posts: 445
  • Country: ca
    • Nerd Ralph
Re: smart auto-baud algorithm?
« Reply #2 on: June 08, 2015, 12:18:19 am »
I'm looking for a generic auto-baud algorithm.
Something similar to spritesmods, but that only eats the first character.
http://spritesmods.com/?art=autobaud&page=1
Unthinking respect for authority is the greatest enemy of truth. Einstein
 

Offline coppice

  • Super Contributor
  • ***
  • Posts: 10289
  • Country: gb
Re: smart auto-baud algorithm?
« Reply #3 on: June 08, 2015, 01:11:46 am »
Autobauding when the mark space ratio of the signal is accurate is pretty easy. The problems come when the mark space ratio is distorted. FSK modems are particularly bad for this, but lots of channels used for serial data cause some distortion.
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2860
  • Country: nz
Re: smart auto-baud algorithm?
« Reply #4 on: June 08, 2015, 02:53:59 am »
Auto-bauding quickly off of readable characters is possible if you *assume* that the the shortest change you see is indicative of the bit time, and that characters are sent back-to-back.

Framing is harder. Imagine that you connected to a serial port using software flow control and saw the following bits streaming down the wire...

...01010101010101010101010101010100010101010101010101....

This is a valid sequence of bits for lots of 'U's in 8N1, with one 'Q', in the middle

...01010101 0101010101 0101010101 0100010101 0101010101 01....

it is also a valid sequence for 'U's with a 'T' in the middle.

...0101010101 0101010101 0101010101 0001010101 0101010101....

And it could also be taken as 'U's with an 'E' in the middle.

If you came in on the middle of that conversation you would be lost until something other than 'U's, 'T's, 'E's or 'Q's were transmitted (or the line became idle for a short while)....

Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4660
  • Country: us
Re: smart auto-baud algorithm?
« Reply #5 on: June 08, 2015, 08:36:46 am »
I've seen "hardware autobaud" features described for some modern UART peripherals.
I'm not sure that it's an interesting problem on a microcontroller.  Just start the pins in GPIO mode and time the start bit.  If there's a specific autobaud character, you can confirm using the rest of the bits.  If not, you could consider timing the whole character...

Quote
the problem is >30 years old
It's not.  30 years ago, the problem was different (110 to 1200bps?)  Each time dialup modems got faster, the problem changed (you'll note that I'm being charitable making 1200bps available in 1985 :-))  We used to be happy with an autobaud that did 300-19200bps in two RETURNS (well, one, plus a second to make sure.)  Then 56k modems with compression came along, and 115200bps became a popular speed (and also, modems could configured the serial speed separate from the modulation/etc anyway, so you just locked them to the top comm speed, and made sure you had hardware flow control.)

The usual problem is not so much that you can't figure out the speed of traffic coming in based on the traffic, but that you don't have driver-level support, and you have to guess based on the traffic you get THROUGH YOUR EXISTING DRIVER AND OS.  After all, if you set the uart to max speed, you should get a unique sequence of characters and errors for any character at a lower speed.  But most drivers will discard the errors, and very few will report them in-sequence with the data.  (and, you may not have buffering turned on when those first characters arrive, causing you to miss some of them.
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 14787
  • Country: gb
    • Mike's Electric Stuff
Re: smart auto-baud algorithm?
« Reply #6 on: June 08, 2015, 08:47:11 am »
In practice I suspect that in many cases, problems due to mis-autobauding are probably more likely than the problem of just manually setting it, with trial and error if necessary.
At the very least you should probaby have a manually instigated "learn" mode, or be clever about when you attempt to autobaud as opposed to using the last value you saw.
Trying to do it through a UART is certainly fraught with problems due to loss of information and sometimes sketchy info on how a particular UART handles errors.
 
Probably the most reliable would be if you could sample bits at >2x the maximum rate, then apply the bitstream to a virtual UART at various baudrates and choose the one that gave the best match.

Of course if you can guarantee a fixed initial character it can be way easier. If that first character is a 00 byte you could autobaud over an 8:1 range with a single byte into a UART set to the lowest rate and count the number of ''0" bits in the result.
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline bktemp

  • Super Contributor
  • ***
  • Posts: 1616
  • Country: de
Re: smart auto-baud algorithm?
« Reply #7 on: June 08, 2015, 09:04:55 am »
If the auto-baud character is known, then it is easy. If not then it may not work at all:
The worst case are the characters 0x55 and 0xF0.
The first one transmits as 0101010101 the other one as 0000011111. If only one of these characters is transmitted continuously, it is impossible to tell if it the first one with the correct baudrate detected or the second one with 1/5 baudrate detected.
Most of the autobaud functions use 0x55 as the first character. It can also be used for FSK based transmissions followed by 0xFF to assure correct framing of the following data.

For a autobaud function in a logic analyser software I created a historgram of all bit lengths found and then tried to find the shortest bit length that matched the UART framing rules like no more than 10 zeros before at least 1 high is inserted. This is not really usable on a small microcontroller because it analyses all data before decoding it, but works really well in the PC based software.
 

Offline coppice

  • Super Contributor
  • ***
  • Posts: 10289
  • Country: gb
Re: smart auto-baud algorithm?
« Reply #8 on: June 08, 2015, 09:06:29 am »
I've seen "hardware autobaud" features described for some modern UART peripherals.
I think that addition has been driven the Lin bus. You really need hardware autobaud to support that efficiently.
 

Offline ralphdTopic starter

  • Frequent Contributor
  • **
  • Posts: 445
  • Country: ca
    • Nerd Ralph
Re: smart auto-baud algorithm?
« Reply #9 on: June 08, 2015, 12:02:17 pm »
I'd like something like the spritesmods project that can plug into a standard USB-ttl dongle.  My current solution is to use a logic analyzer which does baud rate analysis, then set my terminal program to the right baud rate.
And that only works for standard baud rates unless I'm on linux.  A baud rate converter module would also allow reading the funky ~70kbps boot output of the esp8266 on computers that don't support that baud rate.
Unthinking respect for authority is the greatest enemy of truth. Einstein
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 14787
  • Country: gb
    • Mike's Electric Stuff
Re: smart auto-baud algorithm?
« Reply #10 on: June 08, 2015, 12:09:10 pm »
I'd like something like the spritesmods project that can plug into a standard USB-ttl dongle.  My current solution is to use a logic analyzer which does baud rate analysis, then set my terminal program to the right baud rate.
And that only works for standard baud rates unless I'm on linux.  A baud rate converter module would also allow reading the funky ~70kbps boot output of the esp8266 on computers that don't support that baud rate.
The FTDI drivers support funky baudrates via their COM port emulation interface - used to be that you had to mess with baud rate aliasing in the driver config but nowadays it seems to just work in most Windows apps at least. I regularly use 250K,1M 2M and 4Mbaud. there isn't much reason to use the oddball legacy rates these days - good internal RC oscs on MCUs mean that it makes more sense to use 'rounder' numbers for baudrate, e.g. 1Mbaud on a 16MHz osc
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline ralphdTopic starter

  • Frequent Contributor
  • **
  • Posts: 445
  • Country: ca
    • Nerd Ralph
Re: smart auto-baud algorithm?
« Reply #11 on: June 08, 2015, 01:08:38 pm »
Most of the autobaud functions use 0x55 as the first character. It can also be used for FSK based transmissions followed by 0xFF to assure correct framing of the following data.

When you have a device you are trying to debug or reverse engineer, and all you have is the UART pads on the PCB, an autobaud function that requres 0x55 for the first character is no help.
Unthinking respect for authority is the greatest enemy of truth. Einstein
 

Offline ralphdTopic starter

  • Frequent Contributor
  • **
  • Posts: 445
  • Country: ca
    • Nerd Ralph
Re: smart auto-baud algorithm?
« Reply #12 on: June 08, 2015, 01:10:19 pm »
there isn't much reason to use the oddball legacy rates these days [...]

Try telling that to the folks at Espressif.
Unthinking respect for authority is the greatest enemy of truth. Einstein
 

Offline deephaven

  • Frequent Contributor
  • **
  • Posts: 796
  • Country: gb
  • Civilization is just one big bootstrap
    • Deephaven Ltd
Re: smart auto-baud algorithm?
« Reply #13 on: June 08, 2015, 01:13:31 pm »
Most of the autobaud functions use 0x55 as the first character. It can also be used for FSK based transmissions followed by 0xFF to assure correct framing of the following data.

When you have a device you are trying to debug or reverse engineer, and all you have is the UART pads on the PCB, an autobaud function that requres 0x55 for the first character is no help.

If it was an activity like reverse engineering, I would hang a scope on the signal and measure the baud rate myself.
 

Offline FrankBuss

  • Supporter
  • ****
  • Posts: 2425
  • Country: de
    • Frank Buss
Re: smart auto-baud algorithm?
« Reply #14 on: June 08, 2015, 01:18:17 pm »
When you have a device you are trying to debug or reverse engineer, and all you have is the UART pads on the PCB, an autobaud function that requres 0x55 for the first character is no help.
I've never seen any (modern) device which uses something different than 9600 baud or 115.2k baud, 8n1. And it is pretty easy to see in a terminal program that it is 115.2k if it is configured at 9600.
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 14787
  • Country: gb
    • Mike's Electric Stuff
Re: smart auto-baud algorithm?
« Reply #15 on: June 08, 2015, 01:25:51 pm »
there isn't much reason to use the oddball legacy rates these days [...]

Try telling that to the folks at Espressif.
Sounds like they already know if it's using 70Kbaud
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline ralphdTopic starter

  • Frequent Contributor
  • **
  • Posts: 445
  • Country: ca
    • Nerd Ralph
Re: smart auto-baud algorithm?
« Reply #16 on: June 08, 2015, 02:33:23 pm »
When you have a device you are trying to debug or reverse engineer, and all you have is the UART pads on the PCB, an autobaud function that requres 0x55 for the first character is no help.
I've never seen any (modern) device which uses something different than 9600 baud or 115.2k baud, 8n1. And it is pretty easy to see in a terminal program that it is 115.2k if it is configured at 9600.
Check out the esp8266.
Unthinking respect for authority is the greatest enemy of truth. Einstein
 

Offline bson

  • Supporter
  • ****
  • Posts: 2777
  • Country: us
Re: smart auto-baud algorithm?
« Reply #17 on: June 08, 2015, 06:25:37 pm »
The basic problem is that the levels are sampled on the line clock - it's not edge triggered.  This means RS-232C is immune to a lot of distortions - ringing, impedance mismatch reflections, peaking, bandwidth limiting, nonlinear phase effects.  It doesn't matter if each pulse "wiggles" or what it looks like; only its level at the edge of the line clock matters.  This line clock isn't embedded but it set out-of-band by some other means, which means there is an unknown - the one you're trying to solve for.

If you have a fast ADC you could sample the waveform and software decode it using a 2x progression of standard line clocks to see which one fits.  This requires an MCU where the RxD input pin can be temporarily configured as an ADC input.  (Actually, you could probably also do the same using it as a GPIO pin...)
« Last Edit: June 08, 2015, 06:29:03 pm by bson »
 

Offline slateraptor

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: us
Re: smart auto-baud algorithm?
« Reply #18 on: June 10, 2015, 02:57:34 am »
Since the problem is >30 years old, I thought by now someone would have come up with the Holy Grail of autobaud algorithms.  Assuming 8N1 human readable ASCII, I think it is possible to detect the baud rate between 9600 and 115,200 after a single character.  None of the algorithms I have found take advantage of the fact that the 9th bit is always 0 and the 10th bit is always 1 for stop.  It also looks like the shortest run of ones or zeros is never more than 2 bit times, and there will always be an odd number of 0 or 1 bits, with the other count being even.

How do you figure? If your description is correct, then you've just described 7S1, not 8N1.



The basic problem is that the levels are sampled on the line clock - it's not edge triggered (1).  This means RS-232C is immune to a lot of distortions (2) - ringing, impedance mismatch reflections, peaking, bandwidth limiting, nonlinear phase effects.  It doesn't matter if each pulse "wiggles" or what it looks like; only its level at the edge of the line clock matters.  This line clock isn't embedded but it set out-of-band by some other means (3), which means there is an unknown - the one you're trying to solve for.

If you have a fast ADC you could sample the waveform and software decode it using a 2x progression of standard line clocks to see which one fits.  This requires an MCU where the RxD input pin can be temporarily configured as an ADC input.  (Actually, you could probably also do the same using it as a GPIO pin...)

??? (1) Sure it is, at the DCE; (2) false; and (3) if by "set out-of-band" you mean not physically wired in async setups, then sure.

Staying OT, hamster_nz and bktemp hit it spot on with respect to the OP...although I feel like the general discussion has somehow digressed by way of terminology confusion between baud and bit rate.
 

Offline Dago

  • Frequent Contributor
  • **
  • Posts: 659
  • Country: fi
    • Electronics blog about whatever I happen to build!
Re: smart auto-baud algorithm?
« Reply #19 on: June 10, 2015, 05:32:58 am »
I can't remember where I saw this algorithm but something had an auto-baud algorithm and it was simply done by sending 'U' (known to both ends) and changing the baudrate until the receiver end got it right. Maybe some bootloader?
Come and check my projects at http://www.dgkelectronics.com ! I also tweet as https://twitter.com/DGKelectronics
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4660
  • Country: us
Re: smart auto-baud algorithm?
« Reply #20 on: June 10, 2015, 08:43:18 am »
Quote
When you have a device you are trying to debug or reverse engineer, and all you have is the UART pads on the PCB
Ah.   Autobauding on substantial bursts of unknown text at non-standard rates is a significantly different problem than the one that people have been working on for 30 years...  :-(
Measuring the shortest pulse should get close pretty quickly; it's unlikely that the transmission would contain no odd (LSB==1) characters, and one of those would have a measurable start bit.

All bets are off if you get something like the old Tymnet sign-in prompt, which magically (?) displayed correctly regardless of whether you dialed in at 300bps or 110bps (or maybe even 1200bps?)
 

Offline Delta

  • Super Contributor
  • ***
  • Posts: 1221
  • Country: gb
Re: smart auto-baud algorithm?
« Reply #21 on: June 10, 2015, 11:49:10 am »
I've seen "hardware autobaud" features described for some modern UART peripherals.
I'm not sure that it's an interesting problem on a microcontroller.  Just start the pins in GPIO mode and time the start bit.

And how does one determine what's a start bit and what's any other Zero bit?
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2860
  • Country: nz
Re: smart auto-baud algorithm?
« Reply #22 on: June 11, 2015, 07:46:18 am »
I've seen "hardware autobaud" features described for some modern UART peripherals.
I'm not sure that it's an interesting problem on a microcontroller.  Just start the pins in GPIO mode and time the start bit.

And how does one determine what's a start bit and what's any other Zero bit?

One way to know for sure is if the line is idle for a short while (9 or 10 but-times) and then it has to be a start bit.

The only other way is if the data stream unambiguously proves it to be one. This can be quite hard to do in the presence of bit errors, as one in five bit errors will alter either a start or stop bit if the link is running at 100% throughput.
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->