Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
autodetect baud rate?

 
Post new topic   Reply to topic    Forum Index -> ZX-24
Author Message
spamiam



Joined: 13 Nov 2005
Posts: 661

Posted: 02 February 2006, 19:23 PM    Post subject: autodetect baud rate? Reply with quote

Discussions here of serial LCD adapter problems got me thinking about construction one from a dedicated ZX device. Certainly there are cheaper serial adapters out there, but maybe they are not as reliable as we would like.

Maybe I could do better myself.

So, I would like to try making a dedicated serial-input, parallel-output device.

I want to be able to have the ZX AUTOMATICALLY synchronize itself with the incoming serial data. IOW, I do not want to have any specific required baud rate. I want the interface to look a an incoming synchronization stream of characters, and then realize what that baud rate is.

How would do that? I suppose I would look at the timing between rising edges on the data stream, and that will be an integral number of bits of data. The shortest time should be one bit wide. Longer times may 2 or 3 or more bits wide.

I would suppose that after several bits, it would be possible to deduce the baud rate (baud rate == bits per second == 1/bit time, right?)

What do you think would be the most accurate way to measure the bit times?

-Tony
Back to top
spamiam



Joined: 13 Nov 2005
Posts: 661

Posted: 02 February 2006, 19:57 PM    Post subject: Reply with quote

follow-up

I did a little checking. My first idea is to use PulseIn() on the serial input pin.

Have Register.TimerSpeed2 = 1.

I think that 2400 baud would measure 614.4 timer periods, and 115200 baud would measure 12.8.

After sampling about 20 or 30 pulses it probably would be possible to take the shortest duration, and

Baud = 1/(duration * 10)

assume N-8-1. Assume standard speeds 1200, 2400, 48000, 9600, 14.4K, 28.8k, 33.6K, 57.6K, 115.2K. Other data speed could be used as well, I guess.

I could verify bit durations easily enough easily enough on the ZX.

-Tony
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2493
Location: Portland, OR

Posted: 02 February 2006, 21:09 PM    Post subject: Reply with quote

In order to determine the baud rate by examining the receive line you have to know something about the data being transmitted. Often, the detection algorithm requires a specific character to be transmitted, e.g. a carriage return. If the transmitted character has a 1 as its LSB, you can measure the duration of the start bit and deduce the rate from that measurement.

If you search the Internet using the keywords "automatic baud rate detection" you should get some useful hits.
Back to top
spamiam



Joined: 13 Nov 2005
Posts: 661

Posted: 03 February 2006, 0:06 AM    Post subject: Reply with quote

dkinzer wrote:
Often, the detection algorithm requires a specific character to be transmitted, e.g. a carriage return.


Yes, I had thought about something like that. I was considering a binary pattern of 01010101 or something like that so that there would be a bunch of highs and lows alternating. I will check the search you recommend.

-Tony
Back to top
Genesis



Joined: 15 Jan 2006
Posts: 28

Posted: 03 February 2006, 3:25 AM    Post subject: Reply with quote

&H55 is a common one. So is carriage return. There IS a serial backpack out there SOMEWHERE that uses &H55 - I found it once and now have lost the link to it Smile

The carriage return can detect on no more than two characters with a simple UART, so doing so when you can bit-bang should be simpler. I have code that does this in "C" for Unix machines (a custom "getty" program that handled it.)

The only "gotcha" is that you have to make some assumptions about parity and stop bits. If you allow all possible combinations then you must get much more clever.

Mu only caution on something like this is that there's a severe issue with power consumption using the ZX for this. For line-powered things this is not a big deal, but for battery-powered devices it definitely is. The power issue is what drove me away from the Parallax backpack (which works reasonably well - theirs is a power pig) in the first place.
Back to top
spamiam



Joined: 13 Nov 2005
Posts: 661

Posted: 03 February 2006, 18:27 PM    Post subject: Reply with quote

Genesis wrote:
&H55 is a common one. So is carriage return. There IS a serial backpack out there SOMEWHERE that uses &H55 - I found it once and now have lost the link to it Smile

The only "gotcha" is that you have to make some assumptions about parity and stop bits. If you allow all possible combinations then you must get much more clever.

Mu only caution on something like this is that there's a severe issue with power consumption using the ZX for this. For line-powered things this is not a big deal, but for battery-powered devices it definitely is. The power issue is what drove me away from the Parallax backpack (which works reasonably well - theirs is a power pig) in the first place.


Well, I figured that if I am measuring the minimum high or low duration in a sequence of bits, then it really does not matter much what the pattern is as long as there are a few high-low sequences around. &H55 (0101_0101) would have been one of my first picks.

I also figured that it would be nice to allow N-8-1 as the parity and stop bit settings. I am not an expert in serial communication, but I have never had the need for anything else unless I had some oddd hardware I had to conform to. If I were making a serial "backpack", then the sending hardware would have to conform to me. N-8-1 is certainly not going to be a problem, I don't think.

AH, yes. Power drain. The ZX device is offers way more capability than I NEED, but it is one convenient package. I suppose that I could design something using raw AVR hardware that might not require as much power. I suppose that other devices would require even less. I had considered the ATMega8535 becaus eit is small-ish and has hardware support for a bunch of stuff including RAM for deep buffers.

For $50 or so, there are "serial" LCDs which I suppose have their own built-in serial interface. Sionce they are designed from the ground-up for the serial interface, maybe they are better. If I remember correctly, most are quite speed limited.

I will be checking on automatic baudrate detection. I will also check the power needs for my EL backlit 16x2 display (99mm visible screen width).

-Tony
Back to top
Genesis



Joined: 15 Jan 2006
Posts: 28

Posted: 03 February 2006, 22:11 PM    Post subject: Reply with quote

Most so-called "Serial" LCDs are really like the Parallax - just a standard HD-based LCD with a serial backpack grafted on it......

At least this is true for the smaller ones (e.g. 16x2, 20x4, etc)
Back to top
stevech



Joined: 23 Feb 2006
Posts: 656

Posted: 23 February 2006, 21:09 PM    Post subject: Reply with quote

The 40 x 4 LCD I have uses that "backpack" which is a PIC chip with just two possible baud rate choices as I recall.
Back to top
spamiam



Joined: 13 Nov 2005
Posts: 661

Posted: 24 February 2006, 4:06 AM    Post subject: Reply with quote

stevech wrote:
The 40 x 4 LCD I have uses that "backpack" which is a PIC chip with just two possible baud rate choices as I recall.


Yes, I have seen some "Scott-Edwards" brand devices. The PCB is pulky and they are fairly slow. I have seen others with RS232 speeds of up to 19.2K and also have I2C (unspecified bus speed). I am not sure of the type of processor on these boards.

-Tony
Back to top
stevech



Joined: 23 Feb 2006
Posts: 656

Posted: 24 February 2006, 4:53 AM    Post subject: Reply with quote

yes, my 4 x 40 LCD has a "Backpack 443" module; PIC chip. Up to 9600 baud.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZX-24 Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group