Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch.embedded > #10723

Re: baud rate autodetection on AVR 8-bit?

From mike <ham789@netzero.net>
Newsgroups comp.arch.embedded
Subject Re: baud rate autodetection on AVR 8-bit?
Date 2012-12-07 13:35 -0800
Organization A noiseless patient Spider
Message-ID <k9tnfa$8pf$1@dont-email.me> (permalink)
References <86sj7iuetv.fsf@gray.siamics.net> <8s04c8lfe98k422gq3gp8eofpgd0nqecj0@4ax.com> <86obi5vn6u.fsf@gray.siamics.net> <rm94c8dpujk2gs7hi59sdr23ulsm80b7ij@4ax.com>

Show all headers | View raw


On 12/7/2012 9:42 AM, Rich Webb wrote:
> On Fri, 07 Dec 2012 23:31:21 +0700, Ivan Shmakov<oneingray@gmail.com>
> wrote:
>
>>>>>>> Rich Webb<bbew.ar@mapson.nozirev.ten>  writes:
>>>>>>> On Fri, 07 Dec 2012 21:17:16 +0700, Ivan Shmakov wrote:
>>
>>>> BTW, is there an easy way to autodetect the baud rate while using an
>>>> AVR UART?  (Preferably something that works with ATmega8, given that
>>>> those MCU's are such a cheap thing nowadays.)
>>
>>>> There're some ideas (and 8051 code) for that on [1], but I'd like to
>>>> know if there could be any better techniques.
>>
>>> It's pretty straightforward if you can use a timer capture pin; it
>>> takes care of grabbing the timer count on the active edge and you can
>>> examine it at leisure.
>>
>> 	Well, I guess I can use a pin change interrupt instead, and just
>> 	save the timer's counter in the handler.  (Thus introducing a
>> 	constant delay, which will disappear anyway in the delta.)
>>
>>> Essentially, you will want to listen to an incoming serial stream to
>>> measure the narrowest pulse and when you've seen enough identical
>>> pulses, that determines the rate.
>>
>> 	Indeed, thanks!
>>
>>> If you get a narrower pulse (that is wider than a glitch width),
>>> start the count over.
>>
>>> A little more robust is to add N to an accumulator when you see a
>>> pulse within epsilon of the current narrow width, subtract M if there
>>> is a wider pulse, or reset to zero and start over if there is a
>>> narrower.  When the accumulator reaches Q, you've found the pulse
>>> width.  If it counts down to zero (from too many wider pulses),
>>> assume you saw a narrow noise pulse and start over.  A divide-by-16
>>> (>>  4) works pretty well for epsilon.
>>
>> 	I guess I'd need to meditate over this one for some time.
>> 	Thanks.
>
> The problem is that if a rogue pulse is detected then you could end up
> waiting forever for the confirming pulses. Say you expect baud rates
> from 4800 to 115200, corresponding to pulses from 2400 to 100 ticks wide
> (picking an artificial clock rate) and selected a minimum of 80 ticks
> (where 80 or less is ignored as a glitch).
>
> Say the actual baud rate was 4800 but before you sync'd to it a noise
> pulse from, say, inserting the connector was detected that was 1200
> ticks wide. You'd wait forever watching the 4800 baud pulses (2400 wide)
> and never see another, so there has to be some mechanism to abandon the
> current minimum and start the search anew.
>
> One way to avoid the trap is to add, say, 10 to an accumulator for every
> pulse matching the currently observed minimum and declaring a valid
> minimum if, say, a count of 50 is reached. Deduct 1 from the accumulator
> whenever a pulse wider than the current minimum is seen and start the
> search over if the count ever gets back to zero (or if a narrower pulse
> is detected, of course).
>
I gave up several times on a similar project when I couldn't determine
the characteristics of the data stream...or even if there was one.

Been thinking about this for an hour or so.

If you take a random pulse width measurement.
Save that as mmpw, minimum measured pulse width.
Have a table of pulse widths for the allowable baud rates.
Scan up the table till you find a number match.
IF not, multiply the table by 2 then three then four...
Eventually you should find a match.
Program that into the USART.  Have the character input interrupt
start looking for framing errors.

Take another random pulse width measurement.
If it's smaller than mmpw, plug it into mmpw and restart.
If it's larger, subtract the two numbers.  The difference should
be an integral multiple of the REAL pulse width for the actual baud rate.
Divide the numbers.  If the remainder isn't zero, mmpw isn't the
correct bit time.  I think the correct bit time is an integer multiple
of the remainder, but I haven't got my head fully around that one.
Use those numbers to scan for a higher baud rate and an inferred new mmpw.
Quit when you get tired of looking for narrower mmpw or those that
aren't an integral multiple of the trial bit time and aren't
getting framing errors.

Of course, there are all kinds of issues with timing synchronization,
error bounds, glitches etc. that need to be dealt with.  And the
simplest way of thinking about it seems to result in a recursive
algorithm which isn't nice on a simple processor...so maybe the
details kill the concept...but it would be interesting to play with.

I like it because I think it converges even if you never catch an actual
one-bit-wide pulse.

Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

baud rate autodetection on AVR 8-bit? Ivan Shmakov <oneingray@gmail.com> - 2012-12-07 21:17 +0700
  Re: baud rate autodetection on AVR 8-bit? Rich Webb <bbew.ar@mapson.nozirev.ten> - 2012-12-07 10:28 -0500
    Re: baud rate autodetection on AVR 8-bit? Ivan Shmakov <oneingray@gmail.com> - 2012-12-07 23:31 +0700
      Re: baud rate autodetection on AVR 8-bit? Rich Webb <bbew.ar@mapson.nozirev.ten> - 2012-12-07 12:42 -0500
        Re: baud rate autodetection on AVR 8-bit? mike <ham789@netzero.net> - 2012-12-07 13:35 -0800
          Re: baud rate autodetection on AVR 8-bit? Rich Webb <bbew.ar@mapson.nozirev.ten> - 2012-12-07 20:07 -0500
          Re: baud rate autodetection on AVR 8-bit? Mark Borgerson <mborgerson@comcast.net> - 2012-12-07 23:43 -0800
      Re: baud rate autodetection on AVR 8-bit? Tim Wescott <tim@seemywebsite.com> - 2012-12-07 13:07 -0600
      Re: baud rate autodetection on AVR 8-bit? Dave Nadler <drn@nadler.com> - 2012-12-07 12:09 -0800
        Re: baud rate autodetection on AVR 8-bit? Ivan Shmakov <oneingray@gmail.com> - 2012-12-08 03:47 +0700
          Re: baud rate autodetection on AVR 8-bit? MK <mk@nospam.co.uk> - 2012-12-08 09:44 +0000
            8-bit vs. 32-bit MCU's Ivan Shmakov <oneingray@gmail.com> - 2012-12-08 18:31 +0700
              Re: 8-bit vs. 32-bit MCU's MK <mk@nospam.co.uk> - 2012-12-09 14:13 +0000
                Re: 8-bit vs. 32-bit MCU's Ivan Shmakov <oneingray@gmail.com> - 2012-12-09 22:52 +0700
    Re: baud rate autodetection on AVR 8-bit? upsidedown@downunder.com - 2012-12-08 15:01 +0200
  Re: baud rate autodetection on AVR 8-bit? Dombo <dombo@disposable.invalid> - 2012-12-08 15:18 +0100
  Re: baud rate autodetection on AVR 8-bit? [ User friendly RS-232/EIA-232 ? ] Glenn <glenn2233@gmail.com> - 2012-12-09 10:47 +0100
    Re: baud rate autodetection on AVR 8-bit? [ User friendly RS-232/EIA-232 ? ] "Paul E. Bennett" <Paul_E.Bennett@topmail.co.uk> - 2012-12-09 10:22 +0000
    Re: baud rate autodetection on AVR 8-bit? [ User friendly RS-232/EIA-232 ? ] "Bruce Varley" <bv@NoSpam.com> - 2012-12-09 19:07 +0800
    Re: baud rate autodetection on AVR 8-bit? [ User friendly RS-232/EIA-232 ? ] Paul <paul@pcserviceselectronics.co.uk> - 2012-12-09 13:27 +0000
    Re: baud rate autodetection on AVR 8-bit? [ User friendly RS-232/EIA-232   ? ] Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2012-12-09 16:19 +0100
    Re: baud rate autodetection on AVR 8-bit? [ User friendly RS-232/EIA-232 ? ] "TTman" <pcw1.cad@ntlworld.com> - 2012-12-09 15:38 +0000
      Re: baud rate autodetection on AVR 8-bit? [ User friendly RS-232/EIA-232 ? ] amdyer@gmail.com - 2012-12-09 07:45 -0800
    Re: baud rate autodetection on AVR 8-bit? [ User friendly RS-232/EIA-232 ? ] upsidedown@downunder.com - 2012-12-09 17:45 +0200
      Re: baud rate autodetection on AVR 8-bit? [ User friendly RS-232/EIA-232 ? ] Paul <paul@pcserviceselectronics.co.uk> - 2012-12-09 21:30 +0000
    Re: baud rate autodetection on AVR 8-bit? [ User friendly RS-232/EIA-232 ? ] John Larkin <jjlarkin@highNOTlandTHIStechnologyPART.com> - 2012-12-09 09:02 -0800
      Re: baud rate autodetection on AVR 8-bit? [ User friendly RS-232/EIA-232 ? ] Lanarcam <lanarcam1@yahoo.fr> - 2012-12-09 18:13 +0100
        Re: baud rate autodetection on AVR 8-bit? [ User friendly RS-232/EIA-232 ? ] upsidedown@downunder.com - 2012-12-09 19:44 +0200
        Re: baud rate autodetection on AVR 8-bit? [ User friendly RS-232/EIA-232 ? ] Paul <paul@pcserviceselectronics.co.uk> - 2012-12-09 21:32 +0000
    Re: baud rate autodetection on AVR 8-bit? [ User friendly RS-232/EIA-232 ? ] Robert Wessel <robertwessel2@yahoo.com> - 2012-12-10 00:35 -0600
    Re: baud rate autodetection on AVR 8-bit? [ User friendly RS-232/EIA-232 ? ] josephkk <joseph_barrett@sbcglobal.net> - 2012-12-12 20:30 -0800
  Re: baud rate autodetection on AVR 8-bit? "Meindert Sprang" <ms@NOJUNKcustomORSPAMware.nl> - 2012-12-10 13:38 +0100
    Re: baud rate autodetection on AVR 8-bit? Ivan Shmakov <oneingray@gmail.com> - 2012-12-10 20:19 +0700
      Re: baud rate autodetection on AVR 8-bit? "Meindert Sprang" <ms@NOJUNKcustomORSPAMware.nl> - 2012-12-10 16:24 +0100
        Re: baud rate autodetection on AVR 8-bit? Arlet Ottens <usenet+5@c-scape.nl> - 2012-12-10 16:49 +0100
        Re: baud rate autodetection on AVR 8-bit? Rich Webb <bbew.ar@mapson.nozirev.ten> - 2012-12-12 08:50 -0500
  Re: baud rate autodetection on AVR 8-bit? j.m.granville@gmail.com - 2012-12-11 21:22 -0800
    Re: baud rate autodetection on AVR 8-bit? Robert Wessel <robertwessel2@yahoo.com> - 2012-12-12 00:29 -0600
      Re: baud rate autodetection on AVR 8-bit? Mark Borgerson <mborgerson@comcast.net> - 2012-12-11 23:43 -0800
        Re: baud rate autodetection on AVR 8-bit? Robert Wessel <robertwessel2@yahoo.com> - 2012-12-12 02:38 -0600
          Re: baud rate autodetection on AVR 8-bit? Mark Borgerson <mborgerson@comcast.net> - 2012-12-12 07:46 -0800
            Re: baud rate autodetection on AVR 8-bit? linnix <me@linnix.info-for.us> - 2012-12-12 10:50 -0800
              Re: baud rate autodetection on AVR 8-bit? Jon Kirwan <jonk@infinitefactors.org> - 2012-12-12 12:42 -0800
                Re: baud rate autodetection on AVR 8-bit? Jon Kirwan <jonk@infinitefactors.org> - 2012-12-12 12:56 -0800
                Re: baud rate autodetection on AVR 8-bit? upsidedown@downunder.com - 2012-12-12 23:22 +0200
                Re: baud rate autodetection on AVR 8-bit? Robert Wessel <robertwessel2@yahoo.com> - 2012-12-12 15:39 -0600
                Re: baud rate autodetection on AVR 8-bit? Jon Kirwan <jonk@infinitefactors.org> - 2012-12-12 15:13 -0800
                Re: baud rate autodetection on AVR 8-bit? Jon Kirwan <jonk@infinitefactors.org> - 2012-12-12 15:28 -0800
                Re: baud rate autodetection on AVR 8-bit? Robert Wessel <robertwessel2@yahoo.com> - 2012-12-12 18:41 -0600
                Re: baud rate autodetection on AVR 8-bit? Jon Kirwan <jonk@infinitefactors.org> - 2012-12-12 17:12 -0800
              Re: baud rate autodetection on AVR 8-bit? Mark Borgerson <mborgerson@comcast.net> - 2012-12-12 12:43 -0800
                Communications under pressure (was Re: baud rate...) Frnak McKenney <frnak@far.from.the.madding.crowd.com> - 2012-12-13 10:25 -0600
                Re: Communications under pressure (was Re: baud rate...) Robert Wessel <robertwessel2@yahoo.com> - 2012-12-13 12:34 -0600
                Re: Communications under pressure (was Re: baud rate...) upsidedown@downunder.com - 2012-12-14 10:33 +0200
                Re: Communications under pressure (was Re: baud rate...) Mark Borgerson <mborgerson@comcast.net> - 2012-12-14 07:43 -0800
                Re: Communications under pressure (was Re: baud rate...) Mark Borgerson <mborgerson@comcast.net> - 2012-12-13 16:47 -0800
                Re: Communications under pressure (was Re: baud rate...) Jon Kirwan <jonk@infinitefactors.org> - 2012-12-13 18:22 -0800
                Re: Communications under pressure (was Re: baud rate...) Jon Kirwan <jonk@infinitefactors.org> - 2012-12-13 18:27 -0800
                Re: Communications under pressure (was Re: baud rate...) Mark Borgerson <mborgerson@comcast.net> - 2012-12-13 23:20 -0800
                Re: Communications under pressure (was Re: baud rate...) Frank Miles <fpm@u.washington.edu> - 2012-12-14 17:50 +0000
                Re: Communications under pressure (was Re: baud rate...) Mark Borgerson <mborgerson@comcast.net> - 2012-12-14 14:28 -0800
          serial host-to-device communication in amateur designs Ivan Shmakov <oneingray@gmail.com> - 2012-12-14 23:21 +0700
            Re: serial host-to-device communication in amateur designs Rob Gaddi <rgaddi@technologyhighland.invalid> - 2012-12-14 09:18 -0800
              Re: serial host-to-device communication in amateur designs Jon Kirwan <jonk@infinitefactors.org> - 2012-12-14 11:19 -0800
                Re: serial host-to-device communication in amateur designs Ivan Shmakov <oneingray@gmail.com> - 2012-12-16 21:00 +0700
                Re: serial host-to-device communication in amateur designs Jon Kirwan <jonk@infinitefactors.org> - 2012-12-16 13:46 -0800
                USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> - 2012-12-17 00:53 +0000
                Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Jon Kirwan <jonk@infinitefactors.org> - 2012-12-16 17:46 -0800
                Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> - 2012-12-17 13:27 +0000
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Mel Wilson <mwilson@the-wire.com> - 2012-12-17 10:32 -0500
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs me@linnix.info-for.us - 2012-12-17 11:13 -0800
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Jon Kirwan <jonk@infinitefactors.org> - 2012-12-17 12:03 -0800
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Jon Kirwan <jonk@infinitefactors.org> - 2012-12-17 12:17 -0800
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Christopher Head <chead@is.invalid> - 2012-12-17 23:36 -0800
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Jon Kirwan <jonk@infinitefactors.org> - 2012-12-17 23:54 -0800
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> - 2012-12-18 13:06 +0000
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs j.m.granville@gmail.com - 2012-12-18 14:04 -0800
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Jon Kirwan <jonk@infinitefactors.org> - 2012-12-18 14:13 -0800
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Christopher Head <chead@is.invalid> - 2012-12-19 02:37 -0800
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> - 2012-12-19 12:59 +0000
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Rocky <RobertGush@gmail.com> - 2012-12-19 10:19 -0800
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Jon Kirwan <jonk@infinitefactors.org> - 2012-12-19 10:43 -0800
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Jon Kirwan <jonk@infinitefactors.org> - 2012-12-19 10:39 -0800
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Jon Kirwan <jonk@infinitefactors.org> - 2012-12-19 10:44 -0800
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Christopher Head <chead@is.invalid> - 2012-12-19 18:42 -0800
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Jon Kirwan <jonk@infinitefactors.org> - 2012-12-19 21:05 -0800
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> - 2012-12-20 14:13 +0000
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Jon Kirwan <jonk@infinitefactors.org> - 2012-12-20 11:58 -0800
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Waldek Hebisch <hebisch@math.uni.wroc.pl> - 2012-12-24 00:41 +0000
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Waldek Hebisch <hebisch@math.uni.wroc.pl> - 2012-12-24 15:45 +0000
                Re: Writing a USB device stack, was: Re: USB CDC ACM, was: Re: serial host-to-device communication in amateur designs Jon Kirwan <jonk@infinitefactors.org> - 2012-12-24 11:40 -0800
                Re: serial host-to-device communication in amateur designs Frnak McKenney <frnak@far.from.the.madding.crowd.com> - 2012-12-20 10:00 -0600
                Re: serial host-to-device communication in amateur designs Jon Kirwan <jonk@infinitefactors.org> - 2012-12-20 11:54 -0800
                Re: serial host-to-device communication in amateur designs Rob Gaddi <rgaddi@technologyhighland.invalid> - 2012-12-20 12:01 -0800
                Re: serial host-to-device communication in amateur designs Jon Kirwan <jonk@infinitefactors.org> - 2012-12-20 12:27 -0800
            Re: serial host-to-device communication in amateur designs Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> - 2012-12-14 17:53 +0000
              Re: serial host-to-device communication in amateur designs Ivan Shmakov <oneingray@gmail.com> - 2012-12-15 01:26 +0700
                Re: serial host-to-device communication in amateur designs Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> - 2012-12-14 19:30 +0000
                Re: serial host-to-device communication in amateur designs Ivan Shmakov <oneingray@gmail.com> - 2012-12-15 11:25 +0700
                Re: serial host-to-device communication in amateur designs Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> - 2012-12-17 00:29 +0000
                Re: serial host-to-device communication in amateur designs me@linnix.info-for.us - 2012-12-17 11:05 -0800
                Re: serial host-to-device communication in amateur designs Rich Webb <bbew.ar@mapson.nozirev.ten> - 2012-12-14 14:34 -0500
                Re: serial host-to-device communication in amateur designs Paul <paul@pcserviceselectronics.co.uk> - 2012-12-14 23:25 +0000
                finer pitches Ivan Shmakov <oneingray@gmail.com> - 2012-12-16 20:48 +0700
              Re: serial host-to-device communication in amateur designs Mark Borgerson <mborgerson@comcast.net> - 2012-12-14 21:26 -0800

csiph-web