Go Down

Topic: Max Baud Rate for Arduino Uno (Read 15 times) previous topic - next topic

nitin29

Quote

There are faster alternatives to using this overload of Serial.print.


What are the faster alternatives to Serial.print() ?

At 38400 bps: Difference to call to Dx() (248 usec/byte) and Serial.print() (264 usec/byte) is 16 usec/byte.

-- Nitin

dc42


What are the faster alternatives to Serial.print() ?

At 38400 bps: Difference to call to Dx() (248 usec/byte) and Serial.print() (264 usec/byte) is 16 usec/byte.


I don't understand what you are comparing. Do you mean that Serial.print(Dx()) takes only 16us longer to execute than Dx() ? If so, I am wrong and you may ignore what follows.

I am referring to the overload of Serial.print() that takes an integer. This is the one you use to print the values of Dx() and Dy(). If you time calls to different overloads of Serial.print(), I think you will find that printing a number e.g. "Serial.print(123)" or "Serial.print(123, DEC)" is, at the very high baud rates you are trying to use, slower than printing a character e.g. "Serial.print(';')" or printing a short string e.g. "Serial.print("123")". This is because printing a number involves quite a lot of code to convert the number into characters. It is made worse because the atmega processor doesn't have a hardware divide instruction, so to divide by 10 and get quotient and remainder is quite slow.

It would be faster to do the integer-to-characters conversion using a lookup table, or else to convert the number to hex instead of decimal so you can use shift and mask instead of quotient and remainder.
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.

nitin29

Yes, I meant what you understood in your first line.

However, I couldn't resist to read further. You pointed something interesting about conversion from int to char and int to hex. I will check how long the execution takes for both of these conversion. If it take less for int to hex conversion than I can improve the 16 usec time difference as I can do the hex to char conversion on PC.
-- Nitin

dc42

Conversion to hex using Serial.print is unlikely to be any faster than conversion to decimal, because it uses the same code but with a different divisor. However, it is possible to write a more efficient function for converting to hex and then printing the result, by using shift instead of divide.
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.

jumshed63

Hi,
How did you tested 1,2 mbps as window7 does not support these higher baud rates.

Thanks

Go Up