Pages: [1]   Go Down
Author Topic: Serial library with non standard bit rates?  (Read 967 times)
0 Members and 1 Guest are viewing this topic.
Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I am searching for a serial library which can use non-standard bit rates, e.g. 19304 bit/s on a digital port. In fact I just only need to send at this speed with no start and stop bits - just one byte after another. I am not new to programing but new to Arduino and microcontrollers, so I hope someone can give me a hint where I can find such a library or how to set up such functions (I think with timers an interrupts, or?)

Thanks, Holger
Logged

Perl is the only language that looks the same before and after RSA encryption.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The source code for the HardwareSerial class, which is what Serial is an instance of, is available on your computer. Hack away (at a copy).
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13478
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the baudrates are non standard but fixed (known in advance) you can patch the NewSoftSerial internal tables relative easily.

I recently tested and noted that standard baudrates work +/- 5%
==> So if you make a table with steps chosen carefully (5% maybe 8%) you should be able to cover any speed.

to manage a range
from 1200 - 2400    (factor 2)   you need log(2) / log(1,05)   = 15 steps  [8% steps => 9]
from 1200 - 115200 (factor 96) you need log(96) / log(1,05) = 93 steps  [8% steps => 60]


Alternative is to derive a formula for the timing parameters for NewSoftWareSerial (possible but not trivial, Excel might be helpfull)
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It sounds like you are talking about synchronous communication - no start or stop bits. If that is the case, you can use the SPI function of the processor. For a 16MHz processor, you would set the baud rate register to 413 to get the baud rate you are looking for.Read the Atmel328 data sheet topic about the USART in SPI mode.

It looks like the SPI library will do what you are looking for but you'll have to modify the source for your custom baud rate.
« Last Edit: August 11, 2011, 10:30:27 am by EmilyJane » Logged

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

thanks for your answers!
I think I will try to patch NewSoftSerial or use the SPI library. After testing I will post my results here.

Have a nice weekend,

Holger
Logged

Perl is the only language that looks the same before and after RSA encryption.

Smithfield, Rhode Island
Offline Offline
God Member
*****
Karma: 3
Posts: 843
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you plan to use NewSoftSerial with an on chip UART or with digital pins? If you don't have a hardware UART, and you're working with sync data, you're going to be banging your head against the wall. Its easy enough to make it move data, but as soon as you try to do something with that data at the same time, its gets frustrating.
Logged

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi skyjumper,

no UART :-)
I need to generate a signal for driving digital modell locomotives (not DCC but Motorola-Märklin). So my other end of the communication is a decoder chip inside the locomotive. I have a rough manual how to generate the frames with a serial line at 19200 bit/s but you have to do some strange timing things to get the right signal. I thaught that it is better to generate the signal without that strange things but for this you "might" have to send the frames with a non-standard bit rate (s. http://modell-zug.com/Support/HowToArticles/DigCtrlSys/DigitalTransmission.htm). I read some documentation where they don't use exactly 4800 bit/s... but I'm not sure.

Regards, Holger
« Last Edit: August 12, 2011, 07:22:24 am by Codeman » Logged

Perl is the only language that looks the same before and after RSA encryption.

0
Offline Offline
Shannon Member
****
Karma: 199
Posts: 11671
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It sounds like you are talking about synchronous communication - no start or stop bits. If that is the case, you can use the SPI function of the processor.

The Arduino hardware SPI is limited to a fixed set of frequencies derived from the processor clock divided by powers of two.  Successive bytes may not be bit-synchronous with each other - you'd have to test that.

To generate an accurate fixed frequency the use of timer1 (which has 16bit precision) is a possible way - using a timer interrupt would be the most accurate way to use that timer to push bits out.

However the UART is probably the simplest way (if you can configure 0 start bits and 0 stop bits?)
Logged

[ I won't respond to messages, use the forum please ]

Calgary, AB
Offline Offline
Newbie
*
Karma: 2
Posts: 46
Arduino Newbie
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Codeman

Just a thought, have you considered using the Motorola Trinary Encoder to handle the packet generation and timing.  It has its own oscillator timing.

http://www.datasheetcatalog.org/datasheet/motorola/SC41343DW.pdf

You would have to provide the 8 bit byte to the chip, but it may simplify your processor design/programming as the chip would handle packet generation and the resend for reliability.

Quick google, and the chip appears to be in the $15-$20 US range.

Regards  Bill
Logged

Don't you just hate ONE D 10 T problems?

Smithfield, Rhode Island
Offline Offline
God Member
*****
Karma: 3
Posts: 843
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi skyjumper,

no UART :-)
I need to generate a signal for driving digital modell locomotives (not DCC but Motorola-Märklin). So my other end of the communication is a decoder chip inside the locomotive. I have a rough manual how to generate the frames with a serial line at 19200 bit/s but you have to do some strange timing things to get the right signal. I thaught that it is better to generate the signal without that strange things but for this you "might" have to send the frames with a non-standard bit rate (s. http://modell-zug.com/Support/HowToArticles/DigCtrlSys/DigitalTransmission.htm). I read some documentation where they don't use exactly 4800 bit/s... but I'm not sure.

Regards, Holger

Which Arduino are you using? You should be able to do this with a bunch of them. For example, the 324/644/1284 chip should be able to do this nicely with its onboard USART. These USARTs can do quite a bit more then the arduino code allows as is, but its very easy to hack the code to set up the USART as you need it. If you look at the HardwareSerial.cpp begin() method, you'll see that there is not too much to it.

 
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I took a look at the data sheet for the system you are trying to simulate and I don't think a USART is going to do the job. The Motorola decoder expects a "binary-encoded trinary" signal with two different bit times, not the uniform bit times that conventional USARTs use. You could probably modify SoftwareSerial to accomplish what you're after.
« Last Edit: August 12, 2011, 06:27:25 pm by EmilyJane » Logged

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

thanks for your responses!

@MarkT: I hoped to find a way to avoid writing the interrupt driven code :-) but it seems that I have to write such library (which will take more time for me than I thaught). My problem is that I have no scope, so I have to do trial & error for the signal generation (that's a problem with all other solutions, too).

@Bill_Kerr: Yes, that's also a possibility to avoid the software signal generation code. But I know that there is a working(!) software implementation based on UARTs (http://srcpd.sourceforge.net/srcpd/index.html). I will keep in mind to change to the hardware signal generation when everything will fail.

@skyjumper: I will use the the Arduino UNO (328P). It seems that someone has made a Port from OpenDCC to the Arduino (http://developer.berlios.de/projects/microsrcp/) which is also based on UART output (like srcpd). But I hope to get arround the tricky timings when using the "right" bit rate to communicate with.

It seems that I have to write my own signal generation code with interrupts or I have to use the hardware encoder from Motorola...

Regards, Holger
Logged

Perl is the only language that looks the same before and after RSA encryption.

Pages: [1]   Go Up
Jump to: