Signal detection method and device of optocoupler switch and electronic equipment
By acquiring the input state of the optocoupler switch and performing state transition processing, combined with coded state table matching, the problem of oscillation interference in optocoupler switch signal detection is solved, and the effect of accurately determining the rotation direction and number of rotations is achieved.
Patent Information
- Application Number
- CN202311383713.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-24
- Publication Date
- 2026-01-27
- Estimated Expiration
- 2043-10-24
AI Technical Summary
In existing technologies, oscillation interference exists during the signal detection process of optocoupler switches, which reduces the accuracy of signal detection.
By acquiring the input states of the first and second output ports of the optocoupler switch, representing them with two binary digits, and obtaining intermediate and detection states through polling and state transition processing, the rotation state and direction of the optocoupler switch are determined by matching them with a preset encoded state table.
It improves the accuracy of optocoupler switch signal detection, reduces the impact of oscillation interference, and can accurately determine the rotation direction and number of rotations.
Smart Images

Figure CN117491858B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of automotive technology, specifically to a signal detection method, device, and electronic device for an optocoupler switch. Background Technology
[0002] In related technologies, interrupt methods are commonly used to detect the signal of optocouplers. One output of the optocoupler is connected to a GPIO pin of a microcontroller that supports interrupt functionality, and the other output is connected to a regular GPIO pin of the microcontroller. The GPIO pin connected to the interrupt functionality is configured to operate in interrupt mode, and the interrupt trigger condition is configured to level trigger. When the optocoupler is rotated, an interrupt is triggered. According to the configured trigger condition, the interrupt handler checks the level of the regular GPIO pin; a low level indicates clockwise rotation, and a high level indicates counterclockwise rotation. However, in the process of using the interrupt method to detect the signal of the optocoupler, there will be oscillation interference, which will reduce the accuracy of the signal detection.
[0003] Therefore, there is an urgent need for a signal detection method, device, and electronic equipment for optocouplers to solve the problem that oscillation interference reduces the accuracy of signal detection in optocouplers. Summary of the Invention
[0004] This application provides a signal detection method, apparatus, and electronic device for optocoupler switches, which can improve the accuracy of signal detection for optocoupler switches.
[0005] In a first aspect, embodiments of this application provide a signal detection method for an optocoupler switch, the method comprising:
[0006] Obtain the first input state of the first output port and the second output port of the optocoupler switch, wherein the first input state is represented by a two-bit binary number;
[0007] Poll the first output port and the second output port. When the first input state changes, obtain the second input state of the first output port and the second output port. Shift the first input state two bits to the high bit and supplement the low bit of the first input state with the second input state to obtain the intermediate state.
[0008] When the second input state changes state, the third input state of the first output port and the second output port is obtained, the intermediate state is shifted two bits to the high bit, and the third input state is added to the low bit of the intermediate state to obtain the detection state;
[0009] Based on the detection status, determine the rotation state of the optocoupler switch;
[0010] When the rotation state is an effective rotation state, the rotation direction and number of rotations of the optocoupler switch are determined according to the detection state to obtain the detection result.
[0011] By adopting the above technical solution, the first input state of the first and second output ports of the optocoupler switch is obtained. The first input state is represented by a two-bit binary number, which facilitates subsequent combination and judgment. The first and second output ports are polled. When the first input state changes, the second input state of the first and second output ports is obtained. The first input state is shifted two bits to the higher bit, and the second input state is added to the lower bit of the first input state to obtain an intermediate state. When the second input state changes, the third input state of the first and second output ports is obtained. The intermediate state is shifted two bits to the higher bit, and the third input state is added to the lower bit of the intermediate state to obtain a detection state. Each state transition involves only one binary bit change, which can reduce the impact of oscillation interference on the signal detection of the optocoupler switch. Based on the detection state, the rotation state of the optocoupler switch is determined, which can verify the validity of the optocoupler switch rotation. When the rotation state is a valid rotation state, the rotation direction and number of rotations of the optocoupler switch are determined based on the detection state to obtain the detection result. This allows determination of whether the rotation direction is clockwise or counterclockwise, and also allows counting the number of rotations. The embodiments of this application can improve the accuracy of signal detection of the optocoupler switch.
[0012] In some embodiments of this application, before obtaining the first input state of the first output port and the second output port of the optocoupler switch, wherein the first input state is represented by a two-bit binary number, the method further includes:
[0013] The first input value of the first output port and the first input value of the second output port of the optocoupler switch are read using the preset GPIO interface. The first input value of the first output port and the first input value of the second output port are either high level or low level.
[0014] The first input value of the first output port and the first input value of the second output port are combined using a preset combination method to obtain the first input state of the first output port and the second output port of the optocoupler switch.
[0015] By adopting the above technical solution, the first input value of the first output port and the first input value of the second output port of the optocoupler switch are read using a preset GPIO interface; the first input value of the first output port and the first input value of the second output port are combined using a preset combination method to obtain the first input state of the first output port and the second output port of the optocoupler switch, which can obtain the current input state of the optocoupler switch and facilitate subsequent state combination.
[0016] In some embodiments of this application, shifting the first input state two bits to the higher bit and supplementing the lower bit of the first input state with the second input state to obtain an intermediate state includes:
[0017] The first input state is shifted two bits to the higher bit using a preset left shift operator;
[0018] In the lower bits of the first input state, the second input state is supplemented using a preset bitwise OR operator to obtain an intermediate state.
[0019] By adopting the above technical solution, the first input state is shifted two bits to the higher bit using a preset left shift operator; the second input state is supplemented by a preset bitwise OR operator in the lower bit of the first input state to obtain an intermediate state, which can combine the input states and facilitate further combination of subsequent states.
[0020] In some embodiments of this application, determining the rotation state of the optocoupler switch based on the detection state includes:
[0021] Obtain a preset encoding state table of the optocoupler switch, wherein the preset encoding state table includes encoding states and corresponding rotation states;
[0022] The detection state is matched with the encoding state to obtain a matching result;
[0023] If the matching result indicates a successful match, the rotation state corresponding to the detection state is obtained based on the matching result.
[0024] By adopting the above technical solution, a preset encoding state table of the optocoupler switch is obtained. The preset encoding state table includes the encoding state and the corresponding rotation state, which can understand the encoding state and its corresponding rotation state. The detection state is matched with the encoding state to obtain the matching result. When the matching result indicates that the matching is successful, the rotation state corresponding to the detection state is obtained according to the matching result, which can quickly determine the rotation state of the optocoupler switch.
[0025] In some embodiments of this application, the preset encoding state table further includes: a rotation direction corresponding to the encoding state;
[0026] When the rotation state is an effective rotation state, the rotation direction and number of rotations of the optocoupler switch are determined according to the detection state to obtain the detection result, including:
[0027] When the rotation state is a valid rotation state, the rotation direction corresponding to the detection state is obtained according to the encoding state;
[0028] When the rotation direction corresponding to the detection state is clockwise, after controlling the optocoupler switch to rotate clockwise once, the step of polling the first output port and the second output port is executed.
[0029] By adopting the above technical solution, the preset encoding state table also includes the rotation direction corresponding to the encoding state, so that the encoding state and its corresponding rotation direction can be understood; when the rotation state is a valid rotation, the rotation direction corresponding to the detection state can be obtained according to the encoding state, so that the rotation direction of the optocoupler switch can be quickly determined; when the rotation direction corresponding to the detection state is clockwise, after controlling the optocoupler switch to rotate clockwise once, the step of polling the first output port and the second output port is executed, which can end the current signal detection and start a new round of polling detection.
[0030] In some embodiments of this application, after obtaining the rotation direction corresponding to the detection state based on the encoded state when the rotation state is an effective rotation, the method further includes:
[0031] When the rotation direction corresponding to the detection state is counterclockwise, after controlling the optocoupler switch to rotate counterclockwise once, the step of polling the first output port and the second output port is executed.
[0032] By adopting the above technical solution, when the rotation direction corresponding to the detection state is counterclockwise, after controlling the optocoupler switch to rotate counterclockwise once, the step of polling the first output port and the second output port is executed, which can end the current signal detection and start a new round of polling detection.
[0033] In some embodiments of this application, after obtaining the rotation direction corresponding to the detection state based on the encoded state when the rotation state is an effective rotation, the method further includes:
[0034] If the rotation direction corresponding to the detection state is not clockwise or counterclockwise, the step of polling the first output port and the second output port is executed.
[0035] By adopting the above technical solution, when the rotation direction corresponding to the detection state is not clockwise or counterclockwise, the step of polling the first output port and the second output port can be executed to end the current signal detection and start a new round of polling detection.
[0036] Secondly, embodiments of this application provide a signal detection device for an optocoupler switch, the device comprising:
[0037] The first state acquisition module is used to acquire the first input state of the first output port and the second output port of the optocoupler switch. The first input state is represented by two binary numbers.
[0038] The intermediate state acquisition module is used to poll the first output port and the second output port. When the first input state changes, it acquires the second input state of the first output port and the second output port, shifts the first input state two bits to the high bit, and fills the low bit of the first input state with the second input state to obtain the intermediate state.
[0039] The detection state acquisition module is used to acquire the third input state of the first output port and the second output port when the second input state undergoes a state transition, shift the intermediate state two bits to the high bit, and supplement the third input state in the low bit of the intermediate state to obtain the detection state;
[0040] The rotation state determination module is used to determine the rotation state of the optocoupler switch based on the detection state.
[0041] The direction and number of rotations determination module is used to determine the rotation direction and number of rotations of the optocoupler switch based on the detection state when the rotation state is an effective rotation state, and to obtain the detection result.
[0042] By employing the aforementioned device, the first state acquisition module is invoked to acquire the first input states of the first and second output ports of the optocoupler switch. The first input state is represented by a two-bit binary number for convenient subsequent combination and judgment. The intermediate state acquisition module is invoked to poll the first and second output ports. If a state change occurs in the first input state, the second input state of the first and second output ports is acquired, the first input state is shifted two bits to the higher bit, and the second input state is added to the lower bit of the first input state to obtain the intermediate state. The detection state acquisition module is invoked to acquire the first and second input states when a state change occurs in the second input state. The third input state of the output port is obtained by shifting the intermediate state two bits to the higher bit and supplementing the lower bit of the intermediate state with the third input state. Each state transition involves only one binary bit change, which reduces the impact of oscillation interference on the signal detection of the optocoupler switch. The rotation state judgment module is called to determine the rotation state of the optocoupler switch based on the detection state, verifying the validity of the optocoupler switch rotation. The direction and number of rotations judgment module is called, and if the rotation state is valid, determines the rotation direction and number of rotations of the optocoupler switch based on the detection state, obtaining the detection result. This allows determining whether the rotation direction is clockwise or counterclockwise and counting the number of rotations. The embodiments of this application can improve the accuracy of signal detection of the optocoupler switch.
[0043] Thirdly, embodiments of this application provide an electronic device, including a processor, a memory, a user interface, and a network interface. The memory is used to store instructions, the user interface and the network interface are used to communicate with other devices, and the processor is used to execute the instructions stored in the memory to cause the electronic device to perform any of the methods provided in the first aspect above.
[0044] Fourthly, embodiments of this application provide a computer-readable storage medium storing instructions that, when executed, perform the method described in any one of the methods provided in the first aspect above.
[0045] In summary, one or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages:
[0046] 1. Obtain the first input states of the first and second output ports of the optocoupler switch; poll the first and second output ports, and when the first input state changes, obtain the second input state; combine the first and second input states to obtain an intermediate state; when the second input state changes, obtain the third input state; combine the intermediate state and the third input state to obtain a detection state; determine the rotation state of the optocoupler switch based on the detection state; if the rotation state is a valid rotation state, determine the rotation direction and number of rotations of the optocoupler switch based on the detection state to obtain a detection result. In this embodiment, the first input state of the optocoupler switch is first obtained, and the second and third input states are obtained when the first input state changes, resulting in a detection state. The rotation state is determined based on the detection state, and the rotation direction and number of rotations are determined to obtain a detection result. Since each state transition involves only one binary bit change, the impact of oscillation interference on the signal detection of the optocoupler switch can be reduced, thereby improving the accuracy of the optocoupler switch's signal detection.
[0047] 2. The first input state is shifted two bits to the higher bit using a preset left shift operator, and the second input state is supplemented in the lower bit using a preset bitwise OR operator. This allows the input states to be combined, providing a method for obtaining the subsequent detection state.
[0048] 3. Obtain the preset encoding state table of the optocoupler switch; match the detected state with the encoded state to obtain the matching result; based on the matching result, obtain the rotation state corresponding to the detected state, so as to understand the encoded state and its corresponding rotation state and quickly determine the rotation state of the optocoupler switch.
[0049] 4. Obtain the preset encoding state table of the optocoupler switch. The preset encoding state table also includes the rotation direction corresponding to the encoding state. When the rotation state is valid rotation, obtain the rotation direction corresponding to the detection state according to the encoding state. Determine whether the rotation direction is clockwise, counterclockwise, or neither. Control the optocoupler switch to rotate clockwise once, counterclockwise once, or not rotate at all. Then start a new round of polling detection. This allows you to understand the encoding state and its corresponding rotation direction, quickly determine the rotation direction of the optocoupler switch, end the current signal detection, and start a new round of polling detection. Attached Figure Description
[0050] Figure 1 This is a schematic flowchart of a signal detection method for an optocoupler switch provided in an embodiment of this application;
[0051] Figure 2 yes Figure 1 A flowchart illustrating a sub-step of step S4 in the middle section;
[0052] Figure 3 yes Figure 1 A flowchart illustrating a sub-step of step S5 in the middle section;
[0053] Figure 4 This is a schematic diagram of the structure of a signal detection device for an optocoupler switch provided in an embodiment of this application;
[0054] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0055] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.
[0056] In the description of the embodiments of this application, the words "for example" or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design that is described as "for example" or "for instance" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design options. Rather, the use of the words "for example" or "for instance" is intended to present the relevant concepts in a specific manner.
[0057] In the description of the embodiments of this application, the term "multiple" means two or more. For example, multiple systems means two or more systems, and multiple screen terminals means two or more screen terminals. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the indicated technical features. Thus, a feature defined with "first" or "second" may explicitly or implicitly include one or more of that feature. The terms "comprising," "including," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized.
[0058] Before providing a further detailed description of the embodiments of this application, the nouns and terms involved in the embodiments of this application will be explained, and the nouns and terms involved in the embodiments of this application shall be interpreted as follows.
[0059] An MCU (Microcontroller Unit) chip is the main control chip in an embedded system. It integrates functional modules such as a processor core, memory, input / output interfaces, clock, and timers. MCU chips are typically used to control and manage various tasks and functions of an embedded system.
[0060] An optocoupler switch is a device that isolates input and output signals. It consists of an optocoupler isolation device and a switching circuit. The optocoupler isolation device typically consists of a light-emitting diode (LED) and a phototransistor. When an input signal is applied to the LED, it emits a light signal. This light signal is conducted through an isolation medium (usually an optocoupler shield) to the phototransistor. Upon receiving the light signal, the phototransistor generates a corresponding current or voltage output.
[0061] GPIO (General Purpose Input / Output) interfaces are general-purpose input / output ports that can be programmed to connect and communicate with external devices. GPIO ports are commonly used to connect and control various external devices, such as LEDs, buttons, and sensors. In MCU chips, GPIO interfaces are typically implemented through digital I / O (Input / Output) pins. Each I / O pin can be configured as either an input or an output, and its input state can be read or its output state set through programming.
[0062] This application provides a signal detection method, apparatus, and electronic device for an optocoupler switch. The signal detection method includes acquiring a first input state of a first output port and a second output port of the optocoupler switch, wherein the first input state is represented by a two-bit binary number; polling the first and second output ports, and if the first input state changes, acquiring a second input state of the first and second output ports, shifting the first input state two bits to the higher bit, and supplementing the lower bit of the first input state with the second input state to obtain an intermediate state; if the second input state changes, acquiring a third input state of the first and second output ports, shifting the intermediate state two bits to the higher bit, and supplementing the lower bit of the intermediate state with the third input state to obtain a detection state; determining the rotation state of the optocoupler switch based on the detection state; and if the rotation state is valid rotation, determining the rotation direction and number of rotations of the optocoupler switch based on the detection state to obtain a detection result. In applications such as gear adjustment, signal selection, and equipment control, the signal detection method for optocouplers provides a way to detect the signal and signal changes of optocouplers, determine the rotation direction and number of rotations of the optocoupler, and obtain the detection result. This method obtains the first input state of the optocoupler and the second and third input states when the first input state changes, thus obtaining the detection state. Each state change involves only one binary bit transition, which can reduce the influence of oscillation interference and improve the accuracy of signal detection of optocouplers.
[0063] The technical solutions provided in the embodiments of this application will be further described below with reference to the accompanying drawings.
[0064] In one embodiment, the optocoupler switch can be used as a component of an automobile. The signal detection method of the optocoupler switch is described below using an automobile component as an example. (Refer to...) Figure 1 , Figure 1 This is a schematic flowchart of a signal detection method for an optocoupler switch provided in an embodiment of this application. The signal detection method for the optocoupler switch includes steps S1, S2, S3, S4, and S5.
[0065] Step S1: Obtain the first input state of the first output port and the second output port of the optocoupler switch. The first input state is represented by two binary digits.
[0066] In one embodiment, an MCU chip and an optocoupler switch are deployed on a pre-defined vehicle. The first and second output ports of the optocoupler switch are connected to the GPIO interface of the MCU chip. The GPIO interface initialization function of the MCU chip is used to set the first and second output ports of the optocoupler switch to output mode and the GPIO interface to input mode. When the optocoupler switch is not rotated, the GPIO interface read function of the MCU chip is used to read the input level value of the first output port to obtain the first input value of the first output port; the GPIO interface read function of the MCU chip is also used to read the input level value of the second output port to obtain the first input value of the second output port. For example, the input level value is either high level 1 or low level 0. Then, the first input value of the first output port and the first input value of the second output port are combined using a preset combination method to obtain the first input state of the first and second output ports of the optocoupler switch. For example, the preset combination method can be byte concatenation, bit operation, etc. The obtained first input state can be used for subsequent state combinations to facilitate subsequent state combinations. For example, the representation of the first input state corresponds to byte concatenation, bit operation, etc.
[0067] Step S2: Poll the first output port and the second output port. If the first input state changes, obtain the second input state of the first output port and the second output port, shift the first input state two bits to the high bit, and supplement the low bit of the first input state with the second input state to obtain the intermediate state.
[0068] In one embodiment, a state monitoring program and a timer are deployed in the MCU chip, and a preset time interval is set for the timer. Based on the preset time interval, after obtaining the first input states of the first and second output ports of the optocoupler switch, the timer triggers the state monitoring program to continuously monitor the first input states of the first and second output ports. When the state monitoring program detects a state transition in the first input state, the GPIO interface read function is used to read the input level value of the first output port to obtain the second input value of the first output port; the GPIO interface read function is also used to read the input level value of the second output port to obtain the second input value of the second output port. Then, byte concatenation or bitwise operations are used to combine the second input values of the first and second output ports to obtain the second input states of the first and second output ports of the optocoupler switch. A preset left shift operator is used to shift the first input state obtained in step S1 two bits to the high-order bits, and a preset bitwise OR operation bit is used to supplement the second input state in the low-order bits of the first input state to obtain an intermediate state. The obtained intermediate state can be used for subsequent state combinations to facilitate subsequent state processing.
[0069] Step S3: When the second input state changes, obtain the third input state of the first output port and the second output port, shift the intermediate state two bits to the high bit, and supplement the low bit of the intermediate state with the third input state to obtain the detection state.
[0070] In one embodiment, based on the preset time interval set in step S2, after obtaining the second input states of the first and second output ports of the optocoupler switch, the timer deployed in step S2 triggers a state monitoring program to continuously monitor the second input states of the first and second output ports. When the state monitoring program detects a state transition in the second input state, the GPIO interface read function is used to read the input level value of the first output port to obtain the third input value of the first output port; the GPIO interface read function is also used to read the input level value of the second output port to obtain the third input value of the second output port. Then, byte concatenation or bitwise operations are used to combine the third input value of the first and second output ports to obtain the third input states of the first and second output ports of the optocoupler switch. A preset left shift operator is used to shift the intermediate state obtained in step S2 two bits to the higher bit, and a preset bitwise OR operation is used to supplement the third input state in the lower bit of the intermediate state to obtain the detection state. The obtained detection state can be used to obtain the subsequent rotation state, facilitating the acquisition of the subsequent rotation state.
[0071] Step S4: Determine the rotation state of the optocoupler switch based on the detection status.
[0072] In one embodiment, based on the detection state obtained in step S3, a string matching algorithm or similar method is used to match the detection state with the encoded state to obtain a matching result. If the matching result indicates a successful match, the rotation state corresponding to the detection state is obtained based on the matching result. The obtained rotation state can be used to determine the validity of the optocoupler switch rotation, facilitating the subsequent determination of the rotation direction and number of rotations.
[0073] It's possible that during the process of determining the rotation state of the optocoupler switch based on the detection status, since only four rotation states of the optocoupler switch are valid, some rotation states may be invalid. Therefore, a restart signal detection process needs to be deployed in the MCU chip. If the optocoupler switch's rotation state is invalid, a restart signal detection process command should be sent to the process interrupt routine. The process interrupt routine should then receive the restart signal detection process command and begin a new round of polling detection, executing the steps of polling the first and second output ports.
[0074] like Figure 2 As shown, the rotation state of the optocoupler switch is determined based on the detection status, including but not limited to the following steps:
[0075] Step S41: Obtain the preset encoding state table of the optocoupler switch. The preset encoding state table includes the encoding state and the rotation state corresponding to the encoding state.
[0076] In one possible embodiment of this application, for the detection state obtained in step S3, since the detection state is a 6-bit binary number and the corresponding encoded state is also a 6-bit binary number, it can be easily calculated that there are a total of 2 to the power of 6, or 64, possible encoded states. Then, the rotation state corresponding to the encoded state is obtained. In this embodiment, the rotation states are divided into valid rotation states and invalid rotation states, with only four rotation states being valid and the remaining rotation states being invalid. First, an association is established between the four valid rotation states and their corresponding four encoded states. Then, an association is established between the remaining invalid rotation states and their encoded states. All associations are placed in a table to obtain a preset encoded state table. The obtained preset encoded state table can be used to quickly find rotation states, facilitating subsequent searches for rotation states.
[0077] In one possible embodiment of this application, the preset encoding state table includes not only the association between encoding states and rotation states, but also the association between rotation states and rotation directions. In this embodiment, rotation directions are divided into clockwise and counterclockwise rotations, and only four valid rotation states have a rotation direction, while the remaining invalid rotation states have no rotation direction. First, the four valid rotation states are associated with their corresponding rotation directions, and then the remaining invalid rotation states are associated with no rotation direction, thus obtaining the preset encoding state table. The preset encoding state table obtained in this embodiment is the same as the preset encoding state table obtained in the previous embodiment; the only difference is that this embodiment includes the association between encoding states, rotation states, and rotation directions.
[0078] Step S42: Match the detection state with the encoding state to obtain the matching result.
[0079] In one possible embodiment of this application, a preset matching algorithm is used to match the detection state obtained in step S3 with the 64 encoded states in step S41 to obtain the encoded state that matches the detection state. The detection state and the encoded state that matches the detection state are recorded as the matching result. For example, the preset matching algorithm can be a string matching algorithm, a fuzzy matching algorithm, etc. The obtained matching result can be used to find the corresponding rotation state, which facilitates the subsequent search for the rotation state.
[0080] Step S43: If the matching result indicates a successful match, obtain the rotation state corresponding to the detection state based on the matching result.
[0081] In one possible embodiment of this application, if the matching result obtained in step S42 indicates a successful match, the rotation state matching the detection state is obtained based on the matching result. Specifically, based on the coded state matching the detection state in the matching result, the rotation state corresponding to the coded state matching the detection state is searched from the preset coded state table obtained in step S41 using a traversal method, thus obtaining the rotation state corresponding to the detection state. The obtained rotation state corresponding to the detection state can provide a basis for determining the subsequent rotation direction, facilitating the determination of the rotation direction.
[0082] Step S5: When the rotation state is in an effective rotation state, determine the rotation direction and number of rotations of the optocoupler switch based on the detection state, and obtain the detection result.
[0083] In one embodiment, if the rotation state obtained in step S4 is a valid rotation state, a string matching algorithm is used to find the rotation direction corresponding to the coded state that matches the detection state from a preset coded state table, thus obtaining the rotation direction corresponding to the detection state. Then, the rotation type of the rotation direction is determined. If the rotation direction is clockwise, the optocoupler switch is controlled to rotate clockwise once, and a new round of polling detection begins. If the rotation direction is counterclockwise, the optocoupler switch is controlled to rotate counterclockwise once, and a new round of polling detection begins. If the rotation direction is neither clockwise nor counterclockwise, a new round of polling detection begins, and the detection result is obtained.
[0084] like Figure 3 As shown, when the rotation state is an effective rotation state, the rotation direction and number of rotations of the optocoupler switch are determined according to the detection state to obtain the detection result, including but not limited to the following steps:
[0085] Step S51: Obtain a preset encoding state table of the optocoupler switch. The preset encoding state table also includes the rotation direction corresponding to the encoding state.
[0086] In one possible embodiment of this application, the preset encoding state table in this step is the same table as the preset encoding state table obtained in step S41, except that the rotation direction corresponding to the encoding state is now added to the preset encoding state table. Obtaining the rotation direction corresponding to the encoding state: In this embodiment of the application, the rotation direction includes clockwise rotation and counterclockwise rotation, and only valid rotation states have a rotation direction, meaning only four rotation states have a rotation direction. First, an association is established between the encoding state and rotation direction corresponding to the four valid rotation states in step S41. Then, an association is established between the encoding state and no rotation direction corresponding to the remaining invalid rotation states. All associations are added to the preset encoding state table, resulting in a preset encoding state table with the added associations for the rotation direction corresponding to the encoding state. The resulting preset encoding state table with the added associations for the rotation direction corresponding to the encoding state can be used to find the rotation direction, facilitating subsequent rotation direction searches.
[0087] Step S52: When the rotation state is a valid rotation state, obtain the rotation direction corresponding to the detection state according to the encoded state.
[0088] In one possible embodiment of this application, if the rotation state obtained in step S4 is a valid rotation state, based on the encoded state matching the detection state in step S42, a string matching algorithm is used to search for the rotation direction corresponding to the encoded state in the preset encoded state table obtained in step S51 after adding the association relationship between the rotation direction corresponding to the encoded state, thus obtaining the rotation direction corresponding to the detection state. The obtained rotation direction can be used to perform different steps in subsequent steps depending on the rotation type.
[0089] Step S53: When the rotation direction corresponding to the detection state is clockwise, control the optocoupler switch to rotate clockwise once, and then start a new round of polling detection.
[0090] In one possible embodiment of this application, after obtaining the rotation direction corresponding to the detection state, if the rotation direction corresponding to the detection state is clockwise, controlling the optocoupler switch to rotate clockwise once is equivalent to rotating clockwise once. After controlling the optocoupler switch to rotate clockwise once, the program for restarting the signal detection process deployed in step S4 is used to start a new round of polling detection, executing the step of polling the first output port and the second output port.
[0091] Step S54: When the rotation direction corresponding to the detection state is counterclockwise, control the optocoupler switch to rotate counterclockwise once, and then start a new round of polling detection.
[0092] In one possible embodiment of this application, after obtaining the rotation direction corresponding to the detection state, if the rotation direction corresponding to the detection state is counterclockwise, the optocoupler switch is controlled to rotate counterclockwise once, which is equivalent to rotating counterclockwise by one gear. After controlling the optocoupler switch to rotate counterclockwise once, a new round of polling detection is started using the program for restarting the signal detection process deployed in step S4, executing the step of polling the first output port and the second output port.
[0093] Step S55: If the rotation direction corresponding to the detection state is neither clockwise nor counterclockwise, a new round of polling detection begins.
[0094] In one possible embodiment of this application, after obtaining the rotation direction corresponding to the detection state, if the rotation direction corresponding to the detection state is not clockwise or counterclockwise, the program for restarting the signal detection process deployed in step S4 is used directly to start a new round of polling detection, and the steps of polling the first output port and the second output port are executed.
[0095] like Figure 4As shown in the figure, this application embodiment provides a signal detection device for an optocoupler switch. The device first calls a first state acquisition module 110 to acquire the first input values of the first output port and the second output port of the optocoupler switch. The first input values of the first output port and the second output port are combined to obtain the first input states of the first output port and the second output port. The first state acquisition module 110 is connected to an intermediate state acquisition module 120, which includes a first state combination module 121. The intermediate state acquisition module 120 polls the first output port and the second output port. When a state change occurs in the first input state, the second input values of the first output port and the second output port of the optocoupler switch are acquired. The second input values of the first output port and the second output port are combined to obtain the second input states of the first output port and the second output port. Then, the first state combination module 121 is called to shift the first input state two bits to the higher bit and supplement the lower bit of the first input state with the second input state to obtain the intermediate state. The intermediate state combination module 120 is connected to the detection state acquisition module 130. The detection state acquisition module 130 includes a second state combination module 131. When the second input state changes, the detection state acquisition module 130 acquires the third input values of the first and second output ports of the optocoupler switch. These third input values are combined to obtain the third input states of the first and second output ports. Then, the second state combination module 131 is called to shift the intermediate state two bits to the higher bit and supplement the lower bit with the third input state to obtain the detection state. The detection state acquisition module 130 is connected to the rotation state judgment module 140. Based on the detection state, the rotation state judgment module 140 acquires a preset encoded state table of the optocoupler switch. The preset encoded state table includes a mapping relationship between encoded states and their corresponding rotation states. The detection state is matched with the encoded states to obtain a matching result. If the matching result indicates a successful match, the rotation state corresponding to the detection state is obtained based on the matching result and the mapping relationship. The rotation state judgment module 140 is connected to the direction count determination module 150. When the rotation state is valid rotation, the direction count determination module 150 is called to obtain the preset encoding state table of the optocoupler switch. The preset encoding state table includes the mapping relationship between the encoding state and the corresponding rotation direction. The detection state is matched with the encoding state to obtain the encoding state that matches the detection state. Based on the encoding state that matches the detection state and the mapping relationship, the rotation direction corresponding to the detection state is obtained, and it is determined whether the rotation direction is clockwise or counterclockwise.When the rotation direction is clockwise, after controlling the optocoupler switch to rotate clockwise once, a new round of polling detection begins; when the rotation direction is counterclockwise, after controlling the optocoupler switch to rotate counterclockwise once, a new round of polling detection begins; when the rotation direction is neither clockwise nor counterclockwise, a new round of polling detection begins. The above-described signal detection method for the optocoupler switch is applied to the signal detection device for this optocoupler switch.
[0096] It should be noted that the above embodiments of the apparatus are only illustrated by the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0097] This application also discloses an electronic device. (See reference...) Figure 5 , Figure 5 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of this application. The electronic device 500 may include: at least one processor 501, at least one network interface 504, a user interface 503, a memory 505, and at least one communication bus 502.
[0098] The communication bus 502 is used to enable communication between these components.
[0099] The user interface 503 may include a display screen and a camera. Optionally, the user interface 503 may also include a standard wired interface and a wireless interface.
[0100] The network interface 504 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface).
[0101] The processor 501 may include one or more processing cores. The processor 501 connects to various parts of the server using various interfaces and lines, and performs various server functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in memory 505, and by calling data stored in memory 505. Optionally, the processor 501 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 501 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the content to be displayed on the screen; and the modem handles wireless communication. It is understood that the modem may also not be integrated into the processor 501 and may be implemented as a separate chip.
[0102] The memory 505 may include random access memory (RAM) or read-only memory. Optionally, the memory 505 may include a non-transitory computer-readable storage medium. The memory 505 may be used to store instructions, programs, code, code sets, or instruction sets. The memory 505 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the above-described method embodiments, etc.; the data storage area may store data involved in the above-described method embodiments, etc. Optionally, the memory 505 may also be at least one storage device located remotely from the aforementioned processor 501. (Refer to...) Figure 5 The memory 505, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and an application program for a signal detection method of an optocoupler switch.
[0103] exist Figure 5In the illustrated electronic device 500, the user interface 503 is mainly used to provide an input interface for the user and acquire user input data; while the processor 501 can be used to call an application program of a signal detection method for an optocoupler switch stored in the memory 505. When executed by one or more processors 501, the electronic device 500 performs one or more methods as described in the above embodiments. It should be noted that, for the foregoing method embodiments, for the sake of simplicity, they are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, because according to this application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0104] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0105] In the various embodiments provided in this application, it should be understood that the disclosed system can be implemented in other ways. For example, the system embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some service interfaces, devices, or units, and may be electrical or other forms.
[0106] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0107] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0108] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as USB flash drives, portable hard drives, magnetic disks, or optical disks.
[0109] The above are merely exemplary embodiments of this disclosure and should not be construed as limiting the scope of this disclosure. Any equivalent changes and modifications made in accordance with the teachings of this disclosure shall still fall within the scope of this disclosure. Other embodiments of this disclosure will readily conceive of those skilled in the art upon consideration of the specification and the disclosure of practical truths.
[0110] This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not described in this disclosure. The specification and embodiments are to be considered exemplary only, and the scope and spirit of this disclosure are defined by the claims.
Claims
1. A signal detection method for an optocoupler switch, characterized in that, The method includes: Obtain the first input state of the first output port and the second output port of the optocoupler switch, wherein the first input state is represented by a two-bit binary number; Poll the first output port and the second output port. If the first input state changes, obtain the second input state of the first output port and the second output port. Use a preset left shift operator to shift the first input state two bits to the high bit. Use a preset bitwise OR operator to supplement the second input state in the low bit of the first input state to obtain the intermediate state. When the second input state changes state, the third input state of the first output port and the second output port is obtained, the intermediate state is shifted two bits to the high bit, and the third input state is added to the low bit of the intermediate state to obtain the detection state; Obtain a preset encoding state table of the optocoupler switch, wherein the preset encoding state table includes encoding states and corresponding rotation states; The detection state is matched with the encoding state to obtain a matching result; If the matching result indicates a successful match, the rotation state corresponding to the detection state is obtained based on the matching result. The preset encoding state table includes not only the association between encoding state and rotation state, but also the association between rotation state and rotation direction. The rotation direction is divided into clockwise rotation and counterclockwise rotation. Only four valid rotation states have a rotation direction, and the remaining invalid rotation states have no rotation direction. First, the association between the four valid rotation states and their corresponding rotation directions is established. Then, the association between the remaining invalid rotation states and the no rotation direction is established to obtain the preset encoding state table. When the rotation state is an effective rotation state, the rotation direction and number of rotations of the optocoupler switch are determined according to the detection state to obtain the detection result, including: When the rotation state is a valid rotation state, the rotation direction corresponding to the detection state is obtained according to the encoding state; When the rotation direction corresponding to the detection state is clockwise, after controlling the optocoupler switch to rotate clockwise once, the step of polling the first output port and the second output port is executed. When the rotation direction corresponding to the detection state is counterclockwise, after controlling the optocoupler switch to rotate counterclockwise once, the step of polling the first output port and the second output port is executed. If the rotation direction corresponding to the detection state is neither clockwise nor counterclockwise, the step of polling the first output port and the second output port is executed.
2. The method as described in claim 1, characterized in that, Before acquiring the first input state of the first output port and the second output port of the optocoupler switch, wherein the first input state is represented by a two-bit binary number, the method further includes: The first input value of the first output port and the first input value of the second output port of the optocoupler switch are read using the preset GPIO interface. The first input value of the first output port and the first input value of the second output port are either high level or low level. The first input value of the first output port and the first input value of the second output port are combined using a preset combination method to obtain the first input state of the first output port and the second output port of the optocoupler switch.
3. A signal detection device for an optocoupler switch, characterized in that, For implementing the signal detection method of an optocoupler switch as described in claim 1, the apparatus includes: The first state acquisition module (110) is used to acquire the first input state of the first output port and the second output port of the optocoupler switch, wherein the first input state is represented by a two-bit binary number. The intermediate state acquisition module (120) is used to poll the first output port and the second output port. When the first input state changes, it acquires the second input state of the first output port and the second output port, shifts the first input state two bits to the high bit, and supplements the second input state in the low bit of the first input state to obtain the intermediate state. The detection state acquisition module (130) is used to acquire the third input state of the first output port and the second output port when the second input state undergoes a state change, shift the intermediate state two bits to the high bit, and supplement the third input state in the low bit of the intermediate state to obtain the detection state; The rotation state determination module (140) is used to determine the rotation state of the optocoupler switch based on the detection state. The direction and number of rotations determination module (150) is used to determine the rotation direction and number of rotations of the optocoupler switch according to the detection state when the rotation state is an effective rotation state, and to obtain the detection result.
4. An electronic device, characterized in that, The electronic device (500) includes a processor (501), a memory (505), a user interface (503), and a network interface (504). The memory (505) is used to store instructions. The user interface (503) and the network interface (504) are used to communicate with other devices. The processor (501) is used to execute the instructions stored in the memory (505) to cause the electronic device (500) to perform the method as described in any one of claims 1-2.
5. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions that, when executed, perform the method as described in any one of claims 1-2.
Citation Information
Patent Citations
Code switch detection method, computer storage medium and equipment
CN114113993A