Pulse width modulation wave generation method and device, storage medium and electronic equipment
By dynamically updating the number of sampling points in PWM wave generation, the overflow and response speed limitation of traditional counter methods are solved, and the high-precision and stable output of PWM waveform is achieved, which is suitable for models such as motor control and LED dimming.
Patent Information
- Application Number
- CN202510575353.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-06
- Publication Date
- 2025-07-22
AI Technical Summary
The traditional fixed-period counter method is difficult to meet the time continuity and accuracy requirements when generating PWM waves, especially when the input frequency and duty cycle change, resulting in counter overflow and limited response speed.
By obtaining the input frequency, duty cycle and count variables of the current frame, the sampling point update conditions are determined, and the sampling point number is updated according to the offset, proportion and duty cycle of the PWM period and the simulation scheduling period, and the PWM wave output result is generated. A flexible and variable counter mechanism is used to avoid overflow and adapt to dynamic needs.
It realizes high-precision and stable output of PWM module in complex dynamic environments, solves the problems of counter overflow and limited response speed, and ensures the continuity and accuracy of PWM waveforms.
Smart Images

Figure CN120353150A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of simulation control technology, and particularly to a method, device, storage medium and electronic device for generating a pulse width modulation wave. Background Art
[0002] Pulse width modulation (PWM) waves are widely used in fields such as motor control, signal modulation, and power electronics. When generating PWM waves in a simulation environment, since the input frequency and duty cycle may change, and there may be a non-integer multiple relationship between the simulation step size and the PWM period, the traditional fixed-period counter method is difficult to meet the requirements of time continuity and accuracy. Summary of the Invention
[0003] The technical problem to be solved by this application is to provide a method, device, storage medium and electronic device for generating a pulse width modulation wave, which can solve the problem that the traditional fixed-period counter method is difficult to meet the requirements of time continuity and accuracy. The specific solutions are as follows:
[0004] A method for generating a pulse width modulation wave, the method includes:
[0005] During the process of simulating a control model, obtain the input frequency, duty cycle, number of sampling points, and counting variable of the current frame;
[0006] Determine whether a preset sampling point update condition is satisfied according to the frequency of the current frame and the counting variable;
[0007] When the sampling point update condition is satisfied, update the number of sampling points according to the offset between the PWM period of the pulse width modulation wave and the simulation scheduling period, the proportion of the offset in the PWM period, the input frequency, and the duty cycle;
[0008] Generate the PWM wave output result of the current frame according to the updated number of sampling points and the counting variable.
[0009] For the above method, optionally, the determining whether a preset sampling point update condition is satisfied according to the frequency of the current frame and the counting variable includes:
[0010] When the counting variable is not zero, obtain the historical input frequency of the previous frame of the current frame. If the input frequency of the current frame is the same as the historical input frequency of the previous frame, it is determined that the preset sampling point update condition is not satisfied; if the input frequency of the current frame is different from the historical input frequency of the previous frame, it is determined that the preset sampling point update condition is satisfied;
[0011] When the counting variable is zero, it is determined that the preset sampling point update condition is satisfied.
[0012] Optionally, the above method further includes:
[0013] When the sampling point update condition is not satisfied, generate the PWM wave output result of the current frame according to the number of sampling points and the count variable.
[0014] Optionally, for the above method, the step of updating the number of sampling points according to the offset between the PWM period of the pulse width modulation wave and the simulation scheduling period, the ratio of the offset to the PWM period, the input frequency, and the duty cycle includes:
[0015] Calculate the current period according to the input frequency;
[0016] Calculate the target total number of sampling points according to the current period, the offset between the PWM period of the pulse width modulation wave and the simulation scheduling period, and the simulation step size;
[0017] Calculate the number of high-level sampling points of the target according to the ratio of the offset to the PWM period and the duty cycle;
[0018] Use the target total number of sampling points and the number of high-level sampling points of the target as the updated number of sampling points.
[0019] Optionally, after generating the PWM wave output result of the current frame, the above method includes:
[0020] Update the count variable, the offset, and the ratio of the offset to the PWM period, and return to execute the step of obtaining the input frequency, duty cycle, number of sampling points, and count variable of the current frame until the simulation ends.
[0021] A pulse width modulation wave generating device includes:
[0022] An acquisition unit, configured to acquire the input frequency, duty cycle, number of sampling points, and count variable of the current frame during the simulation of the control model;
[0023] A determination unit, configured to determine whether a preset sampling point update condition is satisfied according to the frequency of the current frame and the count variable;
[0024] An update unit, configured to update the number of sampling points according to the offset between the PWM period of the pulse width modulation wave and the simulation scheduling period, the ratio of the offset to the PWM period, the input frequency, and the duty cycle when the sampling point update condition is satisfied;
[0025] A generation unit, configured to generate the PWM wave output result of the current frame according to the updated number of sampling points and the count variable.
[0026] The above-mentioned device, optionally, the determining unit includes:
[0027] A first execution subunit, configured to, when the count variable is not zero, obtain the historical input frequency of the previous frame of the current frame. If the input frequency of the current frame is the same as the historical input frequency of the previous frame, it is determined that the preset sampling point update condition is not satisfied; if the input frequency of the current frame is different from the historical input frequency of the previous frame, it is determined that the preset sampling point update condition is satisfied;
[0028] A second execution subunit, configured to, when the count variable is zero, determine that the preset sampling point update condition is satisfied.
[0029] The above-mentioned device, optionally, further includes:
[0030] A generating unit, configured to, when the sampling point update condition is not satisfied, generate a PWM wave output result of the current frame according to the number of sampling points and the count variable. A storage medium, the storage medium includes stored instructions, wherein when the instructions run, the device where the storage medium is located is controlled to execute the pulse width modulation wave generation method as described above.
[0031] An electronic device includes a memory, and one or more instructions, wherein one or more instructions are stored in the memory and are configured to be executed by one or more processors to execute the pulse width modulation wave generation method as described above.
[0032] Based on the pulse width modulation wave generation method and system provided by the embodiments of the present application described above, the method includes: during the process of controlling model simulation, obtaining the input frequency, duty cycle, number of sampling points, and count variable of the current frame; determining whether the preset sampling point update condition is satisfied according to the frequency of the current frame and the count variable; when the sampling point update condition is satisfied, updating the number of sampling points according to the offset between the pulse width modulation wave PWM period and the simulation scheduling period, the proportion of the offset in the PWM period, the input frequency, and the duty cycle; generating a PWM wave output result of the current frame according to the updated number of sampling points and the count variable. Applying the method provided by the embodiments of the present application can accurately simulate the continuous time process and ensure the high precision and stability of the output of the PWM module. Description of the Drawings
[0033] To more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only the embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on the provided drawings.
[0034] Figure 1 It is a flowchart of a method for generating a pulse width modulation wave provided by the present application;
[0035] Figure 2 It is a flowchart of a process for generating a pulse width modulation wave provided by the present application;
[0036] Figure 3 It is an example diagram of inputting a variable into a PWM generator module provided by the present application;
[0037] Figure 4 It is an example diagram of a PWM wave provided by the present application;
[0038] Figure 5 It is an example diagram of a period offset provided by the present application;
[0039] Figure 6 It is a schematic structural diagram of a pulse width modulation wave generating device provided by the present application;
[0040] Figure 7 It is a schematic structural diagram of an electronic device provided by the present application. Detailed implementation manners
[0041] The following will clearly and completely describe the technical solutions in the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments of the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present application.
[0042] In the present application, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, the element defined by the statement "including one..." does not exclude the existence of another identical element in the process, method, article or device including the said element.
[0043] Currently, implementing PWM (Pulse Width Modulation) waves using a counter is a common method, but it also has some limitations and drawbacks in specific scenarios, mainly reflected in: (1) The overflow problem of the counter: The number of bits of the counter determines its maximum count value. When the count value exceeds this value, it will overflow. In a system running for a long time, the overflow will cause abnormalities in the frequency or duty cycle of the PWM signal, thereby affecting the stability of the system. (2) Inability to adapt to dynamic requirements: The PWM wave implemented using a counter usually has a fixed frequency and a fixed duty cycle. In a dynamic system (such as motor speed control, frequency converter, audio signal generation, etc.), the response speed may be limited. Especially when the duty cycle changes rapidly, obvious control lag may occur.
[0044] Based on this, the embodiments of the present application provide a method for generating a pulse width modulation wave. This method can be applied to electronic devices. The flowchart of the method is as Figure 1 shown and specifically includes:
[0045] S101: During the process of controlling model simulation, obtain the input frequency, duty cycle, number of sampling points, and count variable of the current frame.
[0046] In this embodiment, the control model can be various simulation models involving pulse width modulation PWM, such as motor control, LED dimming, and other models.
[0047] S102: Determine whether the preset sampling point update condition is satisfied according to the frequency of the current frame and the count variable.
[0048] In this embodiment, if the count variable is zero, or the count variable is not zero and the input frequency of the current frame is inconsistent with the historical input frequency of the previous frame, it is determined that the count variable satisfies the preset sampling point update condition; if the count variable is not zero and the input frequency of the current frame is consistent with the historical input frequency of the previous frame, it can be determined that the count variable does not satisfy the sampling point update condition.
[0049] In an embodiment provided by the present application, based on the above solution, optionally, the process of determining whether the preset sampling point update condition is satisfied according to the frequency of the current frame and the count variable includes:
[0050] When the count variable is not zero, obtain the historical input frequency of the previous frame of the current frame. If the input frequency of the current frame is consistent with the historical input frequency of the previous frame, it is determined that the preset sampling point update condition is not satisfied; if the input frequency of the current frame is inconsistent with the historical input frequency of the previous frame, it is determined that the preset sampling point update condition is satisfied;
[0051] When the count variable is zero, it is determined that the preset sampling point update condition is satisfied.
[0052] In this embodiment, it is possible to first determine whether the counting variable is zero. When the counting variable is not zero, it indicates that a new counting cycle has not been entered. It is possible to determine whether the input frequency of the current frame is the same as the historical input frequency of the previous frame. If they are the same, it means that the output signal does not need to be updated. In this case, the sampling points can be not updated, that is, it is determined that the sampling point condition is not satisfied. If they are not the same, it is determined that the output signal needs to be updated. In this case, it can be determined that the sampling point update condition is satisfied. When the counting variable is zero, it indicates that a new counting cycle has been entered. In this case, it can be determined that the sampling point update condition is satisfied.
[0053] In an embodiment provided by the present application, based on the above solution, optionally, it further includes:
[0054] When the sampling point update condition is not satisfied, generate the PWM wave output result of the current frame according to the number of sampling points and the counting variable.
[0055] S103: When the sampling point update condition is satisfied, update the number of sampling points according to the offset between the PWM period of the pulse width modulation wave and the simulation scheduling period, the proportion of the offset in the PWM period, the input frequency, and the duty cycle.
[0056] In an embodiment provided by the present application, based on the above solution, optionally, the updating the number of sampling points according to the offset between the PWM period of the pulse width modulation wave and the simulation scheduling period, the proportion of the offset in the PWM period, the input frequency, and the duty cycle includes:
[0057] Calculate the current period according to the input frequency;
[0058] Calculate the target total number of sampling points according to the current period, the offset between the PWM period of the pulse width modulation wave and the simulation scheduling period, and the simulation step size;
[0059] Calculate the number of target high-level sampling points according to the proportion of the offset in the PWM period and the duty cycle;
[0060] Use the target total number of sampling points and the number of target high-level sampling points as the updated number of sampling points.
[0061] S104: Generate the PWM wave output result of the current frame according to the updated number of sampling points and the counting variable.
[0062] In an embodiment provided by the present application, based on the above solution, optionally, after generating the PWM wave output result of the current frame, it includes:
[0063] Update the count variable, offset, and the proportion of the offset in the PWM period, and return to execute the steps of obtaining the input frequency, duty cycle, number of sampling points, and count variable of the current frame until the simulation ends.
[0064] Applying the method provided in the embodiments of the present application, during the simulation of the control model, obtain the input frequency, duty cycle, number of sampling points, and count variable of the current frame; determine whether the preset sampling point update condition is satisfied according to the frequency of the current frame and the count variable; when the sampling point update condition is satisfied, update the number of sampling points according to the offset between the pulse width modulation wave (PWM) period and the simulation scheduling period, the proportion of the offset in the PWM period, the input frequency, and the duty cycle; generate the PWM wave output result of the current frame according to the updated number of sampling points and the count variable. Applying the method provided in the embodiments of the present application can accurately simulate the continuous-time process and ensure the high precision and stability of the output of the PWM module.
[0065] See Figure 2 , which is a flowchart of a pulse width modulation wave generation process provided by the present application, including the following steps:
[0066] Step 1: Obtain the input frequency and duty cycle, and determine the required variables.
[0067] In this embodiment, as Figure 3 shown, variables with a frequency of 1 HZ and a duty cycle of 0.5 can be input into the PWM generator module of the simulation model. If the frequency does not change within the period, the PWM waveform generated based on this frequency and duty cycle can be as Figure 4 shown.
[0068] In this embodiment, the required variables are as follows:
[0069] (1) The frequency PWMGenerator_preFVal and duty cycle variable PWMGenerator_preDVal of the previous frame, and the frequency PWMGenerator_curFVal and duty cycle variable PWMGenerator_curDVal of the current frame. Optionally, it is possible to determine whether it is necessary to recalculate the total number of sampling points and the number of high-level sampling points by comparing the frequencies of the previous and current frames; when the duty cycle changes, update the output signal in the next PWM period.
[0070] (2) The count variable PWMGenerator_counter. The count variable is a periodically reset count variable, which is used to replace the traditional counter to avoid overflow problems and is suitable for adapting to the generation of PWM waves with infinite time.
[0071] (3) The number of sampling points in one period, PWMGenerator_fCycleNumStep. The number of sampling points represents the number of sampling points in one PWM period, which is calculated based on the input frequency and the simulation sampling step, and the influence of the offset is also considered.
[0072] (4) The number of high-level sampling points, PWMGenerator_DutySteps, represents the number of high-level sampling points in one counting period. The output value of the PWM wave is determined by comparing this variable with the counting variable.
[0073] (5) Record the offset, PWMGenerator_fractionalPart, which records the offset between the PWM period and the simulation sampling period and is used to update the variables in the next period.
[0074] (6) The ratio of the offset to the whole period, WMGenerator_ratio, is used to accurately simulate the PWM wave output in continuous time and achieve period connection between simulation steps.
[0075] Step 2: Update the number of sampling points. In this embodiment, the condition for updating the number of sampling points is that the current frame frequency changes compared with the previous frame frequency; or the counting variable is equal to 0.
[0076] The update process is as follows:
[0077] a. Calculate the period according to the current frame frequency. The calculation method is: period = 1 / frequency.
[0078] b. Subtract the offset part from the period: the adjusted period = period - offset.
[0079] c. Calculate the total number of sampling points, specifically as follows:
[0080] The total number of sampling points = simulation step / adjusted period
[0081] d. Saturate the duty cycle: if the duty cycle is greater than 1, set it to 1; if it is less than 0, set it to 0.
[0082] e. Calculate the number of high-level sampling points according to the offset ratio and the duty cycle.
[0083] In this embodiment, if the offset ratio is greater than the duty cycle, the number of high-level sampling points is set to 0; otherwise: the number of high-level sampling points = (duty cycle - offset ratio) × period / simulation step.
[0084] Step 3: Determine the output of the current frame.
[0085] In this embodiment, the current frame output can be determined in combination with the counting variable according to the total number of sampling points and the number of high-level sampling points calculated in step 2.
[0086] In this embodiment, if the counting variable is less than the number of high-level sampling points, output 1; otherwise output 0.
[0087] Step 4: Update the counting variable.
[0088] In this embodiment, after the judgment in step 3 is completed, the counting variable is incremented by 1. If the counting variable is greater than or equal to the total number of sampling points, the counting variable is reset to 0 and enters the next cycle.
[0089] Step 5: Calculate the offset and its ratio.
[0090] In this embodiment, when the counting variable is greater than or equal to the total number of sampling points, it indicates that one counting cycle has ended. Refer to Figure 5 , since there may be a non-integer multiple relationship between the PWM period and the simulation sampling period, it is necessary to calculate the offset part of the next period and its proportion in the whole period for use when updating the total number of sampling points and the number of high-level sampling points.
[0091] In this embodiment, the counter overflow problem is solved by introducing a periodic reset mechanism, and the requirement of adapting to the uncertainty of the relationship between the PWM waveform period and the simulation scheduling period (sampling period) is met. This mechanism automatically resets to zero when the counter reaches the set threshold, effectively avoiding floating-point overflow and improving accuracy. In particular, for the variability of the PWM wave period and duty cycle, the non-divisibility between the PWM wave period and the scheduling period, and the case where the PWM wave period may be less than the scheduling period, the embodiments of the present application provide a flexible and variable reset counter, which takes into account the remaining part of the previous period and aims to simulate the continuous-time process as accurately as possible to ensure the high precision and stability of the PWM module output. The embodiments of the present application provide a more flexible PWM wave generation algorithm applicable to an infinite time range to solve the data overflow and precision problems and improve the applicability and response speed of the PWM wave in a complex dynamic environment.
[0092] Corresponding to Figure 1 the method described above, the embodiments of the present application also provide a pulse width modulation wave generation device, which is applied to an electronic device and used for Figure 1 the specific implementation of the method in Figure 6 as shown, and includes:
[0093] An acquisition unit 601, configured to acquire the input frequency, duty cycle, number of sampling points, and counting variable of the current frame during the control model simulation;
[0094] A determination unit 602, configured to determine whether a preset sampling point update condition is satisfied according to the frequency of the current frame and the count variable;
[0095] An update unit 603, configured to update the number of sampling points according to the offset between the pulse width modulation wave PWM period and the simulation scheduling period, the ratio of the offset to the PWM period, the input frequency, and the duty cycle when the sampling point update condition is satisfied;
[0096] A generation unit 604, configured to generate a PWM wave output result of the current frame according to the updated number of sampling points and the count variable.
[0097] In an embodiment provided by the present application, based on the above solution, optionally, the determination unit includes:
[0098] A first execution subunit, configured to obtain the historical input frequency of the previous frame of the current frame when the count variable is not zero. If the input frequency of the current frame is the same as the historical input frequency of the previous frame, it is determined that the preset sampling point update condition is not satisfied; if the input frequency of the current frame is different from the historical input frequency of the previous frame, it is determined that the preset sampling point update condition is satisfied;
[0099] A second execution subunit, configured to determine that the preset sampling point update condition is satisfied when the count variable is zero.
[0100] In an embodiment provided by the present application, based on the above solution, optionally, the PWM wave generating device further includes:
[0101] A generation unit, configured to generate a PWM wave output result of the current frame according to the number of sampling points and the count variable when the sampling point update condition is not satisfied.
[0102] In an embodiment provided by the present application, based on the above solution, optionally, the update unit includes:
[0103] A first calculation subunit, configured to calculate a current period according to the input frequency;
[0104] A second calculation subunit, configured to calculate a target total number of sampling points according to the current period, the offset between the pulse width modulation wave PWM period and the simulation scheduling period, and the simulation step size;
[0105] A third calculation subunit, configured to calculate a target number of high-level sampling points according to the ratio of the offset to the PWM period and the duty cycle;
[0106] An update subunit, configured to use the target total number of sampling points and the target number of high-level sampling points as the updated number of sampling points.
[0107] In an embodiment provided by the present application, based on the above solution, optionally, the pulse width modulation wave generation device further includes:
[0108] An execution unit, configured to update a count variable, an offset, and a proportion of the offset in the PWM period, and return to trigger the acquisition unit to execute the steps of acquiring the input frequency, duty cycle, number of sampling points, and count variable of the current frame until the simulation ends.
[0109] The specific principles and execution processes of each unit and module in the pulse width modulation wave generation device disclosed in the embodiments of the present application are the same as those of the pulse width modulation wave generation method disclosed in the embodiments of the present application. Reference can be made to the corresponding parts in the pulse width modulation wave generation method provided in the embodiments of the present application, and details will not be elaborated here.
[0110] The embodiments of the present application further provide a storage medium, where the storage medium includes stored instructions. When the instructions run, the device where the storage medium is located is controlled to execute the above-mentioned pulse width modulation wave generation method.
[0111] The embodiments of the present application further provide an electronic device, and its structural schematic diagram is as Figure 7 shown, specifically including a memory 701 and one or more instructions 702. One or more instructions 702 are stored in the memory 701 and are configured to be executed by one or more processors 703 to execute the above-mentioned pulse width modulation wave generation method.
[0112] It should be noted that the embodiments in this specification are all described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The same or similar parts among the embodiments can be referred to each other. For device embodiments, since they are basically similar to method embodiments, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiments.
[0113] Finally, it should also be noted that in this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations.
[0114] For the convenience of description, when describing the above device, various units are described separately according to their functions. Of course, when implementing the present application, the functions of each unit can be implemented in one or more software and / or hardware.
[0115] As can be seen from the description of the above embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of this application, in essence, or the part that makes a contribution to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions for causing a computer device (which can be a personal computer, a server, etc.) to execute the methods described in various embodiments or some parts of the embodiments of this application.
[0116] The above has introduced in detail a method for generating a pulse width modulation wave provided by this application. Specific examples are used in this article to elaborate on the principle and implementation manner of this application. The description of the above embodiments is only used to help understand the method and its core idea of this application; at the same time, for those of ordinary skill in the art, according to the idea of this application, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to this application.
Claims
1. A pulse width modulation wave generation method, characterized in that, Including: During the process of controlling model simulation, obtain the input frequency, duty cycle, number of sampling points, and count variable of the current frame; Determine whether a preset sampling point update condition is satisfied according to the frequency of the current frame and the count variable; When the sampling point update condition is satisfied, update the number of sampling points according to the offset between the PWM period of the pulse width modulation wave and the simulation scheduling period, the proportion of the offset in the PWM period, the input frequency, and the duty cycle; Generate the PWM wave output result of the current frame according to the updated number of sampling points and the count variable.
2. The method according to claim 1, wherein The determining whether a preset sampling point update condition is satisfied according to the frequency of the current frame and the count variable includes: When the count variable is not zero, obtain the historical input frequency of the previous frame of the current frame. If the input frequency of the current frame is the same as the historical input frequency of the previous frame, it is determined that the preset sampling point update condition is not satisfied; if the input frequency of the current frame is different from the historical input frequency of the previous frame, it is determined that the preset sampling point update condition is satisfied; When the count variable is zero, it is determined that the preset sampling point update condition is satisfied.
3. The method according to claim 1 or 2, characterized in that, Also including: When the sampling point update condition is not satisfied, generate the PWM wave output result of the current frame according to the number of sampling points and the count variable.
4. The method according to claim 1, wherein The updating the number of sampling points according to the offset between the PWM period of the pulse width modulation wave and the simulation scheduling period, the proportion of the offset in the PWM period, the input frequency, and the duty cycle includes: Calculate the current period according to the input frequency; Calculate the target total number of sampling points according to the current period, the offset between the PWM period of the pulse width modulation wave and the simulation scheduling period, and the simulation step size; Calculate the number of target high-level sampling points according to the proportion of the offset in the PWM period and the duty cycle; Use the target total number of sampling points and the number of target high-level sampling points as the updated number of sampling points.
5. The method according to claim 1, wherein After generating the PWM wave output result of the current frame, it includes: Update the count variable, offset, and the proportion of the offset in the PWM period, and return to execute the step of obtaining the input frequency, duty cycle, number of sampling points, and count variable of the current frame until the simulation ends.
6. A pulse width modulation wave generating device, characterized in that, Including: An acquisition unit for obtaining the input frequency, duty cycle, number of sampling points, and count variable of the current frame during the process of controlling model simulation; A determination unit for determining whether a preset sampling point update condition is satisfied according to the frequency of the current frame and the count variable; An update unit for updating the number of sampling points according to the offset between the PWM period of the pulse width modulation wave and the simulation scheduling period, the proportion of the offset in the PWM period, the input frequency, and the duty cycle when the sampling point update condition is satisfied; A generation unit for generating the PWM wave output result of the current frame according to the updated number of sampling points and the count variable.
7. The device according to claim 6, characterized in that, The determination unit includes: The first execution subunit is configured to, when the counting variable is not zero, obtain the historical input frequency of the previous frame of the current frame. If the input frequency of the current frame is the same as the historical input frequency of the previous frame, it is determined that the preset sampling point update condition is not satisfied; if the input frequency of the current frame is different from the historical input frequency of the previous frame, it is determined that the preset sampling point update condition is satisfied. The second execution subunit is configured to, when the counting variable is zero, determine that the preset sampling point update condition is satisfied.
8. The device according to claim 6 or 7, characterized in that, It further includes: The generating unit is configured to, when the sampling point update condition is not satisfied, generate the PWM wave output result of the current frame according to the number of sampling points and the counting variable.
9. A storage medium, characterized in that, The storage medium includes stored instructions, wherein when the instructions run, they control the device where the storage medium is located to execute the pulse width modulation wave generation method according to any one of claims 1 to 5.
10. An electronic device, characterized in that, It includes a memory and one or more instructions, wherein one or more instructions are stored in the memory and are configured to be executed by one or more processors to execute the pulse width modulation wave generation method according to any one of claims 1 to 5.