PWM (Pulse Width Modulation) control method based on microcontroller

By using the MCAL configuration tool on the microcontroller for basic settings and initialization, and setting the comparator value based on the GTM clock and ATOM counter, the precise control of the PWM signal frequency and duty cycle is achieved, solving the problems of cumbersome configuration and insufficient flexibility in the existing technology, and meeting the high-precision and high-efficiency motor control needs.

CN119882557APending Publication Date: 2025-04-25CHONGQING TSINGSHAN IND
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510023488.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-07
Publication Date
2025-04-25

AI Technical Summary

Technical Problem

The existing PWM control schemes are cumbersome to configure and lack flexibility, making it difficult to quickly adapt to the diverse needs of different application scenarios. Especially in the automotive industry, due to the high system complexity and strong real-time requirements, traditional PWM control methods are difficult to meet the control requirements of high precision and high efficiency.

Method used

The PWM control method based on the microcontroller is adopted, and the basic settings are performed through the MCAL configuration tool, including PWM output port setting, GTM clock allocation and GTM ATOM channel configuration, the GTM and Port modules are initialized, the signal output mode of the ATOM channel is set, and the ATOM comparator value is set to control the frequency and duty cycle of the PWM signal based on the counting mode of the GTM clock and the ATOM counter.

Benefits of technology

It realizes PWM signal control with high configuration flexibility, clear initialization process and high efficiency, and can accurately control the PWM signal frequency and duty cycle, meeting the needs of the automotive industry and other fields for high-precision and high-efficiency motor control.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119882557A_ABST
    Figure CN119882557A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of PWM (Pulse Width Modulation) signal control, and particularly relates to a PWM control method based on a microcontroller, which comprises the following steps of: S1, carrying out basic setting by utilizing an MCAL configuration tool; the basic setting comprises PWM output port setting, GTM clock distribution and GTM ATOM channel configuration; s2, initializing a GTM module and a Port module; setting a signal output mode of an ATOM channel according to a PWM output requirement; s3, based on a GTM clock and a counting mode of an ATOM counter, setting an ATOM comparator value for controlling the frequency and the duty ratio of the PWM signal, and storing the frequency and the duty ratio in a register; s4, outputting a corresponding PWM (Pulse Width Modulation) signal according to the setting; s5, the output PWM signal is used for controlling equipment, and the accurate control effect is achieved. The method is flexible in configuration and easy to implement, can accurately control the PWM signal frequency and the duty ratio, and can meet the high-precision and high-efficiency requirements of the automobile industry and other fields for motor control.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of PWM signal control, and in particular relates to a PWM control method based on a microcontroller. Background Art

[0002] In recent years, with the continuous deepening of the needs of the automotive industry, the control schemes of automotive systems have become increasingly complex, and the electrical system has also ushered in continuous updates and upgrades. As a key component of the motor system, the performance and efficiency of the motor controller are directly related to the performance of the entire motor system. With the rapid development of electronic technology and the continuous improvement of the market demand for high efficiency and energy saving, the motor controller industry is undergoing profound changes and development. In this context, how to optimize the motor control strategy and improve the control accuracy and efficiency has become the focus of the industry.

[0003] As an important modulation method, PWM (Pulse Width Modulation) control technology plays a vital role in the field of motor control. It achieves precise control of motor speed by adjusting the duty cycle of the pulse signal, that is, the ratio of pulse width to period. The PWM method of controlling motor speed has been widely used in modern industry, especially in the automotive field, due to its many advantages such as high efficiency, stability, and easy implementation. From the drive motor control of electric vehicles to the fan speed regulation of automotive air-conditioning systems, PWM control technology is everywhere, providing strong support for improving system performance and energy efficiency.

[0004] However, in practical applications, in order to achieve different PWM pulse width modulation to meet specific control requirements, the underlying software development of various controllers often needs to face the challenge of complex waveform output. This requires developers to be able to flexibly configure parameters such as PWM output ports, clock distribution, and signal output mode to ensure that the output PWM waveform has accurate frequency and duty cycle. However, existing PWM control schemes often have problems such as cumbersome configuration and insufficient flexibility, making it difficult to quickly adapt to the diverse needs of different application scenarios. Especially in the automotive industry, due to the high system complexity and strong real-time requirements, traditional PWM control methods often find it difficult to meet high-precision and high-efficiency control requirements.

[0005] Therefore, how to provide a microcontroller PWM control method that is flexible in configuration, easy to implement and can accurately control the PWM signal frequency and duty cycle to meet the high-precision and high-efficiency requirements of motor control in the automotive industry and other fields has become an urgent problem to be solved. Summary of the invention

[0006] In view of the above-mentioned deficiencies in the prior art, the present invention provides a microcontroller-based PWM control method, which is flexible in configuration, easy to implement and can accurately control the PWM signal frequency and duty cycle, and can meet the high-precision and high-efficiency requirements of motor control in the automotive industry and other fields.

[0007] In order to solve the above technical problems, the present invention adopts the following technical solutions:

[0008] A PWM control method based on a microcontroller comprises the following steps:

[0009] S1. Use the MCAL configuration tool to perform basic settings; basic settings include PWM output port settings, GTM clock distribution, and GTM ATOM channel configuration;

[0010] S2. Initialize the GTM and Port modules; set the signal output mode of the ATOM channel according to the PWM output requirements;

[0011] S3, based on the GTM clock and the counting mode of the ATOM counter, set the ATOM comparator value to control the frequency and duty cycle of the PWM signal and store it in the register;

[0012] S4, output corresponding PWM signal according to the setting;

[0013] S5. Use the output PWM signal to control the device to achieve precise control effect.

[0014] Compared with the prior art, the present invention has the following beneficial effects:

[0015] 1. High configuration flexibility. By using the MCAL (Microcontroller Abstraction Layer) configuration tool, this technical solution can easily perform basic settings such as PWM output port settings, GTM (Global Timer Module) clock distribution, and GTM ATOM (Global Timer ATOM) channel configuration. This configuration method not only simplifies the development process, but also improves the flexibility of configuration, allowing developers to quickly adjust PWM control parameters according to different application scenarios.

[0016] 2. The initialization process is clear and efficient. When initializing the GTM and Port modules, this method clearly sets the signal output mode of the ATOM channel according to the PWM output requirements and stores it in the register. This step ensures the stability and consistency of the PWM signal output, while improving the efficiency of the initialization process, laying the foundation for the precise control of the subsequent PWM signal.

[0017] 3. Accurately control the PWM signal frequency and duty cycle. Through the counting mode based on the GTM clock and the ATOM counter, this technical solution can accurately set the ATOM comparator value, thereby achieving accurate control of the PWM signal frequency and duty cycle. This control method not only improves the accuracy of the PWM signal, but also makes the motor control more stable and reliable, meeting the needs of the automotive industry and other fields for high-precision and high-efficiency motor control.

[0018] 4. Easy to implement and adaptable. The steps of this technical solution are clear and easy to implement. Through flexible configuration and precise control, the PWM signal can adapt to the diverse needs of different application scenarios. Whether in motor control in the automotive industry or in other fields that require precise control of PWM signals, this method has shown strong adaptability and practicality.

[0019] In summary, this method is flexible in configuration, easy to implement, and can accurately control the PWM signal frequency and duty cycle. By using the MCAL configuration tool for basic settings, explicitly and efficiently initializing the GTM and Port modules, and accurately setting the ATOM comparator value, this technical solution achieves precise control of the PWM signal. This control method not only improves the accuracy and stability of motor control, but also meets the needs of the automotive industry and other fields for high-precision and high-efficiency motor control, showing strong application potential and market value.

[0020] Preferably, in S3, the set comparator values ​​include CM0 and CM1; CM0 is the duration of the cycle of the PWM signal, used to control the frequency of the PWM signal; CM1 is the duration of the duty cycle of the clock beat, used to control the duty cycle of the PWM signal.

[0021] Such a setting can, 1. accurately control the frequency of the PWM signal. CM0 is the duration of the cycle of the PWM signal, and its value directly determines the frequency of the PWM signal. By accurately setting the value of CM0, this method can flexibly adjust the frequency of the PWM signal to meet the frequency requirements in different application scenarios. This ability to accurately control the frequency makes the motor control more stable and responsive, improving the overall performance of the system.

[0022] 2. The duty cycle of the PWM signal can be precisely controlled. CM1 is the duration of the duty cycle of the clock beat, and its value determines the high level time of the PWM signal in one cycle, that is, the duty cycle. By adjusting the value of CM1, this method can precisely control the duty cycle of the PWM signal, thereby achieving fine adjustment of parameters such as motor speed and power. This ability to precisely control the duty cycle makes motor control more precise and efficient, improving energy utilization and system efficiency.

[0023] Preferably, in S4 , when the count value of the counter CN0 reaches the comparator CM0 , the counter is reset and a rising edge or a falling edge of the PWM signal is generated.

[0024] With this setup, the reset of counter CN0 ensures that the PWM signal has a fixed period. Every time the counter reaches the value set by CM0, it starts counting again, thus forming a stable period. This is the basis for achieving stable speed and performance when the PWM signal controls devices such as motors.

[0025] By accurately setting the value of comparator CM0, the generation time of the rising edge or falling edge of the PWM signal can be accurately controlled. This is crucial for applications that require precise control of motor start and stop moments, adjustment of speed, or implementation of specific control strategies. Due to the precise counting of the counter and the precise comparison of the comparator, the generated PWM signal has high accuracy and stability. This helps reduce noise and jitter in motor control and improves the overall performance and reliability of the system.

[0026] By adjusting the value of the comparator CM0 and the counting mode of the counter (such as increasing, decreasing or bidirectional counting, etc.), PWM signals of different modes can be generated, such as standard PWM, reverse PWM, center-aligned PWM, etc. This increases the flexibility and adaptability of the PWM control method, enabling it to meet the needs of different application scenarios.

[0027] Preferably, in S4, when the count value of the counter CN0 exceeds CM1, the output level of the PWM signal is changed, thereby controlling the duty cycle of the PWM signal.

[0028] This setting, by accurately setting the value of comparator CM1, can accurately control the high level time of the PWM signal in one cycle, that is, the duty cycle. The duty cycle is a very important parameter in PWM control, which directly determines the average voltage and speed of the motor. Therefore, this technical content enables the PWM control method to achieve accurate regulation of the motor speed and performance.

[0029] Since the value of comparator CM1 can be flexibly set, PWM signals with different duty cycles can be generated to meet the needs of different application scenarios. This flexibility enables the PWM control method to be widely used in various motor control, LED dimming, servo control and other fields. Since the duty cycle of the PWM signal can be precisely controlled, the noise and jitter in the motor control can be reduced, and the overall stability and reliability of the system can be improved. This is especially important for application scenarios that require high-precision and high-reliability control.

[0030] By precisely controlling the duty cycle of the PWM signal, the motor's operating performance and energy efficiency can be optimized. For example, in electric vehicles, by adjusting the duty cycle of the PWM signal, the motor speed and torque can be precisely controlled, thereby improving the vehicle's acceleration performance and driving stability. At the same time, precise duty cycle control can also reduce the motor's energy consumption and heat generation, extending the motor's service life.

[0031] Preferably, in S2, when setting the signal output mode of the ATOM channel, the effective level of the PWM output waveform is set to a high level.

[0032] Such a setting, setting the effective level of the PWM output waveform to a high level, can simplify the design of the motor control circuit. Because many motor drivers are designed to work at a high level input, there is no need for additional level conversion circuits to adapt to low-level effective PWM signals.

[0033] In addition, in some cases, high-level signals have better anti-interference ability than low-level signals. Setting the effective level of the PWM output waveform to a high level can reduce false triggering or signal loss caused by noise interference, thereby improving the stability and reliability of the system.

[0034] Preferably, in S2, when setting the signal output mode of the ATOM channel, the counting mode of the channel counter is set to the upward mode, and the reset condition of the counter is configured.

[0035] With this setting, the up-counting mode means that the counter starts from 0 and gradually increases until it reaches a preset value (such as the value of comparator CM0) and resets. This counting method can generate a stable PWM signal, whose frequency and duty cycle can be precisely controlled by adjusting the preset value and reset condition of the counter. This is crucial for application scenarios that require stable PWM signal output (such as motor control).

[0036] Moreover, the configuration of the up-counting mode and the counter reset condition is relatively simple and intuitive. By adjusting a few key parameters (such as the preset value of the counter, the reset condition, the clock frequency of the timer, and the prescaler value), the required PWM signal can be easily generated. This simplifies the configuration and debugging process of the PWM signal and reduces development cost and time.

[0037] Since the up-counting mode and counter reset conditions can be flexibly configured, the parameters of the PWM signal can be adjusted according to the requirements of different application scenarios. This flexibility enables the system to adapt to different motor types, control strategies and working environments, thereby enhancing the scalability and adaptability of the system.

[0038] Preferably, in S2, the signal output mode of the selected ATOM channel is the SOMP ATOM signal output mode.

[0039] SOMP (ATOM Signal Output Mode PWM) ATOM signal output mode allows ATOM channels to generate complex PWM signals. SOMP mode supports synchronous and asynchronous updates of the duty cycle and period of the PWM signal. Synchronous update means that the change of the duty cycle or period occurs after the end of the previous cycle, while asynchronous update allows changes during the actual running PWM cycle. This flexibility enables the PWM signal to adapt to different control strategies and working environments, improving the adaptability of the system. By configuring the relevant registers, the period, duty cycle, phase and other parameters of the PWM signal can be accurately controlled. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In order to make the purpose, technical solution and advantages of the invention more clear, the present invention will be further described in detail below with reference to the accompanying drawings, in which:

[0041] Figure 1 A flowchart of the method is shown in FIG.

[0042] Figure 2 It is a waveform diagram of an example in the embodiment. DETAILED DESCRIPTION

[0043] The following is a further detailed description through specific implementation methods:

[0044] Example:

[0045] like Figure 1 As shown, this embodiment discloses a PWM control method based on a microcontroller. For ease of description, during specific implementation, the microcontroller used may be a TC3xx series microcontroller.

[0046] The method comprises the following steps:

[0047] S1. Use the MCAL configuration tool to perform basic settings; the basic settings include PWM output port settings, GTM clock distribution, and GTMATOM channel configuration.

[0048] About PWM output port settings:

[0049] Use the MCAL configuration tool to set the direction, initial level, and function mode (such as PWM mode) of the PWM output port.

[0050] Generate corresponding functions and interfaces for subsequent steps to call.

[0051] About GTM clock distribution:

[0052] Use the MCAL configuration tool to assign GTM (Generic Timer Module) clock parameters to the PWM output.

[0053] These parameters will be used as the basic clock for PWM counting to control the frequency of the output waveform.

[0054] About GTM ATOM channel configuration:

[0055] Select a GTM-enabled port and a matching ATOM channel.

[0056] Configure the GTMA TOM channel, including hardware channel selection and matching pin selection.

[0057] Generate corresponding .c and .h files to provide function interface for upper-level software.

[0058] S2. Initialize the GTM and Port modules to prepare for the subsequent PWM output. Set the signal output mode (PWM mode) of the ATOM channel according to the PWM output requirements.

[0059] PORT module configuration: Taking pin P13.0 as an example, select the direction, level and mode of the PWM output pin as shown in the following table:

[0060] PORT PortPinDirection PortPinLevelValue PortPinInputPullResistor PortPinInitialMode RX Input / Pullup / TX Output Low / GTM muxed output

[0061] MCU module configuration: McuClockSettingConfig configures the GMT clock to 200 000 000 Hz, configures the frequency division factor of cluster 0 to 2, and configures the total clock frequency division factor of GTM: 1 / 1 (GCLK_NUM / GCLK_DEN). Through frequency division, the total GTM module clock is 200 000 000 / 2=100 000 000 Hz.

[0062] ATOM channel configuration: Select module ATOM2 channel CH5 hardware channel, pin PIN13.0 output port.

[0063] In specific implementation, the signal output mode of the selected ATOM channel is SOMP (ATOM Signal Output Mode PWM). The ATOM channel can generate simple and complex PWM output signals by comparing its operation register with the submodule internal counter. The ATOM shadow register can be reloaded by the CPU and the background ARU, while the channel operates on the operation register.

[0064] SOMP mode allows the ATOM channel to generate complex PWM signals. SOMP mode supports synchronous and asynchronous updates of the duty cycle and period of the PWM signal. Synchronous update means that the change of the duty cycle or period occurs after the end of the previous cycle, while asynchronous update allows changes during the actual running PWM cycle. This flexibility enables the PWM signal to adapt to different control strategies and working environments, improving the adaptability of the system. By configuring the relevant registers, the period, duty cycle, phase and other parameters of the PWM signal can be accurately controlled.

[0065] In specific implementation, when setting the signal output mode of the ATOM channel, set the effective level of the PWM output waveform to a high level. In this way, setting the effective level of the PWM output waveform to a high level can simplify the design of the motor control circuit. Because many motor drivers are designed to work at a high level input, there is no need for additional level conversion circuits to adapt to low-level effective PWM signals. In addition, in some cases, high-level signals have better anti-interference capabilities than low-level signals. Setting the effective level of the PWM output waveform to a high level can reduce false triggering or signal loss caused by noise interference, thereby improving the stability and reliability of the system.

[0066] Set the counting mode of the channel counter to the up mode and configure the reset condition of the counter. In this way, the up counting mode means that the counter starts from 0 and gradually increases until it reaches a preset value (such as the value of comparator CM0) and resets. This counting method can generate a stable PWM signal, whose frequency and duty cycle can be precisely controlled by adjusting the preset value and reset condition of the counter. This is crucial for application scenarios that require stable PWM signal output (such as motor control). In addition, the configuration of the up counting mode and the counter reset condition is relatively simple and intuitive. By adjusting several key parameters (such as the preset value of the counter, the reset condition, the clock frequency of the timer, and the prescaler value), the required PWM signal can be easily generated. This simplifies the configuration and debugging process of the PWM signal and reduces development costs and time. In addition, since the up counting mode and the counter reset condition can be flexibly configured, the parameters of the PWM signal can be adjusted according to the requirements of different application scenarios. This flexibility enables the system to adapt to different motor types, control strategies, and working environments, thereby enhancing the scalability and adaptability of the system.

[0067] S3. Based on the GTM clock and the counting mode of the ATOM counter, the ATOM comparator value is set to control the frequency and duty cycle of the PWM signal and is stored in the register.

[0068] The set comparator values ​​include CM0 and CM1; CM0 is the duration of the cycle of the PWM signal, which is used to control the frequency of the PWM signal; CM1 is the duration of the duty cycle of the clock beat, which is used to control the duty cycle of the PWM signal.

[0069] In this way, the frequency of the PWM signal can be precisely controlled. CM0 is the duration of the cycle of the PWM signal, and its value directly determines the frequency of the PWM signal. By accurately setting the value of CM0, this method can achieve flexible adjustment of the frequency of the PWM signal, thereby meeting the frequency requirements in different application scenarios. This ability to accurately control the frequency makes the motor control more stable and responsive, improving the overall performance of the system. In addition, the duty cycle of the PWM signal can also be precisely controlled. CM1 is the duration of the duty cycle of the clock beat, and its value determines the high level time of the PWM signal within a cycle, that is, the duty cycle. By adjusting the value of CM1, this method can accurately control the duty cycle of the PWM signal, thereby achieving fine adjustment of parameters such as motor speed and power. This ability to accurately control the duty cycle makes motor control more precise and efficient, improving energy utilization and system efficiency.

[0070] To set the ATOM channel related parameters, you can enable the ATOM channel by configuring the ATOMi_AGC related registers, and set the ATOM channel mode and CN0 counting mode through the ATOMi_CHi_SOMP register. The specific register bit settings are as follows:

[0071] 1) Set the ATOM channel transmission mode bit MODE = 10: SOMP mode;

[0072] 2) Bit SR0_TRIG = 0: Use SR0 as the shadow register of CM0;

[0073] 3) SL = 1: High Level;

[0074] 4) Bit RST_CCU0 = 0: When the CN0 counter value reaches the comparator CM0 Reset is 0;

[0075] 5) Bit UDMODE = 00: CN0 is in continuous up counting mode.

[0076] S4. Output the corresponding PWM signal according to the setting.

[0077] In a specific implementation, when the count value of the counter CN0 reaches the comparator CM0, the counter is reset and a rising edge or a falling edge of the PWM signal is generated.

[0078] In this way, the reset of counter CN0 ensures that the PWM signal has a fixed period. Whenever the counter reaches the value set by CM0, it will restart counting, thus forming a stable period. This is the basis for achieving stable speed and performance when the PWM signal controls devices such as motors. In addition, by accurately setting the value of comparator CM0, the generation time of the rising or falling edge of the PWM signal can be accurately controlled. This is crucial for applications that require precise control of the start and stop moments of the motor, adjustment of the speed, or implementation of specific control strategies. Due to the precise counting of the counter and the precise comparison of the comparator, the generated PWM signal has high accuracy and stability. This helps to reduce noise and jitter in motor control and improve the overall performance and reliability of the system. In addition, by adjusting the value of comparator CM0 and the counting mode of the counter (such as increasing, decreasing or bidirectional counting, etc.), PWM signals of different modes can be generated, such as standard PWM, reverse PWM, center-aligned PWM, etc. This increases the flexibility and adaptability of the PWM control method, enabling it to meet the needs of different application scenarios.

[0079] When the count value of the counter CN0 exceeds CM1, the output level of the PWM signal is changed, thereby controlling the duty cycle of the PWM signal.

[0080] By accurately setting the value of comparator CM1, the high level time of the PWM signal within one cycle, that is, the duty cycle, can be accurately controlled. Duty cycle is a very important parameter in PWM control, which directly determines the average voltage and speed of the motor. Therefore, this technical content enables the PWM control method to achieve precise adjustment of the motor speed and performance. In addition, since the value of comparator CM1 can be flexibly set, PWM signals with different duty cycles can be generated to meet the needs of different application scenarios. This flexibility enables the PWM control method to be widely used in various motor control, LED dimming, steering gear control and other fields. Since the duty cycle of the PWM signal can be accurately controlled, the noise and jitter in the motor control can be reduced, and the overall stability and reliability of the system can be improved. This is especially important for application scenarios that require high-precision and high-reliability control. In addition, by accurately controlling the duty cycle of the PWM signal, the operating performance and energy efficiency of the motor can be optimized. For example, in electric vehicles, by adjusting the duty cycle of the PWM signal, the motor speed and torque can be accurately controlled, thereby improving the acceleration performance and driving stability of the vehicle. At the same time, accurate control of the duty cycle can also reduce the energy consumption and heat generation of the motor and extend the service life of the motor.

[0081] The PWM frequency and duty cycle are controlled by counters and comparators. The output PWM frequency is determined by setting the comparison count value through ATOMi_CHi_SR0 / CM0, and the output PWM duty cycle is determined by setting the comparison count value through ATOMi_CHi_SR1 / CM1. Taking the PWM waveform with an output frequency of 1khz and a duty cycle of 60% as an example, the specific register settings are as follows:

[0082] 1) CM0 = SR0: The comparator count value determines the PWM cycle. Here, the count is set to 100000. The output PWM waveform frequency after conversion based on 100 000000 Hz should be (1*10 8 *100000) / (1*10 8 )=1000hz, when CN0 counts from 0 to 99999 and then resets to 0, when CN0 resets from 100000 to 0, an edge to the high level is generated.

[0083] 2) CM1 = SR1: SR1 is the shadow register of CM1 and determines the PWM duty cycle. Here it is set to 100000*0.6 (the output PWM waveform duty cycle is 60%). When CN0 increases and reaches CN0>60000, a low level edge is generated.

[0084] S5. Use the output PWM signal to control the device to achieve precise control effect.

[0085] This method has high configuration flexibility. By using the MCAL (Microcontroller Abstraction Layer) configuration tool, this technical solution can easily perform basic settings such as PWM output port settings, GTM (Global Timer Module) clock distribution, and GTMATOM (Global Timer ATOM) channel configuration. This configuration method not only simplifies the development process, but also improves the flexibility of configuration, allowing developers to quickly adjust PWM control parameters according to different application scenarios. In addition, the initialization process of this method is clear and efficient. When initializing the GTM and Port modules, this method clearly sets the signal output mode of the ATOM channel according to the PWM output requirements and stores it in the register. This step ensures the stability and consistency of the PWM signal output, while improving the efficiency of the initialization process, laying the foundation for the subsequent precise control of the PWM signal.

[0086] This method can also accurately control the frequency and duty cycle of the PWM signal. Through the counting mode based on the GTM clock and the ATOM counter, the technical solution can accurately set the ATOM comparator value, thereby realizing accurate control of the frequency and duty cycle of the PWM signal. This control method not only improves the accuracy of the PWM signal, but also makes the motor control more stable and reliable, meeting the needs of the automotive industry and other fields for high-precision and high-efficiency motor control. In addition, this method is easy to implement and has strong adaptability. The steps of this technical solution are clear and easy to implement, and through flexible configuration and precise control, the PWM signal can adapt to the diverse needs in different application scenarios. Whether in motor control in the automotive industry or in other fields that require precise control of PWM signals, this method has demonstrated strong adaptability and practicality.

[0087] This method is flexible in configuration, easy to implement, and can accurately control the PWM signal frequency and duty cycle. By using the MCAL configuration tool for basic settings, explicitly and efficiently initializing the GTM and Port modules, and accurately setting the ATOM comparator value, this technical solution achieves accurate control of the PWM signal. This control method not only improves the accuracy and stability of motor control, but also meets the needs of the automotive industry and other fields for high-precision and high-efficiency motor control, showing strong application potential and market value.

[0088] In order to better illustrate the effect of this method, the following example is given.

[0089] Taking the PWM waveform with an output frequency of 1khz and a duty cycle of 60% as an example, the specific implementation is carried out based on the single-board (Tc36x development board) experimental environment, using the driver layer configuration tool EB tresos, compiler Tasking, debugging tool UDE, oscilloscope, and power supply for software development, debugging, and data acquisition. Through EB tresos, the GTM module clock is assigned to 1Khz, and the pin P13.0 with the GTMmuxed output function is assigned as the output pin. The corresponding channel resource is ATOM2CH5, and the ATOM channel register is set as follows:

[0090] GTM_ATOM2_CH5_SOMP.U=0x01000802U;

[0091] GTM_ATOM2_CH5_CN0.U=0x00000000U;

[0092] GTM_ATOM2_CH5_CM0.U=100000;

[0093] GTM_ATOM2_CH5_CM1.U = 0;

[0094] GTM_ATOM2_CH5_SR0.U=100000;

[0095] GTM_ATOM2_CH5_SR1.U=100000*0.6;

[0096] After running the code to initialize the module and enable the channel, view the relevant register values ​​through UDE and the P13.0 pin waveform through an oscilloscope. Figure 2 As shown in the figure, the frequency and duty cycle of the PWM signal generated by the method of the present invention can be precisely controlled as needed, and the generated PWM signal has less jitter and good stability. By flexibly using the frequency, duty cycle and SOMP mode, various dead zones, mutually exclusive and scalable multi-type PWM can be output more controllably to more efficiently control various drives.

[0097] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit the technical solution. Those skilled in the art should understand that those modifications or equivalent substitutions of the technical solution of the present invention that do not depart from the purpose and scope of the technical solution should be included in the scope of the claims of the present invention.

Claims

1. A PWM control method based on a microcontroller, characterized in that: The following steps are involved: S1. Use the MCAL configuration tool to perform basic settings; basic settings include PWM output port settings, GTM clock distribution, and GTM ATOM channel configuration; S2, initialize GTM and Port modules; According to the PWM output requirements, set the signal output mode of the ATOM channel; S3, based on the GTM clock and the counting mode of the ATOM counter, set the ATOM comparator value to control the frequency and duty cycle of the PWM signal and store it in the register; S4, output corresponding PWM signal according to the setting; S5. Use the output PWM signal to control the device to achieve precise control effect.

2. The microcontroller-based PWM control method according to claim 1, characterized in that: In S3, the set comparator values ​​include CM0 and CM1; CM0 is the duration of the cycle of the PWM signal, which is used to control the frequency of the PWM signal; CM1 is the duration of the duty cycle of the clock beat, which is used to control the duty cycle of the PWM signal.

3. The microcontroller-based PWM control method according to claim 2, characterized in that: In S4 , when the count value of the counter CN0 reaches the comparator CM0 , the counter is reset and a rising edge or a falling edge of the PWM signal is generated.

4. The microcontroller-based PWM control method according to claim 2, characterized in that: In S4, when the count value of the counter CN0 exceeds CM1, the output level of the PWM signal is changed, thereby controlling the duty cycle of the PWM signal.

5. The microcontroller-based PWM control method according to claim 1, characterized in that: In S2, when setting the signal output mode of the ATOM channel, the effective level of the PWM output waveform is set to a high level.

6. The microcontroller-based PWM control method according to claim 5, characterized in that: In S2, when setting the signal output mode of the ATOM channel, set the counting mode of the channel counter to the upward mode, and configure the reset condition of the counter.

7. The microcontroller-based PWM control method according to claim 6, characterized in that: In S2, the signal output mode of the selected ATOM channel is SOMP ATOM signal output mode.