Clock domain crossing pulse counting device and method supporting clear reading

By using read-clear registers and Gray code methods in cross-clock domain pulse counting, the problem in the prior art that pulse counting does not support read-clear is solved, the counting accuracy is improved, and the calculation process is simplified.

CN118573178APending Publication Date: 2024-08-30WELL CORE MICROELECTRONICS TECH (TIANJIN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410762363.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-13
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

The existing cross-clock pulse counting method does not support read clearing, resulting in low pulse counting accuracy. Software is required to process and distinguish between the two counting methods, which increases the human calculation burden and reduces accuracy.

Method used

Read clear registers, handshake method across clock domain modules and Gray code method to cross clock domain modules, realize cross-clock domain data transmission through register access bus and Gray code method, avoid pulse loss and improve counting accuracy.

Benefits of technology

The accuracy of cross-clock domain pulse counting is improved, pulse loss is avoided, the counting process is simplified, and the calculation burden is reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118573178A
    Figure CN118573178A
Patent Text Reader

Abstract

The invention discloses a clock domain crossing pulse counting device and method supporting read clear, which can be applied to the technical field of pulse counting, and the device comprises a read clear register, a handshake mode clock domain crossing module, a pulse driving counter and a Gray code mode clock domain crossing module, the read clear register is arranged in the first clock domain, one end of the read clear register is connected with the register access bus, and the other end of the read clear register is connected with the pulse driving counter through the handshake mode clock domain crossing module; the pulse driving counter is arranged in a second clock domain and is connected with the read clear register through a Gray code mode clock domain crossing module; the data returned to the host by the read clear register through the register access bus is consistent with the response data sent to the pulse driving counter. Therefore, the problem of pulse loss easily caused by clock domain crossing pulse counting is avoided, the pulse driving counter can realize a read clear function based on the response data, and the accuracy of pulse counting is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of pulse counting technology, and in particular to a cross-clock domain pulse counting device and method supporting clear reading. Background Art

[0002] The complexity and integration of existing chips are getting higher and higher. There are many different signals working at different clock frequencies on a chip or Field Programmable Gate Array (FPGA). In the demand for chip maintenance and testability, it is necessary to count a certain time, such as the number of insulation received and sent by the system. In order to reduce the occurrence of metastable states, cross-clock domain processing is required.

[0003] In the performance counting scenario, the count value must be accurate and no pulse loss should occur. The existing cross-clock pulse counting method usually does not support clear reading and needs to be implemented in combination with software processing. Such an unconventional processing solution, if there is synchronous pulse counting, must distinguish between two different counting methods, which introduces a manual calculation burden and leads to the problem of low pulse counting accuracy.

[0004] Therefore, how to improve the accuracy of cross-clock pulse counting is a problem that technical personnel in this field need to solve urgently. Summary of the invention

[0005] Based on the above problems, the present application provides a cross-clock domain pulse counting device and method that supports clear reading, which avoids the problem of pulse loss that is prone to occur in cross-clock domain pulse counting, and the pulse-driven counter can realize the clear reading function based on the response data, thereby improving the accuracy of pulse counting.

[0006] In a first aspect, an embodiment of the present application provides a cross-clock domain pulse counting device supporting clear reading, comprising: a clear reading register, a handshake mode cross-clock domain module, a pulse driving counter, and a Gray code mode cross-clock domain module;

[0007] The read clear register is placed in the first clock domain, and one end is connected to the register access bus, and the other end is connected to the pulse drive counter through the handshake mode cross-clock domain module;

[0008] The handshake mode cross-clock domain module is used to pass the response data generated by the read-clear register to the pulse drive counter; the response data is consistent with the data returned by the read-clear register to the host through the register access bus;

[0009] The pulse drive counter is placed in the second clock domain and connected to the clear read register via the Gray code cross-clock domain module;

[0010] The Gray code mode cross-clock domain module is used to transfer the counting result of the pulse drive counter to the read clear register.

[0011] In a second aspect, an embodiment of the present application provides a cross-clock domain pulse counting method supporting clear reading, characterized in that it is applied to the pulse driven counter according to claim 1, and the method includes:

[0012] receiving a first counting result sent by a clear read register; the first counting result being a count value of a clock cycle to be measured stored in the clear read register when the clear read register receives a register access signal;

[0013] determining a second counting result based on the first counting result;

[0014] The second counting result is sent to the clear read register, so that the clear read register receives and stores the second counting result.

[0015] Optionally, determining a second counting result based on the first counting result includes:

[0016] When the first counting result is valid, a second counting result is determined based on a difference between a current counting value of the clock cycle to be measured and the first counting result.

[0017] Optionally, when the first counting result is valid, determining the second counting result based on the difference between the current counting value of the clock cycle to be measured and the first counting result includes:

[0018] When the first counting result and the counting pulse are both valid, the difference between the target counting value and the first counting result is increased by one to determine the second counting result;

[0019] The target count value is a count value of a previous cycle of the second clock domain generated by the count pulse.

[0020] Optionally, when the first counting result is valid, determining the second counting result based on the difference between the current counting value of the clock cycle to be measured and the first counting result includes:

[0021] When the first counting result and the counting pulse are not valid at the same time, determining the difference between the target counting value and the first counting result as the second counting result;

[0022] The target count value is a count value of a previous cycle of the second clock domain generated by the count pulse.

[0023] In a third aspect, an embodiment of the present application provides a cross-clock domain pulse counting method supporting clear reading, characterized in that it is applied to the clear reading register according to claim 1, and the method includes:

[0024] receiving and storing a first counting result sent by a pulse driving counter;

[0025] In response to a register access signal, sending the first counting result to the pulse drive counter, so that the pulse drive counter calculates a second counting result based on the first counting result;

[0026] The second counting result sent by the pulse driving counter is received and stored.

[0027] Optionally, the receiving and storing a first counting result sent by the pulse driving counter includes:

[0028] receiving a first counting result sent by a pulse-driven counter in a Gray code manner;

[0029] The first counting result is stored.

[0030] Optionally, sending the first counting result to the pulse drive counter includes:

[0031] The first counting result is sent to the pulse driving counter based on a handshake manner.

[0032] Optionally, the method further includes:

[0033] In response to the register access signal, the first counting result is fed back to the host through a register access bus.

[0034] In a fourth aspect, an embodiment of the present application provides a cross-clock domain pulse counting method supporting clear reading, characterized in that the clear reading register and the pulse drive counter described in claim 1 are used to interact, and the method includes:

[0035] The pulse driving counter counts the clock cycle to be measured, and sends the first counting result obtained by counting to the clear read register for storage in a Gray code manner;

[0036] When the read clear register receives the register access signal, the first counting result is fed back through the register access bus, and the first counting result is sent to the pulse drive counter in a handshake manner;

[0037] The pulse driven counter calculates a second counting result based on the first counting result, and sends the second counting result to the read clear register for storage in a Gray code manner.

[0038] It can be seen from the above technical solutions that compared with the prior art, the present application has the following advantages:

[0039] A cross-clock domain pulse counting device supporting clear reading provided by an embodiment of the present application includes a clear reading register, a cross-clock domain module in a handshake mode, a pulse drive counter, and a Gray code cross-clock domain module. Among them, the clear reading register is placed in the first clock domain, and one end is connected to the register access bus, and the other end is connected to the pulse drive counter through the cross-clock domain module in a handshake mode. The pulse drive counter is placed in the second clock domain and is connected to the clear reading register through the cross-clock domain module in a Gray code mode. It is important that the data returned to the host by the clear reading register through the register access bus is consistent with the response data sent to the pulse drive counter. In this way, the problem of pulse loss that is prone to occur in cross-clock domain pulse counting is avoided, and the pulse drive counter can realize the clear reading function based on the response data, thereby improving the accuracy of pulse counting. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 An interface diagram of a cross-clock domain pulse counting device supporting clear reading provided in an embodiment of the present application;

[0041] Figure 2 A flowchart of a cross-clock domain pulse counting method supporting clear reading applied to a pulse driven counter provided in an embodiment of the present application;

[0042] Figure 3 A flowchart of a method for counting cross-clock domain pulses supporting clear reading applied to a clear reading register provided in an embodiment of the present application;

[0043] Figure 4 A flowchart of a cross-clock domain pulse counting method supporting clear reading that interacts with a pulse-driven counter and a clear reading register provided in an embodiment of the present application;

[0044] Figure 5 A waveform diagram provided for an embodiment of the present application. DETAILED DESCRIPTION

[0045] As mentioned above, the existing cross-clock pulse counting method has the problem of low pulse counting accuracy. Specifically, the existing counting scheme is usually implemented by cross-clock domain pulse counting that does not support clear reading plus software processing, but this processing scheme is not conventional. When there is synchronous pulse counting, it is also necessary to distinguish between two different counting methods, which adds additional calculation requirements to the software, thereby introducing artificial calculation burden, resulting in the problem of low cross-clock pulse counting accuracy.

[0046] To solve the above problems, an embodiment of the present application provides a cross-clock domain pulse counting device that supports clear reading, including: a clear reading register, a handshake cross-clock domain module, a pulse drive counter and a Gray code cross-clock domain module; the clear reading register is placed in the first clock domain, and one end is connected to the register access bus, and the other end is connected to the pulse drive counter through the handshake cross-clock domain module; the handshake cross-clock domain module is used to pass the response data generated by the clear reading register to the pulse drive counter; the response data is consistent with the data returned to the host by the clear reading register through the register access bus; the pulse drive counter is placed in the second clock domain, and is connected to the clear reading register through the Gray code cross-clock domain module; the Gray code cross-clock domain module is used to pass the counting result of the pulse drive counter to the clear reading register.

[0047] In this way, the clear read register and the pulse driven counter are placed in different clock domains, and the cross-clock domain data transmission is realized by using the handshake mode cross-clock domain module and the Gray code mode cross-clock domain module, thereby avoiding the problem of pulse loss in cross-clock domain pulse counting. The pulse driven counter can realize the clear read function based on the response data, thereby improving the accuracy of pulse counting.

[0048] It should be noted that the cross-clock domain pulse counting device and method supporting clear reading provided in the embodiment of the present application can be applied to the field of pulse counting technology. The above is only an example and does not limit the application field of the cross-clock domain pulse counting device and method supporting clear reading provided in the present application.

[0049] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0050] Figure 1 The interface diagram of a cross-clock domain pulse counting device supporting clear reading provided by the embodiment of the present application. Figure 1 As shown, the cross-clock domain pulse counting device 100 supporting clear reading provided by the embodiment of the present application includes: a clear reading register 101, a handshake mode cross-clock domain module 102, a pulse driving counter 103 and a Gray code mode cross-clock domain module 104;

[0051] Among them, the clear read register 101 is placed in the first clock domain, and one end is connected to the register access bus, and the other end is connected to the pulse drive counter 103 through the handshake mode cross-clock domain module 102; the pulse drive counter 103 is placed in the second clock domain, and is connected to the clear read register 101 through the Gray code mode cross-clock domain module 104.

[0052] In addition, the register 101 is read and cleared to receive and store the first counting result sent by the pulse drive counter 103; in response to the register access signal, the first counting result is sent to the pulse drive counter 103, so that the pulse drive counter calculates the second counting result based on the first counting result; and the second counting result sent by the pulse drive counter 103 is received and stored.

[0053] The handshake mode cross-clock domain module 102 is used to pass the response data generated by the read register 101 to the pulse drive counter 103; the response data is consistent with the data (first counting result) returned to the host by the read register 101 through the register access bus;

[0054] The pulse driven counter 103 is used to receive the first counting result (response data) sent by the clear read register 101; the first counting result is the count value of the clock cycle to be measured stored in the clear read register 101 when the clear read register 101 receives the register access signal; the second counting result is determined based on the first counting result; the second counting result is sent to the clear read register 101, so that the clear read register 101 receives and stores the second counting result.

[0055] The Gray code clock domain crossing module 104 is used to transfer the counting result of the pulse driving counter 103 to the clear read register 101 .

[0056] In summary, an embodiment of the present application provides a cross-clock domain pulse counting device that supports clear reading, including a clear reading register, a handshake cross-clock domain module, a pulse drive counter, and a Gray code cross-clock domain module. Among them, the clear reading register is placed in the first clock domain, and one end is connected to the register access bus, and the other end is connected to the pulse drive counter through the handshake cross-clock domain module. The pulse drive counter is placed in the second clock domain and is connected to the clear reading register through the Gray code cross-clock domain module. It is important that the data returned to the host by the clear reading register through the register access bus is consistent with the response data sent to the pulse drive counter. In this way, the problem of pulse loss that is prone to occur in cross-clock domain pulse counting is avoided, and the pulse drive counter can realize the clear reading function based on the response data, thereby improving the accuracy of pulse counting.

[0057] Based on the above embodiment, a cross-clock domain pulse counting device supporting clear reading is provided, and the embodiment of the present application further provides a cross-clock domain pulse counting method supporting clear reading. The cross-clock domain pulse counting method supporting clear reading is described below in conjunction with the embodiments and drawings.

[0058] Figure 2 A flow chart of a method for cross-clock domain pulse counting supporting clear reading applied to a pulse driven counter provided in an embodiment of the present application. Figure 2 As shown, when the method is applied to a pulse driven counter, the method may include:

[0059] S201: Receive a first counting result sent by a clear read register; the first counting result is a count value of a clock cycle to be measured stored in the clear read register when the clear read register receives a register access signal.

[0060] In practical applications, the clock domain accessed by the read-clear register is recorded as clk1 (first clock domain), and the clock domain generated by the counting pulse (cnt_pulse) is recorded as clk2 (second clock domain). The pulse-driven counter is set in clk2, which is used to count cnt_pulse, obtain the number of clock cycles (pulse_cnt) and send pulse_cnt in real time to the read-clear register placed in clk1 for storage. Since the transmission of signals across clock domains can cause metastable phenomena, the gray code cross-clock domain module is introduced to transmit pulse_cnt in clk1 as storage data (rd_cnt_sync). It can be understood that in the process of the pulse-driven counter transmitting the counting result to the read-clear register, due to the possible delay across the clock domain, the actual count value of the pulse-driven counter at a certain moment may be different from the count value stored in the read-clear register, that is, the values ​​of pulse_cnt and rd_cnt_sync at a certain moment are different. Specifically, the rd_cnt_sync stored in the clear read register before the host sends a register access signal to the clear read register through the register access bus can be called the first counting result (the count value of the clock cycle to be measured corresponding to the counting pulse). To implement the clear read function, when the host sends a register access signal (rd_en), the clear read register returns the rd_cnt_sync at that moment as the bus return data (rd_data) to the read access initiator, and returns the response data (clr_cnt and clr_en) corresponding to rd_cnt_sync to the handshake mode cross-clock domain module, and the corresponding transmission across the clock domain in clk2 is (clr_cnt_sync and clr_en_sync). It should be noted that in order to implement the clear read function, the values ​​of clr_cnt and rd_data need to be consistent, that is, both are the first counting results. The pulse-driven counter receives the first counting result sent by the clear read register.

[0061] S202: Determine a second counting result based on the first counting result.

[0062] In practical applications, the pulse drive counter can re-count cnt_pulse after the host reads rd_cnt_sync (first counting result) and obtain a second counting result. For example, cnt_pulse inputs the continuous clock cycle number pulse_cnt, and the pulse drive counter starts counting. As time accumulates, there may be counting results such as 0, 1, 2, 3, 4, and 5. The count result sent by the pulse drive counter is stored in the clear read register. If the first count result stored in the clear read register at the first moment is 2, the host sends rd_en at this time, and the clear read register sends 2 as response data to the pulse drive counter. During this period, the pulse drive counter has been counting cnt_pulse and obtaining the corresponding actual counting result, which is greater than or equal to 2. The actual counting result and the first counting result are used for calculation to obtain the total number of cycles of cnt_pulse (second counting result) from the first moment to the present, thereby realizing the clear read function.

[0063] In addition, since the methods for determining the second counting result are not the same, the embodiment of the present application can illustrate a possible determination method.

[0064] In one case, S202: determining a second counting result based on the first counting result may specifically include:

[0065] When the first counting result is valid, a second counting result is determined based on a difference between a current counting value of the clock cycle to be measured and the first counting result.

[0066] In practical applications, the pulse drive counter always counts the number of clock cycles pulse_cnt that the cnt_pulse input lasts. The first counting result is represented by clr_cnt_sync and clr_en_sync in clk2, where clr_cnt_sync is the count value and clr_en_sync is used to characterize whether its count value is valid. When clr_en_sync is valid, clr_cnt_sync can be subtracted from the current count value of the clock cycle to be measured (the actual count result of cnt_pulse) to obtain the second counting result.

[0067] In addition, since the methods for determining the second counting result are not the same, the embodiment of the present application can illustrate a possible determination method.

[0068] In one case, when the first counting result is valid, determining the second counting result based on the difference between the current counting value of the clock cycle to be measured and the first counting result includes:

[0069] When the first counting result and the counting pulse are both valid, the difference between the target counting value and the first counting result is increased by one to determine the second counting result;

[0070] The target count value is a count value of a previous cycle of the second clock domain generated by the count pulse.

[0071] In practical applications, there are two situations in which the second counting result is obtained by subtracting clr_cnt_sync from the current counting value of cnt_pulse. First, when clr_en_syn and cnt_pulse are valid at the same time, the new pulse_cnt = old pulse_cnt-clr_en_syn+1. Among them, the new pulse_cnt is the second counting result, and the old pulse_cnt (target counting value) is the pulse_cnt value of the previous clk2 cycle.

[0072] In addition, since the methods for determining the second counting result are not the same, the embodiment of the present application can illustrate a possible determination method.

[0073] In one case, when the first counting result is valid, determining the second counting result based on the difference between the current counting value of the clock cycle to be measured and the first counting result includes:

[0074] When the first counting result and the counting pulse are not valid at the same time, determining the difference between the target counting value and the first counting result as the second counting result;

[0075] The target count value is a count value of a previous cycle of the second clock domain generated by the count pulse.

[0076] In practical applications, there are two situations in which the current count value of cnt_pulse is subtracted from clr_cnt_sync to obtain the second count result. Second, when clr_en_syn and cnt_pulse are not valid at the same time, the new pulse_cnt = old pulse_cnt-clr_en_syn. Among them, the new pulse_cnt is the second count result, and the old pulse_cnt (target count value) is the pulse_cnt value of the previous clk2 cycle.

[0077] S203: Send the second counting result to the clear read register, so that the clear read register receives and stores the second counting result.

[0078] In practical applications, the pulse-driven counter calculates based on the first counting result and obtains the second counting result. Since the cross-clock domain signal cannot be directly used, otherwise information errors will be caused due to metastable phenomena, or information loss will occur due to the relationship between different frequencies. Therefore, the embodiment of the present application introduces a Gray code mode cross-clock domain module, one end of which is connected to the read-clear register and the other end is connected to the pulse-driven counter. The second counting result is sent to the read-clear register by the Gray code mode, and the read-clear register receives and stores the second counting result.

[0079] In summary, an embodiment of the present application provides a cross-clock domain pulse counting method that supports clear reading and is applied to a pulse-driven counter, and first receives a first counting result sent by a clear reading register. Among them, the first counting result is the count of the clock cycle to be measured stored in the clear reading register when the clear reading register receives a register access signal. Then the second counting result is determined based on the first counting result. Finally, the second counting result is sent to the clear reading register, so that the clear reading register receives and stores the second counting result. In this way, the problem of pulse loss that is prone to occur in cross-clock domain pulse counting is avoided, and the pulse-driven counter can realize the clear reading function based on the response data, thereby improving the accuracy of pulse counting.

[0080] Figure 3 A flowchart of a method for counting pulses across clock domains that supports clear reading and is applied to a clear reading register provided in an embodiment of the present application. Figure 3 As shown, when the method is applied to read a register, the method may include:

[0081] S301: Receive and store a first counting result sent by a pulse driving counter.

[0082] In practical applications, in combination with the above, the clock domain accessed by the read-clear register is recorded as clk1 (first clock domain), and the clock domain generated by the counting pulse (cnt_pulse) is recorded as clk2 (second clock domain). The pulse-driven counter is set in clk2, which is used to count cnt_pulse, obtain the number of clock cycles (pulse_cnt) and send pulse_cnt in real time to the read-clear register placed in clk1 for storage. Since the signal transmission across clock domains will cause metastable phenomena, the gray code mode cross-clock domain module is introduced to transmit pulse_cnt in clk1 as storage data (rd_cnt_sync). It can be understood that in the process of the pulse-driven counter transmitting the counting result to the read-clear register, due to the delay that may exist across the clock domain, the actual count value of the pulse-driven counter at a certain moment may be different from the count value stored in the read-clear register, that is, the values ​​of pulse_cnt and rd_cnt_sync at a certain moment are different. Specifically, the pulse_cnt sent by the pulse-driven counter before the host sends the register access signal (rd_en) to the read-clear register through the register access bus can be the first counting result. In this way, when the impulse driving counter sends the first counting result, the read clear register receives and stores the first counting result.

[0083] In addition, since the methods for receiving the first counting result are different, the embodiment of the present application can illustrate a possible receiving method.

[0084] In one case, S301: receiving and storing a first counting result sent by a pulse driving counter, comprises:

[0085] receiving a first counting result sent by a pulse-driven counter in a Gray code manner;

[0086] The first counting result is stored.

[0087] In practical applications, before the host sends rd_en to the clear read register through the register access bus, the pulse drive counter calculates the number of clock cycles pulse_cnt of the cnt_pulse input and sends it to the clear read register for storage as the first counting result. Since the cross-clock domain signal cannot be used directly, otherwise information errors will be caused due to metastable phenomena, or information loss will occur due to the relationship between different frequencies. Therefore, the embodiment of the present application introduces a Gray code method, in which one end of the cross-clock domain module is connected to the clear read register and the other end is connected to the pulse drive counter. The clear read register receives the first counting result sent by the pulse drive counter in a Gray code manner, and stores the first counting result.

[0088] S302: In response to a register access signal, sending the first counting result to the pulse drive counter, so that the pulse drive counter calculates a second counting result based on the first counting result.

[0089] In actual applications, in order to realize the clear read function, the clear read register needs to return the response data (clr_cnt and clr_en) corresponding to the rd_cnt_sync at that moment to the handshake mode cross-clock domain module when receiving the rd_en sent by the host to the clear read register through the register access bus. The corresponding transmission of the cross-clock domain in clk2 is (clr_cnt_sync and clr_en_sync). It should be noted that the values ​​of rd_cnt_sync, response data clr_cnt and clr_cnt_sync to be transmitted at this moment should all be the first counting result. Then the pulse-driven counter receives the first counter and determines the second counting result by calculation.

[0090] S303: Receive and store the second counting result sent by the pulse driving counter.

[0091] In practical applications, the pulse drive counter calculates the second calculation result based on the first calculation result. It is understandable that, in order to realize the clear read function, the second calculation result should be obtained by subtracting clr_cnt_sync from the current count value when clr_en_sync is valid. In this way, the pulse drive counter sends the second calculation result to the clear read register, and the clear read register receives and stores the second count result sent by the pulse drive counter.

[0092] In addition, since the methods for receiving the second counting result are not the same, the embodiment of the present application can illustrate a possible receiving method.

[0093] In one case, S103: receiving and storing the second counting result sent by the pulse driving counter may include:

[0094] The first counting result is sent to the pulse driving counter based on a handshake manner.

[0095] In practical applications, in order to realize the clear reading function, it is necessary to send the count value of the clock cycle to be measured stored at that moment to the pulse drive counter when the clear reading register receives the register access signal, that is, send the first count result to the pulse drive counter. Since the cross-clock domain signal cannot be used directly, otherwise information errors will be caused due to the metastable phenomenon, or information loss will occur due to the relationship between different frequencies. Therefore, the embodiment of the present application introduces a handshake mode cross-clock domain module, one end of which is connected to the clear reading register, and the other end is connected to the pulse drive counter. The first count result is sent to the pulse drive counter by handshake, and the pulse drive counter receives and calculates the second count result through the first count result.

[0096] In addition, since the responses to register access signals are not the same, the embodiments of the present application can be described in terms of a possible response method.

[0097] In one embodiment, the method further comprises:

[0098] In response to the register access signal, the first counting result is fed back to the host through a register access bus.

[0099] In practical applications, the pulse driving counter calculates the number of cycles of cnt_pulse pulse_cnt, and the clear read register receives and stores the rd_cnt_sync corresponding to pulse_cnt through the Gray code cross-clock domain module. When the host sends a register access signal to the clear read register through the register access bus, the clear read register needs to feed back the rd_cnt_sync stored at that moment as the first calculation result through the register access bus to the host.

[0100] In summary, the embodiment of the present application provides a method for cross-clock domain pulse counting that supports clear reading and is applied to a clear reading register. First, a first counting result sent by a pulse-driven counter is received and stored. Then, in response to a register access signal, the first counting result is sent to the pulse-driven counter, so that the pulse-driven counter calculates a second counting result based on the first counting result. Finally, the second counting result sent by the pulse-driven counter is received and stored. In this way, the problem of pulse loss that is prone to occur in cross-clock domain pulse counting is avoided, and the pulse-driven counter can realize the clear reading function based on the response data, thereby improving the accuracy of pulse counting.

[0101] Figure 4 A flow chart of a pulse-driven counter and a clear read register interaction cross-clock domain pulse counting method supporting clear read provided in an embodiment of the present application. Figure 4 As shown, when the method is applied to the interaction between the read register and the pulse drive counter, it may include:

[0102] S401: A pulse driving counter counts the clock cycle to be measured, and sends a first counting result obtained by counting to a clear read register for storage in a Gray code manner.

[0103] In practical applications, in combination with the above, the clock domain accessed by the clear read register is recorded as clk1 (first clock domain), and the clock domain generated by the counting pulse (cnt_pulse) is recorded as clk2 (second clock domain). The pulse-driven counter is set in clk2, which is used to count cnt_pulse, obtain the number of clock cycles (pulse_cnt) and send pulse_cnt in real time to the clear read register placed in clk1 for storage. Since the transmission of signals across clock domains can cause metastable phenomena, a Gray code-based cross-clock domain module is introduced to transmit pulse_cnt in clk1 as storage data (rd_cnt_sync). Specifically, the pulse-driven counter first counts the clock cycle to be measured, and sends the first counting result obtained by counting to the clear read register for storage through the Gray code method.

[0104] S402: When the clear read register receives a register access signal, the first counting result is fed back through a register access bus, and the first counting result is sent to the pulse drive counter in a handshake manner.

[0105] In actual applications, the host reads information from the clear read register through the register access bus. When the clear read register receives the register access signal (rd_en), the first count result (rd_cnt_sync stored in the clear read register at this time) is fed back to the host as rd_data through the register access bus. And the response data (clr_cnt and clr_en) corresponding to the first count result is sent to the pulse drive counter through handshake. It should be noted that in order to ensure the realization of the clear read function, the rd_data fed back to the host by the clear read register should be consistent with the clr_cnt sent to the pulse drive counter.

[0106] S403: The pulse driving counter calculates a second counting result based on the first counting result, and sends the second counting result to the clear read register in a Gray code manner for storage.

[0107] In actual application, the pulse driving counter counts the number of clock cycles pulse_cnt that the cnt_pulse input lasts. When clr_en_sync is valid, the clr_cnt_sync (first count result) stored when the read clear register receives the register access signal is subtracted from the current count value to obtain the second count result. The calculated second count result is then sent to the read clear register across the clock domain module in a Gray code manner for storage.

[0108] In summary, Figure 5 A waveform diagram provided in an embodiment of the present application. Figure 5 As shown, clk1 is the clock domain where the clear read register is located, rd_en is the data output by the bus initiator to the clear read register, rd_cnt_sync is the data stored in the clear read register, rd_data is the data returned by the clear read register, and clr_en is used to indicate whether its count value is valid. In the actual implementation, rd_data can be in the same cycle as rd_en or delayed by any cycle due to timing requirements, which is not limited in this solution; what needs to be limited is that clr_cnt must be consistent with the data rd_data returned to the host, which is the key to the implementation of the clear read function.

[0109] In summary, the embodiment of the present application provides a cross-clock domain pulse counting method that supports clear reading in which a pulse-driven counter and a clear reading register interact. First, the pulse-driven counter counts the clock cycle to be measured, and sends the first counting result obtained by counting to the clear reading register for storage in a Gray code manner. When the clear reading register receives a register access signal, the first counting result is fed back through the register access bus, and the first counting result is sent to the pulse-driven counter through a handshake. The pulse-driven counter calculates the second counting result based on the first counting result, and sends the second counting result to the clear reading register for storage in a Gray code manner. In this way, the problem of pulse loss that is prone to occur in cross-clock domain pulse counting is avoided, and the pulse-driven counter can realize the clear reading function based on the response data, thereby improving the accuracy of pulse counting.

[0110] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be 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 application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A cross-clock domain pulse counting device supporting clear reading, characterized in that: include: Read registers, handshake mode cross-clock domain modules, pulse drive counters, and Gray code mode cross-clock domain modules; The read clear register is placed in the first clock domain, and one end is connected to the register access bus, and the other end is connected to the pulse drive counter through the handshake mode cross-clock domain module; The handshake mode cross-clock domain module is used to transfer the response data generated by the read register to the pulse drive counter; The response data is consistent with the data returned by the read-clear register to the host through the register access bus; The pulse drive counter is placed in the second clock domain and connected to the clear read register via the Gray code cross-clock domain module; The Gray code mode clock domain crossing module is used to transfer the counting result of the pulse driving counter to the clear read register.

2. A method for counting pulses across clock domains that supports clear reading, characterized in that: Applied to the pulse driven counter according to claim 1, the method comprises: receiving a first counting result sent by a clear read register; the first counting result being a count value of a clock cycle to be measured stored in the clear read register when the clear read register receives a register access signal; determining a second counting result based on the first counting result; The second counting result is sent to the clear read register, so that the clear read register receives and stores the second counting result.

3. The method according to claim 2, characterized in that The determining a second counting result based on the first counting result includes: When the first counting result is valid, a second counting result is determined based on a difference between a current counting value of the clock cycle to be measured and the first counting result.

4. The method according to claim 3, characterized in that When the first counting result is valid, determining a second counting result based on a difference between a current counting value of the clock cycle to be measured and the first counting result comprises: When the first counting result and the counting pulse are both valid, the difference between the target counting value and the first counting result is increased by one to determine the second counting result; The target count value is a count value of a previous cycle of the second clock domain generated by the count pulse.

5. The method according to claim 3, characterized in that: When the first counting result is valid, determining a second counting result based on a difference between a current counting value of the clock cycle to be measured and the first counting result comprises: When the first counting result and the counting pulse are not valid at the same time, determining the difference between the target counting value and the first counting result as the second counting result; The target count value is a count value of a previous cycle of the second clock domain generated by the count pulse.

6. A method for counting pulses across clock domains that supports clear reading, characterized in that: Applied to the clear read register of claim 1, the method comprises: receiving and storing a first counting result sent by a pulse driving counter; In response to a register access signal, sending the first counting result to the pulse drive counter, so that the pulse drive counter calculates a second counting result based on the first counting result; The second counting result sent by the pulse driving counter is received and stored.

7. The method according to claim 6, characterized in that The receiving and storing the first counting result sent by the pulse driving counter comprises: receiving a first counting result sent by a pulse-driven counter in a Gray code manner; The first counting result is stored.

8. The method according to claim 6, characterized in that The sending the first counting result to the pulse driving counter comprises: The first counting result is sent to the pulse driving counter based on a handshake manner.

9. The method according to claim 6, characterized in that The method further comprises: In response to the register access signal, the first counting result is fed back to the host through a register access bus.

10. A method for counting pulses across clock domains that supports clear reading, characterized in that: Applied to the interaction between the clear read register and the pulse drive counter as claimed in claim 1, the method comprises: The pulse driving counter counts the clock cycle to be measured, and sends the first counting result obtained by counting to the clear read register for storage in a Gray code manner; When the read clear register receives the register access signal, the first counting result is fed back through the register access bus, and the first counting result is sent to the pulse drive counter in a handshake manner; The pulse driven counter calculates a second counting result based on the first counting result, and sends the second counting result to the read clear register for storage in a Gray code manner.