Motor controller software FOC task timeout detection method and device based on GTM channel

By using the GTM channel motor controller method, advanced timers and analog-to-digital converters are used to detect FOC task timeouts, solving the problem of inaccurate FOC task detection, achieving accurate timeout detection and resource optimization, and avoiding motor controller failures.

CN121597531APending Publication Date: 2026-03-03JIANGSU XCMG CONSTRUCTION MACHINERY RESEARCH INSTITUTE LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511604252.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-04
Publication Date
2026-03-03

AI Technical Summary

Technical Problem

Existing technologies struggle to accurately detect timeouts in field-oriented control (FOC) tasks within motor controllers, leading to excessive current, motor vibration, or damage to power devices. Traditional methods, such as software timers and watchdogs, cannot meet the real-time requirements of FOC tasks.

Method used

The method based on the GTM channel utilizes the advanced timer output module of the general-purpose timer module as a time reference, combined with analog-to-digital converter and direct memory access, to detect FOC task timeout by comparing the level values ​​at the start and end of the task.

Benefits of technology

It achieves accurate timeout detection for FOC tasks, reduces CPU resource consumption, lowers system overhead, and can accurately locate the cause of timeout, thus avoiding motor control misalignment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121597531A_ABST
    Figure CN121597531A_ABST
Patent Text Reader

Abstract

The invention discloses a motor controller software FOC task timeout detection method and device based on a GTM channel. An output level value of an advanced timer output module of a general timer module is used as a time reference of a field-oriented control period; after the sampling is finished, triggering an interrupt execution direct memory access channel to trigger and execute a field-oriented control task; reading a reference level value output by an advanced timer output module before the execution of the field-oriented control task is started; setting a task cycle time timeout threshold value based on an advanced timer output module, comparing the level value when the magnetic field orientation control task starts to be executed with the level value when the magnetic field orientation control task ends, if the level values are kept consistent, considering that the magnetic field orientation control task is not overtime, and if the level values pass the detection, judging that the magnetic field orientation control task is overtime. If the level values are different, it is considered that timeout occurs in the field-oriented control task, and the specific task causing the timeout processing action can be accurately positioned.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to a method and apparatus for detecting timeout of FOC tasks in motor controller software based on GTM channels, belonging to the field of motor control technology. Background Technology

[0002] In motor control systems, especially in new energy vehicles and industrial servo drives, field-oriented control (FOC) is widely used due to its high efficiency and stable performance. The FOC algorithm typically runs as a high-priority periodic task in a microcontroller (MCU), and its real-time performance and periodic stability are crucial. Because the real-time performance of the motor controller is critical, the FOC algorithm requires each FOC task to complete within a control cycle. If an FOC task times out (i.e., the task execution time exceeds the preset cycle) or completely freezes due to software bugs, external interference, or processor overload, it will lead to motor control malfunction, causing excessive current, motor vibration, and even damage to power devices.

[0003] Traditional task timeout detection methods typically rely on watchdog timers or software timers. However, operating system watchdog timers can usually only detect system-wide crashes and cannot monitor individual tasks. Software timers lack sufficient timing accuracy and cannot meet the accuracy requirements of FOC task runtime.

[0004] Existing task timeout detection technologies mainly fall into two categories: one is using software timers, such as... Figure 1 As shown, the software timer technology solution uses a global variable for counting, based on a hardware clock. Each time the clock source emits an oscillation beat after one cycle, the timer is incremented by 1, and the time is controlled by the count value of the timer.

[0005] Another method is to use a watchdog for timing, such as... Figure 2 As shown, if the watchdog timer is not fed within the specified timeout period, a reset will be triggered. The watchdog timer technology uses a timer to keep track of the count. The watchdog timer duration is determined by the reload register controller; the value in the reload register determines the watchdog timer's duration. After the watchdog timer is enabled, the reload register begins to decrement. "Feeding" the watchdog timer occurs before the count in the reload register reaches zero, restoring the reload register value to its pre-decrement value; otherwise, a program reset will be triggered.

[0006] Using a software timer to monitor FOC task timeouts can be problematic because using a global variable to count timers consumes CPU resources, increases system overhead, and is susceptible to interrupted tasks, making it difficult to accurately capture short-term timeouts.

[0007] A watchdog timer is used to detect FOC task timeouts. Since a watchdog timeout will directly cause the program to reset, multiple tasks in the program use a watchdog timer to detect timeouts. When a program reset occurs, it can only be known that the watchdog timer has been triggered, but it cannot be detected whether the FOC task has timed out. Summary of the Invention

[0008] The purpose of this invention is to overcome the shortcomings of the prior art and provide a method and device for detecting FOC task timeout in motor controller software based on the GTM channel. The method generates an accurate time reference through the GTM timer and reports FOC task timeout issues while performing FOC task timeout monitoring. To achieve the above objectives / to solve the above technical problems, the present invention is implemented using the following technical solution: First aspect: A method for detecting timeout in FOC tasks of motor controller software based on GTM channels, the method comprising: Use the output level value of the advanced timer output module of the general timer module as the time reference for the magnetic field orientation control cycle; The three-phase current signal is sampled by an analog-to-digital converter, and an interrupt is triggered after sampling to execute the field-oriented control task in the direct memory access channel. After direct memory access triggers the execution of the field orientation control task, the reference level value output by the advanced timer output module is read before the field orientation control task begins execution, and the reference level value output by the advanced timer output module is recorded at this moment after the field orientation control task ends. The task cycle timeout threshold is set based on the advanced timer output module. The level value at the start of the field-oriented control task is compared with the level value at the end of the field-oriented control task. If the level values ​​are the same, it is considered that the field-oriented control task has not timed out. If the level values ​​are different, it is considered that the field-oriented control task has timed out.

[0009] Optionally, the advanced timer output module sets the task cycle timeout threshold to the sum of the magnetic field orientation control task time and its task time margin.

[0010] Optionally, the advanced timer output module sets a task cycle timeout threshold, including: The general-purpose timer module uses the numerical inputs of the control registers Cm0 and Cm1 to control the output waveform of the advanced timer output module as a timing reference for the FOC periodic task. The timeout threshold setting of the magnetic field orientation control task cycle time is determined by the theoretical maximum execution time of the magnetic field orientation control plus a variable dynamic margin, and the input is controlled by the Cm1 register.

[0011] Optionally, when the analog-to-digital converter performs three-phase current sampling, the rising edge of the advanced timer output module channel starting to count down is used as the starting sampling signal of the analog-to-digital converter.

[0012] Optionally, if the level values ​​are different, it is considered that the field orientation control task has timed out. The global variable ProgramFlow_Err, which monitors the timeout error of the field orientation control task, is set to 1, and the field orientation control timeout fault is reported and processed in the 500us task.

[0013] Optionally, the advanced timer output module channel 0_6 outputs a high level when Cm1 timing starts, triggering the analog-to-digital converter to sample. After the analog-to-digital converter completes sampling, it moves data through direct memory access. Upon completion, it triggers the execution of the magnetic field orientation control task.

[0014] Optionally, the timing length set in the Cm1 register is greater than the maximum theoretical execution time of the field orientation control task to provide sufficient safety margin and prevent misjudgment of timeout due to system delay.

[0015] The second aspect: A timeout detection device for FOC tasks in motor controller software based on GTM channels, comprising: A general-purpose timer module is used to generate timing control signals and configure the Cm0 and Cm1 registers to control the output waveforms of the advanced timer output module channels. Advanced timer output module, used to output high / low levels as a time reference for field orientation control tasks; The analog-to-digital converter module receives the rising edge trigger signal from the advanced timer output module channel to sample the three-phase current. The direct memory access controller is used to move the sampled data after the analog-to-digital converter has finished sampling and to trigger the field-oriented control task after the sampling is completed. The interrupt handling unit is used to execute the field orientation control task and record the channel level value of the advanced timer output module in the direct memory access interrupt service routine; The timeout detection logic is used to compare the channel level values ​​of the advanced timer output module before and after the field orientation control task, and set the global error flag ProgramFlow_Err based on the comparison result; Optionally, the device further includes: The fault handling module is used to read the ProgramFlow_Err flag and execute the corresponding field orientation control timeout handling process in the 500μs cycle task.

[0016] Third aspect: A computer-readable storage medium having a computer program stored thereon that, when the program is run on a processor, implements the method described in the first aspect.

[0017] Compared with the prior art, the beneficial effects achieved by the present invention are as follows: (1) The general-purpose timer module hardware generates an accurate time reference, and the time accuracy is much higher than that of the software timer. The general-purpose timer module generates an independent peripheral hardware time reference without interference, which can accurately complete the timeout detection of the magnetic field orientation control task, while reducing the use of interrupts, releasing CPU resources, and reducing system overhead.

[0018] (2) The reference level value output by the detection general timer module is used to determine whether the field orientation control task has timed out. While completing the timeout protection processing of the field orientation control task, compared with the watchdog scheme, the specific task that caused the timeout processing action can be accurately located.

[0019] (3) The timeout threshold can be flexibly configured. The timeout detection threshold can be set according to the actual requirements of the system for the duration of the magnetic field orientation control task. Attached Figure Description

[0020] Figure 1 The diagram shown is a schematic of an existing watchdog solution. Figure 2 The diagram shown is a schematic of an existing software timer solution; Figure 3 This is a schematic diagram illustrating the implementation principle of the present invention; Figure 4 This is a flowchart of the detection method of the present invention. Detailed Implementation

[0021] To make the technical means, creative features, objectives and effects of this invention easier to understand, the invention will be further described below in conjunction with specific embodiments.

[0022] In the description of this invention, it should be understood that the terms "center," "longitudinal," "lateral," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," "bottom," "inner," and "outer," etc., indicating orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, are used only for the convenience of describing the 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 the invention. Furthermore, the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, a feature defined with "first," "second," etc., may explicitly or implicitly include one or more of that feature. In the description of this invention, unless otherwise stated, "a plurality of" means two or more.

[0023] In the description of this invention, it should be noted that, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art will understand the specific meaning of the above terms in this invention based on the specific circumstances.

[0024] Example 1, such as Figures 3-4 As shown, this invention discloses a method for detecting timeout of FOC tasks in motor controller software based on the GTM channel. The method includes: Use the output level value of the advanced timer output module of the general timer module as the time reference for the magnetic field orientation control cycle; The three-phase current signal is sampled by an analog-to-digital converter, and an interrupt is triggered after sampling to execute the field-oriented control task in the direct memory access channel. After direct memory access triggers the execution of the field orientation control task, the reference level value output by the advanced timer output module is read before the field orientation control task begins execution, and the reference level value output by the advanced timer output module is recorded at this moment after the field orientation control task ends. The task cycle timeout threshold is set based on the advanced timer output module. The level value at the start of the field-oriented control task is compared with the level value at the end of the field-oriented control task. If the level values ​​are the same, it is considered that the field-oriented control task has not timed out. If the level values ​​are different, it is considered that the field-oriented control task has timed out.

[0025] The specific methods will be further elaborated upon here, and it is important to note that: FOC is an abbreviation for Field Oriented Control. GTM is an abbreviation for Generic Timer Module, which means a general-purpose timer module; ATOM is an abbreviation for ARU-connected Timer Output Module, which stands for Advanced Timer Output Module. ADC is an abbreviation for Analog-to-Digital Converter. DMA is an abbreviation for Direct Memory Access. Step 1: First, initialize the GTM module by enabling the ATOM channel of the GTM module as a time reference for entering the FOC cycle.

[0026] Step 2: Using the numerical inputs of the GTM module control registers Cm0 and Cm1, control the output waveform of the ATOM channel as a timing reference for the FOC cycle task. The FOC task cycle timeout threshold can be set by adding the theoretical maximum FOC execution time to the variable dynamic margin, and the input is controlled by the Cm1 register.

[0027] Step 3: When using the ADC to sample three-phase current, the rising edge of the ATOM channel start timing output is used as the ADC start sampling signal, and an interrupt is triggered after the ADC sampling is completed to execute the DMA interrupt function, and the FOC task is triggered in the DMA channel.

[0028] Step 4: After triggering the execution of the FOC task in the DMA interrupt service routine, read the ATOM channel output reference level before the FOC task starts execution, and read and record the ATOM channel output reference level value after the FOC task ends.

[0029] Step 5: Compare the voltage level at the start of the FOC task with the voltage level at the end of the FOC task. If the voltage levels are the same, the FOC task is considered not to have timed out. If the voltage levels are different, the FOC task is considered to have timed out. Set the global variable ProgramFlow_Err, which monitors FOC task timeout errors, to 1, and report the FOC timeout fault in the 500us task.

[0030] like Figure 3 As shown, the internal GTM module control registers cm1 and cm2 are used to control the high and low level waveforms output by the ATOM channel. The ATOM channel output level serves as the FOC task time reference. The FOC task time and a time margin need to be considered. Therefore, the timing input to the cm1 register should be the sum of the FOC task time and its time margin. In the diagram, the ATOM channel outputs a high level when cm1 starts timing. The blue portion in the ATOM output reference level segment represents the time margin reserved before triggering the FOC task. In this scheme, this time margin is reserved for triggering the FOC task, mainly for ADC sampling and DMA data transfer. The red portion in the latter half represents the actual execution time of the FOC task, typically 50µs. ATOM channels 1_1 to 1_6 serve as the six-channel PWM wave generation channels for the FOC task. When ATOM channel 0_6 starts counting, it simultaneously triggers the generation of six complementary PWM waves, as shown by the black lines in the diagram.

[0031] When the ATOM channel outputs a high level, the cm1 control register starts timing. At this time, the ADC receives the ATOM enable signal and starts sampling. After sampling is completed, the interrupt DMA channel is triggered to transfer data.

[0032] After DMA data transfer is complete, a FOC task is triggered synchronously. At the start of the FOC task, the level value of ATOM channel 0_6 is recorded. At the end of the FOC task, the level value of ATOM channel 0_6 is also recorded synchronously. After recording ends, the two level values ​​are compared. If the recorded level values ​​at the start and end of the FOC task are equal, the FOC task is considered to have not timed out. If the recorded level values ​​at the start and end of the FOC task are not equal, the FOC task is considered to have timed out. At this point, the global variable ProgramFlow_Err, which is the FOC task timeout flag, is set. This flag is accessed during the 500us task, and the FOC task timeout is handled simultaneously. The Cm0 control register is responsible for controlling the duration of the second half of the cycle. The trigger content task is the same as that of the first half of the cycle. Similarly, when setting the cm0 control register, it is necessary to consider giving the FOC task a certain time margin. The only difference is that the FOC task start and end level values ​​recorded in the FOC task during the second half of the cycle are both low level values. Figure 4 This is a flowchart illustrating the execution of the technical solution described in the entire invention.

[0033] Example 2: A timeout detection device for FOC tasks in motor controller software based on the GTM channel is disclosed, comprising: A general-purpose timer module is used to generate timing control signals and configure the Cm0 and Cm1 registers to control the output waveforms of the advanced timer output module channels. Advanced timer output module, used to output high / low levels as a time reference for field orientation control tasks; The analog-to-digital converter module receives the rising edge trigger signal from the advanced timer output module channel to sample the three-phase current. The direct memory access controller is used to move the sampled data after the analog-to-digital converter has finished sampling and to trigger the field-oriented control task after the sampling is completed. The interrupt handling unit is used to execute the field orientation control task and record the channel level value of the advanced timer output module in the direct memory access interrupt service routine; The timeout detection logic is used to compare the channel level values ​​of the advanced timer output module before and after the field orientation control task, and set the global error flag ProgramFlow_Err based on the comparison result; Optionally, the device further includes: The fault handling module is used to read the ProgramFlow_Err flag and execute the corresponding field orientation control timeout handling process in the 500μs cycle task.

[0034] Example 3: A computer-readable storage medium having a computer program stored thereon, which, when run on a processor, implements the method described in Example 1.

[0035] This invention generates a time reference standard through an independent hardware peripheral device called GTM. By reading and comparing the GTM output level values ​​at the start and end of the FOC task, it achieves FOC task timeout detection, avoiding the inaccuracies of software timing and enabling accurate detection of FOC task timeout. Furthermore, by modifying the input values ​​of the GTM control registers cm0 and cm1, the FOC task timeout threshold can be flexibly configured, allowing for flexible modification of the FOC task time margin according to actual FOC operating requirements.

[0036] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the technical principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A method for detecting timeout of FOC tasks in motor controller software based on GTM channels, characterized in that, The method includes: Use the output level value of the advanced timer output module of the general timer module as the time reference for the magnetic field orientation control cycle; The three-phase current signal is sampled by an analog-to-digital converter, and an interrupt is triggered after sampling to execute the field-oriented control task in the direct memory access channel. After direct memory access triggers the execution of the field orientation control task, the reference level value output by the advanced timer output module is read before the field orientation control task begins execution, and the reference level value output by the advanced timer output module is recorded at this moment after the field orientation control task ends. The task cycle timeout threshold is set based on the advanced timer output module. The level value at the start of the field-oriented control task is compared with the level value at the end of the field-oriented control task. If the level values ​​are the same, it is considered that the field-oriented control task has not timed out. If the level values ​​are different, it is considered that the field-oriented control task has timed out.

2. The method for detecting timeout of motor controller software FOC task based on GTM channel according to claim 1, characterized in that, The advanced timer output module sets the task cycle timeout threshold to the sum of the magnetic field orientation control task time and its task time margin.

3. The method for detecting timeout of motor controller software FOC task based on GTM channel according to claim 1, characterized in that, The advanced timer output module sets the task cycle timeout threshold, including: The general-purpose timer module uses the numerical inputs of the control registers Cm0 and Cm1 to control the output waveform of the advanced timer output module as a timing reference for the FOC periodic task. The timeout threshold setting of the magnetic field orientation control task cycle time is determined by the theoretical maximum execution time of the magnetic field orientation control plus a variable dynamic margin, and the input is controlled by the Cm1 register.

4. The method for detecting timeout of motor controller software FOC task based on GTM channel according to claim 1, characterized in that, When the analog-to-digital converter performs three-phase current sampling, the rising edge of the advanced timer output module channel starts timing as the starting sampling signal of the analog-to-digital converter.

5. The method for detecting timeout of motor controller software FOC task based on GTM channel according to claim 1, characterized in that, If the level values ​​are different, it is considered that the field orientation control task has timed out. The global variable ProgramFlow_Err, which monitors the timeout error of the field orientation control task, is set to 1, and the field orientation control timeout fault is reported and processed in the 500us task.

6. The method for detecting timeout of motor controller software FOC task based on GTM channel according to claim 1, characterized in that, The advanced timer output module channel 0_6 outputs a high level when Cm1 timing begins, triggering the analog-to-digital converter to sample. After the analog-to-digital converter completes sampling, it moves data through direct memory access. Upon completion, it triggers the execution of the magnetic field orientation control task.

7. The method for detecting timeout of motor controller software FOC task based on GTM channel according to claim 1, characterized in that, The timing length set in the Cm1 register is greater than the maximum theoretical execution time of the field orientation control task, in order to provide sufficient safety margin and prevent misjudgment of timeout due to system delay.

8. A timeout detection device for FOC tasks in motor controller software based on GTM channels, characterized in that, include: A general-purpose timer module is used to generate timing control signals and configure the Cm0 and Cm1 registers to control the output waveforms of the advanced timer output module channels. Advanced timer output module, used to output high / low levels as a time reference for field orientation control tasks; The analog-to-digital converter module receives the rising edge trigger signal from the advanced timer output module channel to sample the three-phase current. The direct memory access controller is used to move the sampled data after the analog-to-digital converter has finished sampling and to trigger the field-oriented control task after the sampling is completed. The interrupt handling unit is used to execute the field orientation control task and record the channel level value of the advanced timer output module in the direct memory access interrupt service routine; The timeout detection logic is used to compare the channel level values ​​of the advanced timer output module before and after the field orientation control task, and set the global error flag ProgramFlow_Err based on the comparison result.

9. The motor controller software FOC task timeout detection device based on GTM channel according to claim 8, characterized in that, The device further includes: The fault handling module is used to read the ProgramFlow_Err flag and execute the corresponding field orientation control timeout handling process in the 500μs cycle task.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is run on a processor, it implements the method as described in any one of claims 1 to 7.