A method and system for baud rate adaptation detection of a can bus

By using multiple sampling and calculation of the greatest common divisor, combined with hardware circuits and software modules, the problem of CAN bus baud rate detection error was solved, achieving more accurate baud rate detection and reliable data transmission.

CN116633813BActive Publication Date: 2025-11-21GUANGZHOU XINYUNYUAN MICROELECTRONICS CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310808802.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-30
Publication Date
2025-11-21
Estimated Expiration
2043-06-30

AI Technical Summary

Technical Problem

In existing CAN bus baud rate adaptive detection methods, the hardware acquisition and processing leads to inaccurate error ranges.

Method used

By sampling CAN data frames from the CAN bus multiple times, the effective pulse width data is obtained, the greatest common divisor is calculated, and the current baud rate value is determined using a pre-stored baud rate table. The hardware circuit and software module are then used for correction and judgment.

Benefits of technology

This improves the accuracy of CAN bus baud rate detection, ensuring data transmission reliability and system performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116633813B_ABST
    Figure CN116633813B_ABST
Patent Text Reader

Abstract

The application provides a baud rate adaptive detection method and system of a CAN bus, the baud rate adaptive detection method of the CAN bus at least includes the following steps: firstly, sampling the CAN data frame of the CAN bus for multiple times, and processing each CAN data frame to obtain effective pulse width data; then, calculating all the effective pulse width data to obtain the greatest common divisor; finally, determining the final baud rate value based on all the greatest common divisors and a pre-stored baud rate table. The application can accurately detect the baud rate of the CAN bus, thereby ensuring the reliability of data transmission in the CAN bus system. The baud rate adaptive detection system of the CAN bus of the application improves the accuracy of detecting the baud rate of the CAN bus through the mutual combination of hardware circuit and software function module, thereby making the baud rate-based data transmission more reliable and the performance of the CAN bus system better.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of industrial field bus communication, in particular to a baud rate adaptive detection method and system of CAN bus. BACKGROUND

[0002] CAN bus is valued for its high reliability and good error detection capability, and is widely used in industrial automation, monitoring system and many other fields. CAN bus uses different baud rates in different application environments. Baud rate refers to the rate of effective pulse width data signal modulating carrier, and is also an index of transmission channel bandwidth. At present, the detection methods of baud rate adaptation include:

[0003] Method one: software controls CAN controller to open the listening mode, configures a certain baud rate to listen to CAN bus, generates error interrupt or completes interrupt, and finally obtains the matching baud rate. This method takes a long time to operate, and the software intervention control is more.

[0004] Method two: hardware collects each pulse width of CAN bus message, and then compares the obtained data one by one to obtain the relationship of pulse width. Because the pulse width of CAN message may be 1-5 bits, such as 3 bits and 2 bits, the ratio is 1.5. Because this relationship can only be obtained by 2 and 3, the pulse width of 1 bit can be known. However, this method does not consider the jitter of CAN bus itself and the sampling error, and the ratio calculation involves floating point number, which makes the error range more uncertain and the hardware implementation more inconvenient. SUMMARY

[0005] In view of the above-mentioned shortcomings of the prior art, the purpose of the present application is to provide a baud rate adaptive detection method and system of CAN bus, which is used to solve the problem of inaccurate error range caused by hardware collection and processing in the prior art.

[0006] To achieve the above-mentioned purpose, the present application provides a baud rate adaptive detection method of CAN bus, which at least includes the following steps:

[0007] S1, sampling CAN data frame of CAN bus for multiple times, and processing each CAN data frame to obtain effective pulse width data;

[0008] S2, calculating all effective pulse width data to obtain the greatest common divisor;

[0009] S3, determining the current baud rate value of CAN bus based on all greatest common divisors and a pre-stored baud rate table.

[0010] Preferably, the process of processing each CAN data frame to obtain effective pulse width data includes:

[0011] synchronizing, statistically processing the CAN data frames to obtain intermediate pulse width data;

[0012] correcting each intermediate pulse width data to obtain the effective pulse width data.

[0013] Preferably, the process of correcting each intermediate pulse width data to obtain the effective pulse width data is:

[0014] (1) screening all the intermediate pulse width data based on ideal pulse width of multiple set baud rates to obtain screened pulse width data;

[0015] (2) processing the screened pulse width data to obtain the effective pulse width data.

[0016] Preferably, the correction is based on the ideal pulse width, the jitter tolerance and the error caused by the synchronization circuit.

[0017] Preferably, the effective pulse width data is [(ideal pulse width*(1-jitter tolerance) – compensation value) ~ (ideal pulse width*(1+ jitter tolerance) + compensation value)], wherein the compensation value is used to compensate the error caused by the first level synchronization circuit.

[0018] Preferably, Stein algorithm is used to calculate all the effective pulse width data to obtain the greatest common divisor.

[0019] Preferably, the process of determining the current baud rate value of the CAN bus based on all the greatest common divisors and the pre-stored baud rate table comprises:

[0020] obtaining the initial baud rate value of each CAN data frame based on the greatest common divisor of each CAN data frame and the pre-stored baud rate matching table;

[0021] determining the final baud rate value based on all the initial baud rate values, and taking the final baud rate value as the current baud rate value of the CAN bus.

[0022] Preferably, the process of determining the initial baud rate value by using the maximum pulse width and the minimum pulse width for secondary judgment comprises:

[0023] (1) taking the maximum pulse width and the minimum pulse width as a ratio to obtain a ratio result;

[0024] (2) recalculating the ratio result to obtain a matching pulse width;

[0025] (3) determining the initial baud rate value based on the matching pulse width and the pre-stored baud rate table.

[0026] Preferably, determining the final baud rate value based on all the initial baud rate values comprises:

[0027] If all frames have the same initial baud rate value, then the initial baud rate value is directly determined as the final baud rate value;

[0028] If the initial baud rate values ​​of multiple frames are not all the same, the initial baud rate value with the same majority will be determined as the final baud rate value.

[0029] To achieve the above objectives, the present invention also provides a baud rate adaptive detection system for a CAN bus, comprising a synchronization circuit module, a correction module, a calculation module, and a decision module;

[0030] The input terminal of the synchronization circuit module is connected to the CAN bus and is used to synchronize the interpolation level output by the CAN bus to obtain intermediate pulse width data.

[0031] The correction module corrects the intermediate pulse width data to obtain effective pulse width data;

[0032] The calculation module calculates the greatest common divisor of the effective pulse width data;

[0033] The decision module performs matching and judgment based on the greatest common divisor and the pre-stored baud rate table to obtain the current baud rate value of the CAN bus.

[0034] As described above, the CAN bus baud rate adaptive detection method and system of the present invention have the following beneficial effects:

[0035] This invention provides a method and system for adaptive baud rate detection of a CAN bus. The method includes at least the following steps: first, sampling CAN data frames multiple times and processing each CAN data frame to obtain effective pulse width data; then, calculating the greatest common divisor (GCD) of all effective pulse width data; and finally, determining the final baud rate value based on all GCDs and a pre-stored baud rate table. This invention can accurately detect the baud rate of the CAN bus, thereby ensuring the reliability of data transmission in the CAN bus system. The adaptive baud rate detection system of this invention improves the accuracy of baud rate detection by combining hardware circuits and software functional modules, thus making baud rate-based data transmission more reliable and improving the performance of the CAN bus system. Attached Figure Description

[0036] Figure 1 The diagram shows a flowchart of the baud rate adaptive detection method for the CAN bus.

[0037] Figure 2 The diagram shown is a structural schematic of the CAN bus of this invention.

[0038] Figure 3The diagram shows the signal transmission and reception in the CAN bus of this invention.

[0039] Figure 4 The diagram shown is a structural schematic of the CAN bus baud rate adaptive detection system of the present invention. Detailed Implementation

[0040] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention.

[0041] Please see Figures 1-4 It should be noted that the illustrations provided in this embodiment are only schematic representations of the basic concept of the present invention. Therefore, the drawings only show the components related to the present invention and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.

[0042] Example 1

[0043] The flowchart of the CAN bus baud rate adaptive detection method of the present invention is as follows: Figure 1 As shown, now combined with Figure 1 This invention provides a detailed description of the adaptive baud rate detection method for the CAN bus, which includes at least the following:

[0044] S1, sample the CAN data frames of the CAN bus multiple times, and process each CAN data frame to obtain the effective pulse width data;

[0045] like Figure 2 The diagram shows a CAN bus. The CAN bus is a shared network bus consisting of two buses, CAN H and CAN L. These two buses form a differential voltage to achieve data transmission. Each end has a terminating resistor. When receiving a bus signal, the CAN transceiver converts the signal level into a logic state; that is, it subtracts the CAN H and CAN L levels to obtain an interpolated level. A dominant level is represented by logic 0, and a recessive level by logic 1. The MCU's CAN Tx pin (i.e., the transmit port) is connected to the CAN transceiver's receive port, and the MCU's CAN Rx pin (i.e., the receive port) is connected to the CAN transceiver's transmit port, supporting CAN bus transmission and reception respectively. Figure 3 As shown.

[0046] CAN defines the idle state as recessive. The initial state is recessive (received level is 1), and then it waits for the level to become 0. Specifically, when the system starts up, it waits for normal CAN data frames to be sent on the CAN bus, detects the level of CAN Rx, and when a falling edge is detected, it starts using clock counting to record the length of each subsequent pulse.

[0047] In addition, the maximum pulse width and minimum pulse width can also be recorded during the sampling and recording process.

[0048] In this invention, the process of processing each CAN data frame to obtain effective pulse width data includes:

[0049] S11, Synchronize and statistically process the CAN data frame to obtain intermediate pulse width data;

[0050] This invention uses a high-frequency clock (taking an 80MHz clock as an example) to synchronize the CANRx signal to ensure the accuracy of data sampling.

[0051] This invention records the synchronization signal based on clock counting to count the length of each pulse width in the CAN data frame; during the recording process, this invention also counts the maximum and minimum pulse widths to assist in matching with a pre-stored baud rate table.

[0052] S12, each intermediate pulse width data is corrected to obtain the effective pulse width data;

[0053] This invention corrects each pulse width to eliminate the effects of synchronization errors and a specified jitter tolerance (e.g., 3%).

[0054] The process of correcting each intermediate pulse width data to obtain the effective pulse width data is as follows:

[0055] (1) Based on multiple ideal pulse widths with set baud rates, all intermediate pulse width data are filtered to obtain filtered pulse width data;

[0056] In this invention, the ideal pulse width for multiple baud rates is 1 bit to 5 bits.

[0057] If the pulse width of intermediate pulse width data is outside the ideal pulse width range, the intermediate pulse width data is discarded; otherwise, it is retained. In other words, if the pulse width of a certain baud rate is outside the correction range, the data is discarded. Alternatively, unwanted baud rates can be configured to be excluded from the comparison based on known information.

[0058] (2) The filtered pulse width data is processed to obtain the effective pulse width data.

[0059] This invention corrects errors based on ideal pulse width, jitter tolerance, and synchronization circuit.

[0060] The present invention processes each selected pulse width data to obtain the corresponding effective pulse width data, which is the pulse width data range.

[0061] The effective pulse width data is [(ideal pulse width * (1 - jitter tolerance) - compensation value) ~ (ideal pulse width * (1 + jitter tolerance) + compensation value)], where the compensation value is used to compensate for the error caused by the first-stage synchronization circuit.

[0062] In this embodiment of the invention, taking a 1M baud rate as an example, based on an 80M clock count, the ideal pulse width of 1 bit is 80, the compensation value is 2, considering a 3% error, it is 75.6~84.4, considering a 5% error, it is 74~86, considering a 10% error, it is 70~90; and so on, to obtain pulse width data of other bits and other baud rates for correction and filtering of pulse width data.

[0063] S2, calculate the greatest common divisor of all valid pulse width data;

[0064] In this invention, the Stein algorithm is used to calculate the greatest common divisor of all valid pulse width data. The steps of the Stein algorithm are as follows:

[0065] (1) When both numbers are even, divide them by 2 until at least one number is odd, and record the product k of all the common factors 2 that have been removed.

[0066] (2) If there is still an even number, divide by 2 continuously until the number becomes odd;

[0067] (3) Use the Euclidean algorithm (the method of subtraction between two odd numbers), i.e., GCD(a,b)=GCD(ab,b), or the Euclidean algorithm to find the greatest common divisor d of the two odd numbers;

[0068] (4) The greatest common divisor of the two numbers is d*k.

[0069] Specifically, the greatest common divisor is continuously calculated before the CAN frame ends to obtain the final GCD value. The CAN frame format's end flag (EOF) is a 7-bit recessive state, plus the last recessive separator in the ACK field, totaling 8 bits. Since there will be no pulse width greater than 5 bits in the middle of the frame, 7 * the minimum pulse width is taken as the end-of-sampling flag.

[0070] The first and second valid pulse width data are directly used to calculate the first greatest common divisor. The third valid pulse width data and the first greatest common divisor are used to calculate the greatest common divisor. The value of the greatest common divisor is continuously updated until one CAN frame ends.

[0071] More specifically, taking 1, 2, 3, 4, 5 as an example to calculate the greatest common divisor (GCD), as long as 1 appears, the GCD is 1. The GCDs of 2 and 3, 2 and 5 are 1, 3 and 4, 3 and 5 are 1, and 4 and 5 are 1. Only the GCD of 2 and 4, which are both even numbers, is 2. However, the content of a CAN data frame cannot contain only 2 bits and 4 bits because the frame contains a CRC field. Even if all the preceding fields are only 2 bits and 4 bits wide, the CRC calculation will yield other pulse width data. In addition, data frames containing acknowledgments include an ACK flag, which is definitely only 1 bit wide. Therefore, under the premise of satisfying the calculation conditions, the obtained GCD must be 1 bit wide.

[0072] S3 determines the current baud rate value of the CAN bus based on all the greatest common divisors and the pre-stored baud rate table.

[0073] The pre-stored baud rate table of this invention represents the correspondence between the greatest common divisor and the baud rate.

[0074] The process by which this invention determines the current baud rate value of the CAN bus based on all greatest common divisors and a pre-stored baud rate table includes:

[0075] S31, the initial baud rate value of each CAN data frame is obtained based on the greatest common divisor of each CAN data frame and the pre-stored baud rate matching table;

[0076] In this embodiment of the invention, taking 1M as an example, the effective pulse width data after 2-bit and 3-bit correction are 160 and 240 respectively. The calculated greatest common divisor is 80, which is the ideal pulse width of 1 bit. The greatest common divisor 80 is matched with the pre-stored baud rate table to obtain the corresponding initial baud rate value of 1M.

[0077] In this invention, we take into account that during the actual matching process, there may be a large matching error between the greatest common divisor and the pre-stored baud rate table. Therefore, we need to use the maximum and minimum pulse widths recorded during the sampling process for secondary judgment before performing the matching process.

[0078] The process of determining the initial baud rate value using a two-step judgment based on the maximum and minimum pulse widths in this invention is as follows:

[0079] (1) Compare the maximum pulse width and the minimum pulse width to obtain the ratio result;

[0080] Specifically, the maximum pulse width value is divided by the minimum pulse width value.

[0081] (2) The ratio result is recalculated to obtain the matching pulse width;

[0082] If the ratio is close to 5 / 4, the minimum pulse width is 4 bits. Then calculate and divide by 4 to get a 1-bit pulse width.

[0083] If the ratio is close to 5 / 3 or 4 / 3, the minimum pulse width is 3 bits. Then, divide by 3 to get a 1-bit pulse width.

[0084] If the ratio is close to 3 / 2, the minimum pulse width is 2 bits. Then calculate and divide by 2 to get a 1-bit pulse width.

[0085] If the ratio is close to 5 / 1, 4 / 1, or 3 / 1, then the minimum pulse width is considered to be 1 bit wide.

[0086] If the ratio is close to 2 / 1, the result from step 6 will not be 4bit / 2bit, but only 2bit / 1bit, so it is also used as a 1bit pulse width for judgment.

[0087] (3) Determine the initial baud rate value based on the matched pulse width and the pre-stored baud rate table.

[0088] In this invention, after calculating the matching pulse width, the initial baud rate value is directly determined by a pre-stored baud rate table.

[0089] S32, determine the final baud rate value based on all the initial baud rate values, and use the final baud rate value as the current baud rate value of the CAN bus.

[0090] If all frames have the same initial baud rate value, then the initial baud rate value is directly determined as the final baud rate value;

[0091] If the initial baud rate values ​​of multiple frames are not all the same, the initial baud rate value with the same majority will be determined as the final baud rate value.

[0092] This invention uses the results of multiple frames as the final output baud rate value, which can prevent occasional errors caused by bus noise interference.

[0093] As a preferred embodiment, since sampling of CAN data frames requires data from the CAN bus, this invention triggers a wake-up signal to wake up the CAN network node and send a CAN message when the CAN bus has not generated a CAN data frame. The detection will be interrupted if multiple wake-up attempts fail.

[0094] The present invention can eliminate the errors caused by the synchronization circuit and the influence of the specified jitter tolerance through the baud rate detection method described above, and accurately detect the baud rate of the CAN2.0 bus, thereby ensuring the reliability of data transmission in the CAN bus system.

[0095] Example 2

[0096] The baud rate adaptive detection system structure of the present invention is as follows: Figure 4 As shown, it includes a synchronization circuit module, a correction module, a calculation module, and a decision module;

[0097] The input terminal of the synchronization circuit module is connected to the CAN bus and is used to synchronize the interpolation level output by the CAN bus to obtain intermediate pulse width data.

[0098] The correction module corrects the intermediate pulse width data to obtain effective pulse width data;

[0099] The calculation module calculates the greatest common divisor of the effective pulse width data;

[0100] The decision module performs matching and judgment based on the greatest common divisor and the pre-stored baud rate table to obtain the current baud rate value of the CAN bus.

[0101] The present invention mainly adopts hardware circuit (synchronization circuit), and combines it with software correction module, calculation module and decision module for adjustment and optimization. It obtains the current baud rate value of CAN bus based on the pre-stored baud rate table, and performs subsequent operations based on the detected baud rate value, which can ensure the best performance and reliability.

[0102] The synchronization circuit module of this invention uses a high-frequency clock to synchronize the CAN Rx signal to ensure the accuracy of data sampling.

[0103] The correction module of this invention corrects errors based on ideal pulse width, jitter tolerance, and the error caused by the synchronization circuit.

[0104] The calculation module of this invention uses the Stein algorithm to calculate the greatest common divisor of all valid pulse width data.

[0105] The decision module of this invention first determines the final baud rate value based on all greatest common divisors and a pre-stored baud rate table. When a large mismatch occurs between the greatest common divisor and the pre-stored baud rate table, a secondary judgment is performed based on the maximum and minimum pulse widths to determine the final baud rate value, which is then used as the current baud rate value of the CAN bus. This invention considers that during actual matching processing, occasional noise may cause a large mismatch between the greatest common divisor and the pre-stored baud rate table. Therefore, by using the maximum and minimum pulse widths recorded during sampling for secondary judgment, the baud rate of the CAN bus can be accurately detected.

[0106] In summary, this invention first samples CAN data frames from the CAN bus multiple times and processes each CAN data frame to obtain effective pulse width data; then, it calculates the greatest common divisor (GCD) of all effective pulse width data; finally, it determines the final baud rate value based on all GCDs and a pre-stored baud rate table. This invention can accurately detect the baud rate of the CAN bus, thereby ensuring the reliability of data transmission in the CAN bus system. The CAN bus baud rate adaptive detection system of this invention improves the accuracy of detecting the CAN bus baud rate through the combination of hardware circuits and software functional modules, thus making baud rate-based data transmission more reliable and improving the performance of the CAN bus system. Therefore, this invention effectively overcomes the various shortcomings of the prior art and has high industrial applicability. The above embodiments are merely illustrative of the principles and effects of this invention and are not intended to limit the invention. Any person skilled in the art can modify or change the above embodiments without departing from the spirit and scope of this invention. Therefore, all equivalent modifications or changes made by those skilled in the art without departing from the spirit and technical concept disclosed in this invention should still be covered by the claims of this invention.

Claims

1. A baud rate adaptive detection method for a CAN bus, characterized in that, It should include at least the following steps: S1, sample the CAN data frames of the CAN bus multiple times, and process each CAN data frame to obtain the effective pulse width data; S2, calculate the greatest common divisor of all valid pulse width data; S3 determines the current baud rate value of the CAN bus based on all the greatest common divisors and the pre-stored baud rate table; The process of determining the current baud rate value of the CAN bus based on all the greatest common divisors and the pre-stored baud rate table includes: obtaining the initial baud rate value of each CAN data frame based on the greatest common divisor of each CAN data frame and the pre-stored baud rate matching table; determining the final baud rate value based on all the initial baud rate values, and using the final baud rate value as the current baud rate value of the CAN bus. The initial baud rate value is determined by a secondary judgment using the maximum pulse width and the minimum pulse width, in order to reduce the matching error between the greatest common divisor and the pre-stored baud rate table. The secondary judgment process is as follows: (1) the maximum pulse width and the minimum pulse width are compared to obtain a ratio result; (2) the ratio result is recalculated to obtain the matching pulse width; (3) the initial baud rate value is determined based on the matching pulse width and the pre-stored baud rate table. Determining the final baud rate value based on all initial baud rate values ​​includes: if all frames have the same initial baud rate value, then the initial baud rate value is directly determined as the final baud rate value; if multiple frames have different initial baud rate values, the initial baud rate value with the same number of values ​​is determined as the final baud rate value.

2. The CAN bus baud rate adaptive detection method according to claim 1, characterized in that, The process of processing each CAN data frame to obtain the effective pulse width data includes: The intermediate pulse width data is obtained by synchronizing and statistically processing the CAN data frames. The effective pulse width data is obtained by correcting each intermediate pulse width data.

3. The CAN bus baud rate adaptive detection method according to claim 2, characterized in that, The process of correcting each intermediate pulse width data to obtain the effective pulse width data is as follows: (1) Based on multiple ideal pulse widths with set baud rates, all intermediate pulse width data are filtered to obtain filtered pulse width data; (2) The filtered pulse width data is processed to obtain the effective pulse width data.

4. The CAN bus baud rate adaptive detection method according to claim 3, characterized in that, The effective pulse width data is obtained by processing the filtered pulse width data, including correction based on the ideal pulse width, jitter tolerance, and errors caused by the synchronization circuit.

5. The CAN bus baud rate adaptive detection method according to claim 4, characterized in that, The effective pulse width data is [ideal pulse width * (1 - jitter tolerance) - compensation value] ~ [ideal pulse width * (1 + jitter tolerance) + compensation value], where the compensation value is used to compensate for the error caused by the synchronization circuit.

6. The CAN bus baud rate adaptive detection method according to claim 1, characterized in that, The greatest common divisor was calculated using the Stein algorithm on all valid pulse width data.

7. A CAN bus baud rate adaptive detection system, used to implement the CAN bus baud rate adaptive detection method of any one of claims 1-6, characterized in that, It includes a synchronization circuit module, a correction module, a calculation module, and a decision module; The input terminal of the synchronization circuit module is connected to the CAN bus and is used to synchronize the interpolation level output by the CAN bus to obtain intermediate pulse width data. The correction module corrects the intermediate pulse width data to obtain effective pulse width data; The calculation module calculates the greatest common divisor of the effective pulse width data; The decision module performs matching and judgment based on the greatest common divisor and the pre-stored baud rate table to obtain the current baud rate value of the CAN bus.

Citation Information

Patent Citations

  • Baud rate detection method and device for serial communication interface

    CN110958156A