Pages: [1]   Go Down
Author Topic: Non-Standard Baud Rate Not Working  (Read 2615 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I have an Arduino Pro (8MHz/m328/3.3v) and wanted to use a serial baud rate that's higher than 57.6k. I realize that 115.2k and 230.4k aren't going to work as the "error" is too high. So, I tried to use 250k, as it has a 0% error in accordance with page 202 of the manual: http://www.atmel.com/Images/doc8161.pdf

Well, when I ran the following command to read outputted serial data:
Code:
screen  /dev/tty.usbserial-A601EKZ6 250000

I get an endless supply of this:


Do I need to change something else before I can use this baud rate?

Thanks!
Aakash

PS. Here's the code I'm using. Basically, I need the higher baud rate so I can output data faster. I'm needing to transfer ~30bytes in about a millisecond and (10/57600)*30= ~5ms. So, 250000K might remedy this, as (10/250000)*30 = 1.2ms

Code:
int counter = 0;
unsigned long oldTime = 0;
String output = "";
void setup(){

  Serial.begin(250000);
  Serial.println("---BASIC SERIAL TIMER APP INITIALIZED---");
  oldTime = micros();
}
void loop(){
 
      output += micros()-oldTime;
      oldTime = micros();
      Serial.println(output);
      output = "";
      counter++;
     

}
Logged

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

better send the value of output binary as 4 bytes iso as text. Then you do not need to convert and it is less bytes to send.
now the unsigned long takes 8=12 chars,, while in fact you only need 4 bytes. (50-66% reduction.

the easiest way is to make a union of an array of 4 bytes and an unsigned long,
fill it as an UL and use the byte array for sending.





Logged

Rob Tillaart

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

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

@robtillaart - Thanks for the suggestion! However, if I understand correctly, that will improve the performance of my current app at 57.6k. But, at that rate there is still a 3.5% error rate and the project I'm working will spit out a lot of data and needs to be accurate (it's for scientific data collection). The next lowest baud rate is 38.4k (0.2% error) and that's way too slow for my use as that 30 character figure I stated earlier might increase as I proceed with my project.

So my question remains - how can I get 250k baud rate working? I'm interested in the 500k baud rate as well (it has 0% error as well, according to the manual), but thought it would be wise to get the lower of the two rates working first.

Thanks a lot!
Aakash
« Last Edit: September 27, 2013, 12:05:56 am by Aakash » Logged

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

The first thing to learn is if the problem is at the sending end or the receiving end. Do you have a oscilloscope or logic analyzer?

Also try to use another terminal program iso screen.  Can the  <?> chars be caused by reading an empty buffer?

Note that if the Crystal of the Arduino deviates a bit from the 8/16Mhz you can get an additional error.
You can try to compensate errors by using non standard baudrates e.g. 243000 (==250000 -3%) or 257000 baud. (trial and error is your friend)

tweaked the test code a bit to make it slightly faster. (~10% @115200baud)
Code:
int counter = 0;
unsigned long oldTime = 0;

void setup(){

  Serial.begin(115200);
  Serial.println("---BASIC SERIAL TIMER APP INITIALIZED---");
  oldTime = micros();
}
void loop()
{
      String output(micros()-oldTime);
      oldTime = micros();
      Serial.println(output);
      counter++;
}
Logged

Rob Tillaart

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

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

robtillaart - Okay, so I used a logic analyzer with the Arduino set to various baud rates (9600, 19200, 38400, 57600, and 250000bps)  and found something strange.

When using the following command on every test, excluding 250000, I was able to get "HELLO" printed repeatedly.
Code:
screen  /dev/tty.usbserial-A601EKZ6 <BAUDRATE>

The strange part is that the logic analyzer was only able successfully show correct data on 9600bps.  

Please see the attached files for the logic analyzer screenshot (excluding 19200, due to the attachment limit). The filenames correspond with the baud rate.

Is this a clock problem? If so, is my oscillator really *that* bad?

Thanks,
Aakash

Here's the code I used to test:
Code:
void setup(){

  Serial.begin(57600);
  Serial.println("---BASIC SERIAL TIMER APP INITIALIZED---");
}
void loop(){

      Serial.println("HELLO");

}


* 9600.png (148.29 KB, 1434x642 - viewed 30 times.)

* 19200.png (151.29 KB, 1434x642 - viewed 32 times.)

* 57600.png (150.38 KB, 1434x550 - viewed 25 times.)

* 250000.png (163.79 KB, 1434x642 - viewed 31 times.)
« Last Edit: September 27, 2013, 11:32:05 am by Aakash » Logged

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

the signals seems to be ok at first sight.
How do you connect the Arduino to the linux device? I mean do you use a voltage converter?
Logged

Rob Tillaart

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

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

Rob,

Why isn't the logic analyzer able to decipher the bytes correctly and gives those errors on the higher baud rates?

Also, I'm connecting to the Arduino via a Macbook Air running OS X 10.8. The converter I'm using is this: https://www.sparkfun.com/products/9873
The board I'm using is this: https://www.sparkfun.com/products/10914
So, they're both 3.3v devices.

Thanks again for your help,
Aakash
« Last Edit: September 27, 2013, 05:10:55 pm by Aakash » Logged

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

Rob,

Why isn't the logic analyzer able to decipher the bytes correctly and gives those errors on the higher baud rates?
don't know, the signal seems OK, as I see quite some pulses.

Can you make some screen shots from this sketch, it will only send 4 bytes with distinct patterns (should fit on a screenshot) that should be recognizable at every baud rate.

Code:
void setup()
{
  Serial.begin(115200); // try baudrates 9600 - 19200 - 38400 -57600 - 115200

  Serial.write(0xAA);   // 10101010
  Serial.write(0x66);   // 01100110
  Serial.write(0xF7);   // 11110111
  Serial.write(0x31);   // 00110001
}
void loop()
{
}

Logged

Rob Tillaart

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

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

Rob,

The logic analyzer output looked great in all cases.

EDIT 1: Okay, so I tried using PuTTY on Windows inside of a VM and I got it to work at both 250000bps and 500000bps.

EDIT 2: I just tried with CoolTerm on OS X at 500000bps and it worked. Guess the screen command is just wonky.

So a question remains:

When measuring the loop-time at 250k and 500k using the sketch in my first post, they both got the same loop time (Around ~240-250 microseconds.) When adding more characters to each line [about 12 in total] and reading the state of a pin I get around 1100-1200 microseconds per loop in both (I measured that the logic, excluding the Serial.print(), takes around 240 microseconds). Why are these times the same?
More importantly, would using an Arduino Uno @ 16MHz improve these times dramatically?  What about the Arduino Due?

Thanks again!
Aakash
« Last Edit: September 29, 2013, 02:56:49 am by Aakash » Logged

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

Quote
When measuring the loop-time at 250k and 500k using the sketch in my first post, they both got the same loop time (Around ~240-250 microseconds.)
...
Why are these times the same?
250Kbit => 25KB/sec = 40uSec/char
In theory 12 chars @250K  => (at least) 500 usec for sending;  @500K  ==> 250 usec for sending,

so you must see differences. Can you post screen shots of the LA?


Quote
would using an Arduino Uno @ 16MHz improve these times dramatically?  What about the Arduino Due?
An Arduino UNO =16Mhz and it would do everything except the actual transmit twice as fast as a 8 Mhz, so you should get loop times of about 600usec.
A DUE is 80+Mhz so 10x faster so loop times of 150 usec might be possible but I dont have much Due experience.

Logged

Rob Tillaart

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

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

Rob,

Here are the analyzer outputs you requested:

9600:

19200:

38400:

57600:

115200:

250000:

500000:


Thanks
Aakash

EDIT: Added 500k screenshot.

EDIT 2: After looking closely, I noticed that it took ~150 microseconds at 250k and ~120 microseconds at 500k. I didn't have a serial console attached during these tests. Why is there such a huge gap in time between each byte? Would buying the faster Due remedy this?
« Last Edit: September 29, 2013, 08:22:51 pm by Aakash » Logged

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

Quote
Why is there such a huge gap in time between each byte? Would buying the faster Due remedy this?
It seems that at 500K the transmission is not the bottleneck any more, probably the overhead of the serial library itself...

A Due should perform better as it runs at 80+ Mhz..
Logged

Rob Tillaart

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

Pages: [1]   Go Up
Jump to: