Electromagnet position detection method, device and medium
Patent Information
- Application Number
- CN202510529326.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-25
- Publication Date
- 2026-10-27
AI Technical Summary
这种采样方式的缺点是:
[0034]1、本发明通过TOM单元产生的高频脉冲触发数字转换器寄存器周期性更新,采样频率可达10-100kHz,提高了采样频率,实现了对完整波形的高分辨率还原。
Smart Images

Figure CN122981990A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of electromagnet position detection technology, and in particular to an electromagnet position detection method, device and medium. Background Technology
[0002] Electromagnets are commonly used actuators in automobiles, such as... Figure 1 As shown, electromagnets are widely used in various control systems, especially in automatic transmission gear selection mechanisms. Accurate and rapid detection of the current working position of the electromagnet plays a crucial role in the control of vehicle gear selection. Using position sensors to acquire position signals is a common position detection solution, but it leads to increased costs and system complexity.
[0003] Currently, a sensorless solution has emerged on the market. This solution uses a coil at both ends, i.e. Figure 1 The voltage pulse width is applied to pins U and W, which are on the order of milliseconds, to measure the waveform of the current signal change on the coil or a measurement point in the middle of the coil. Figure 1 The voltage signal change waveform of pin V is as follows: Figure 2 As shown, the difference in signal waveform at different positions of the electromagnet is used to determine whether the electromagnet has moved into place.
[0004] Therefore, how the controller performs high-frequency sampling of the signal waveform and how the software processes the data to restore the complete original waveform are the key aspects of this solution.
[0005] Currently, the controller samples voltage or current signals primarily through the MCU's ADC port. During controller software operation, data is collected from the ADC port into the MCU's internal ADC register at a certain frequency. The software module then simply retrieves and processes the sampled values from the ADC register at a set frequency. The disadvantage of this sampling method is:
[0006] 1. Only a single valid value can be obtained each time, and the data processing within the software module can only process a single value. In reality, when the controller is running in a very complex system, it is subject to various external mechanical and electromagnetic interferences, and the signal changes very frequently and disorderly, which is not conducive to the stability and accuracy of control.
[0007] 2. The sampling frequency is limited by the design of the software OS and the memory and performance of the CPU itself. The software module can only read the signal value directly from the ADC register at a frequency of a few hundred hertz, which makes it impossible to achieve high-frequency sampling for a short period of time during position detection, thus affecting the sampling accuracy of the waveform.
[0008] 3. Each time the software module acquires a sample value, the CPU needs to execute the process, which consumes additional CPU load on the MCU. This means that sufficient resources must be reserved when designing the controller. Summary of the Invention
[0009] This invention discloses an electromagnet position detection method, device, and medium, which can improve the accuracy of electromagnet position detection.
[0010] To achieve the above objectives, one approach is to provide a method for detecting the position of an electromagnet, the specific method of which is as follows:
[0011] A periodically varying voltage pulse width is applied across the electromagnet coil.
[0012] The electrical signal on the electromagnet coil is acquired using the data port of the analog-to-digital converter.
[0013] The TOM unit within the microcontroller generates high-frequency pulses to trigger periodic updates to the analog-to-digital converter registers, storing the electrical signals acquired by the analog-to-digital converter's data port in real time.
[0014] The central processing unit (CPU) within the microcontroller moves the data stored in the analog-to-digital converter registers to the CPU's random access memory via the direct memory access channel.
[0015] The electromagnet position determination software acquires the complete waveform signal of the electromagnet based on the data in the random access memory, and completes the electromagnet position detection.
[0016] Furthermore, the electrical signals on the electromagnet coil are acquired through the data port of the analog-to-digital converter, specifically including the three-phase voltage signals of the electromagnet: U, V, and W.
[0017] Furthermore, the U, V, and W phase voltage signals are all configured on the same analog-to-digital converter data port.
[0018] Furthermore, the central processing unit within the microcontroller moves the data stored in the analog-to-digital converter registers to the central processing unit's random access memory via the direct memory access channel, as follows:
[0019] Associate the analog-to-digital converter register with the specified direct memory access channel;
[0020] Associate a direct memory access channel with a specified central processing unit random access memory;
[0021] At each fixed time interval, the analog-to-digital converter register is updated, and the direct memory access channel moves the data in the analog-to-digital converter register to the circular buffer.
[0022] An interrupt is generated every time the circular buffer moves a first fixed amount of data, and the central processing unit acquires the first fixed amount of data between two interrupts at once.
[0023] Furthermore, the electromagnet position determination software, based on the data in the random access memory, needs to coordinate with the direct memory access channel and the electromagnet position determination software. The specific method is as follows:
[0024] The circular buffer generates a first fixed amount of data at a first fixed time interval, and the electromagnet position determination software retrieves a second fixed amount of data at a second fixed time interval. The first fixed time interval is less than the second fixed time interval, and the first fixed amount is less than the second fixed amount.
[0025] The electromagnet position determination software first retrieves a fixed amount of data generated at a fixed time before the ring buffer, then reinitializes and configures the corresponding direct memory access channel, and continues to retrieve a second fixed amount of data generated at a fixed time after the ring buffer, until the second fixed time ends and the retrieved amount reaches the second fixed amount.
[0026] Furthermore, the position detection of the electromagnet is completed, and the specific method is as follows:
[0027] After obtaining the complete waveform signal of the electromagnet, the waveform is compared with the preset waveform of the corresponding position in the software to complete the electromagnet position detection.
[0028] To achieve the above objectives, another aspect is provided: an electromagnet position detection device, comprising:
[0029] The electrical signal acquisition module applies a periodically varying voltage pulse width excitation to both ends of the electromagnet coil to acquire the electrical signal on the electromagnet coil via the analog-to-digital converter data port.
[0030] The electrical signal transfer module uses a TOM unit within the microcontroller to generate high-frequency pulses that trigger periodic updates to the analog-to-digital converter (ADC) registers, storing the electrical signals acquired by the ADC data port in real time. The central processing unit (CPU) within the microcontroller then transfers the data stored in the ADC registers to the CPU's random access memory (RAM) via a direct memory access channel.
[0031] The position detection module and the electromagnet position determination software acquire the complete waveform signal of the electromagnet based on the data in the random access memory, and complete the position detection of the electromagnet.
[0032] To achieve the above objectives, another approach is to provide a storage medium storing several instructions, which a processor loads to execute the electromagnet position detection method described above.
[0033] Due to the adoption of the above technical solutions, the present invention has the following beneficial effects:
[0034] 1. This invention uses high-frequency pulses generated by the TOM unit to trigger periodic updates of the digital converter register, with a sampling frequency of up to 10-100kHz, thereby improving the sampling frequency and achieving high-resolution restoration of the complete waveform.
[0035] 2. The data transfer in this invention is completed through the direct memory access channel, without interrupting CPU operation, without additionally occupying the CPU load of the MCU, and significantly reducing the consumption of the controller's main chip resources.
[0036] 3. The electromagnet position determination software of the present invention achieves data collaboration with the direct memory access channel. The uniquely designed data interaction method can ensure that the data within the cycle is true and complete and will not be lost, which greatly improves the accuracy of electromagnet position detection and avoids false detection.
[0037] It should be noted that the terms "first," "second," and similar terms used in this article are merely for describing the constituent elements of the technical solution and do not constitute a limitation on the technical solution, nor should they be interpreted as an indication or implication of the importance of the corresponding elements; elements with terms such as "first," "second," or similar terms indicate that at least one of the elements is included in the corresponding technical solution. Attached Figure Description
[0038] To more clearly illustrate the technical solution of the present invention and facilitate a further understanding of its technical effects, features, and objectives, the present invention will be described in detail below with reference to the accompanying drawings. The drawings constitute an essential part of the specification and are used together with Embodiment 1 of the present invention to illustrate the technical solution of the present invention, but do not constitute a limitation on the present invention.
[0039] The same reference numerals in the attached diagrams represent the same parts, specifically:
[0040] Figure 1 This is a simplified schematic diagram of an electromagnet.
[0041] Figure 2 This is a schematic diagram of the voltage signal waveforms at the U, V, and W pins of the electromagnet.
[0042] Figure 3 This is a schematic diagram of a microcontroller architecture.
[0043] Figure 4 A schematic diagram of the trigger source waveform generated by the TOM unit.
[0044] Figure 5 This is a sequence diagram of data loss when using a conventional design for MDA and OS collaboration.
[0045] Figure 6 The data interaction timing diagram is shown for the MDA and OS collaborative design in Example 1.
[0046] Figure 7 This is a schematic diagram of the detection results when the electromagnet is in position 1.
[0047] Figure 8 This is a schematic diagram of the detection results when the electromagnet is in position 2. Detailed Implementation
[0048] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Of course, the specific embodiments described below are merely illustrative of the technical solutions of the present invention, and not intended to limit the invention. Furthermore, the parts described in the embodiments or drawings are merely illustrative examples of relevant parts of the present invention, and not the entirety of the invention.
[0049] Example 1:
[0050] An electromagnet position detection method is proposed, which is implemented based on a microcontroller (MCU). The basic architecture of the MCU is as follows: Figure 3 As shown, the specific steps for electromagnet position detection in this embodiment are as follows:
[0051] S1. Apply a periodically varying voltage pulse width excitation to both ends of the electromagnet coil.
[0052] S2. Acquire the electrical signal on the electromagnet coil using the data port of the analog-to-digital converter.
[0053] The electromagnet in this embodiment includes three pins: U, V, and W. The phase voltages of the three phases U, V, and W need to be acquired simultaneously. Therefore, the ADC ports of the three voltage signals U, V, and W need to be configured in the same ADC group. This ensures that the voltage signals converted by the ADC registers corresponding to the three pins are data from the same moment each time a conversion is triggered.
[0054] S3. The TOM unit inside the microcontroller generates high-frequency pulses to trigger the periodic update of the analog-to-digital converter register, and stores the electrical signals acquired by the analog-to-digital converter data port in real time.
[0055] In this embodiment, the TOM cell period is given as 50µs and the duty cycle as 50%, with both the upper and lower edges serving as trigger sources. Figure 4 At this point, the ADC register will update the signal value every 25µs.
[0056] S4. The central processing unit inside the microcontroller moves the data stored in the analog-to-digital converter register to the central processing unit's random access memory through the direct memory access channel.
[0057] In this embodiment, the ADC register is first associated with a designated DMA channel, and the DMA channel is simultaneously associated with a data buffer (Ring Buffer) in the CPU's RAM. Every 25µs after the ADC register is updated, the DMA automatically moves the register data to the Ring Buffer. If the Ring Buffer has a size of 50 elements, an interrupt will be generated every 50 data items moved, allowing the CPU to acquire the results of 50 ADC samples within 1.25ms at once.
[0058] S5. The electromagnet position determination software obtains the complete waveform signal of the electromagnet based on the data in the random access memory, and completes the electromagnet position detection.
[0059] In this embodiment, the minimum periodic task of the electromagnet position determination software OS is 1.25ms. When the Ring Buffer has 50 elements, a DMA interrupt is triggered exactly every 1.25ms. However, since the clock of the OS's 1.25ms periodic task is not synchronized with the clock of the ADCDMA transfer, and the periodic task may be interrupted by other interrupt tasks, these problems will make it difficult to guarantee the timing of the overflow interrupt after the DMA Ring Buffer is filled with 50 elements and the OS's 1.25ms periodic task. Figure 5 As shown, even if the initial DMA interrupt is synchronized with the first OS 1.25ms task through software configuration adjustments, subsequent DMA interrupts may lag behind the 1.25ms task execution as the software dynamically runs. In this case, the software module will be unable to acquire the latest 50 sampling points during the execution of this cycle task. Furthermore, the next DMA interrupt might precede the next 1.25ms task execution, resulting in the permanent loss of 50 sampling points of data. Therefore, in practical applications, DMA and OS cycle tasks need to work in coordination.
[0060] Therefore, this embodiment proposes a method for coordinated DMA and software OS, specifically: the circular buffer generates a first fixed amount of data at a first fixed time interval, and the electromagnet position determination software retrieves a second fixed amount of data at a second fixed time interval, wherein the first fixed time interval is less than the second fixed time interval, and the first fixed amount is less than the second fixed amount; the electromagnet position determination software first retrieves the first fixed amount of data generated by the circular buffer at the previous fixed time interval, then reinitializes and configures the corresponding direct memory access channel, and continues to retrieve the second fixed amount of data generated by the circular buffer at the next fixed time interval, until the second fixed time interval ends and the retrieved amount reaches the second fixed amount.
[0061] In this embodiment, the DMA Ring Buffer is configured with 40 elements, so that the theoretical period for triggering a DMA overflow interrupt is 1ms, thus ensuring that each DMA interrupt is executed before the OS 1.25ms task. Furthermore, each time the 1.25ms periodic task is executed, the software needs to reinitialize and configure the corresponding DMA channel, which will cause the DMA to restart moving data to the 0th element of the Ring Buffer from this point onwards.
[0062] like Figure 6 As shown, each time the OS executes a second fixed-time task (1.25ms), the DMA channel restarts and begins moving data from the 0th element of the Ring Buffer until the Ring Buffer is filled with the first fixed number of data points (40 elements), approximately 1ms (the first fixed time). After this, an overflow interrupt is triggered. In this interrupt task, the software module first acquires the data from the first 0-1ms of the second fixed time (1.25ms), which is the first fixed time and represents the first fixed number of data points. After the interrupt, the DMA continues moving data from the 0th element of the Ring Buffer for approximately 0.25ms, moving about 10 points. Then, the new 1.25ms second fixed-time task begins execution. The software module first retrieves all the data points from the first 10 elements of the DMA Ring Buffer, then reinitializes and configures the corresponding DMA channel. The DMA channel is then manually restarted and begins moving data from the 0th element of the Ring Buffer again, ensuring that the timing of each DMA move and each OS 1.25ms task is synchronized.
[0063] Actual test results:
[0064] After using the method shown in Example 1, the effect is as follows: Figure 7 and Figure 8 As shown, each time the position detection command is executed, the value of the software observation representing the position of the electromagnet is 1, while at position 2, each time the position detection command is executed, the value of the software observation representing the position of the electromagnet is 2.
[0065] Example 2:
[0066] An electromagnet position detection device, comprising:
[0067] The electrical signal acquisition module applies a periodically varying voltage pulse width excitation to both ends of the electromagnet coil to acquire the electrical signal on the electromagnet coil via the analog-to-digital converter data port.
[0068] The electrical signal transfer module uses a TOM unit within the microcontroller to generate high-frequency pulses that trigger periodic updates to the analog-to-digital converter (ADC) registers, storing the electrical signals acquired by the ADC data port in real time. The central processing unit (CPU) within the microcontroller then transfers the data stored in the ADC registers to the CPU's random access memory (RAM) via a direct memory access channel.
[0069] The position detection module and the electromagnet position determination software acquire the complete waveform signal of the electromagnet based on the data in the random access memory, and complete the position detection of the electromagnet.
[0070] It should be noted that the above embodiments are only for more clearly illustrating the technical solution of the present invention. Those skilled in the art will understand that the implementation of the present invention is not limited to the above content. Any obvious changes, substitutions or replacements made based on the above content do not exceed the scope of the technical solution of the present invention. Other implementations will also fall within the scope of the present invention without departing from the concept of the present invention.
Claims
1. A method for detecting the position of an electromagnet, characterized in that, The specific method is as follows: A periodically varying voltage pulse width is applied across the electromagnet coil. The electrical signal on the electromagnet coil is acquired using the data port of the analog-to-digital converter. The TOM unit within the microcontroller generates high-frequency pulses to trigger periodic updates to the analog-to-digital converter registers, storing the electrical signals acquired by the analog-to-digital converter's data port in real time. The central processing unit (CPU) within the microcontroller moves the data stored in the analog-to-digital converter registers to the CPU's random access memory via the direct memory access channel. The electromagnet position determination software acquires the complete waveform signal of the electromagnet based on the data in the random access memory, and completes the electromagnet position detection.
2. The electromagnet position detection method as described in claim 1, characterized in that, The electrical signals on the electromagnet coil are acquired through the data port of the analog-to-digital converter, specifically including the three-phase voltage signals of the electromagnet: U, V, and W.
3. The electromagnet position detection method as described in claim 2, characterized in that, The U, V, and W phase voltage signals are all configured on the same analog-to-digital converter data port.
4. The electromagnet position detection method as described in claim 1, characterized in that, The central processing unit (CPU) within the microcontroller moves data stored in the analog-to-digital converter registers to the CPU's random access memory (RAM) via direct memory access (DRAM). The specific method is as follows: Associate the analog-to-digital converter register with the specified direct memory access channel; Associate a direct memory access channel with a specified central processing unit random access memory; At each fixed time interval, the analog-to-digital converter register is updated, and the direct memory access channel moves the data in the analog-to-digital converter register to the circular buffer. An interrupt is generated every time the circular buffer moves a first fixed amount of data, and the central processing unit acquires the first fixed amount of data between two interrupts at once.
5. The electromagnet position detection method as described in claim 4, characterized in that, The electromagnet position determination software relies on data from the random access memory (RAM) and requires the direct memory access channel (DRAM) to work in conjunction with the electromagnet position determination software. The specific method is as follows: The circular buffer generates a first fixed amount of data at a first fixed time interval, and the electromagnet position determination software retrieves a second fixed amount of data at a second fixed time interval. The first fixed time interval is less than the second fixed time interval, and the first fixed amount is less than the second fixed amount. The electromagnet position determination software first retrieves a fixed amount of data generated at a fixed time before the ring buffer, then reinitializes and configures the corresponding direct memory access channel, and continues to retrieve a second fixed amount of data generated at a fixed time after the ring buffer, until the second fixed time ends and the retrieved amount reaches the second fixed amount.
6. The electromagnet position detection method as described in claim 1, characterized in that, The specific method for detecting the position of an electromagnet is as follows: After obtaining the complete waveform signal of the electromagnet, the waveform is compared with the preset waveform of the corresponding position in the software to complete the electromagnet position detection.
7. An electromagnet position detection device, characterized in that, include: The electrical signal acquisition module applies a periodically varying voltage pulse width excitation to both ends of the electromagnet coil to acquire the electrical signal on the electromagnet coil via the analog-to-digital converter data port. The electrical signal transport module uses the TOM unit within the microcontroller to generate high-frequency pulses that trigger periodic updates to the analog-to-digital converter registers, storing the electrical signals acquired by the analog-to-digital converter's data port in real time. The central processing unit (CPU) within the microcontroller moves the data stored in the analog-to-digital converter registers to the CPU's random access memory via the direct memory access channel. The position detection module and the electromagnet position determination software acquire the complete waveform signal of the electromagnet based on the data in the random access memory, and complete the position detection of the electromagnet.
8. A storage medium, characterized in that, The processor stores several instructions, which are loaded by the processor to execute the electromagnet position detection method according to any one of claims 1 to 5.