View previous topic :: View next topic |
Author |
Message |
BlackSky
Joined: 01 Jan 2008 Posts: 21 Location: South Korea
|
Posted: Sat Oct 08, 2022 4:02 am Post subject: baud rate of UART to 1000000bps in Atmega2560? |
|
|
hello?
Is it possible to set the baud rate of the UART to 1000000 on the Atmega2560?
This time, we need to communicate with the radar sensor (iSys-5005), but this sensor only supports communication speed of 1000000bps.
The crystal I am using is 11.0592Mhz.
Crystals can be changed if necessary.
Anyone please help
thank you
(BASCOM-AVR version : 2.0.8.5 , Latest : 2.0.8.5 ) _________________ I love freedom....
and....
I enjoy programming.... |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Sat Oct 08, 2022 10:19 am Post subject: |
|
|
yes 1MB should not be a problem. I think the highest possible is 3MB which i recent tested on a different chip.
to get a real good 1MB you need to alter the xtal to 12 Mhz or for more power to 24 Mhz _________________ Mark |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Sat Oct 08, 2022 10:22 am Post subject: |
|
|
do not forget to use buffered serial input and output. _________________ Mark |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Oct 08, 2022 10:27 am Post subject: |
|
|
If you want use a complex product as the iSys-5005, you should know its data sheet by heart.
I do hard to understand that in contrary you can't look up such simple thing in the ATM2560 data sheet.
As more the ATM2560's data sheet does not even require to calculate some fancy formula, instead various tables and samples are shown in section: 22.11 Examples of Baud Rate Setting.
You have to look for something ideally with zero percent error, table 22.11 shows for 11.0592MHz a line: 1M with two times a '-', means: not possible.
Walking through the tables, zero percent error is found at 1M only with 8MHz (U2Xn = 1) and 16MHz (U2Xn = 0 or 1) clock.
Be aware that at 8MHz system clock and 10 bits length per received byte (8 data-, 1 start- and 1 stop-bit), the available clock-cycles to process each byte is only 80 cycles.
A Bascom-command consists out of at least one, but more likely out of a few machine-/op-codes.
Each op-code uses up one to four clock cycles (most opcodes are one cycle), the available 80 clock cycles are fast used up.
For example the buffered receive routine (which is written in machine-code) uses interrupts, each interrupt call takes 69 to 73 clock cycles.
This means at 8MHz system clock the ATM2560 is busy for at least 86% of its available processing power as a byte stream is coming in.
A 16MHz crystal is recommendable, with 128 clock cycles to process one byte it leaves more power to process a stream.
Another option for receiving a stream is to write your own receive-routines, by clever coding you can do already with the 64 cycles of an 8MHz crystal.
Allover I'd say: Not knowing what crystal allows for 1 MBaud will be your tiniest problem. |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Oct 08, 2022 10:38 am Post subject: |
|
|
albertsm wrote: | to get a real good 1MB you need to alter the xtal to 12 Mhz |
You're not serious. |
|
Back to top |
|
|
BlackSky
Joined: 01 Jan 2008 Posts: 21 Location: South Korea
|
Posted: Sat Oct 08, 2022 11:00 pm Post subject: Thanks to everyone who gave advice. |
|
|
Thanks to everyone who gave advice.
I looked at the datasheet 22.11 of the Mega2560 you mentioned and it was explained.
I was lost without understanding this basic thing.
By changing the crystal to 16MHz according to the table, communication works normally.
Thanks again to everyone who gave advice. _________________ I love freedom....
and....
I enjoy programming.... |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Sun Oct 09, 2022 9:49 am Post subject: |
|
|
when you look in the report you will see the baud error. when 0% the baud is ok.
at 1 mb you should use the higher possible xtal possible. that is either 16 or 24 mhz. the reason is that you need time to handle the communication.
the radar sensor seems like a great device to work on.
let us know when you can actual interface it. _________________ Mark |
|
Back to top |
|
|
BlackSky
Joined: 01 Jan 2008 Posts: 21 Location: South Korea
|
|
Back to top |
|
|
|