A timing compensation device based on CAN protocol and electronic equipment
By optimizing the timing compensation device of the CAN protocol and using components such as the fractional frequency divider module to achieve glitch suppression and phase error quantization, the problems of easy timing compensation and limited synchronization jump width in the traditional CAN protocol are solved, thereby improving communication stability and data transmission accuracy.
Patent Information
- Application Number
- CN202511349372.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-22
- Publication Date
- 2026-07-24
Smart Images

Figure CN122457217A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of signal processing, and more particularly to a timing compensation device and electronic device based on the CAN protocol. Background Technology
[0002] Controller Area Network (CAN) is a serial communication protocol bus system widely used in real-time applications. This protocol holds an important position in industrial control, automotive electronics, aerospace, and other fields due to its high performance and reliability. The CAN protocol uses twisted-pair cable as the transmission medium, possesses complete serial data communication capabilities, supports a 29-bit identifier addressing mechanism, and integrates real-time error correction / detection functions. Its maximum transmission rate can reach 1Mb / s.
[0003] The high reliability of the CAN protocol is attributed to its timing compensation mechanism. The standard CAN timing compensation structure comprises four core parts: a synchronization segment, a transmission segment, phase buffer segment 1, and phase buffer segment 2. The synchronization segment compensates for errors in the synchronization edges of different nodes on the bus, ensuring clock synchronization accuracy. The transmission segment compensates for physical transmission delays, ensuring stable signal transmission through the medium. Phase buffer segment 1 and phase buffer segment 2 work together to compensate for phase errors, maintaining the stability of communication timing.
[0004] However, traditional timing compensation methods have significant technical drawbacks: First, they require distinguishing between positive and negative phases for calculation, which is cumbersome and prone to human error; second, the timing compensation process is susceptible to glitches, and when a CAN node misidentifies a glitch on the bus as a synchronization edge, it will lead to the generation of incorrect timing compensation parameters, thereby causing communication errors; third, the adjustment range of the phase buffer segment in traditional schemes is limited by the synchronization jump width (usually limited to between 1tq and 4tq). When the actual phase error exceeds this range, the timing compensation capability will be significantly reduced, and in severe cases, it may lead to complete communication failure. Summary of the Invention
[0005] This application provides a timing compensation device and electronic device based on the CAN protocol, which can solve the problem of poor timing compensation effect of the CAN protocol in the prior art. The technical solution is as follows:
[0006] In a first aspect, embodiments of this application provide a timing compensation device based on the CAN protocol, characterized in that it includes:
[0007] The system includes a fractional frequency division module, a filter, an edge detection module, a pulse synchronization module, a phase error calculation module, a baud rate counter, and a synchronization identification module.
[0008] The fractional frequency divider module is used to generate a clock frequency divider signal based on the input frequency divider coefficient signal and the sampling mode selection signal, and to transmit the clock frequency divider signal to the filter, the pulse synchronization module, the phase error calculation module, the baud rate counter and the synchronization identification module.
[0009] The filter is used to determine the current sampling mode based on the input sampling mode selection signal, and to convert the input CANRX endpoint signal into a synchronization signal and a decoding signal based on the current sampling mode.
[0010] The edge detection module is used to detect the falling edge of the decoded signal output by the filter and generate a synchronization edge signal;
[0011] The pulse synchronization signal is used to synchronize the synchronization edge signal output by the edge detection module to the baud rate clock to generate a synchronization pulse signal; the synchronization pulse signal corresponds to the synchronization segment of the CAN protocol and is used to identify the start time of timing compensation.
[0012] The synchronization identification module is used to output a synchronization identification flag signal according to the current CAN node status, and to transmit the synchronization identification flag signal to the baud rate counter and the phase error calculation module; the synchronization identification flag signal is used to indicate whether the current CAN node status is hard synchronization or resynchronization.
[0013] The baud rate counter is used to adjust the current baud rate counter value according to the phase adjustment signal input by the phase error module, and to send the adjusted baud rate counter value to the phase error calculation module.
[0014] The phase error calculation module is used to generate a phase adjustment signal and a sampling signal based on the input phase buffer width, synchronization jump width, synchronization pulse signal, clock frequency division signal, the count value of the baud rate counter, and synchronization identification flag signal. The phase adjustment signal includes a hysteresis compensation value, a lead compensation value, and a bit time end flag.
[0015] Secondly, embodiments of this application provide an electronic device that may include the timing compensation device described above.
[0016] The beneficial effects of the technical solutions provided in some embodiments of this application include at least the following:
[0017] An optimized glitch suppression mechanism effectively filters out 2tq-width pulse interference, ensuring stable transmission of bus signals even in complex electromagnetic environments and significantly reducing the impact of transient noise on data parsing. In terms of timing compensation capabilities, the synchronous jump width range has been innovatively expanded, breaking through the traditional 1tq-4tq limitation to achieve a wider range of phase error correction capabilities, enabling nodes to achieve precise timing alignment even under scenarios with larger clock skew.
[0018] Employing an intelligent state discrimination algorithm, it can accurately distinguish between three operating states: leading, lagging, and no synchronization required, and dynamically generate compensation commands based on real-time status. The baud rate counter value is directly corrected through a phase error quantization calculation module, replacing the traditional zero-reset compensation method. This precise compensation mechanism ensures strict synchronization between the sampling point and the transmitting node, effectively avoiding data misjudgment caused by sampling timing deviations. Simultaneously, closed-loop timing management improves the stability and anti-interference redundancy of bus communication, ultimately achieving a dual improvement in data transmission accuracy and system reliability. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is a schematic diagram of the network architecture provided in the embodiments of this application;
[0021] Figure 2 This is a timing diagram of hard synchronization compensation provided in an embodiment of this application;
[0022] Figure 3 This is a timing diagram of the resynchronization lag before compensation provided in the embodiments of this application;
[0023] Figure 4 This is a time series diagram of the compensated resynchronization lag provided in this application;
[0024] Figure 5 This is the timing diagram of the resynchronization lead before compensation provided in this application;
[0025] Figure 6 The timing diagram provided for this application is the compensated resynchronization advance. Detailed Implementation
[0026] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0027] like Figure 1 As shown, the timing compensation device based on the CAN protocol includes: a fractional frequency division module, a filter, an edge detection module, a pulse synchronization module, a phase error calculation module, a baud rate counter, and a synchronization identification module.
[0028] The fractional frequency divider counter is connected to the filter, the pulse synchronization signal, the synchronization identification module, the baud rate counter, and the phase error calculation module; the filter is connected to the edge detection module, the edge detection module is connected to the pulse synchronization module, the pulse synchronization module is connected to the phase error calculation module, the synchronization identification module, and the baud rate counter; the synchronization identification module is connected to the phase error calculation module and the baud rate counter; the baud rate counter is connected to the phase error calculation module; and the phase error calculation module is connected to the pulse synchronization module.
[0029] The functions of each module are explained below.
[0030] The fractional frequency divider module is used to generate a clock frequency divider signal based on the input frequency divider coefficient signal and the sampling mode selection signal, and to transmit the clock frequency divider signal to the filter, the pulse synchronization module, the phase error calculation module, the baud rate counter, and the synchronization identification module.
[0031] The fractional-order frequency divider module, as the core unit for clock generation, primarily provides a precise counting clock (baud_clk) for the baud rate counter (tq_cnt). This module uses the division coefficient signal (r_s_presc) and the sampling mode selection signal (r_divmode) as input control parameters, and dynamically configures the switching between integer and fractional frequency division.
[0032] At the sampling mode control level, the r_divmode signal acts as a mode selection switch, configuring the module to operate in pure integer division or fractional sampling mode. In integer sampling mode, the module directly divides the system clock by an integer multiple based on the integer value of r_s_presc; while in fractional sampling mode, the module uses a fractional division algorithm to achieve non-integer division, where r_s_presc must contain a composite division coefficient of both integer and fractional parts to support finer frequency adjustment.
[0033] The frequency division factor signal r_s_presc is the core parameter for frequency adjustment, and its value directly determines the frequency characteristics of the output clock baud_clk. This signal, by quantizing the division ratio, ensures that the period accuracy of the generated clock meets the timing requirements of the baud rate counter. The baud_clk signal after frequency division directly drives the counting operation of the baud rate counter (tq_cnt), where each baud rate counting cycle (i.e., 1tq) corresponds to a count value of the counter, forming a stable timing reference.
[0034] The filter is used to determine the current sampling mode based on the input sampling mode selection signal, and to convert the input CANRX endpoint signal into a synchronization signal and a decoding signal based on the current sampling mode.
[0035] Among them, the filter, as a key signal processing unit of the CAN communication interface, undertakes the core function of mode adaptation and conversion of the CANRX endpoint signals. Its working logic is dynamically controlled by the sampling mode selection signal. By analyzing the encoding state of this signal, it can accurately determine whether the current working mode is non-glitch filtering mode or glitch filtering mode, and then implement the corresponding signal conversion strategy.
[0036] Furthermore, in some embodiments of this application, the filter integrates a synchronizer and mode-configurable signal processing logic to form a key processing unit in the CAN bus signal receiving link. The synchronizer module uses clock domain transition technology to precisely synchronize the asynchronous timing of the CAN RX endpoint signal (rxd) with the internal system clock, outputting a synchronization signal (rx_sync) with stable clock domain attributes, providing a timing reference for subsequent processing.
[0037] The filter dynamically switches its operating mode via a sampling mode selection signal (r_smpmode). In non-glitch filtering mode, the system directly outputs the synchronization signal (rx_sync) as the decoding signal (get_sample), preserving the real-time characteristics of the original signal, making it suitable for scenarios sensitive to timing delays.
[0038] In glitch filtering mode, the filter enables glitch filtering, achieving sub-tq level precision filtering through three-stage signal sampling and logic combination. Specifically, the synchronization signal (rx_sync) is first sampled using a clock divider (baud_clk) to generate a primary sample signal A (sample_a). Then, sample_a is sampled again using baud_clk to form a secondary sample signal B (sample_b). Finally, rx_sync, sample_a, and sample_b are combined using a logical OR operation to generate a decoded signal (get_sample) with glitch suppression characteristics. This design, through multi-stage sampling delay and logical judgment, effectively filters out transient glitches lasting less than 2tq, ensuring that the decoded signal only responds to a continuously valid stable level, thus improving signal anti-interference capability.
[0039] The combined operation of the two modes ensures both low-latency transmission and highly reliable signal purification. This configurable architecture allows the filter to meet basic synchronization requirements while enhancing the system's robustness in noisy environments through glitch filtering. It provides a precise and interference-resistant signal source for CAN protocol data parsing, ensuring the integrity and timing accuracy of bus communication.
[0040] The edge detection module is used to detect the falling edge of the decoded signal output by the filter and generate a synchronization edge signal.
[0041] Among them, the edge detection module, as a key timing monitoring unit in the CAN receive link, is responsible for accurately capturing changes in the input signal level. Its input sources are the decoded signal (get_sample) and the synchronization signal (rx_sync) output from the filter, and its output is the synchronization edge signal (sync_edge), which is specifically used to detect the falling edge event of the decoded signal transitioning from high level to low level and generate a synchronization edge signal with a clear timing identifier.
[0042] In terms of implementation mechanism, this module latches the previous cycle state of the input signal through a register and compares it with the current input signal in real time. When a low level is detected in the current signal and a high level is detected in the previous cycle, it is determined to be a valid falling edge event, at which point the sync_edge signal is triggered and set. This edge detection logic ensures accurate capture of input signal level transitions, and is particularly suitable for monitoring the level transition process of decoded signals.
[0043] The generation of the sync edge signal strictly follows the signal timing change rules. Its output pulse width is synchronized with the system clock cycle, providing a precise timing trigger reference for subsequent frame synchronization, bit parsing and other operations.
[0044] The pulse synchronization module, as the core processing unit for timing alignment in the CAN receive link, plays a crucial role in synchronizing asynchronous edge events to the baud rate clock domain. Its input sources include the synchronization edge signal (sync_edge) output from the edge detection module, the clock division signal (baud_clk) generated by the fractional divider module, and the sampling signal (sample). Its output is a synchronization pulse signal (sync_pulse) that is strictly aligned to the baud rate clock. This signal directly corresponds to the synchronization segment defined by the CAN protocol, providing a precise timing starting point for bit synchronization adjustment.
[0045] In terms of implementation mechanism, the module employs multi-level register synchronization technology to process input edge signals. First, a two-stage flip-flop chain synchronizes `sync_edge` across clock domains to eliminate metastability risks and ensure the stability of the edge signal in the baud rate clock domain. Then, the synchronized edge signal is aligned with the rising edge of `baud_clk` to generate a synchronization pulse signal with a defined timing relationship. This pulse signal is strictly limited to the baud rate clock cycle, and its leading edge precisely identifies the start time of timing compensation, meeting the stringent timing accuracy requirements of the CAN protocol for the synchronization segment.
[0046] The synchronization pulse signal (sync_pulse) plays a dual role in the system: on the one hand, it serves as a reference signal for frame synchronization, triggering subsequent bit synchronization adjustment processes to ensure that the data sampling points are fully aligned with the synchronization segments defined by the protocol; on the other hand, it provides a precise time reference for timing compensation. When a bus bit width deviation is detected, phase calibration is achieved by adjusting the sampling point position to ensure the timing accuracy of data transmission.
[0047] The synchronization identification module, as the core decision-making unit of the CAN protocol timing compensation mechanism, is responsible for the accurate identification and flag generation of hard synchronization and resynchronization. Its inputs include the hard synchronization / resynchronization identification state signal (sync_hard_state), the sample signal, and the synchronization pulse signal (sync_pulse) implemented based on the CAN protocol state machine. Through multi-dimensional signal collaborative processing, it accurately determines the synchronization type and outputs the corresponding hard synchronization identification flag signal (sync_hard_flag) or resynchronization identification flag signal (re_sync_flag), providing a clear synchronization type identifier for subsequent timing compensation.
[0048] At the synchronization identification logic level, the module strictly adheres to the timing definition of synchronization scenarios in the CAN protocol. Hard synchronization detection is limited to triggering within the Start of Frame (SOF) and bus recovery segments. When the synchronization pulse signal (sync_pulse) falls within the time period specified by the above protocol, and the synchronization status signal (sync_hard_state) indicates that the hard synchronization condition is met, the module will set the hard synchronization identification flag signal. At this point, unlike the traditional coarse compensation method of resetting the baud rate counter, this module adopts a direct phase error compensation mechanism. Timing calibration is achieved by accurately calculating the phase deviation value, avoiding timing abrupt changes caused by counter resetting, and improving the smoothness and accuracy of the synchronization process.
[0049] Resynchronization detection covers the entire protocol transmission cycle except for the SOF segment and the bus recovery segment. When the sample signal and the synchronization status signal (sync_hard_state) jointly indicate that the resynchronization condition is met, the module will generate a resynchronization identification flag signal. In terms of compensation range, this module breaks through the traditional 1tq to 4tq jump limitation and expands the compensable phase error range to 1tq to 15tq by optimizing the synchronization jump width control algorithm.
[0050] The baud rate counter, as the core quantization unit for CAN bit time counting, is responsible for accurately counting each timing segment within the bit cycle. Its input includes multi-dimensional control signals and parameters: the clock divider signal (baud_clk) serves as the counting drive clock, directly determining the counting step rhythm; the synchronization pulse signal (sync_pulse) corresponds to the CAN protocol synchronization segment, providing a precise alignment reference for the start time of bit time counting; the phase buffer parameters seg1 and seg2 define the adjustable timing interval length in the bit time, excluding the synchronization segment, in units of tq; the phase adjustment signals carry_over (lag compensation value), tq_end (lead compensation value), and the bit time end flag clock together implement the dynamic timing compensation function. carry_over shortens the current count value tq_cnt when a clock deviation is detected causing the counting to be too fast, tq_end extends tq_cnt when the counting is too slow, and clock triggers a counter reset or the start of the next cycle, forming a closed-loop management system.
[0051] From the perspective of bit-time structure, the CAN standard specifies that a bit time consists of a synchronization segment, phase buffer segment 1 (seg1), and phase buffer segment 2 (seg2). The synchronization segment is fixed at 1tq in length, while the phase buffer segment length is configurable in units of tq. Therefore, the total bit time length is calculated as: seg1 + 2tq + seg2 + 1tq (i.e., synchronization segment 1tq + seg1 + seg2). The baud rate counter performs tq-level quantization counting of the bit time using tq_cnt, with each tq corresponding to one counting cycle. This ensures that the timing ratio of each segment of the bit time strictly conforms to the protocol specification, providing a precise timing quantization basis for bit synchronization adjustment, data sampling, and other operations.
[0052] The phase error calculation module, as the core computing unit for CAN timing compensation, is responsible for the quantization calculation of bit-time phase deviation and the generation of compensation instructions. Its input signals include phase buffer parameters seg1 and seg2, synchronization jump width sjw, synchronization pulse signal sync_pulse, clock divider signal baud_clk, current baud rate counter value tq_cnt, and hard synchronization identification flags sync_hard_flag and resynchronization identification flags re_sync_flag. Output signals include phase adjustment instructions carry_over, tq_end, clock, and a sampling signal sample, used to drive the dynamic adjustment of the baud rate counter and control data decoding timing. The sample signal sample output by the phase error calculation module is sent to the backend CAN decoder for sampling.
[0053] The module's compensation logic follows the CAN protocol timing specification, and its implementation is divided into three scenarios:
[0054] In normal operation without timing compensation, when the baud rate counter tq_cnt reaches the count value of seg1+2-1, the module generates a sampling signal sample, which triggers the sampling operation of CAN data decoding; when tq_cnt reaches the count value of seg1+2+seg2+1-1, the module generates a bit time end flag clock, which instructs the baud rate counter to be cleared to start a new bit cycle counting.
[0055] When advance compensation is required (clock-fast scenario), the module performs tiered processing based on the relative magnitude of the phase error (phase_error) and the synchronization jump width (sjw): if phase_error ≤ sjw, the sample signal is generated when tq_cnt = seg1 + 2 - 1 + phase_error, and the clock signal is generated when tq_cnt = seg1 + 2 + seg2 + 1 - 1 + phase_error; if phase_error > sjw, the sample signal is generated when tq_cnt = seg1 + 2 - 1 + sjw, and the clock signal is generated when tq_cnt = seg1 + 2 + seg2 + 1 - 1 + sjw. That is, the phase advance error is compensated by extending the length of phase buffer segment 1.
[0056] When lag compensation (clock slow scenario) is required, the module also operates based on the relationship between phase_error and sjw: if phase_error≤sjw, tq_cnt is immediately cleared and the phase_error value is added, and a clock signal is generated to indicate the end of the time; if phase_error>sjw, tq_cnt is cleared and the sjw value is added before generating the clock signal. That is, the lag phase error is compensated by resetting the counter and shortening the length of phase buffer segment 2.
[0057] The above compensation logic is strictly based on the triggering conditions of the hard synchronization / resynchronization flag signal, ensuring that the timing compensation operation is precisely matched with the timing structure of the synchronization segment and phase buffer segment specified by the CAN protocol, providing dynamically adjustable timing compensation capability for bit time quantization counting.
[0058] The timing compensation process of this application is illustrated below with several specific examples.
[0059] In the following examples, the width of phase buffer segment 1 (seg1) is 6tq, and the length of phase buffer segment 2 (seg2) is 1tq. One bit time is 6 + 2 + 1 + 1 - 1 = 9tq. When no timing compensation is required, the baud rate counter (tq_cnt) needs to count to 9. When the baud rate counter's count value tq_cnt equals phase buffer segment 1 (seg1) + 2 - 1, that is, when tq_cnt equals 6 + 2 - 1 = 7, the sample signal (sample) will be generated.
[0060] See Figure 2 , is the timing diagram for hard synchronization compensation.
[0061] In the CAN protocol receive link, the edge detection module and the pulse synchronization module work together to detect the falling edge of the CAN signal and synchronize it to the baud rate clock domain, generating a synchronization edge signal (sync_edge) and a synchronization segment signal (sync_pulse) respectively. When the hard synchronization / resynchronization identification module determines that the current state is hard synchronization and the synchronization segment signal (sync_pulse) falls within the phase buffer segment 2 (seg2) interval, the receiving node will trigger the hard synchronization compensation process.
[0062] At this point, the phase error calculation module performs phase deviation quantization based on the protocol specification: the phase error value (phase_error) is precisely calculated using the formula "seg1+2+seg2+1-latched tq_cnt value". For example, in a specific scenario, when seg1=6, seg2=1, and latched tq_cnt=9, the calculated phase_error = 6+2+1+1-9=1. This error value is directly used to adjust the baud rate counter (tq_cnt) of the receiving node, correcting it from its original value of 9 to 1, thus achieving timing alignment.
[0063] Unlike the traditional coarse compensation method of directly zeroing tq_cnt in hard synchronization, this scheme performs dynamic compensation by accurately calculating the phase error value. Traditional zeroing operations result in a fixed deviation of 1tq, while this scheme directly corrects tq_cnt to the corresponding error value, ensuring that the tq_cnt sequences of the receiving and transmitting nodes highly overlap after compensation, and the sampling points are also basically aligned, significantly improving timing synchronization accuracy and data transmission reliability.
[0064] This compensation mechanism, based on precise calculation of phase error, not only follows the strict definition of hard synchronization timing segments in the CAN protocol, but also replaces empirical zeroing operations with quantitative compensation. While ensuring protocol compliance, it realizes a technical upgrade of timing compensation from "qualitative adjustment" to "quantitative correction", providing more accurate timing synchronization guarantee for high-speed CAN communication systems.
[0065] See Figure 3 This is a time series diagram showing the resynchronization lag before compensation.
[0066] Taking the above diagram as an example, when there is a timing discrepancy between the sampling points of the sending node (tx) and the receiving node (rx), and the receiving node's sampling point lags behind the sending node, it may cause data parsing errors and bus-level faults. Specifically, because the rx node's sampling time is later than the tx node's, during data transmission, the rx may not be able to capture valid data levels within the optimal sampling window specified by the protocol, resulting in a deviation between the sampled value and the actual transmitted value.
[0067] If this timing deviation persists, it will increase the risk of data frame parsing errors. For example, when an RX node reads a signal that has already undergone a level transition due to sampling lag, it may misinterpret a correct high level as a low level, or vice versa, leading to a single-bit error. According to the CAN protocol specification, if such errors are not detected and corrected in time by the node's own error detection mechanism, they may further trigger bus error states, manifesting as the transmission of erroneous frames or the interruption of bus communication, ultimately affecting the real-time performance and reliability of the entire network.
[0068] See Figure 4 , is the timing diagram of the resynchronization lag after compensation.
[0069] When the receiving node (rx) captures the falling edge through the edge detection module and generates a synchronization segment signal (sync_pulse) through the pulse synchronization module, and the hard synchronization / resynchronization identification module determines that the current state is resynchronization and the synchronization segment enters the phase buffer segment 2 (seg2) interval, the receiving node will trigger the resynchronization compensation process.
[0070] At this point, the phase error calculation module performs phase deviation calculation according to the quantization rules defined in the protocol: the phase error value (phase_error) is precisely obtained using the formula "seg1 + 2tq + seg2 + 1 - latched baud rate counter (tq_cnt) value". For a specific example, when seg1 = 6, seg2 = 1, and latched tq_cnt = 8, the calculated phase_error = 6 + 2 + 1 + 1 - 8 = 2. This error value is directly used to adjust the receiver node's tq_cnt, correcting it from the original value of 8 to 2, thus achieving timing alignment.
[0071] See Figure 5 This is the timing diagram for resynchronization advance before compensation.
[0072] Taking the above diagram as an example, when the sampling point of the receiving node (rx) precedes that of the transmitting node (tx), it can lead to timing misalignment, potentially causing data parsing failure and bus-level errors. Specifically, because the rx node samples earlier than the tx node, during data transmission, the rx may sample in an area where the signal level has not yet stabilized or has already transitioned, thus capturing a level state that does not match the actual transmitted value. If this advance sampling continues, it will directly lead to data frame parsing errors. For example, if the rx node completes sampling before the tx node's level transition, it may misinterpret a correct low level as a high level, or vice versa, causing a single-bit error. According to the CAN protocol specification, if such errors are not promptly identified and corrected by the node's own error detection mechanism (such as CRC check, bit stuffing check), it will trigger a bus error response, manifested as the transmission of erroneous frames or a temporary interruption of bus communication, ultimately affecting the overall real-time performance and reliability of the network.
[0073] See Figure 6 This is the timing diagram for the compensated resynchronization advance.
[0074] The receiving node (rx) captures the falling edge of the signal through the edge detection module and generates a synchronization segment signal (sync_pulse) through the pulse synchronization module. When the hard synchronization / resynchronization identification module determines that the current state is resynchronization and the synchronization segment enters the phase buffer segment 1 (seg1) interval, the resynchronization compensation mechanism will be triggered.
[0075] At this point, the phase error calculation module performs deviation quantization based on the real-time latched baud rate counter (tq_cnt) value: the phase error value (phase_error) is directly equal to the current latched tq_cnt value. For example, if the latched tq_cnt is 4, then phase_error = 4. This error value is used to dynamically adjust the timing of the receiving node. The original tq_cnt value is extended to 4 + 9 = 13 before being cleared, and the data sampling point position is adjusted accordingly from the original 7 to 7 + 4 = 11, achieving precise correction of the timing offset.
[0076] After resynchronization compensation, the tq_cnt sequences of the receiving and transmitting nodes are precisely aligned after the compensation point, and the data sampling points also coincide synchronously. This compensation method based on real-time latch counter values strictly follows the CAN protocol's definition specifications for resynchronization timing segments. It replaces traditional empirical adjustments with direct correction of quantization errors, ensuring protocol compliance while achieving a technical upgrade in timing synchronization accuracy from "time period calibration" to "point correction." This provides a more reliable timing synchronization guarantee for high-speed CAN communication systems, ensuring the accuracy of data transmission and bus stability.
[0077] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory, or random access memory, etc.
[0078] The above-disclosed embodiments are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, any equivalent variations made in accordance with the claims of this application shall still fall within the scope of this application.
Claims
1. A timing compensation device based on the CAN protocol, characterized in that, include: The system includes a fractional frequency division module, a filter, an edge detection module, a pulse synchronization module, a phase error calculation module, a baud rate counter, and a synchronization identification module. The fractional frequency divider module is used to generate a clock frequency divider signal based on the input frequency divider coefficient signal and the sampling mode selection signal, and to transmit the clock frequency divider signal to the filter, the pulse synchronization module, the phase error calculation module, the baud rate counter and the synchronization identification module. The filter is used to determine the current sampling mode based on the input sampling mode selection signal, and to convert the input CANRX endpoint signal into a synchronization signal and a decoding signal based on the current sampling mode. The edge detection module is used to detect the falling edge of the decoded signal output by the filter and generate a synchronization edge signal; The pulse synchronization signal is used to synchronize the synchronization edge signal output by the edge detection module to the baud rate clock to generate a synchronization pulse signal; The synchronization pulse signal corresponds to the synchronization segment of the CAN protocol and is used to identify the start time of timing compensation. The synchronization identification module is used to output a synchronization identification flag signal according to the current CAN node status, and to transmit the synchronization identification flag signal to the baud rate counter and the phase error calculation module; the synchronization identification flag signal is used to indicate whether the current CAN node status is hard synchronization or resynchronization. The baud rate counter is used to adjust the current baud rate counter value according to the phase adjustment signal input by the phase error module, and to send the adjusted baud rate counter value to the phase error calculation module. The phase error calculation module is used to generate a phase adjustment signal and a sampling signal based on the input phase buffer width, synchronization jump width, synchronization pulse signal, clock frequency division signal, the count value of the baud rate counter, and synchronization identification flag signal. The phase adjustment signal includes a hysteresis compensation value, a lead compensation value, and a bit time end flag.
2. The apparatus according to claim 1, characterized in that, The phase error calculation module is specifically used for: ① When timing compensation is not required, when the baud rate counter count value is equal to phase buffer segment 1+2-1, the phase error calculation module will generate a sampling signal, which is used for sampling of CAN protocol data decoding; When the baud rate counter's count value equals phase buffer segment 1+2+phase buffer segment 2+1-1, a clock signal is generated. This clock signal is used to instruct the baud rate counter to perform a clear-to-zero operation. ② When advance compensation is required, If the phase error is less than the synchronization jump width, and if the baud rate counter count value is equal to the phase buffer segment 1 + 2 - 1 + phase error, a sample signal is generated. This sample signal has compensated for the error caused by the leading phase. When the baud rate counter count value is equal to the phase buffer segment 1 + 2 + phase buffer segment 2 + 1 - 1 + phase error value, a clock signal is generated to indicate that the baud rate counter is cleared to mark the end of one bit time of the CAN protocol. If the phase error is greater than the synchronization jump width, and if the baud rate counter count value is equal to the phase buffer segment 1 + 2 - 1 + synchronization jump width, a sample signal is generated. This sample signal has compensated for the error caused by the leading phase. When the baud rate counter count value is equal to the phase buffer segment 1 + 2 + phase buffer segment 2 + 1 - 1 + synchronization jump width, a clock signal is generated to indicate that the baud rate counter is cleared to mark the end of a bit time in the CAN protocol. ③ When delayed compensation is required, If the phase error is less than the synchronization jump width, the baud rate counter is immediately reset to zero, and the count value of the baud rate counter is added to the phase error. Then, a clock signal is generated to indicate that the baud rate counter is reset to zero to mark the end of a bit time in the CAN protocol. If the phase error is greater than the synchronization jump width, the baud rate counter is immediately reset to 0, and the baud rate counter value is increased by the synchronization jump width. Then, a clock signal is generated to indicate that the baud rate counter is reset to zero to mark the end of a bit time in the CAN protocol.
3. The apparatus according to claim 1 or 2, characterized in that, The filter includes a synchronizer, which is used to synchronize the CAN RX endpoint signal to the system clock and generate a synchronization signal; The filter determines the current sampling mode based on the input sampling mode selection signal; If the current sampling mode is the glitch filtering mode, the synchronization signal is sampled using the clock frequency division signal to generate a primary sampling signal A, and then the primary sampling signal A is sampled a second time using the clock frequency division signal to generate a secondary sampling signal B. Then, the primary sampling signal A, the secondary sampling signal B, and the synchronization signal are respectively ORed to generate a decoding signal. The decoding signal has completed the filtering of glitch lengths within 2tq. If the current sampling mode is a non-glitch filtering mode, the synchronization signal is directly used as the decoding signal without performing glitch filtering.
4. The method according to claim 3, characterized in that, The fractional frequency divider module supports fractional frequency division, and the count value tq of one baud rate counter is equal to one baud rate counting time.
5. An electronic device, characterized in that, The apparatus as described in any one of claims 1 to 4.
