CAN bus baud rate adaptive method, terminal and storage medium
By using the pin multiplexing and input capture module of the main control chip MCU, combined with the preset baud rate matching table and weight sorting algorithm, the width of the CAN bus pulse signal is directly measured, which solves the problems of time consumption and hardware cost of CAN network baud rate adaptation, realizes fast and accurate baud rate adaptation, and improves system startup speed and reliability.
Patent Information
- Application Number
- CN202411271795.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-11
- Publication Date
- 2024-11-29
- Estimated Expiration
- 2044-09-11
AI Technical Summary
Existing methods for baud rate adaptation in CAN networks suffer from time consumption or increased hardware costs, making it difficult to achieve fast and accurate baud rate adaptation without adding extra hardware burden.
By using the pin multiplexing and input capture module of the main control chip MCU, and utilizing a preset baud rate matching table and weight sorting algorithm, the width of the CAN bus pulse signal is directly measured, the baud rate search range is quickly narrowed, and baud rate self-adaptation is achieved.
It improves adaptive efficiency, reduces hardware costs, enhances system compatibility and reliability, simplifies operation processes, and is suitable for cost-sensitive application scenarios.
Smart Images

Figure CN119052020A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of vehicle communication, and in particular relates to a CAN bus baud rate self-adaptation method, a terminal and a storage medium. Background Art
[0002] With the rapid development of automotive electronic technology, the controller area network (CAN) has become an indispensable part of modern automobiles as an efficient and reliable communication method between various control units in the vehicle. With its high reliability, strong anti-interference ability and flexible communication mechanism, the CAN network has shown excellent performance in complex and changing vehicle environments and is widely used in power control, body control, safety systems and other fields. However, in order to ensure the stability and effectiveness of communication between nodes in the CAN network, each node must strictly follow the same communication rate, that is, the baud rate.
[0003] Although CAN networks occupy an important position in automotive communications, in actual applications, especially between vehicles of different models or years, the baud rate settings of CAN networks may be different due to differences in manufacturers or upgrade requirements. This requires CAN nodes to have baud rate adaptation capabilities to automatically match the communication rate on the bus. At present, there are two main problems with the methods for implementing baud rate adaptation: one is the use of software polling method, which continuously tries different baud rates to send messages and detect responses. Although this method is flexible, it takes a long time and affects the system startup speed and responsiveness; the other is the use of hardware acquisition method, which directly measures the pulse width of CAN messages by adding additional pins. Although the speed is improved, it undoubtedly increases the hardware cost and design complexity, which is not ideal for cost-sensitive application scenarios. Therefore, how to achieve fast and accurate baud rate adaptation without adding too much hardware burden has become a problem that needs to be solved urgently. Summary of the invention
[0004] In view of the above-mentioned deficiencies in the prior art, the present invention provides a CAN bus baud rate self-adaptation method, a terminal and a storage medium to solve the above-mentioned technical problems.
[0005] In a first aspect, the present invention provides a CAN bus baud rate self-adaptation method, wherein the CAN bus is connected to a main control chip MCU via a CAN transceiver, comprising:
[0006] Step 110, in the initial state, the message sending pin of the main control chip MCU is connected to the message sending pin of the CAN function module in the main control chip MCU through the pin multiplexing module configuration in the main control chip MCU, and the message receiving pin of the main control chip MCU is connected to the message receiving pin of the CAN function module for sending and receiving messages;
[0007] Step 120, read the preset baud rate value and send a message to the CAN bus at the preset baud rate, check the error flag bit of the internal status register of the CAN function module; if the error flag bit is 0, it indicates that the preset baud rate matches the baud rate of the CAN bus, and the adaptive process ends; if the error flag bit is 1, go to step 130;
[0008] Step 130, update the pin multiplexing module configuration, connect the message receiving pin of the main control chip MCU to the input capture module in the main control chip MCU, initialize the input capture module, set the clock frequency to measure the pulse width of the current CAN pulse signal;
[0009] Step 140, calculating the pulse width upper and lower limits and the overall upper and lower limits corresponding to each baud rate according to a preset baud rate matching table;
[0010] Step 150, reading the pulse signal on the CAN bus, and calculating the weights of all baud rates according to the pulse width of the read pulse signal;
[0011] Step 160, sorting all baud rate weights, selecting the baud rate with the largest weight as a candidate value, updating the pin multiplexing module configuration, initializing the CAN function module according to the candidate baud rate, and sending a message to the CAN bus through the CAN transceiver;
[0012] Step 170, judging whether the match is successful according to the error flag bit of the internal status register of the CAN functional module; if successful, updating the initial value of the baud rate and ending the adaptive process; if failed, excluding the candidate values in this adaptive process and repeating steps 160 and 170 until the match is successful.
[0013] A further improvement of the technical solution is that the clock frequency is 10MHZ.
[0014] A further improvement of the technical solution is that the specific method for calculating the upper and lower limits of the pulse width corresponding to each baud rate includes:
[0015] After the CAN pulse signal enters the input capture module, the state of the captured CAN pulse signal is determined;
[0016] When the rising edge of the CAN pulse signal is captured, the cnt register in the input capture module is reset and automatically accumulated from 0;
[0017] When the falling edge of the CAN pulse signal is captured, the value of the cnt register is automatically stored in the data register;
[0018] Calculate the pulse width of the captured CAN pulse signal based on the value of the data register and the current clock frequency of the input capture module;
[0019] According to the calculated pulse width, the upper and lower limits of the pulse width corresponding to the baud rate are obtained from the preset baud rate matching table. A further improvement of the technical solution is that the formula for calculating the pulse width of the captured CAN pulse signal is:
[0020] Width = Tick / freq;
[0021] Among them, Width is the pulse width, Tick is the read data register value, and freq is the current clock frequency of the input capture module.
[0022] A further improvement of the technical solution is to calculate the overall upper and lower limits based on the upper and lower limits of the pulse width corresponding to each baud rate and in combination with the bit filling rule.
[0023] A further improvement of the technical solution is to read the pulse signal on the CAN bus and calculate the weights of all baud rates according to the pulse width of the read pulse signal. The specific method includes:
[0024] Determine whether the read pulse width falls within the upper and lower limits of the pulse width corresponding to the preset baud rate;
[0025] When the read pulse width falls within the upper and lower limits of the pulse width of the preset baud rate, the hit count of the preset baud rate is increased by 1; when the read pulse width exceeds the overall upper and lower limits, it is regarded as an abnormal signal and is discarded; when the read pulse width exceeds the upper and lower limits of the pulse width of the preset baud rate but does not exceed the overall upper and lower limits, the miss count of the preset baud rate is increased by 1;
[0026] The weight corresponding to the preset baud rate is calculated according to the judgment result and the baud rate weight calculation formula.
[0027] A further improvement of this technical solution is that the baud rate weight calculation formula is:
[0028] W = k1·n1-k2·n2;
[0029] Wherein, W is the weight of the preset baud rate, n1 is the number of hits of the preset baud rate, n2 is the number of misses of the preset baud rate, k1 is the weight coefficient of the hit, and k2 is the weight coefficient of the miss.
[0030] A further improvement of the technical solution is that all baud rates in the preset baud rate matching table share the same k1 and k2.
[0031] In a second aspect, a terminal is provided, including:
[0032] processor, memory, wherein:
[0033] The memory is used to store computer programs.
[0034] The processor is used to call and run the computer program from the memory, so that the terminal executes the above-mentioned terminal method.
[0035] According to a third aspect, a computer storage medium is provided, wherein the computer-readable storage medium stores instructions, and when the instructions are executed on a computer, the computer executes the methods described in the above aspects.
[0036] The beneficial effect of the present invention is that the CAN bus baud rate adaptation method provided by the present invention, by cleverly utilizing the pin multiplexing function of the main control chip MCU and the input capture module, realizes the rapid and accurate adaptation of the CAN bus baud rate without adding additional hardware resources. Compared with the traditional method, this technical solution has the following significant effects:
[0037] Improve adaptive efficiency: By directly measuring the pulse signal width on the CAN bus and combining it with a preset baud rate matching table, the present invention can quickly narrow the baud rate search range and reduce the number of unnecessary attempts, thereby significantly shortening the time required for the adaptive process and improving the system startup speed and responsiveness.
[0038] Reduce hardware costs: There is no need to add additional acquisition pins or complex peripheral circuits. Adaptive baud rate detection can be achieved by using the existing pin multiplexing and input capture functions inside the main control chip MCU, which effectively reduces hardware costs and makes this technical solution more suitable for cost-sensitive application scenarios.
[0039] Enhanced system compatibility: Since the baud rates of the CAN network may differ between vehicles of different models or years, the adaptive method provided by the present invention can automatically match the communication rate on the bus, thereby enhancing the compatibility and flexibility of the system and facilitating communication and data exchange between different vehicles.
[0040] Improve system reliability: By real-time detection of the error flag bit of the internal status register of the CAN functional module, the present invention can accurately determine whether the preset baud rate matches the baud rate of the CAN bus, and automatically adjust it when it does not match, thereby avoiding communication failure and data loss caused by baud rate mismatch and improving the stability and reliability of the system.
[0041] Simplified operation process: The entire adaptive process is automatically controlled by the main control chip MCU, without manual intervention, which simplifies the operation process and reduces the difficulty and cost of maintenance. At the same time, the preset baud rate matching table and weight sorting algorithm make the adaptive process more intelligent and efficient. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0043] Figure 1 is a schematic flow chart of a method according to an embodiment of the present invention.
[0044] Figure 2 It is a schematic block diagram of a CAN communication system corresponding to the method of the present invention.
[0045] Figure 3 A schematic diagram of the structure of a terminal provided by an embodiment of the present invention.
[0046] 211 is a pin multiplexing module, 212 is a CAN function module, 213 is an input capture module, 220 is a CAN bus, and 230 is a CAN transceiver. DETAILED DESCRIPTION
[0047] In order to enable those skilled in the art to better understand the technical solutions in the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0048] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in the specification of the present invention herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention.
[0049] The key terms appearing in the present invention are explained below.
[0050] CAN (Controller Area Network) is a serial communication protocol bus for real-time applications. It can use twisted pair cables to transmit signals and is one of the most widely used fieldbuses in the world. The CAN protocol is used for communication between various components in the car to replace expensive and bulky distribution harnesses. The robustness of the protocol extends its use to other automation and industrial applications. The characteristics of the CAN protocol include complete serial data communication, real-time support, transmission speeds up to 1Mb / s, and 11-bit addressing and error detection capabilities.
[0051] MCU (Microcontroller Unit), also known as single chip microcomputer or single chip microcomputer, is a chip-level computer that appropriately reduces the frequency and specifications of the central processing unit (CPU) and integrates peripheral interfaces such as memory, timer, A / D conversion, etc. on a single chip to provide different combination controls for different applications. MCU can be found in mobile phones, PC peripherals, remote controls, automotive electronics, industrial stepper motors, and robot arm control.
[0052] Figure 1 The following is a schematic flow chart of a CAN bus baud rate adaptation method. Figure 1 The execution entity can be Figure 2 The CAN communication system shown in the figure is specifically a CAN bus connected to a main control chip MCU through a CAN transceiver, and the main control chip MCU includes a pin multiplexing module, a CAN function module and an input capture module. According to different requirements, the order of the steps in the flowchart can be changed, and some can be omitted.
[0053] like Figure 1 As shown, the method includes:
[0054] Step 110, in the initial state, the message sending pin (P01) of the main control chip MCU is connected to the message sending pin of the CAN function module in the main control chip MCU through the pin multiplexing module configuration in the main control chip MCU, and the message receiving pin (P02) of the main control chip MCU is connected to the message receiving pin of the CAN function module for sending and receiving messages;
[0055] Step 120, read the preset baud rate value and send a message to the CAN bus at the preset baud rate, check the error flag bit of the internal status register of the CAN function module; if the error flag bit is 0, it indicates that the preset baud rate matches the baud rate of the CAN bus, and the adaptive process ends; if the error flag bit is 1, go to step 130;
[0056] Step 130, update the pin multiplexing module configuration, connect the message receiving pin of the main control chip MCU to the input capture module in the main control chip MCU, initialize the input capture module, set the clock frequency to measure the pulse width of the current CAN pulse signal;
[0057] Step 140, calculating the pulse width upper and lower limits and the overall upper and lower limits corresponding to each baud rate according to a preset baud rate matching table;
[0058] Step 150, reading the pulse signal on the CAN bus, and calculating the weights of all baud rates according to the pulse width of the read pulse signal;
[0059] Step 160, sorting all baud rate weights, selecting the baud rate with the largest weight as a candidate value, updating the pin multiplexing module configuration, initializing the CAN function module according to the candidate baud rate, and sending a message to the CAN bus through the CAN transceiver;
[0060] Step 170, judging whether the match is successful according to the error flag bit of the internal status register of the CAN functional module; if successful, updating the initial value of the baud rate and ending the adaptive process; if failed, excluding the candidate values in this adaptive process and repeating steps 160 and 170 until the match is successful.
[0061] Specifically, the message receiving pin of the main control chip MCU also has a pin reset function, and can be used to receive CAN messages or to collect pulse signals according to different configurations of the pin multiplexing module.
[0062] In addition, the specific methods for calculating the upper and lower limits of the pulse width corresponding to each baud rate include:
[0063] Step 141, after the CAN pulse signal enters the input capture module, determine the state of the captured CAN pulse signal;
[0064] Step 142, when the rising edge of the CAN pulse signal is captured, the cnt register in the input capture module is reset and automatically accumulated from 0;
[0065] Step 143, when the falling edge of the CAN pulse signal is captured, the value of the cnt register is automatically stored in the data register;
[0066] Step 144, calculating the pulse width of the captured CAN pulse signal according to the value of the data register and the current clock frequency of the input capture module;
[0067] Step 145 , obtaining the upper and lower limits of the pulse width corresponding to the baud rate from a preset baud rate matching table according to the calculated pulse width.
[0068] Specifically, the formula for calculating the pulse width of the captured CAN pulse signal is:
[0069] Width = Tick / freq;
[0070] Wherein, Width is the pulse width, Tick is the data register value read, and freq is the current clock frequency of the input capture module. For example, when the clock frequency is 1MHZ and the Tick value is 100, the calculated pulse width is 100 microseconds. According to the bit filling rule of the CAN message, after sending 5 identical bits in succession (whether 5 1s or 5 0s), a bit opposite to it will be inserted at the 6th position. Therefore, under normal circumstances, the pulse width of the CAN pulse signal ranges from 1 to 5 bits. The clock frequency here refers to the clock frequency of the input capture module involved in calculating the pulse width. The clock frequency of the input capture module is not fixed. Too high a frequency may cause data overflow in the internal register of the input capture module when collecting signals. Too low a frequency may cause insufficient accuracy of the collected data. In order to ensure the adaptation effect of each baud rate in the baud rate matching table, the preferred clock frequency is 10MHZ.
[0071] Table 1: Preset baud rate matching table
[0072] Baud rate (kbit / s) Pulse width upper limit (μs) Pulse width lower limit (μs) 5 1000 200 10 500 100 20 250 50 50 100 20 100 50 10 125 40 8 250 20 4 500 10 2 1000 5 1 .
[0073] For example, when the baud rate is 1000 kbit / s, the actual pulse width should be in the range of 1 microsecond to 5 microseconds.
[0074] Furthermore, the overall upper and lower limits are calculated based on the obtained pulse width upper and lower limits corresponding to each baud rate and in combination with the bit filling rule.
[0075] Afterwards, the pulse signal on the CAN bus is read, and the weights of all baud rates are calculated according to the pulse width of the read pulse signal. The specific method includes:
[0076] Step 151, determining whether the read pulse width falls within the upper and lower limits of the pulse width corresponding to the preset baud rate;
[0077] Step 152, when the read pulse width falls within the pulse width upper and lower limits of the preset baud rate, the hit count of the preset baud rate is increased by 1; when the read pulse width exceeds the overall upper and lower limits, it is regarded as an abnormal signal and is discarded; when the read pulse width exceeds the pulse width upper and lower limits of the preset baud rate but does not exceed the overall upper and lower limits, the miss count of the preset baud rate is increased by 1;
[0078] Step 153, calculate the weight corresponding to the preset baud rate according to the judgment result and the baud rate weight calculation formula. Specifically, the baud rate weight calculation formula is:
[0079] W = k1·n1-k2·n2;
[0080] Wherein, W is the weight of the preset baud rate, n1 is the number of hits of the preset baud rate, n2 is the number of misses of the preset baud rate, k1 is the weight coefficient of the hit, and k2 is the weight coefficient of the miss.
[0081] Specifically, all baud rates in the preset baud rate matching table share the same k1 and k2. According to the above rules, after multiple iterations, the weights of all baud rates are obtained, and all baud rates are sorted according to the weights. The larger the weight, the greater the possibility that the baud rate is the current bus baud rate. For example, k1=1, k2=2, the current baud rate matching table contains 250K, 500K, 1000K, then the corresponding pulse width upper and lower limits are 4 to 20, 2 to 10, 1 to 5, and the overall upper and lower limits are 1 to 20. Assuming that the measured pulse widths are 2, 4, 6, 8, and 21, the weight of 250K is calculated to be 1, the weight of 500K is 4, and the weight of 1000K is -2. The most likely baud rate of the bus is 500K.
[0082] Figure 3 The present invention provides a schematic diagram of the structure of a terminal 300 provided in an embodiment of the present invention. The terminal 300 can be used to execute the CAN bus baud rate adaptation method provided in an embodiment of the present invention.
[0083] The terminal 300 may include: a processor 310, a memory 320 and a communication module 330. These components communicate via one or more buses. Those skilled in the art will appreciate that the server structure shown in the figure does not limit the present invention, and it may be a bus structure or a star structure, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0084] The memory 320 can be used to store the execution instructions of the processor 310, and the memory 320 can be implemented by any type of volatile or non-volatile storage terminal or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. When the execution instructions in the memory 320 are executed by the processor 310, the terminal 300 can perform some or all of the steps in the following method embodiments.
[0085] The processor 310 is the control center of the storage terminal, and uses various interfaces and lines to connect various parts of the entire electronic terminal. It runs or executes software programs and / or modules stored in the memory 320, and calls data stored in the memory to perform various functions of the electronic terminal and / or process data. The processor can be composed of an integrated circuit (IC), for example, it can be composed of a single packaged IC, or it can be composed of a plurality of packaged ICs with the same or different functions. For example, the processor 310 can include only a central processing unit (CPU). In the embodiment of the present invention, the CPU can be a single computing core or multiple computing cores.
[0086] The communication module 330 is used to establish a communication channel so that the storage terminal can communicate with other terminals, receive user data sent by other terminals or send user data to other terminals.
[0087] The present invention also provides a computer storage medium, wherein the computer storage medium may store a program, and when the program is executed, the program may include some or all of the steps in each embodiment provided by the present invention. The storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM).
[0088] Those skilled in the art can clearly understand that the technology in the embodiments of the present invention can be implemented by means of software plus a necessary general hardware platform. Based on this understanding, the technical solution in the embodiments of the present invention, in essence or in other words, the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, and other media that can store program codes, including several instructions for enabling a computer terminal (which can be a personal computer, a server, or a second terminal, a network terminal, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention.
[0089] In this specification, the same or similar parts between the various embodiments can be referred to each other. In particular, for the terminal embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description in the method embodiment.
[0090] In the several embodiments provided by the present invention, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of systems or modules, which can be electrical, mechanical or other forms.
[0091] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0092] In addition, each functional module in each embodiment of the present invention may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.
[0093] Although the present invention has been described in detail with reference to the accompanying drawings and in combination with the preferred embodiments, the present invention is not limited thereto. Without departing from the spirit and essence of the present invention, a person of ordinary skill in the art may make various equivalent modifications or substitutions to the embodiments of the present invention, and these modifications or substitutions shall be within the scope of the present invention. Any person of ordinary skill in the art may easily think of changes or substitutions within the technical scope disclosed by the present invention, and these shall be within the scope of protection of the present invention.
Claims
1. A CAN bus baud rate adaptive method, wherein the CAN bus is connected to a main control chip MCU via a CAN transceiver, characterized in that: include: Step 110, in the initial state, the message sending pin of the main control chip MCU is connected to the message sending pin of the CAN function module in the main control chip MCU through the pin multiplexing module configuration in the main control chip MCU, and the message receiving pin of the main control chip MCU is connected to the message receiving pin of the CAN function module for sending and receiving messages; Step 120, read the preset baud rate value and send a message to the CAN bus at the preset baud rate, and check the error flag bit of the internal status register of the CAN function module; If the error flag is 0, it means that the preset baud rate matches the baud rate of the CAN bus, and the adaptive process ends; If the error flag is 1, go to step 130; Step 130, update the pin multiplexing module configuration, connect the message receiving pin of the main control chip MCU to the input capture module in the main control chip MCU, initialize the input capture module, set the clock frequency to measure the pulse width of the current CAN pulse signal; Step 140, calculating the pulse width upper and lower limits and the overall upper and lower limits corresponding to each baud rate according to a preset baud rate matching table; Step 150, reading the pulse signal on the CAN bus, and calculating the weights of all baud rates according to the pulse width of the read pulse signal; Step 160, sorting all baud rate weights, selecting the baud rate with the largest weight as a candidate value, updating the pin multiplexing module configuration, initializing the CAN function module according to the candidate baud rate, and sending a message to the CAN bus through the CAN transceiver; Step 170, judging whether the match is successful according to the error flag bit of the internal status register of the CAN functional module; if successful, updating the initial value of the baud rate and ending the adaptive process; if failed, excluding the candidate values in this adaptive process and repeating steps 160 and 170 until the match is successful.
2. The CAN bus baud rate adaptive method according to claim 1, characterized in that: The clock frequency is 10MHZ.
3. The CAN bus baud rate self-adaptation method according to claim 1, characterized in that: The specific methods for calculating the upper and lower limits of the pulse width corresponding to each baud rate include: After the CAN pulse signal enters the input capture module, the state of the captured CAN pulse signal is determined; When the rising edge of the CAN pulse signal is captured, the cnt register in the input capture module is reset and automatically accumulated from 0; When the falling edge of the CAN pulse signal is captured, the value of the cnt register is automatically stored in the data register; Calculate the pulse width of the captured CAN pulse signal based on the value of the data register and the current clock frequency of the input capture module; The upper and lower limits of the pulse width corresponding to the baud rate are obtained from the preset baud rate matching table according to the calculated pulse width.
4. The CAN bus baud rate self-adaptation method according to claim 3, characterized in that: The formula for calculating the pulse width of the captured CAN pulse signal is: Width = Tick / freq; Among them, Width is the pulse width, Tick is the read data register value, and freq is the current clock frequency of the input capture module.
5. The CAN bus baud rate self-adaptation method according to claim 3, characterized in that: The overall upper and lower limits are calculated based on the upper and lower limits of the pulse width corresponding to each baud rate and the bit filling rule.
6. The CAN bus baud rate self-adaptation method according to claim 1, characterized in that: Read the pulse signal on the CAN bus, and calculate the weights of all baud rates according to the pulse width of the read pulse signal. The specific method includes: Determine whether the read pulse width falls within the upper and lower limits of the pulse width corresponding to the preset baud rate; When the read pulse width falls within the upper and lower limits of the pulse width of the preset baud rate, the hit count of the preset baud rate is increased by 1; when the read pulse width exceeds the overall upper and lower limits, it is regarded as an abnormal signal and is discarded; when the read pulse width exceeds the upper and lower limits of the pulse width of the preset baud rate but does not exceed the overall upper and lower limits, the miss count of the preset baud rate is increased by 1; The weight corresponding to the preset baud rate is calculated according to the judgment result and the baud rate weight calculation formula.
7. The CAN bus baud rate self-adaptation method according to claim 6, characterized in that: The baud rate weight calculation formula is: W = k1·n1-k2·n2; Wherein, W is the weight of the preset baud rate, n1 is the number of hits of the preset baud rate, n2 is the number of misses of the preset baud rate, k1 is the weight coefficient of the hit, and k2 is the weight coefficient of the miss.
8. The CAN bus baud rate self-adaptation method according to claim 6, characterized in that: All baud rates in the preset baud rate matching table share the same k1 and k2.
9. A terminal, characterized in that: include: processor; A memory for storing execution instructions of the processor; The processor is configured to execute the method according to any one of claims 1 to 8.
10. A computer-readable storage medium storing a computer program, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
CAN bus baud rate self-adaption method and device
CN112118075A
Baud rate adaptive system, method and device
CN114095296A
CAN network baud rate matching method and system, and electronic device
CN115277296A
CAN Baud rate rapid matching method and system
CN115643125A
Cited By
CAN communication anti-interference method and device based on BMS architecture and electronic equipment
CN120785676A
