Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

baud rate of UART to 1000000bps in Atmega2560?

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
BlackSky

Bascom Member



Joined: 01 Jan 2008
Posts: 21
Location: South Korea

south_korea.gif
PostPosted: Sat Oct 08, 2022 4:02 am    Post subject: baud rate of UART to 1000000bps in Atmega2560? Reply with quote

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
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Sat Oct 08, 2022 10:19 am    Post subject: Reply with quote

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
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Sat Oct 08, 2022 10:22 am    Post subject: Reply with quote

do not forget to use buffered serial input and output.
_________________
Mark
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sat Oct 08, 2022 10:27 am    Post subject: Reply with quote

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. Very Happy
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sat Oct 08, 2022 10:38 am    Post subject: Reply with quote

albertsm wrote:
to get a real good 1MB you need to alter the xtal to 12 Mhz

You're not serious. Shocked
Back to top
View user's profile
BlackSky

Bascom Member



Joined: 01 Jan 2008
Posts: 21
Location: South Korea

south_korea.gif
PostPosted: Sat Oct 08, 2022 11:00 pm    Post subject: Thanks to everyone who gave advice. Reply with quote

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
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Sun Oct 09, 2022 9:49 am    Post subject: Reply with quote

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
View user's profile Visit poster's website
BlackSky

Bascom Member



Joined: 01 Jan 2008
Posts: 21
Location: South Korea

south_korea.gif
PostPosted: Thu Oct 13, 2022 1:17 am    Post subject: Reply with quote

The code was completed with the help of many people.

Share the source.
https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=15066\

The radar sensor is the following products.
https://www.innosent.de/en/radarsysteme/isys-50er-serie/isys-5005/

I hope to be of some help to those in need.

And I wish MCS prosperity.

thank you

_________________
I love freedom....
and....
I enjoy programming....
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum