Zero firewire reverse connection detection method, device, mcu and storage medium
By configuring the MCU's detection I/O port to AD mode, and reading and updating the count value of the AD sampled value, the false detection problem of reverse connection detection of neutral and live wires is solved, and accurate neutral and live wire detection is achieved.
Patent Information
- Application Number
- CN202310323844.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-29
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2043-03-29
AI Technical Summary
Existing methods for detecting reverse polarity of live and neutral wires are prone to false positives due to differences in components and installation environments, and cannot guarantee the accuracy of the test results.
By configuring the MCU's detection I/O port to AD mode, the AD sampled value is read, the first and second count values are updated, and the live/neutral wire detection result is generated based on the count value, ensuring the accuracy of the detection.
It improves the accuracy of detecting reverse connection of live and neutral wires, avoids false detections, and reduces the cost and risk of modifying hardware circuits.
Smart Images

Figure CN116256667B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of circuit testing technology, and more specifically, to a method, apparatus, MCU, and storage medium for detecting reverse connection of live and neutral wires. Background Technology
[0002] The popularization and development of smart meters are becoming increasingly rapid. Due to differences in installation environment and region, in order to protect the rights and interests of power companies, power companies are also raising their requirements for the anti-theft of smart meters, such as bypass detection and neutral-live wire reverse connection detection.
[0003] The existing method for detecting reversed neutral and live wire connections uses an MCU (Microcontroller Unit) to determine whether the connection is reversed by reading high and low level signals output by the hardware circuit through the I / O port. Ideally, a periodic high and low level signal output by the hardware circuit indicates a normal connection, while a stable low level signal indicates a reversed connection. However, due to differences in components and the installation environment of the electricity meter, even with normal wiring, the hardware circuit may output a low level signal, leading to incorrect detection results. Summary of the Invention
[0004] To ensure the accuracy of the neutral-live wire reverse connection detection results and avoid false detections, this invention provides a method, device, MCU, and storage medium for detecting neutral-live wire reverse connection.
[0005] The technical solution of this invention can be implemented as follows:
[0006] In a first aspect, embodiments of the present invention provide a method for detecting reverse connection of live and neutral wires, applied to an MCU, wherein a detection I / O port on the MCU is connected to a hardware circuit to be detected, the detection I / O port is configured in AD mode, and the method includes:
[0007] Read the AD sampling value of the detection I / O port, where the AD sampling value represents the voltage signal of the hardware circuit under test;
[0008] Based on the AD sampled values, update the first count value and the second count value, where the first count value represents the number of high-level signals and the second count value represents the number of times the AD sampled values are read;
[0009] Based on the first count value and the second count value, a neutral and live wire detection result is generated for the hardware circuit under test, so as to determine whether the neutral and live wires of the hardware circuit under test are reversed.
[0010] Optionally, the step of updating the first count value and the second count value based on the AD sampled value includes:
[0011] If the AD sampled value is not less than a preset threshold, then both the first count value and the second count value are incremented.
[0012] If the AD sample value is less than the preset threshold, then the second count value is incremented.
[0013] Optionally, the step of generating a live / neutral wire detection result for the hardware circuit under test based on the first count value and the second count value includes:
[0014] If the second count value is equal to the first preset count threshold, then determine whether the first count value is less than the second preset count threshold;
[0015] If the first count value is not less than the second preset count threshold, then the detection result of the live and neutral wires of the hardware circuit to be tested is determined to be that the live and neutral wires are connected in the correct direction.
[0016] If the first count value is less than the second preset count threshold, then the detection result of the live and neutral wires of the hardware circuit to be tested is determined to be reversed.
[0017] Optionally, the step of generating the live / neutral wire detection result for the hardware circuit under test based on the first count value and the second count value further includes:
[0018] If the second count value is less than the first preset count threshold, then after a preset time interval, return to the step of reading the AD sampling value of the detection IO port, until the second count value is equal to the first preset count threshold, so as to obtain the live and neutral wire detection result for the hardware circuit under test.
[0019] Optionally, the method further includes:
[0020] After obtaining the detection results of the live and neutral wires for the hardware circuit under test, the first count value and the second count value are cleared to continue the detection of the live and neutral wires reversal for the hardware circuit under test.
[0021] Optionally, the step of clearing the first count value and the second count value includes:
[0022] Reconfigure the detection I / O port to AD mode to clear the first count value and the second count value.
[0023] Secondly, embodiments of the present invention provide a neutral / live wire reverse connection detection device, applied to an MCU, wherein the detection I / O port on the MCU is connected to the hardware circuit to be tested, the detection I / O port is configured in AD mode, and the device includes:
[0024] A reading module is used to read the AD sampling value of the detection I / O port, wherein the AD sampling value represents the voltage signal of the hardware circuit under test;
[0025] The update module is used to update a first count value and a second count value according to the AD sample value, wherein the first count value represents the number of high-level signals and the second count value represents the number of times the AD sample value is read;
[0026] The generation module is used to generate a neutral and live wire detection result for the hardware circuit under test based on the first count value and the second count value, so as to determine whether the neutral and live wires of the hardware circuit under test are reversed based on the neutral and live wire detection result.
[0027] Optionally, the update module is specifically used for:
[0028] If the AD sample value is greater than the preset threshold, then both the first count value and the second count value are incremented.
[0029] If the AD sample value is not greater than the preset threshold, then the second count value is incremented.
[0030] Thirdly, embodiments of the present invention provide an MCU that has a computer program programmed into it, and when the computer program is executed, it implements the neutral-live wire reverse connection detection method as described in the first aspect above.
[0031] Fourthly, the present invention provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the reverse connection detection method for live and neutral wires as described in the first aspect above.
[0032] Compared to existing technologies, the neutral-live wire reverse connection detection method provided in this embodiment of the invention reads the AD sampling value of the detection I / O port. The AD sampling value represents the voltage signal of the hardware circuit under test. Based on the AD sampling value, a first count value and a second count value are updated. The first count value represents the number of high-level signals, and the second count value represents the number of times the AD sampling value is read. Based on the first count value and the second count value, a neutral-live wire detection result for the hardware circuit under test is generated to determine whether the neutral and live wires of the hardware circuit under test are reversed. Because this embodiment of the invention configures the detection I / O port to AD mode, updates the first count value representing the number of high-level signals and the second count value representing the number of times the AD sampling value is read based on the read AD sampling value, and then determines whether the neutral and live wires of the hardware circuit under test are reversed based on the first count value and the second count value, the correctness of the neutral-live wire reverse connection detection result is ensured, and false detections are avoided. Attached Figure Description
[0033] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0034] Figure 1 This is an application scenario diagram of a method for detecting reverse connection of live and neutral wires provided in an embodiment of the present invention;
[0035] Figure 2 A flowchart illustrating a method for detecting reverse connection of live and neutral wires provided in an embodiment of the present invention. Figure 1 ;
[0036] Figure 3 A flowchart illustrating a method for detecting reverse connection of live and neutral wires provided in an embodiment of the present invention. Figure 2 ;
[0037] Figure 4 A flowchart illustrating a method for detecting reverse connection of live and neutral wires provided in an embodiment of the present invention. Figure 3 ;
[0038] Figure 5 This is a functional unit block diagram of a neutral / live wire reverse connection detection device provided in an embodiment of the present invention.
[0039] Icons: 100 - Reverse connection detection device for live and neutral wires; 101 - Reading module; 102 - Update module; 103 - Generation module. Detailed Implementation
[0040] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0041] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0042] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0043] In the description of this invention, it should be noted that if terms such as "upper," "lower," "inner," or "outer" are used to indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, or the orientation or positional relationship in which the product of this invention is usually placed, they are only for the convenience of describing this invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this invention.
[0044] Furthermore, the terms "first" and "second" are used only to distinguish descriptions and should not be interpreted as indicating or implying relative importance.
[0045] It should be noted that, where there is no conflict, the features in the embodiments of the present invention can be combined with each other.
[0046] Currently, the common approach to improving the accuracy of reverse connection results for live and neutral wires is to modify the structure of the hardware circuit. This means that more costs are required, and modifying the hardware circuit also carries the risk of rework.
[0047] Therefore, this invention provides a method for detecting reverse connection of live and neutral wires, which can accurately detect reverse connection of live and neutral wires without changing the hardware circuit. This will be described in detail below.
[0048] like Figure 1 As shown, the MCU's detection I / O port is connected to the hardware circuit under test. MCU, also known as Single Chip Microcomputer or microcontroller, is a chip-level computer that appropriately reduces the frequency and specifications of the Central Processing Unit (CPU) and integrates peripheral interfaces such as memory, timer, USB, A / D conversion, UART, PLC, DMA, and even LCD driver circuits onto a single chip.
[0049] The reverse connection detection method for live and neutral wires provided in this embodiment of the invention is applied to... Figure 1 For the MCU in the text, please refer to... Figure 2 The method includes steps S101 to S103.
[0050] S101, read the AD sampling value of the detection IO port.
[0051] The AD sampling value represents the voltage signal of the hardware circuit under test.
[0052] In this embodiment of the invention, the MCU's detection I / O port is configured in AD mode. The AD sampled value can be converted to obtain the actual voltage of the hardware circuit under test. The conversion formula is as follows:
[0053]
[0054] In the formula, Vad is the actual voltage; Vcc is the input voltage of the MCU; and Dad is the AD sampling value.
[0055] S102, Update the first count value and the second count value according to the AD sample value.
[0056] The first count value represents the number of high-level signals, and the second count value represents the number of times the AD sample value is read.
[0057] In this embodiment of the invention, a first count value can be obtained using a counter CNT_HIGH, and a second count value can be obtained using a counter CNT.
[0058] As one possible implementation, please refer to Figure 3 Step S102 may include sub-steps S102-1 to S102-2.
[0059] S102-1, If the AD sample value is not less than the preset threshold, then both the first count value and the second count value are incremented.
[0060] The preset threshold can be set according to actual needs. For example, the preset threshold can be set to 1.000V.
[0061] Understandably, when the voltage signal represented by the AD sampling value is not less than 1.000V, it indicates that the hardware circuit under test is currently outputting a high-level signal. The first count value is incremented by incrementing the counter CNT_HIGH by 1. The second count value is incremented by incrementing the counter GNT by 1.
[0062] S102-2, If the AD sample value is less than the preset threshold, then the second count value is incremented.
[0063] Understandably, when the voltage signal represented by the AD sampling value is less than 1.000V, it means that the hardware circuit under test is outputting a low-level signal at the current moment. Since the first count value represents the number of times a high-level signal is acquired, the counter GNT does not increment by 1, and the first count value remains unchanged. However, by incrementing the counter GNT by 1, the second count value is automatically incremented.
[0064] S103, based on the first count value and the second count value, generate a neutral and live wire detection result for the hardware circuit under test, so as to know whether the neutral and live wires of the hardware circuit under test are reversed based on the neutral and live wire detection result.
[0065] The test results for the neutral and live wires may show that the neutral and live wires are connected correctly or incorrectly.
[0066] As one possible implementation, please refer to Figure 4 Step S103 includes sub-steps S103-1 to S103-3.
[0067] S103-1, If the second count value is equal to the first preset count threshold, then determine whether the first count value is less than the second preset count threshold.
[0068] The first preset counting threshold and the second preset counting threshold can be set as needed. For example, the first preset counting threshold can be 1600 and the second preset counting threshold can be 50.
[0069] Understandably, when 1600 AD sampling values are read, the system determines whether the live and neutral wires of the hardware circuit under test are connected in the correct direction or in reverse, based on whether the number of times the "voltage signal represented by the AD sampling value is greater than 1.000V" reaches 50.
[0070] In this embodiment of the invention, when the first count value is not less than the second preset count threshold, step S103-2 is executed; when the first count value is less than the second preset count threshold, step S103-3 is executed.
[0071] S103-2, determine that the detection result of the neutral and live wires for the hardware circuit under test is that the neutral and live wires are connected in the correct order.
[0072] For example, assuming the first preset counting threshold is 1600, the second preset counting threshold is 50, and the first count value is 56, since the first count value is not less than the second preset counting threshold, it means that among the 1600 AD sample values read, at least 50 AD sample values represent voltage signals that are not less than the set voltage threshold, which are high-level signals. Based on this, it is determined that the neutral and live wires of the hardware circuit under test are properly connected, and the neutral and live wire detection result is that the neutral and live wires are connected correctly.
[0073] S103-3, the result of the detection of the neutral and live wires for the hardware circuit under test is determined to be that the neutral and live wires are reversed.
[0074] For example, assuming the first preset counting threshold is 1600, the second preset counting threshold is 50, and the first count value is 33, since the first count value is less than the second preset counting threshold, it means that among the 1600 AD sample values read, less than 50 AD sample values represent voltage signals that are not less than the set voltage threshold, which are high-level signals. Based on this, it is determined that the neutral and live wires of the hardware circuit under test are abnormally connected, and the neutral and live wire detection result is that the neutral and live wires are reversed.
[0075] Please refer to this again. Figure 4 The method for detecting reverse connection of live and neutral wires also includes steps S103-4.
[0076] S103-4, if the second count value is less than the first preset count threshold, then after a preset time interval, return to the step of reading the AD sampling value of the detection IO port until the second count value is equal to the first preset count threshold, so as to obtain the live and neutral wire detection result for the hardware circuit under test.
[0077] The preset time interval can be set according to actual needs. For example, the preset time interval can be set to 5ms, that is, the AD sampling value is read once every 5ms.
[0078] Assuming the first preset counting threshold is 1600, it is understandable that the MCU outputs a live / zero wire detection result every time it completes 1600 AD sampling value readings. Since the time interval between two AD sampling value readings is 5ms, it means that a live / zero wire detection result is output every 1600 * 5ms = 8s.
[0079] Therefore, if the current AD sampling value reading count has not reached 1600, after updating the first and second count values according to the AD sampling value, the process directly returns to step S101 until the second count value increments to 1600. Then, steps S103-1 to S103-3 are executed to obtain the zero-live wire detection result.
[0080] In this embodiment of the invention, a timer can be used to control the time for reading AD sample values, that is, the timer is determined to read AD sample values by judging whether the timer has reached 5ms.
[0081] The above technical solution describes the implementation process of a single output of live / neutral wire detection results. Since the hardware circuit under test needs to be continuously tested, the live / neutral wire reverse connection detection solution also includes the following:
[0082] After obtaining the neutral and live wire test results for the hardware circuit under test, the first and second count values are cleared to continue the neutral and live wire reverse connection test for the hardware circuit under test.
[0083] The implementation method for "clearing the first and second count values" can be "reconfiguring the detection I / O port to AD mode".
[0084] The following is an example illustrating the steps involved in the above-mentioned method for detecting reverse connection of live and neutral wires.
[0085] Step 1: Configure the detection I / O port to AD mode;
[0086] Step 2: Determine whether the timer T has reached the time interval T_MAX (e.g., 5ms). If it has not been reached, proceed to step 2; if it has been reached, proceed to step 3.
[0087] Step 3: Read the AD sampling value of the detection IO port. If the voltage signal represented by the sampling value is greater than the voltage threshold V_MIN (e.g., 1.000V), increment the high-level signal counter CNT_HIGH by 1 and execute step 4.
[0088] Step 4: Determine whether the counter CNT has reached the counting threshold C_MAX (e.g., 1600). If not, increment CNT by 1 and return to step 2. If it has reached the threshold, proceed to step 5.
[0089] Step 5: Determine whether CNT_HIGH has reached the counting threshold C_HIGH_MAX (e.g., 50). If it has, the detection result is determined to be a normal connection of the live and neutral wires. If it has not, the detection result is determined to be a reverse connection of the live and neutral wires. After outputting the detection result, return to step 1.
[0090] In order to perform the corresponding steps in the above method embodiments and various possible implementations, an implementation of the neutral-live wire reverse connection detection device 100 is given below.
[0091] Please refer to Figure 5 The neutral and live wire reverse connection detection device 100 includes a reading module 101, an updating module 102, and a generating module 103.
[0092] The reading module 101 is used to read the AD sampling value of the detection IO port. The AD sampling value represents the voltage signal of the hardware circuit under test.
[0093] The update module 102 is used to update a first count value and a second count value according to the AD sample value. The first count value represents the number of high-level signals, and the second count value represents the number of times the AD sample value is read.
[0094] The generation module 103 is used to generate a neutral and live wire detection result for the hardware circuit under test based on the first count value and the second count value, so as to know whether the neutral and live wires of the hardware circuit under test are reversed based on the neutral and live wire detection result.
[0095] Optionally, if the AD sample value is not less than a preset threshold, the update module 102 increments both the first and second count values; if the AD sample value is less than the preset threshold, the second count value increments.
[0096] Optionally, the generation module 103 is specifically used to determine whether the first count value is less than the second preset count threshold if the second count value is equal to the first preset count threshold; if the first count value is not less than the second preset count threshold, determine that the detection result of the neutral and live wires for the hardware circuit to be tested is that the neutral and live wires are connected in the correct direction; if the first count value is less than the second preset count threshold, determine that the detection result of the neutral and live wires for the hardware circuit to be tested is that the neutral and live wires are connected in reverse direction.
[0097] Optionally, the generation module 103 is further configured to, if the second count value is less than the first preset count threshold, return to the step of reading the AD sampling value of the detection IO port after a preset time interval, until the second count value is equal to the first preset count threshold, so as to obtain the live and neutral wire detection result for the hardware circuit to be tested.
[0098] Optionally, the generation module 103 is further configured to clear the first count value and the second count value to zero after obtaining the neutral and live wire detection results for the hardware circuit under test, so as to continue to perform neutral and live wire reverse connection detection on the hardware circuit under test.
[0099] Optionally, the generation module 103 is also specifically used to reconfigure the detection I / O port to AD mode in order to clear the first count value and the second count value.
[0100] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the neutral-live wire reverse connection detection device 100 described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0101] This invention also provides an MCU with a computer program programmed into it. When the computer program is executed, it can be used to perform the relevant operations in the live / zero wire detection method provided in the above-described method embodiments.
[0102] This invention also provides a computer-readable storage medium containing a computer program, which, when executed, can be used to perform related operations in the live wire detection method provided in the above-described method embodiments.
[0103] In summary, the neutral and live wire reverse connection detection method, device, MCU, and storage medium provided in this embodiment of the invention configure the detection I / O port to AD mode, update a first count value representing the number of high-level signals and a second count value representing the number of times the AD sample value is read based on the read AD sample value, and then determine whether the neutral and live wires of the hardware circuit under test are reversed based on the first count value and the second count value, thereby ensuring the correctness of the neutral and live wire reverse connection detection result and avoiding false detection.
[0104] The above are merely specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for detecting reverse connection of live and neutral wires, characterized in that, Applied to an MCU, the method involves connecting a detection I / O port on the MCU to a hardware circuit under test, wherein the detection I / O port is configured in AD mode, and the method includes: Read the AD sampling value of the detection I / O port, where the AD sampling value represents the voltage signal of the hardware circuit under test; Based on the AD sampled values, update the first count value and the second count value, where the first count value represents the number of high-level signals and the second count value represents the number of times the AD sampled values are read; If the second count value is equal to the first preset count threshold, then determine whether the first count value is less than the second preset count threshold; If the first count value is not less than the second preset count threshold, then the detection result of the live and neutral wires of the hardware circuit to be tested is determined to be that the live and neutral wires are connected in the correct direction. If the first count value is less than the second preset count threshold, then the detection result of the live and neutral wires of the hardware circuit to be tested is determined to be reversed.
2. The method as described in claim 1, characterized in that, The step of updating the first count value and the second count value based on the AD sample value includes: If the AD sampled value is not less than a preset threshold, then both the first count value and the second count value are incremented. If the AD sample value is less than the preset threshold, then the second count value is incremented.
3. The method as described in claim 1, characterized in that, The method further includes: If the second count value is less than the first preset count threshold, then after a preset time interval, return to the step of reading the AD sampling value of the detection IO port, until the second count value is equal to the first preset count threshold, so as to obtain the live and neutral wire detection result for the hardware circuit under test.
4. The method as described in claim 1 or 3, characterized in that, The method further includes: After obtaining the detection results of the live and neutral wires for the hardware circuit under test, the first count value and the second count value are cleared to continue the detection of the live and neutral wires reversal for the hardware circuit under test.
5. The method as described in claim 4, characterized in that, The step of clearing the first count value and the second count value includes: Reconfigure the detection I / O port to AD mode to clear the first count value and the second count value.
6. A device for detecting reverse connection of live and neutral wires, characterized in that, Applied to an MCU, the device, wherein a detection I / O port on the MCU is connected to a hardware circuit under test, the detection I / O port is configured in AD mode, and the device includes: A reading module is used to read the AD sampling value of the detection I / O port, wherein the AD sampling value represents the voltage signal of the hardware circuit under test; The update module is used to update a first count value and a second count value according to the AD sample value, wherein the first count value represents the number of high-level signals and the second count value represents the number of times the AD sample value is read; The generation module is configured to determine whether the first count value is less than a second preset count threshold if the second count value is equal to a first preset count threshold; if the first count value is not less than the second preset count threshold, determine that the detection result of the neutral and live wires of the hardware circuit under test is that the neutral and live wires are connected in the correct direction; if the first count value is less than the second preset count threshold, determine that the detection result of the neutral and live wires of the hardware circuit under test is that the neutral and live wires are connected in reverse direction.
7. The apparatus as claimed in claim 6, characterized in that, The update module is specifically used for: If the AD sample value is greater than the preset threshold, then both the first count value and the second count value are incremented. If the AD sample value is not greater than the preset threshold, then the second count value is incremented.
8. An MCU, characterized in that, It contains a computer program, which, when executed, implements the method for detecting reverse connection of live and neutral wires as described in any one of claims 1 to 5.
9. A computer-readable storage medium, characterized in that, It stores a computer program, which, when executed by a processor, implements the method for detecting reverse connection of live and neutral wires as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Ground wire zero line anomaly detection method, device and system and readable storage medium
CN111580019A
Null line and live line reverse connection detection device and electric energy meter
CN217467134U