Pages: 1 [2] 3 4 5   Go Down
Author Topic: Max Baud Rate for Arduino Uno  (Read 14688 times)
0 Members and 1 Guest are viewing this topic.
Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looking continuous on the screen, I can see a lag every 2-3 sec on Teraterm in which the lines are updated. It may be related to the buffer.

Now, a new question came to my mind. Ok, I can set the 1Mbps - 2Mbps on these terminal but am I really getting these transfer rates?

If I do some maths, I have "51,255,65,2,0;" data packet, each of which is 10 Bytes, and in 2 second, the txt file becomes around 25KB = 25000 * 8 bit = 200000 bits, so the transfer rate is indeed 100Kbps instead of 2Mbps!

Any thought?
Logged

 -- Nitin

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Still wiondering if receiveing would work too at such speed.


Well keep in mind that if you are using interrupts that interupts are disabled while inside your ISR, and if the recieve characters are screaming in the receiver pin with interrupts disabled, dropping characters are possible.

Lefty
Logged

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

2Mbs = interrupt occurring at 200Khz (assuming 1 start, 1 stop, 0 parity) , which gives you 16Mhz/200Khz = 80 clock cycles in between interrupts.  If assume single cycle instructions, after saving and restoring context for the ISR, reading the data, and whatever else you need to do, you are looking at not a lot of time.
Logged

http://ilektron-x.blogspot.com - Hacking and General Electronics Goodness

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

I understand a continuous stream at this speed is beyond Arduino's caps, but if bursts of data could be send this fast it opens up possibilities.

Quote
If I do some maths, I have "51,255,65,2,0;" data packet, each of which is 10 Bytes, and in 2 second, the txt file becomes around 25KB = 25000 * 8 bit = 200000 bits, so the transfer rate is indeed 100Kbps instead of 2Mbps!

Any thought?

numbers look quite realistic to me. It just means that you are communicating approx 5% of the time (rest of the time using for measurements, math, formatting etc)
Logged

Rob Tillaart

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

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

Confirmed 2Mbit on Arduino 2009 ==> win7/64 realterm.exe

100K chars took 594 msec @ 200000 baud = 168350 bytes/second   =   5.94 microsec/byte

Note this test sketch leaves no room for additional math so I consider this speed as an upper limit.


Code:
void setup()
{
  Serial.begin(2000000);  
  
  unsigned long t1 = millis();
  for (long i=0; i< 10000; i++)
  {
   Serial.println("12345678");  // 10 bytes incl \r\n  
  }
  unsigned long t2 = millis() - t1;
  
  Serial.println();
  Serial.println(t2);  
}

void loop()
{
}
« Last Edit: August 29, 2011, 03:07:19 am by robtillaart » Logged

Rob Tillaart

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

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6614
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If your need is to get reliable high speed data transfer from your device to a PC via USB, it might be better to use a board that has native USB support (rather than serial over USB) such as the Teensy.
« Last Edit: August 29, 2011, 04:47:54 am by dc42 » Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

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

Now, I feel completely cheated with transfer rates and terminal program.  smiley-mad
I have set the transfer rate of 250Kbps. But, what I get from the captured file shows me a transfer rate of only 48.8Kbps.

Code from another sensor:
Code:
void loop()
{
  Serial.print(Dx(), DEC);
  Serial.print(",");
  Serial.print(Dy(), DEC);
  Serial.print(";");
}

This could be because of ,"DEC" argument?
I don't see any math in my codes?

@dc42: But, isn't Atmega8 at Arduino Uno  also natively support USB protocoll? What difference it will make anyhow?

So, all this data transfer downgrade is because of terminal program that is capturing data or Arduino Uno?
« Last Edit: August 29, 2011, 10:18:17 am by nitin29 » Logged

 -- Nitin

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


No it is because the Serial datastream cannot send bursts of bytes one after another. Each byte is a packet with some interpacket space in between. So you can get ~70% efficiency at max. But as the Arduino is single tasking that number can even be a bit lower.
Logged

Rob Tillaart

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

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

I am only interested in data transfer rate of 250Kbps excluding all the inter packet & background operation down by Arduino or serial protocol.  Sensor data is available at Arduino168 at the rate of 125Kbps.

Do you know, how can this be done? As I have checked with the 2 Mbps, I only got around 100Kbps with Realterm. If I can get around 250Kbps, I would be fine.

Thanks
Logged

 -- Nitin

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

More updates: I tested the Arduino again (in hope to increasing the actual transfer rates). I tested upto 10Mbps.
I could made it work upto 4 Mbps!

But, a big but...the transfer rate to the txt file is somehow stuck to a max of 50 Kbps.
« Last Edit: August 29, 2011, 11:08:26 am by nitin29 » Logged

 -- Nitin

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

4Mbps failed for me (Arduino2009)  so I think above 2Mbps there starts the gray area, at least with the standard Serial class.

Think you can get a factor 2 if you hand optimize the code (but that is the max), but then still you will get stuck at 200K. Then you have to look for compression of the datastream etc.


Quote
I am only interested in data transfer rate of 250Kbps excluding all the inter packet & background operation down by Arduino or serial protocol.
You should investigate SPI communication as Serial will not do 250Kbps , a good starting point may be - http://www.gammon.com.au/forum/?id=10892 -
Logged

Rob Tillaart

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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13707
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
Sensor data is available at Arduino168 at the rate of 125Kbps.
Can you tell more, datasheet?
How do you get this into the Arduino?
Logged

Rob Tillaart

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

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

Quote
About the purpose, I have several Avago optical navigation sensors which I have to tests for performance and collect the data. The Serial Port interface of sensor has 2 Mhz as max. frequency. For your reference, ADNS 6090 (one of the sensor I am using): http://www.avagotech.com/docs/AV02-1362EN

Now, I wish to send some register addresses and retrieve some values in a continuous loop in bit banging way. The values I am interested are, Delta X, Delta Y, Shutter Value and Surface Quality. All are 8 bit register (Only one of sensor has 16 bit for Delta X and Delta Y, which are broken down as  Delta X_L & Delta X_H, both 8 bit so double write & read effort). Register read is sequential.

Now, doing some maths, if 2 Mhz clock has 0.5 usec per cycle. If 8 bit is written (arduino->sensor)and then 8 bit is read (sensor->arduino), a total of 16 cycles of 8 usec for sensor. So, data is available at Arduino  with 125 Kbps/Khz (for a single register readout). Then Arduino must be using some 8 cycles or 1 cycle of 62 nsec each per register for sending data->tx line and assume sampling frequency by nyquist to be double of data available frequency. then question is how much baud rate should be sufficient? About 230.4 Kbps?

I suppose the data (each byte) would be sequentially goes to the serial port.
Logged

 -- Nitin

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13707
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
Now, doing some maths, if 2 Mhz clock has 0.5 usec per cycle. If 8 bit is written (arduino->sensor)and then 8 bit is read (sensor->arduino), a total of 16 cycles of 8 usec for sensor.
OK that's the theory,

disclaimer 0% experience with this sensor:
to write a register you have to send the address or so of the register, and then the data, for reading the same so the bandwidth needed doubles quite easily.

Have you implemented the readout of the sensor and timed it?  How fast can registers be fetched in practice?.

Code:
void setup()
{
  Serial.begin(9600);
  Serial.begin("start");

  unsigned long before = micros();
  for (long i=0; i<1000; i++)
  {
     // insert code to fetch one register to a var here
  }
  unsigned long duration = micros() - before;
  Serial.println(duration);
}

void loop(){}
Logged

Rob Tillaart

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

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

I checked with your code. The usec value is 353748 usec.
Hmm...per register call would be around 0.3537 ms...which would be 2.8 Kbps.

Is this rate so slow because I am using bit banging?
Logged

 -- Nitin

Pages: 1 [2] 3 4 5   Go Up
Jump to: