CAN bus impedance matching method, device and circuit, electronic equipment and storage medium
By dynamically adjusting the bit error rate and reference threshold of the CAN bus and adjusting the resistance value of the adjustable resistor, the device life reduction caused by the CAN bus impedance mismatch is solved, and the automatic impedance matching and communication quality of the CAN bus are achieved.
Patent Information
- Application Number
- CN202510826384.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-19
- Publication Date
- 2025-08-19
AI Technical Summary
The CAN bus is prone to decrease the device life in the impedance mismatch state, and it is difficult for the existing technology to achieve automatic adjustment.
By obtaining the bit error rate of the CAN bus, dynamically adjust the reference threshold, and adjust the resistance value of the adjustable resistor when the bit error rate is greater than the threshold, so that the CAN bus is in an impedance matching state.
The automatic impedance matching of the CAN bus is realized, avoiding the device life reduction caused by the fixed resistance matching resistance, and ensuring communication quality.
Smart Images

Figure CN120512331A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of CAN bus communication technology, and in particular to a CAN bus impedance matching method, device, circuit, electronic device and storage medium. Background Art
[0002] The Controller Area Network (CAN) bus is a serial communication protocol bus used for real-time communication. It uses twisted-pair cables to transmit signals and is one of the most widely used fieldbuses in the world. However, in practical applications, the CAN bus inherently suffers from signal reflections, which can easily lead to poor communication quality, even communication anomalies, or device damage.
[0003] In the prior art, fixed-value matching resistors are typically added at both ends of the CAN bus to maintain impedance matching across the bus, thereby eliminating the adverse effects of signal reflections. However, in practice, these matching resistors do not perfectly match the bus impedance in all situations. Prolonged impedance mismatches can shorten the life of components. Therefore, how to automatically adjust the impedance matching of the CAN bus has become a pressing technical challenge. Summary of the Invention
[0004] The present application provides a CAN bus impedance matching method, device, circuit, electronic device and storage medium to solve the problem in the related art that the CAN bus is easily in an impedance mismatch state, resulting in a decrease in device life.
[0005] In a first aspect, an embodiment of the present application provides a CAN bus impedance matching method, the method comprising:
[0006] Obtaining a bit error rate of the CAN bus, wherein the bit error rate is used to characterize the communication quality of the CAN bus;
[0007] Comparing the bit error rate with a reference threshold, wherein the reference threshold is dynamically adjusted based on a usage status of the CAN bus;
[0008] When the bit error rate is greater than the reference threshold, the resistance of the matching resistor on the CAN bus is adjusted to put the CAN bus in an impedance matching state, wherein the matching resistor is an adjustable resistor.
[0009] Optionally, adjusting the resistance of the matching resistor on the CAN bus includes:
[0010] Obtaining the actual resistance value of the matching resistor through a resistance detection bypass;
[0011] Based on the actual resistance value of the matching resistor and the difference between the bit error rate and the reference threshold, the resistance adjustment device is controlled to adjust the resistance value of the matching resistor.
[0012] Optionally, a first end of the matching resistor is connected to a first connection point on a high-order data line of the CAN bus, and a second end of the matching resistor is connected to a second connection point on a low-order data line of the CAN bus; the resistance detection bypass includes a pull-up resistor and a pull-down resistor, a first end of the pull-up resistor is connected to the first connection point, a second end of the pull-up resistor is connected to a voltage source, a first end of the pull-down resistor is connected to the second connection point, and a second end of the pull-down resistor is connected to a ground terminal;
[0013] The obtaining of the actual resistance value of the matching resistor by detecting the bypass resistance includes:
[0014] sampling a first voltage value of the first connection point in the resistance detection bypass, a second voltage value of the second connection point, and a current value flowing through the matching resistor;
[0015] The actual resistance value of the matching resistor is calculated based on the first voltage value, the second voltage value, and the current value obtained by sampling.
[0016] Optionally, the resistance adjustment device includes a pressure spring, and the pressure spring is connected to the sliding end of the matching resistor;
[0017] The controlling the resistance adjusting device to adjust the resistance of the matching resistor based on the actual resistance of the matching resistor and the difference between the bit error rate and the reference threshold value includes:
[0018] determining the expansion and contraction direction of the pressure spring based on the actual resistance value of the matching resistor;
[0019] determining an extension and contraction amount of the pressure spring based on a difference between the bit error rate and the reference threshold;
[0020] According to the expansion and contraction direction and the expansion and contraction amount of the pressure spring, the pressure spring is controlled to expand and contract, so as to adjust the resistance value of the matching resistor.
[0021] Optionally, after adjusting the resistance of the matching resistor on the CAN bus, the method further includes:
[0022] Monitoring a change in a bit error rate of the CAN bus;
[0023] When the change in the bit error rate of the CAN bus is lower than a preset threshold, an alarm message is generated.
[0024] Optionally, after adjusting the resistance of the matching resistor on the CAN bus, the method further includes:
[0025] Monitoring the operating status of each device node on the CAN bus, the temperature of the environment in which the CAN bus is located, and the changes in the humidity of the environment in which the CAN bus is located;
[0026] updating the reference threshold when the working status of each device node on the CAN bus, the temperature of the environment in which the CAN bus is located, and / or the humidity of the environment in which the CAN bus is located change;
[0027] The resistance value of the matching resistor is adjusted based on the updated reference threshold.
[0028] Optionally, obtaining the bit error rate of the CAN bus includes:
[0029] Obtain the number of error frames and normal frames on the CAN bus within a preset time period;
[0030] A ratio between the number of error frames and the number of normal frames is calculated, and the ratio is determined as the bit error rate.
[0031] In a second aspect, an embodiment of the present application further provides a CAN bus impedance matching device, the device comprising:
[0032] an acquisition module, configured to acquire a bit error rate of the CAN bus, wherein the bit error rate is used to characterize the communication quality of the CAN bus;
[0033] a comparison module, configured to compare the bit error rate with a reference threshold, wherein the reference threshold is dynamically adjusted based on a usage status of the CAN bus;
[0034] The adjustment module is used to adjust the resistance value of the matching resistor on the CAN bus when the bit error rate is greater than the reference threshold, so that the CAN bus is in an impedance matching state, wherein the matching resistor is an adjustable resistor.
[0035] In a third aspect, an embodiment of the present application further provides a CAN bus impedance matching circuit, the CAN bus impedance matching circuit comprising a CAN bus, a matching resistor, a resistance detection bypass, a resistance adjustment device, and a control device;
[0036] Wherein, the first end of the matching resistor is connected to the first connection point on the high-order data line of the CAN bus, and the second end of the matching resistor is connected to the second connection point on the low-order data line of the CAN bus;
[0037] The resistance detection bypass includes a pull-up resistor and a pull-down resistor, wherein a first end of the pull-up resistor is connected to the first connection point, a second end of the pull-up resistor is connected to a voltage source, a first end of the pull-down resistor is connected to the second connection point, and a second end of the pull-down resistor is connected to a ground terminal;
[0038] The first connection point and the second connection point are electrically connected to the control device as sampling points, the resistance adjustment device is electrically connected to the control device, and the control device is used to execute the CAN bus impedance matching method described in the first aspect.
[0039] Optionally, the resistance adjustment device includes a pressure spring, one end of the pressure spring is connected to the control device, and the other end of the pressure spring is connected to the sliding end of the matching resistor.
[0040] In a fourth aspect, an embodiment of the present application further provides an electronic device, which includes the CAN bus impedance matching circuit described in the third aspect.
[0041] In a fifth aspect, an embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the CAN bus impedance matching method described in the first aspect is implemented.
[0042] The above technical solution provided by the embodiment of the present application has the following advantages over the prior art: the method provided by the embodiment of the present application obtains the bit error rate of the CAN bus, wherein the bit error rate is used to characterize the communication quality of the CAN bus; compares the bit error rate with a reference threshold, wherein the reference threshold is dynamically adjusted based on the usage status of the CAN bus; and when the bit error rate is greater than the reference threshold, adjusts the resistance of the matching resistor on the CAN bus to put the CAN bus in an impedance matching state, wherein the matching resistor is an adjustable resistor. Through the above method, the reference threshold can be determined based on the usage status of the CAN bus, and then the resistance of the matching resistor on the CAN bus is adjusted based on the magnitude relationship between the bit error rate and the reference threshold, thereby automatically adjusting the impedance matching state of the CAN bus according to the usage status of the CAN bus, so that the CAN bus is always in an impedance matching state, effectively avoiding the problem of reduced device life due to mismatch between the fixed resistance matching resistor and the CAN bus impedance. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0044] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0045] One or more embodiments are exemplarily illustrated by pictures in the corresponding drawings. These exemplifications do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings are represented as similar elements. Unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0046] Figure 1 A flow chart of a CAN bus impedance matching method provided in an embodiment of the present application;
[0047] Figure 2 A schematic diagram of the structure of a resistance detection bypass provided in an embodiment of the present application;
[0048] Figure 3 A schematic structural diagram of a resistance adjustment device provided in an embodiment of the present application;
[0049] Figure 4 A flow chart of another CAN bus impedance matching method provided in an embodiment of the present application;
[0050] Figure 5 A schematic structural diagram of a CAN bus impedance matching device provided in an embodiment of the present application;
[0051] Figure 6 A schematic structural diagram of a CAN bus impedance matching circuit provided in an embodiment of the present application;
[0052] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0053] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0054] The disclosure below provides many different embodiments or examples for implementing different configurations of the present invention. To simplify the disclosure of the present invention, the components and configurations of specific examples are described below. Of course, these are merely examples and are not intended to limit the present invention. In addition, the present invention may repeat reference numerals and / or letters in different examples. Such repetition is for the purpose of simplicity and clarity and does not in itself indicate the relationship between the various embodiments and / or configurations discussed.
[0055] In order to solve the problem in the related art that the CAN bus is easily in an impedance mismatch state, resulting in a decrease in device life, the present application provides a CAN bus impedance matching method, device, circuit, electronic device and storage medium, which can automatically adjust the impedance matching state of the CAN bus.
[0056] See also Figure 1 , Figure 1 The following is a flow chart of a CAN bus impedance matching method provided in an embodiment of the present application. Figure 1 As shown, the CAN bus impedance matching method may include the following steps:
[0057] Step S101: Acquire the bit error rate of the CAN bus, wherein the bit error rate is used to characterize the communication quality of the CAN bus.
[0058] Specifically, the bit error rate refers to the ratio of the number of error frames transmitted by the CAN bus to the number of normal frames within a preset duration. The preset duration here can be set according to actual needs, such as 10 minutes, 20 minutes, etc., and this application does not impose any specific restrictions. When the communication quality of the CAN bus is lower, the proportion of error frames is greater, and the bit error rate is higher; when the communication quality of the CAN bus is higher, the proportion of error frames is smaller, and the bit error rate is lower. Therefore, the bit error rate can be used to characterize the communication quality of the CAN bus.
[0059] Step S102: Compare the bit error rate with a reference threshold, wherein the reference threshold is dynamically adjusted based on the usage status of the CAN bus.
[0060] Specifically, the reference threshold is used to measure the quality of CAN bus communication. This threshold can be dynamically adjusted based on the CAN bus's usage status (e.g., the operating status of each device node on the CAN bus, the temperature and humidity of the CAN bus environment, etc.). If the operating status of a device node on the CAN bus changes, or if the temperature and humidity of the CAN bus environment change, the reference threshold will also change.
[0061] Step S103 : When the bit error rate is greater than a reference threshold, the resistance of the matching resistor on the CAN bus is adjusted to put the CAN bus in an impedance matching state, wherein the matching resistor is an adjustable resistor.
[0062] Specifically, the matching resistor is an adjustable resistor, such as a sliding rheostat.
[0063] When the bit error rate is greater than the reference threshold, it indicates that the current communication quality of the CAN bus is poor. At this time, the resistance value of the matching resistor on the CAN bus can be adjusted so that the adjusted resistance value of the matching resistor matches the impedance of the CAN bus.
[0064] During the resistance adjustment process, the change of the bit error rate of the CAN bus can be monitored in real time. When the bit error rate of the CAN bus is less than or equal to the reference threshold, the adjustment of the resistance of the matching resistor is stopped.
[0065] Through the above method, a reference threshold value can be determined based on the usage status of the CAN bus, and then the resistance value of the matching resistor on the CAN bus can be adjusted based on the size relationship between the bit error rate and the reference threshold value, thereby automatically adjusting the impedance matching state of the CAN bus according to the usage status of the CAN bus, so that the CAN bus is always in an impedance matching state, effectively avoiding the problem of reduced device life due to mismatch between the matching resistor with a fixed resistance value and the CAN bus impedance.
[0066] In an optional embodiment, the above step S103, adjusting the resistance of the matching resistor on the CAN bus, includes:
[0067] Obtain the actual resistance value of the matching resistor through the resistor detection bypass;
[0068] Based on the actual resistance value of the matching resistor, the difference between the bit error rate and the reference threshold, the resistance adjustment device is controlled to adjust the resistance value of the matching resistor.
[0069] Specifically, the above-mentioned resistance detection bypass can be any circuit structure for assisting in detecting the resistance value of the matching resistor, and the above-mentioned resistance adjustment device can be any device for adjusting the resistance value of the matching resistor, which is not specifically limited in the embodiments of the present application.
[0070] When adjusting the resistance of a matching resistor on a CAN bus, the actual resistance of the matching resistor can be first obtained through a resistance detection bypass to determine the relationship between the actual resistance and the ideal resistance. The ideal resistance here can be understood as a relatively ideal resistance value determined during the design of the CAN bus. The matching resistor adjustment direction is then determined based on the relationship between the actual and ideal resistance values. The adjustment amount of the matching resistor is also determined based on the difference between the bit error rate and a reference threshold value, and the resistance adjustment device is controlled to adjust the resistance of the matching resistor.
[0071] Through the above method, the resistance value of the matching resistor on the CAN bus can be accurately adjusted so that the CAN bus is in an impedance matching state.
[0072] In an alternative embodiment, see Figure 2 The first end of the matching resistor R2 is connected to the first connection point A on the high data line (i.e., CAN_H) of the CAN bus, and the second end of the matching resistor R2 is connected to the second connection point B on the low data line (i.e., CAN_L) of the CAN bus. The resistance detection bypass includes a pull-up resistor R1 and a pull-down resistor R3. The first end of the pull-up resistor R1 is connected to the first connection point A, and the second end of the pull-up resistor R1 is connected to the voltage source VCC. The first end of the pull-down resistor R3 is connected to the second connection point B, and the second end of the pull-down resistor R3 is connected to the ground terminal GND.
[0073] The above steps, in which the actual resistance value of the matching resistor is obtained by the resistor detection bypass, include:
[0074] Sampling a first voltage value of a first connection point in the resistance detection bypass, a second voltage value of a second connection point, and a current value flowing through the matching resistor;
[0075] The actual resistance value of the matching resistor is calculated based on the first voltage value, the second voltage value, and the current value obtained by sampling.
[0076] Specifically, through Figure 2When the resistor detection bypass shown in the figure obtains the actual resistance value of the matching resistor, the first voltage value at the first connection point in the resistor detection bypass, the second voltage value at the second connection point, and the current value flowing through the matching resistor can be sampled. Then, based on the sampled first voltage value, second voltage value, and current value, the actual resistance value of the matching resistor can be calculated. Specifically, sampling points can be set at the first connection point and the second connection point, and each sampling point is connected to a microcontroller unit (MCU). The MCU performs voltage sampling to obtain the first voltage value of the first connection point and the second voltage value of the second connection point. In addition, an ammeter can be connected in series in the circuit between the voltage source VCC and the ground terminal GND to collect the current value, and the ammeter transmits the current value to the MCU via communication. In this way, the MCU can calculate the actual resistance value of the matching resistor based on the acquired data. For example, assuming that the collected first voltage value is U1, the collected second voltage value is U2, and the collected current value is I, then the actual resistance value of the matching resistor R = (U1-U2) / I. Then, the MCU can upload the actual resistance value of the matching resistor to the host computer through CAN communication or 485 communication (the specific method is determined by the communication method between the MCU and the host computer and is not specifically limited here).
[0077] In this embodiment, the actual resistance value of the matching resistor can be accurately obtained through the resistance detection bypass, which facilitates subsequent adjustment of the resistance value of the matching resistor.
[0078] In an alternative embodiment, see Figure 3 The resistance adjustment device includes a pressure spring L, one end of the pressure spring L is connected to the sliding end of the matching resistor R2, and the other end of the pressure spring L is connected to the MCU, so that the MCU can slide the sliding end of the matching resistor R2 through the pressure spring L.
[0079] The above steps of controlling the resistance adjustment device to adjust the resistance value of the matching resistor based on the actual resistance value of the matching resistor, the difference between the bit error rate and the reference threshold value include:
[0080] Determine the expansion and contraction direction of the pressure spring based on the actual resistance value of the matching resistor;
[0081] determining the expansion and contraction amount of the pressure spring based on the difference between the bit error rate and the reference threshold;
[0082] According to the expansion and contraction direction and the expansion and contraction amount of the pressure spring, the pressure spring is controlled to expand and contract, so as to adjust the resistance value of the matching resistor.
[0083] Specifically, when adjusting the resistance of the matching resistor using the resistance adjustment device, the direction of the pressure spring's expansion and contraction can be determined based on the matching resistor's actual resistance. For example, assuming the ideal resistance of the matching resistor in the CAN bus is approximately 120 ohms, but the actual resistance is only 190 ohms, and assuming that the resistance increases when the sliding end of the matching resistor slides to the right, it can be generally determined that the pressure spring's expansion and contraction direction should be to the right. Next, the amount of expansion and contraction of the pressure spring can be determined based on the difference between the bit error rate and a reference threshold. Because the ideal resistance of the matching resistor in the CAN bus is not fixed but changes dynamically based on the CAN bus's usage scenario, the difference between the bit error rate and the reference threshold is needed to determine the amount of expansion and contraction of the pressure spring. The difference between the bit error rate and the reference threshold is positively correlated with the amount of expansion and contraction of the pressure spring: that is, the greater the difference between the bit error rate and the reference threshold, the greater the expansion and contraction of the pressure spring; the smaller the difference between the bit error rate and the reference threshold, the smaller the expansion and contraction of the pressure spring. Finally, the voltage required to be applied to the pressure spring can be determined based on the determined expansion and contraction direction and expansion and contraction amount of the pressure spring to control the expansion and contraction of the pressure spring and adjust the resistance value of the matching resistor.
[0084] In this embodiment, the resistance value of the matching resistor can be accurately adjusted by the resistance adjustment device so that the resistance value of the matching resistor reaches an ideal resistance value, thereby placing the CAN bus in an impedance matching state.
[0085] In an optional embodiment, after the above step S103 of adjusting the resistance of the matching resistor on the CAN bus, the method further includes:
[0086] Monitor the change in the bit error rate of the CAN bus;
[0087] When the change in the bit error rate of the CAN bus is lower than a preset threshold, an alarm message is generated.
[0088] Specifically, the above preset threshold can be set according to actual conditions and is not specifically limited here.
[0089] While adjusting the resistance of the matching resistor on the CAN bus, the change in the bit error rate of the CAN bus can be monitored periodically or in real time. If the bit error rate of the CAN bus is gradually approaching the reference threshold, it indicates that the poor communication quality of the CAN bus is caused by the mismatch between the resistance of the matching resistor and the impedance of the CAN bus. Adjusting the resistance of the matching resistor can solve the problem of poor communication quality of the CAN bus. If the change in the bit error rate of the CAN bus is lower than the preset threshold, it indicates that the poor communication quality of the CAN bus is not caused by the mismatch between the resistance of the matching resistor and the impedance of the CAN bus, but by other reasons. At this time, an alarm message can be generated to prompt the user to conduct an abnormality investigation.
[0090] In this embodiment, an alarm message may be generated when the change in the bit error rate of the CAN bus is lower than a preset threshold, so that the user can promptly check the cause of the problem.
[0091] In an optional embodiment, after the above step S103 of adjusting the resistance of the matching resistor on the CAN bus, the method further includes:
[0092] Monitor the working status of each device node on the CAN bus, the temperature of the environment where the CAN bus is located, and the changes in the humidity of the environment where the CAN bus is located;
[0093] When the working state of each device node on the CAN bus, the temperature of the environment in which the CAN bus is located, and / or the humidity of the environment in which the CAN bus is located change, the reference threshold is updated;
[0094] The resistance value of the matching resistor is adjusted based on the updated reference threshold.
[0095] Specifically, in the process of adjusting the resistance value of the matching resistor on the CAN bus, the working status of each device node on the CAN bus, the temperature of the environment in which the CAN bus is located, and the changes in the humidity of the environment in which the CAN bus is located can also be monitored periodically or in real time. When the working status of each device node on the CAN bus, the temperature of the environment in which the CAN bus is located, and / or the humidity of the environment in which the CAN bus is located changes, the reference threshold is updated, and then the resistance value of the matching resistor is adjusted based on the updated reference threshold.
[0096] Because the communication quality of the CAN bus depends not only on the matching resistor but also on the operating conditions of the devices on the CAN bus and the external environment, the current state of the CAN bus must be considered during judgment to reduce the probability of misjudgment. For example, when a variable-frequency water-cooled chiller is in shutdown or standby mode, the VFD is not running, so interference from device nodes on the CAN bus is reduced. Therefore, the reference threshold should be lowered. Furthermore, varying temperatures affect the driving capability of the CAN driver chip. Therefore, additional detection parameters can be added to refine the judgment and better avoid misjudgments. According to the device specification, the bus voltage difference driven by the CAN driver chip increases at lower temperatures, enhancing its anti-interference capabilities. Therefore, the reference threshold should be lowered, and vice versa.
[0097] As an optional implementation, the reference threshold can be expressed as A*X%, where A is a control coefficient that is adjusted according to the ambient temperature and humidity. When only the temperature is considered, with 20°C as the benchmark, the coefficient A increases by 0.05 for every 10°C increase, and the coefficient A can reach a maximum of 1.30. Similarly, for every 10°C drop in temperature, the coefficient A decreases by 0.05, and the coefficient A can reach a minimum of 0.80 (the coefficient A here is adjusted according to the electrical parameters of the CAN chip, and the specific requirements depend on the CAN chip used. This example only uses the currently commonly used chips as a reference). When considering humidity, if the humidity is less than 70%, the coefficient A is 100%*A after adjusting for temperature; if the humidity is greater than or equal to 70%, the coefficient A is 70%*A after adjusting for temperature. The value of X needs to be determined based on the unit's operating status. If the unit is in the inverter startup phase, interference is greatest, and the reference threshold needs to be increased. X can be between 8 and 15. During normal inverter operation, X can be between 5 and 8. This value can be adjusted based on the inverter's current frequency. The higher the inverter frequency, the larger the value. If there are other inverter devices near the unit, the value should also be increased.
[0098] In this embodiment, the reference threshold can be dynamically adjusted according to the working status of each device node on the CAN bus, the temperature of the environment in which the CAN bus is located, and the changes in the humidity of the environment in which the CAN bus is located, thereby improving the accuracy of detection.
[0099] In an optional embodiment, the above step S101, obtaining the bit error rate of the CAN bus, includes:
[0100] Get the number of error frames and normal frames on the CAN bus within a preset period;
[0101] The ratio between the number of error frames and the number of normal frames is calculated and determined as the bit error rate.
[0102] Specifically, the above-mentioned preset time period can be set according to actual needs, such as 10 minutes, 20 minutes, etc., and is not specifically limited in the embodiment of the present application.
[0103] For the CAN bus, when communication quality deteriorates, device nodes on the bus trigger error frames. This characteristic can be used to monitor CAN bus communication quality. To determine the CAN bus's bit error rate (BER), the number of error frames and normal frames on the CAN bus within a preset time period is calculated. The ratio between the error frames and normal frames is then calculated and used as the BER. This BER can be used to assess the CAN bus's communication status and determine whether further action is required.
[0104] In an optional embodiment, the impedance matching process of the CAN bus provided in the embodiment of the present application is as follows: Figure 4 As shown, it may specifically include the following steps:
[0105] Step S401: Read the number of error frames and normal frames within a time T on the CAN bus.
[0106] Step S402: Calculate the bit error rate based on the number of error frames and the number of normal frames.
[0107] Step S403: Determine whether the bit error rate is greater than a reference threshold within a continuous time t.
[0108] If the bit error rate is greater than the reference threshold within the continuous time t, step S404 is executed; if the bit error rate is not greater than the reference threshold within the continuous time t, the process returns to step S401 and continues to read the number of error frames and normal frames within the time T on the CAN bus.
[0109] Step S404: Adjust the resistance of the matching resistor on the CAN bus.
[0110] When the bit error rate is detected to be greater than the reference threshold for a continuous time t (for example, t can be 5 to 60 seconds, t is 5 seconds when the unit is in a stable working state, and t is longer when the unit is in the starting state or when the frequency is increased or decreased), it is considered that the CAN bus communication quality is abnormal, and the matching resistor needs to be adjusted. Figure 2 As shown, when it is determined that the CAN bus communication is abnormal, the voltage drop across the pull-up resistor R1 and the pull-down resistor R3 can be detected respectively to obtain the voltage values on the pull-up resistor R1 and the pull-down resistor R3. At this time, since the voltage values on the pull-up resistor R1 and the pull-down resistor R3 are confirmed, the voltage value on the matching resistor R2 can be determined. At the same time, the current flowing through the matching resistor R2 can be obtained according to the current flow direction of the circuit, and the resistance value of the matching resistor R2 can be calculated. In this embodiment, the resistance value of the matching resistor R2 obtained can be fed back to the host computer through the communication bus in real time, which is convenient for operation and maintenance personnel to monitor and for subsequent problem finding. If the resistance value of the matching resistor R2 is abnormal, the resistance value of the matching resistor R2 can be adjusted by the resistance adjustment device until the resistance value of the matching resistor R2 returns to normal. For the resistance adjustment device, such as Figure 3 As shown, after the MCU obtains the resistance value of the matching resistor R2, it can change the expansion and contraction of the pressure spring L by adjusting the voltage applied to the pressure spring L, and then pull the slide bar of the sliding rheostat R2 to adjust the resistance value of R2 itself, and finally adjust R2 to a reasonable resistance value.
[0111] Step S405: monitor the change in the bit error rate of the CAN bus.
[0112] Step S406: Determine whether the change in the bit error rate of the CAN bus is lower than a preset threshold.
[0113] If the change in the bit error rate of the CAN bus is lower than the preset threshold, step S407 is executed; if the change in the bit error rate of the CAN bus is greater than or equal to the preset threshold, the process ends.
[0114] Step S407: Generate alarm information.
[0115] If the bit error rate returns to normal, it means that the CAN bus communication abnormality problem has been solved. If the bit error rate is still higher than the reference threshold, it means that the problem is caused by mismatched resistance. At this time, an alarm can be triggered to remind the operation and maintenance personnel to conduct detection and processing.
[0116] By executing the above steps S401 to S407, the impedance mismatch problem of the CAN bus can be discovered in time, and the resistance value of the matching resistor can be automatically adjusted when the impedance mismatch of the CAN bus occurs, thereby automatically adjusting the impedance matching state of the CAN bus. While ensuring the communication quality of the CAN bus, the CAN bus can always be in an impedance matching state, ensuring that the device can work normally.
[0117] See also Figure 5 , Figure 5 This is a schematic diagram of the structure of a CAN bus impedance matching device provided in an embodiment of the present application. Figure 5 As shown, the CAN bus impedance matching device 500 includes:
[0118] An acquisition module 501 is configured to acquire a bit error rate of the CAN bus, wherein the bit error rate is used to characterize the communication quality of the CAN bus;
[0119] a comparison module 502 for comparing the bit error rate with a reference threshold, wherein the reference threshold is dynamically adjusted based on the usage status of the CAN bus;
[0120] The adjustment module 503 is used to adjust the resistance of the matching resistor on the CAN bus when the bit error rate is greater than the reference threshold, so that the CAN bus is in an impedance matching state, wherein the matching resistor is an adjustable resistor.
[0121] Furthermore, the adjustment module 503 includes:
[0122] A first acquisition submodule is used to obtain the actual resistance value of the matching resistor through the resistance detection bypass;
[0123] The control submodule is used to control the resistance adjustment device 500 to adjust the resistance value of the matching resistor based on the actual resistance value of the matching resistor, the difference between the bit error rate and the reference threshold.
[0124] Furthermore, a first end of the matching resistor is connected to a first connection point on a high-order data line of the CAN bus, and a second end of the matching resistor is connected to a second connection point on a low-order data line of the CAN bus; the resistance detection bypass includes a pull-up resistor and a pull-down resistor, a first end of the pull-up resistor is connected to the first connection point, a second end of the pull-up resistor is connected to a voltage source, a first end of the pull-down resistor is connected to the second connection point, and a second end of the pull-down resistor is connected to a ground terminal; and the first acquisition submodule includes:
[0125] a sampling unit, configured to sample a first voltage value of a first connection point in the resistance detection bypass, a second voltage value of a second connection point, and a current value flowing through the matching resistor;
[0126] The calculation unit is used to calculate the actual resistance value of the matching resistor according to the first voltage value, the second voltage value and the current value obtained by sampling.
[0127] Furthermore, the resistance adjustment device 500 includes a pressure spring connected to the sliding end of the matching resistor; the control submodule includes:
[0128] a first determining unit, configured to determine an extension and contraction direction of the pressure spring based on an actual resistance value of the matching resistor;
[0129] a first determining unit, configured to determine an extension and contraction amount of the pressure spring based on a difference between a bit error rate and a reference threshold;
[0130] The control unit is used to control the expansion and contraction of the pressure spring according to the expansion and contraction direction and the expansion and contraction amount of the pressure spring, so as to adjust the resistance value of the matching resistor.
[0131] Furthermore, the CAN bus impedance matching device 500 further includes:
[0132] The first monitoring module is used to monitor the change in the bit error rate of the CAN bus;
[0133] The generating module is used to generate an alarm message when the change in the bit error rate of the CAN bus is lower than a preset threshold.
[0134] Furthermore, the CAN bus impedance matching device 500 further includes:
[0135] The second monitoring module is used to monitor the working status of each device node on the CAN bus, the temperature of the environment where the CAN bus is located, and the changes in the humidity of the environment where the CAN bus is located;
[0136] An updating module, configured to update the reference threshold value when the working state of each device node on the CAN bus, the temperature of the environment in which the CAN bus is located, and / or the humidity of the environment in which the CAN bus is located changes;
[0137] The adjustment module 503 is further configured to adjust the resistance of the matching resistor based on the updated reference threshold.
[0138] Furthermore, the acquisition module 501 includes:
[0139] The second acquisition submodule is used to obtain the number of error frames and the number of normal frames on the CAN bus within a preset time period;
[0140] The calculation submodule is used to calculate the ratio between the number of error frames and the number of normal frames, and determine the ratio as the bit error rate.
[0141] It should be noted that the CAN bus impedance matching device 500 can implement the CAN bus impedance matching method provided by any of the aforementioned method embodiments and can achieve the same technical effects, which will not be described in detail here.
[0142] See also Figure 6 , Figure 6 This is a schematic diagram of a CAN bus impedance matching circuit provided in an embodiment of the present application. Figure 6 As shown, the CAN bus impedance matching circuit includes a CAN bus, a matching resistor R2, a resistance detection bypass 610, a resistance adjustment device 620 and a control device 630;
[0143] The first end of the matching resistor R2 is connected to the first connection point A on the high data line (i.e., CAN_H) of the CAN bus, and the second end of the matching resistor R2 is connected to the second connection point B on the low data line (i.e., CAN_L) of the CAN bus.
[0144] The resistance detection bypass 610 includes a pull-up resistor R1 and a pull-down resistor R2, wherein a first end of the pull-up resistor R1 is connected to a first connection point A, a second end of the pull-up resistor R1 is connected to a voltage source, a first end of the pull-down resistor R2 is connected to a second connection point B, and a second end of the pull-down resistor R2 is connected to the ground.
[0145] The first connection point A and the second connection point B are electrically connected to the control device 630 as sampling points. The resistance adjustment device 620 is electrically connected to the control device 630. The control device 630 is used to execute the CAN bus impedance matching method in the above embodiment.
[0146] In this embodiment, the control device 630 can accurately obtain the actual resistance value of the matching resistor R2 through the resistance detection bypass 610 and adjust the resistance value of the matching resistor R2 through the resistance adjustment device 620. Since the CAN bus impedance matching method in the control device 630 has been described in detail in the previous embodiment, it will not be repeated here.
[0147] In an alternative embodiment, if Figure 3As shown, the resistance adjustment device 620 includes a pressure spring L, one end of the pressure spring L is connected to the control device 630, and the other end of the pressure spring L is connected to the sliding end of the matching resistor R2. Figure 3 The Microcontroller Unit (MCU) in the system.
[0148] In this way, the control device 630 can determine the voltage that needs to be applied to the pressure spring L to control the pressure spring L to expand and contract, thereby adjusting the resistance of the matching resistor R2 so that the resistance of the matching resistor R2 reaches the ideal resistance, thereby placing the CAN bus in an impedance matching state. Figure 7 As shown, an embodiment of the present application further provides an electronic device, and the electronic device 700 includes the CAN bus impedance matching circuit 710 in the aforementioned embodiment.
[0149] Since the CAN bus impedance matching circuit in the electronic device can achieve the same technical effect as the CAN bus impedance matching circuit in the aforementioned embodiment, it will not be described in detail here. The present application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the CAN bus impedance matching method provided in any of the aforementioned method embodiments.
[0150] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of this embodiment.
[0151] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a general hardware platform, or of course, by hardware. Based on this understanding, the above technical solution, in essence, or the part that contributes to the relevant technology, can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or certain parts of the embodiment.
[0152] It should be understood that the terms used herein are for the purpose of describing specific example embodiments only and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "comprise", "include", "contain" and "have" are inclusive and therefore specify the presence of stated features, steps, operations, elements and / or parts, but do not exclude the presence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not to be construed as necessarily requiring them to be performed in the specific order described or illustrated, unless the order of execution is clearly indicated. It should also be understood that additional or alternative steps may be used.
[0153] The foregoing description is intended only to provide specific embodiments of the present invention, which will enable those skilled in the art to understand and implement the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention is not intended to be limited to the embodiments shown herein, but is intended to be accorded the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A CAN bus impedance matching method, characterized in that: The method comprises: Obtaining a bit error rate of the CAN bus, wherein the bit error rate is used to characterize the communication quality of the CAN bus; Comparing the bit error rate with a reference threshold, wherein the reference threshold is dynamically adjusted based on a usage status of the CAN bus; When the bit error rate is greater than the reference threshold, the resistance of the matching resistor on the CAN bus is adjusted to put the CAN bus in an impedance matching state, wherein the matching resistor is an adjustable resistor.
2. The method according to claim 1, characterized in that The adjusting the resistance value of the matching resistor on the CAN bus includes: Obtaining the actual resistance value of the matching resistor through a resistance detection bypass; Based on the actual resistance value of the matching resistor and the difference between the bit error rate and the reference threshold, the resistance adjustment device is controlled to adjust the resistance value of the matching resistor.
3. The method according to claim 2, characterized in that The first end of the matching resistor is connected to a first connection point on the high-order data line of the CAN bus, and the second end of the matching resistor is connected to a second connection point on the low-order data line of the CAN bus; the resistance detection bypass includes a pull-up resistor and a pull-down resistor, the first end of the pull-up resistor is connected to the first connection point, the second end of the pull-up resistor is connected to a voltage source, the first end of the pull-down resistor is connected to the second connection point, and the second end of the pull-down resistor is connected to the ground terminal; The obtaining of the actual resistance value of the matching resistor by detecting the bypass resistance includes: sampling a first voltage value of the first connection point in the resistance detection bypass, a second voltage value of the second connection point, and a current value flowing through the matching resistor; The actual resistance value of the matching resistor is calculated based on the first voltage value, the second voltage value, and the current value obtained by sampling.
4. The method according to claim 2, characterized in that The resistance adjustment device includes a pressure spring connected to the sliding end of the matching resistor; The controlling the resistance adjusting device to adjust the resistance of the matching resistor based on the actual resistance of the matching resistor and the difference between the bit error rate and the reference threshold value includes: determining the expansion and contraction direction of the pressure spring based on the actual resistance value of the matching resistor; determining an extension and contraction amount of the pressure spring based on a difference between the bit error rate and the reference threshold; According to the expansion and contraction direction and the expansion and contraction amount of the pressure spring, the pressure spring is controlled to expand and contract, so as to adjust the resistance value of the matching resistor.
5. The method according to claim 1, wherein After adjusting the resistance of the matching resistor on the CAN bus, the method further includes: Monitoring a change in a bit error rate of the CAN bus; When the change in the bit error rate of the CAN bus is lower than a preset threshold, an alarm message is generated.
6. The method according to claim 1, characterized in that After adjusting the resistance of the matching resistor on the CAN bus, the method further includes: Monitoring the operating status of each device node on the CAN bus, the temperature of the environment in which the CAN bus is located, and the changes in the humidity of the environment in which the CAN bus is located; updating the reference threshold when the working status of each device node on the CAN bus, the temperature of the environment in which the CAN bus is located, and / or the humidity of the environment in which the CAN bus is located change; The resistance value of the matching resistor is adjusted based on the updated reference threshold.
7. The method according to claim 1, characterized in that The obtaining of the bit error rate of the CAN bus includes: Obtain the number of error frames and normal frames on the CAN bus within a preset time period; A ratio between the number of error frames and the number of normal frames is calculated, and the ratio is determined as the bit error rate.
8. A CAN bus impedance matching device, characterized in that: The device comprises: an acquisition module, configured to acquire a bit error rate of the CAN bus, wherein the bit error rate is used to characterize the communication quality of the CAN bus; a comparison module, configured to compare the bit error rate with a reference threshold, wherein the reference threshold is dynamically adjusted based on a usage status of the CAN bus; The adjustment module is used to adjust the resistance value of the matching resistor on the CAN bus when the bit error rate is greater than the reference threshold, so that the CAN bus is in an impedance matching state, wherein the matching resistor is an adjustable resistor.
9. A CAN bus impedance matching circuit, characterized in that: The CAN bus impedance matching circuit includes a CAN bus, a matching resistor, a resistance detection bypass, a resistance adjustment device and a control device; Wherein, the first end of the matching resistor is connected to the first connection point on the high-order data line of the CAN bus, and the second end of the matching resistor is connected to the second connection point on the low-order data line of the CAN bus; The resistance detection bypass includes a pull-up resistor and a pull-down resistor, wherein a first end of the pull-up resistor is connected to the first connection point, a second end of the pull-up resistor is connected to a voltage source, a first end of the pull-down resistor is connected to the second connection point, and a second end of the pull-down resistor is connected to a ground terminal; The first connection point and the second connection point are electrically connected to the control device as sampling points, the resistance adjustment device is electrically connected to the control device, and the control device is used to execute the CAN bus impedance matching method according to any one of claims 1 to 7.
10. The CAN bus impedance matching circuit according to claim 9, characterized in that: The resistance adjustment device includes a pressure spring, one end of the pressure spring is connected to the control device, and the other end of the pressure spring is connected to the sliding end of the matching resistor.
11. An electronic device, characterized in that: The electronic device includes the CAN bus impedance matching circuit according to claim 9.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the CAN bus impedance matching method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Multi-split CAN communication abnormity self-adaptive detection and repair method and display terminal device
CN121664625A
Multi-connected machine CAN communication abnormality self-adaptive detection and repair method and display terminal device
CN121664625B