4909 views|51 replies

3222

Posts

0

Resources
The OP
 

Does anyone know how the baud rate error is calculated? [Copy link]

 

Does anyone know how the baud rate error is calculated?

164949wrrcemrflv7aryyl.jpg (80.07 KB, downloads: 0)

164949wrrcemrflv7aryyl.jpg
This post is from 51mcu

Latest reply

[attach]506561[/attach]Serial communication see Chapter 8   Details Published on 2020-10-20 12:01
 

2w

Posts

0

Resources
2
 

You need to first understand what SMOD=0 and SMOD=1 mean, then understand how asynchronous serial communication is performed, and finally understand how the 51 microcontroller generates the baud rate for asynchronous serial communication.

This post is from 51mcu
 
 
 

2w

Posts

0

Resources
3
 

Note that the two numbers connected by the red line are the same, one is when SMOD=0, the other is when SMOD=1, the baud rates of the two are exactly twice.

This post is from 51mcu
 
 
 

2w

Posts

0

Resources
4
 

To calculate the baud rate error, you first need to know how to calculate the baud rate, right?

This post is from 51mcu

Comments

I looked it up but I really don't understand. Some people say to use clock frequency/division number/timer initial value directly. For example, if the baud rate is 115200 and the clock frequency is 24M, if it is divided by 4, it is {[24000000/4]/[24000000/4/115200]-115200}/11  Details Published on 2020-10-13 15:02
 
 
 

1942

Posts

2

Resources
5
 

You should first learn the formula for calculating the baud rate, and then substitute the corresponding parameters into it. The difference between the obtained baud rate and the desired baud rate can be obtained, and then the error can be obtained. And these have been sorted out by others. If you don't care about these, you can use them directly.

This post is from 51mcu
 
 
 

3222

Posts

0

Resources
6
 
maychang posted on 2020-10-12 19:32 If you want to calculate the baud rate error, you must first know how to calculate the baud rate, right?

I looked it up but I really don't understand. Some people say to use clock frequency/division number/timer initial value directly. For example, if the baud rate is 115200 and the clock frequency is 24M, if it is divided by 4, it is {[24000000/4]/[24000000/4/115200]-115200}/115200 *100%, right? ?

邮洽图片20201013145646.jpg (260.6 KB, downloads: 0)

邮洽图片20201013145646.jpg
This post is from 51mcu

Comments

Don’t worry about Timer 2 for now. The 51 microcontroller only has Timer 0 and Timer 1, but no Timer 2. The 52 microcontroller has Timer 2.  Details Published on 2020-10-13 16:47
Don’t worry about Timer 2 for now. The 51 microcontroller only has Timer 0 and Timer 1, but no Timer 2. The 52 microcontroller has Timer 2.  Details Published on 2020-10-13 16:45
Don’t worry about Timer 2 for now. The 51 microcontroller only has Timer 0 and Timer 1, but no Timer 2. The 52 microcontroller has Timer 2.  Details Published on 2020-10-13 16:31
Don’t worry about Timer 2 for now. The 51 microcontroller only has Timer 0 and Timer 1, but no Timer 2. The 52 microcontroller has Timer 2.  Details Published on 2020-10-13 16:22
Don’t worry about Timer 2 for now. The 51 microcontroller only has Timer 0 and Timer 1, but no Timer 2. The 52 microcontroller has Timer 2.  Details Published on 2020-10-13 15:42
 
 
 

2w

Posts

0

Resources
7
 
QWE4562009 posted on 2020-10-13 15:02 I looked at it but I really didn’t understand it. Some people said that they directly use the clock frequency/division number/timer initial value. For example, if the baud rate is 115200...

Don’t worry about Timer 2 for now. The 51 microcontroller only has Timer 0 and Timer 1, but no Timer 2. The 52 microcontroller has Timer 2.

This post is from 51mcu

Comments

After the quartz crystal frequency is determined, to change the overflow rate of the lower 8 bits of timer 1, you can only change the pre-loaded value of the upper 8 bits of timer 1.  Details Published on 2020-10-13 16:00
 
 
 

2w

Posts

0

Resources
8
 
This post was last edited by maychang on 2020-10-13 15:48
QWE4562009 posted on 2020-10-13 15:02 I looked at it but I really didn't understand it. Some people say that you can use the clock frequency/division number/timer initial value directly. For example, if you need a baud rate of 115200...

The 51 single-chip microcomputer must be connected to a quartz crystal (piezoelectric ceramics can also be used) as a clock generator.

For 51 single-chip microcomputer, 12 quartz crystal oscillation cycles are one clock cycle. Don't ask why, the hardware is designed this way. When the quartz crystal frequency is 12MHz, one clock cycle is 1us. When the quartz crystal frequency is 6MHz, one clock cycle is 2us. When the quartz crystal frequency is 4MHz, one clock cycle is 3us. When the quartz crystal frequency is 3MHz, one clock cycle is 4us. And so on.

Timer 1 has several working modes. Used as a baud rate generator, Timer 1 usually works in 8-bit auto-reload mode (mode 2). When Timer 1 works in 8-bit reload mode, the upper 8 bits are equivalent to an 8-bit register, which can be written with data in advance, and the lower 8 bits are counters that count clock cycles. When the upper 8 bits overflow, the data stored in the lower 8 bits are automatically reloaded into the upper 8 bits, and the clock cycles are still counted.

So if the quartz crystal frequency is 12MHz, and the data stored in the upper 8 bits of Timer 1 is FFH (255), the lower 8 bits of Timer 1 will overflow once every clock cycle (1us) (only one number is counted from FFH to 00H, which is 256). When the data stored in the upper 8 bits of Timer 1 is FEH (254), the lower 8 bits of Timer 1 will overflow once every two clock cycles (2us).

If the quartz crystal frequency is 6MHz, the high 8 bits of timer 1 store data as FFH (255), and the low 8 bits of timer 1 overflow once every clock cycle (2us) (only one number is counted from FFH to 00H, which is 256). When the high 8 bits of timer 1 store data as FEH (254), the low 8 bits of timer 1 overflow once every two clock cycles (4us).

If the quartz crystal frequency is 4MHz, the high 8 bits of timer 1 store data as FFH (255), and the low 8 bits of timer 1 overflow once every clock cycle (3us) (only one number is counted from FFH to 00H, which is 256). When the high 8 bits of timer 1 store data as FEH (254), the low 8 bits of timer 1 overflow once every two clock cycles (6us).

This post is from 51mcu

Comments

Overflow counts once?  Details Published on 2020-10-14 16:08
Overflow counts once?  Details Published on 2020-10-14 16:05
 
 
 

2w

Posts

0

Resources
9
 
This post was last edited by maychang on 2020-10-13 16:25
QWE4562009 posted on 2020-10-13 15:02 I looked at it but I really didn't understand it. Some people say that you can use the clock frequency/division number/timer initial value directly. For example, if you need a baud rate of 115200...

The number of overflows per second in the lower 8 bits of timer 1 is called the overflow rate of the lower 8 bits of timer 1. Therefore, when the quartz crystal frequency is 12MHz and the data stored in the upper 8 bits of timer 1 is 0xE6(230), the lower 8 bits of timer 1 overflow once every 26us, or 38461.54 times per second. When the quartz crystal frequency is 6MHz and the data stored in the upper 8 bits of timer 1 is 0xE6(230), the lower 8 bits of timer 1 overflow once every 52us, or 19230.77 times per second.

This post is from 51mcu

Comments

What should I do if the overflow occurs? Overflow means full, right? Does it mean that 65535 is full?  Details Published on 2020-10-14 16:11
What should I do if the overflow occurs? Overflow means full, right? Does it mean that 65535 is full?  Details Published on 2020-10-14 15:44
 
 
 

2w

Posts

0

Resources
10
 
This post was last edited by maychang on 2020-10-13 16:13
maychang published on 2020-10-13 15:24 Don’t worry about Timer 2 for now. The 51 microcontroller only has Timer 0 and Timer 1, but no Timer 2. Only the 52 microcontroller has Timer 2.

After the quartz crystal frequency is determined, to change the overflow rate of the lower 8 bits of timer 1, you can only change the preload value of the upper 8 bits of timer 1. The larger the preload value, the higher the overflow rate of the lower 8 bits of timer 1. The maximum value can only be FFH (255), at which time the overflow rate of the lower 8 bits of timer 1 is 1/12 of the quartz crystal frequency.

This post is from 51mcu

Comments

What is this overflow rate? 65535-initial value?  Details Published on 2020-10-14 15:43
 
 
 

2w

Posts

0

Resources
11
 
This post was last edited by maychang on 2020-10-13 16:32
QWE4562009 posted on 2020-10-13 15:02 I looked at it but I really didn't understand it. Some people say that you can use the clock frequency/division number/timer initial value directly. For example, if you need a baud rate of 115200...

When SMOD=0, the overflow rate of the lower 8 bits of timer 1 will be divided by 32 (frequency division. Don't ask why, the hardware is designed this way), but when SMOD=1, the overflow rate of the lower 8 bits of timer 1 will be divided by 16, which is the actual baud rate you use.

For example, the quartz crystal frequency is 12MHz, the high 8 bits of timer 1 are preloaded with the value E6H, SMOD = 1, 38461.54/16 = 2403.85, which is the actual baud rate you use. In other words, the time taken by each bit of asynchronous serial communication is 1/2403.85 = 0.000416 seconds.

This post is from 51mcu
 
 
 

2w

Posts

0

Resources
12
 
QWE4562009 posted on 2020-10-13 15:02 I looked at it but I really didn’t understand it. Some people said that they directly use the clock frequency/division number/timer initial value. For example, if the baud rate is 115200...

As for the baud rate error in this case (quartz crystal frequency 12MHz, timer 1 high 8 bits preloaded with value E6H, SMOD=1), you can calculate it yourself.

This post is from 51mcu
 
 
 

2w

Posts

0

Resources
13
 
QWE4562009 posted on 2020-10-13 15:02 I looked at it but I really didn’t understand it. Some people said that they directly use the clock frequency/division number/timer initial value. For example, if the baud rate is 115200...

If the quartz crystal frequency is 6MHz, the high 8 bits of timer 1 are preloaded with the value E6H, and SMOD=1, then your actual baud rate is only 1201.92.

This post is from 51mcu

Comments

Where does this pre-loaded value come from?   Details Published on 2020-10-14 15:42
 
 
 

2w

Posts

0

Resources
14
 
QWE4562009 posted on 2020-10-13 15:02 I looked at it but I really didn’t understand it. Some people said that they directly use the clock frequency/division number/timer initial value. For example, if the baud rate is 115200...

"Some people say that we can use clock frequency/division number/timer initial value directly"

That's nonsense.

This post is from 51mcu
 
 
 

7422

Posts

2

Resources
15
 

What on earth does the OP do? Why do these things... So jumpy

This post is from 51mcu

Comments

If you encounter it, ask about the hardware  Details Published on 2020-10-14 15:41
 
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 

3222

Posts

0

Resources
16
 
freebsder posted on 2020-10-13 21:00 What on earth does the OP do? And he does all this... So jumping

If you encounter it, ask about the hardware

This post is from 51mcu
 
 
 

3222

Posts

0

Resources
17
 
maychang posted on 2020-10-13 16:45 If the quartz crystal frequency is 6MHz, the high 8 bits of timer 1 are preloaded with the value E6H, and SMOD=1, then your actual baud rate is only 1201.92.

Where does this pre-loaded value come from?

This post is from 51mcu

Comments

"Where does this pre-loaded value come from?" When the microcontroller is initialized, you write the high 8 bits of timer 1, that is, write TH1.  Details Published on 2020-10-14 15:48
"Where does this pre-loaded value come from?" When the microcontroller is initialized, you write the high 8 bits of timer 1, that is, write TH1.  Details Published on 2020-10-14 15:44
 
 
 

3222

Posts

0

Resources
18
 
maychang posted on 2020-10-13 16:00 maychang posted on 2020-10-13 15:24 Don't worry about timer 2 for now. The 51 microcontroller only has timer 0 and timer 1, but no timer 2. The 52 microcontroller...

What is this overflow rate? 65535-initial value?

This post is from 51mcu
 
 
 

2w

Posts

0

Resources
19
 
QWE4562009 posted on 2020-10-14 15:42 Where does this pre-installed value come from

“Where does this pre-loaded value come from?”

When the microcontroller is initialized, you write the high 8 bits of timer 1, that is, write TH1.

This post is from 51mcu
 
 
 

3222

Posts

0

Resources
20
 
maychang posted on 2020-10-13 15:59 QWE4562009 posted on 2020-10-13 15:02 I looked at it but I really didn’t understand it. Some people said that the clock frequency/division number/timing can be used directly...

What should I do if the overflow occurs? Overflow means full, right? Does it mean that 65535 is full?

This post is from 51mcu

Comments

When you add 1 and it becomes 0, it is overflow. Just like when you do first grade math, 9 plus 1 equals 10, and when it reaches 10, it goes up by 1, and the ones place is 0.  Details Published on 2020-10-14 15:53
When you add 1 and it becomes 0, it is overflow. Just like when you do first grade math, 9 plus 1 equals 10, and when it reaches 10, it goes up by 1, and the ones place is 0.  Details Published on 2020-10-14 15:51
When you add 1 and it becomes 0, it is overflow. Just like when you do first grade math, 9 plus 1 equals 10, and when it reaches 10, it goes up by 1, and the ones place is 0.  Details Published on 2020-10-14 15:51
 
 
 

Guess Your Favourite
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list