CN114221642A - PWM wave generation and duty ratio control method, device, timer and equipment - Google Patents
PWM wave generation and duty ratio control method, device, timer and equipment Download PDFInfo
- Publication number
- CN114221642A CN114221642A CN202210159333.3A CN202210159333A CN114221642A CN 114221642 A CN114221642 A CN 114221642A CN 202210159333 A CN202210159333 A CN 202210159333A CN 114221642 A CN114221642 A CN 114221642A
- Authority
- CN
- China
- Prior art keywords
- value
- timer
- duty ratio
- real
- time comparison
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 78
- 238000004458 analytical method Methods 0.000 claims description 4
- 238000004590 computer program Methods 0.000 claims description 2
- 238000004364 calculation method Methods 0.000 abstract description 6
- 230000002093 peripheral effect Effects 0.000 description 4
- 230000009286 beneficial effect Effects 0.000 description 3
- 230000008901 benefit Effects 0.000 description 3
- 238000006243 chemical reaction Methods 0.000 description 3
- 238000010586 diagram Methods 0.000 description 3
- 230000006870 function Effects 0.000 description 3
- 230000008569 process Effects 0.000 description 3
- 239000000047 product Substances 0.000 description 3
- 230000001960 triggered effect Effects 0.000 description 3
- 239000011800 void material Substances 0.000 description 3
- 230000007274 generation of a signal involved in cell-cell signaling Effects 0.000 description 2
- 230000009471 action Effects 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 230000000052 comparative effect Effects 0.000 description 1
- 239000012084 conversion product Substances 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000005265 energy consumption Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H03—ELECTRONIC CIRCUITRY
- H03K—PULSE TECHNIQUE
- H03K7/00—Modulating pulses with a continuously-variable modulating signal
- H03K7/08—Duration or width modulation ; Duty cycle modulation
Landscapes
- Dc-Dc Converters (AREA)
Abstract
The application provides a pulse width modulation signal wave generation and duty ratio control method, a device, a timer and electronic equipment, wherein the pulse width modulation signal duty ratio control method is applied to the timer for generating pulse width modulation signals and comprises the following steps: analyzing the target duty ratio to obtain an integral value and a fraction value of the target duty ratio; inquiring a preset precision table according to the score value, and determining a real-time comparison value of a timer of each PWM period; the preset precision table is used for recording the corresponding relation between the fraction value of the target duty ratio and the real-time comparison value of the timer; and adding the integer values with the real-time comparison value of each timer respectively, and writing the addition results into a comparison register of each timer respectively so as to enable the duty ratio of the pulse width modulation signal to reach the target duty ratio. According to the method and the device, complex calculation is not needed, the program is simplified, the requirement on MCU resources is relatively low, and high-precision control of the duty ratio can be realized under the condition of low cost.
Description
Technical Field
The application belongs to the technical field of direct current conversion, and particularly relates to a pulse width modulation signal (PWM wave) wave generation and duty ratio control method, a device, a timer and electronic equipment.
Background
Currently, in the related art of wireless charging, converting dc power into ac power is an essential link for wireless power transmission. For example, the wireless power transmitter generally controls an MCU (micro controller Unit) to output a Pulse Width Modulation (PWM) wave and a bridge circuit composed of MOS transistors to convert the dc power into ac power, and finally transmits the ac power through a coil. The duty ratio of the PWM directly affects the charging power. Therefore, in the current wireless power control, a fixed voltage duty ratio is mostly adopted.
In order to control higher conversion efficiency and reduce energy consumption, the MCU needs more precise closed-loop control of PWM output. Similarly, a method for modulating duty ratio by PWM is widely used in the field of motor control to control the rotating speed of a motor, the angle of a steering engine and the like, and the requirement for higher duty ratio control accuracy is also met.
With the improvement of the quality of life of people, on one hand, a variety of wireless charging products appear in the market, and the demand of the market on direct current conversion is increased day by day; on the other hand, because the high-precision duty ratio control is often performed by an expensive and high-frequency MCU, and the power consumption of the chip is increased, the existing dc conversion product or technology is often low in cost performance and high in power consumption, and more cost-sensitive products are produced, and the development of such products is greatly limited by the high cost.
Disclosure of Invention
The application provides a pulse width modulation signal wave generation and duty ratio control method, a pulse width modulation signal wave generation and duty ratio control device, a timer and electronic equipment.
An embodiment of a first aspect of the present application provides a method for controlling a duty ratio of a pulse width modulation signal, which is applied to a timer for generating the pulse width modulation signal, and includes:
analyzing the target duty ratio to obtain an integral value and a fraction value of the target duty ratio;
inquiring a preset precision table according to the fraction value, and determining a real-time comparison value of a timer of each PWM period; the preset precision table is used for recording the corresponding relation between the fraction value of the target duty ratio and the real-time comparison value of the timer;
and adding the integer value with the real-time comparison value of each timer respectively, and writing the addition result into a comparison register of each timer respectively so as to enable the duty ratio of the pulse width modulation signal to reach the target duty ratio.
In some embodiments of the present application, before querying the preset precision table according to the score value, the method further includes:
aiming at each fraction value of the duty ratio, calculating a timer real-time comparison value of each PWM period corresponding to the fraction value;
and forming the precision table based on the real-time comparison value of the timer of each PWM period corresponding to all the fraction values.
In some embodiments of the present application, for each fractional value of the duty cycle, calculating a real-time comparison value of the timer for each PWM period corresponding to the fractional value includes:
determining, for each fractional value of a duty cycle, an accuracy of the duty cycle;
respectively determining a first parameter and a second parameter of the precision table according to the score value and the precision; the first parameter is used for representing the number of the adjusting frequencies of the real-time comparison value of the timer, and the second parameter is used for representing the number of the cycle periods of the adjusting frequencies of the real-time comparison value of the timer.
In some embodiments of the present application, a value range of the first parameter is 1 to 20, and a value range of the first parameter is 2 to 50.
In some embodiments of the present application, querying a preset precision table according to the score value, and determining a real-time comparison value of the timer in each PWM period further includes:
inquiring a preset precision table according to the score value to obtain the number of the adjusting frequencies of the real-time comparison value of the timer and the number of the cycle periods of the adjusting frequencies of the real-time comparison value of the timer;
and determining a timer real-time comparison value of each PWM period corresponding to the fraction value according to the adjustment frequency number and the cycle period number.
In some embodiments of the present application, determining a real-time comparison value of the timer of each PWM period corresponding to the fractional value according to the number of the adjustment frequencies and the number of the cycle periods includes:
and for each cycle period, sequentially determining the real-time comparison value of the timer corresponding to each PWM period in the current cycle period, and adding one to the count value of the cycle counter when determining the real-time comparison value of one timer until the number of the cycle periods is reached.
In some embodiments of the present application, before analyzing the target duty cycle and obtaining the integer value and the fraction value of the target duty cycle, the method further includes:
receiving an enabling signal sent by an upper computer and a clock counter interrupt signal of a timer;
and when the counter interrupt signal is received and the enable signal is at a high level, the duty ratio control method of the pulse width modulation signal is executed.
Embodiments of the second aspect of the present application provide a method for generating a pulse width modulation signal, the method including:
performing pulse width modulation signal duty cycle control according to the method of the first aspect;
comparing the addition result with a comparison result of a preset comparison value of a timer;
and outputting a high level or a low level according to the comparison result to form a pulse width modulation signal with the target duty ratio.
In some embodiments of the present application, before performing the duty cycle control of the pulse width modulation signal, the method further includes:
acquiring a reloading value of the timer;
and the clock counter counts, interrupts the clock counter when the count value reaches the reloading value, and triggers and executes the pulse width modulation signal duty ratio control method.
An embodiment of a third aspect of the present application provides a pwm signal duty ratio control apparatus, applied to a timer for generating a pwm signal, including:
the analysis module is used for analyzing the target duty ratio to obtain an integral value and a fraction value of the target duty ratio;
the query module is used for querying a preset precision table according to the score value and determining a real-time comparison value of the timer in each PWM period; the preset precision table is used for recording the corresponding relation between the fraction value of the target duty ratio and the real-time comparison value of the timer;
and the adding module is used for adding the integer values with the real-time comparison values of each timer respectively and writing the addition results into comparison registers of the timers respectively so as to enable the duty ratio of the pulse width modulation signals to reach the target duty ratio.
An embodiment of a fourth aspect of the present application provides a timer, which includes a reloading module, a counter, a comparison register, and an output control module, and the timer further includes a pwm signal duty ratio control apparatus according to the first aspect.
An embodiment of a fifth aspect of the present application provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor further includes the timer according to the first aspect.
The technical scheme provided in the embodiment of the application at least has the following technical effects or advantages:
the method for controlling the duty ratio of the pulse width modulation signal comprises the steps of firstly analyzing a target duty ratio to obtain an integral value and a fractional value of the target duty ratio, then inquiring a preset precision table for recording the corresponding relation between the fractional value of the target duty ratio and a real-time comparison value of a timer according to the fractional value to determine the real-time comparison value of the timer in each PWM period to achieve the aim, then respectively adding the integral value and the real-time comparison value of each timer, and respectively writing an addition result into a comparison register of the timer to enable the duty ratio of the pulse width modulation signal to achieve the target duty ratio. Therefore, different (or same) timer comparison values are set in different PWM periods, and the scheme of subdividing and circularly switching the duty ratio is realized by changing the timer comparison values in real time, so that the purpose of improving the control precision of the duty ratio under low clock frequency is achieved. When the duty ratio control method is realized by the MCU, the integral value and the fractional value of the target duty ratio are respectively written into a timer for executing the method only by calculating the target duty ratio to be set in advance, and the module is enabled (providing high level for the execution main body of the pulse width modulation signal duty ratio control method), so that the execution main body can automatically and continuously output the target duty ratio, and the software program of the MCU can ensure accurate and stable output without any operation. When the duty ratio parameters need to be modified subsequently, the calculation and the operation are only needed once, so that the operation requirement of the MCU software is greatly reduced under the condition of ensuring the performance. Meanwhile, the needed register values are few (only 2 registers are needed), the needed gate circuits are few, and only a tiny area is occupied in a chip, so that the method has higher cost performance.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the application. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
fig. 1 is a schematic flowchart illustrating a method for controlling a duty ratio of a pulse width modulation signal according to an embodiment of the present application;
fig. 2 is a logic diagram illustrating a pwm signal generating method according to an embodiment of the present application;
FIG. 3 is a logic diagram illustrating a method for controlling the duty ratio of a PWM signal according to an embodiment of the present application;
fig. 4 shows a schematic structural diagram of a pulse width modulation signal duty ratio control device provided in an embodiment of the present application.
Detailed Description
Exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present application are shown in the drawings, it should be understood that the present application may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
It is to be noted that, unless otherwise specified, technical or scientific terms used herein shall have the ordinary meaning as understood by those skilled in the art to which this application belongs.
The following describes a method, an apparatus, a timer and an electronic device for generating a pwm signal wave and controlling a duty ratio according to an embodiment of the present application with reference to the accompanying drawings.
In the related art, a PWM (pulse width modulation) signal is generated, and usually, the MCU is configured with a timer. For example, a timer running at a frequency of 10MHz, sets the counter overflow value (reload value) to 99, counts the counter of the timer from 0 to 99, then counts down, and reloads. Each time the counting is interrupted, the comparison between the counting value (value in the counter) and the comparison value of the register is carried out, the comparison value of the register is set to be 20, (when the counting value is smaller than the comparison value, high level is output, and when the counting value is larger than or equal to the comparison value, low level is output), then the PWM wave of 100KHz can be obtained, and the output positive duty ratio is 20%. The "control accuracy" of the PWM duty cycle is generally considered to be the minimum duty cycle adjustment unit divided by the number of cycles, i.e. the duty cycle control accuracy controllable by the operating frequency of 10MHz at this time is 1%. In a general scheme, if the duty ratio control accuracy is required to be 0.1%, an operating frequency of 100MHz is required, and the power consumption of a chip is increased, which is contrary to the design concept of high cost performance and low power consumption.
In view of the foregoing, the present embodiment provides a pulse width modulation signal wave generation and duty ratio control method, a device, a timer, and an electronic device, wherein both the pulse width modulation signal generation method and the duty ratio control method are applied to a timer for generating a pulse width modulation signal, and the timer is applicable to wireless charging systems, motor control systems, and other scenarios. The device (or module) can be used as an auxiliary peripheral of the timer, can directly operate a comparison register of the timer, and is preset with an accuracy table. The method is applied to a timer for generating pulse width modulation signals, particularly to the auxiliary peripheral, determines the real-time comparison value of the timer of each PWM period corresponding to the target duty ratio by inquiring the preset precision table, realizes the mode of subdividing and circularly switching the duty ratio, greatly reduces the operation amount, has relatively low requirement on MCU resources, and achieves the purpose of improving the control precision of the duty ratio under the condition of low clock frequency.
According to the embodiment of the application, before the pulse width modulation signal duty ratio control method is executed for the first time, a preset precision table can be generated firstly, so that the pulse width modulation signal duty ratio control method can be realized in a table look-up mode based on the preset precision table.
Based on the principle of generating the pulse width modulation signal, the duty ratio can be subdivided and controlled by setting different real-time comparison values of the timers for different periods, so that the real-time comparison value of the timer for each PWM period corresponding to the fraction value can be calculated for each fraction value of the duty ratio, and then a precision table is formed based on the real-time comparison values of the timers for each PWM period corresponding to all the fraction values.
When calculating the real-time comparison value of the timer of each PWM period corresponding to each fraction value, the precision of the duty ratio can be determined for each fraction value of the duty ratio, and then the first parameter and the second parameter of the precision table are respectively determined according to the fraction value and the precision.
The first parameter is used for representing the number of the adjusting frequencies of the real-time comparison value of the timer, and the second parameter is used for representing the number of the cycle periods of the adjusting frequencies of the real-time comparison value of the timer.
For example, the present embodiment may set the comparison value of the timer to be changed once every 1 (first parameter) PWM period, so that the real-time comparison value of the timer is switched between 20 and 21. The setting is then changed 10 times (second parameter) for one cycle, and it will then be obtained that the average duty cycle value is fixed for any 10 (third parameter) PWM periods. As shown in table 1, switching cycles and resulting average duty cycle for several comparative values, and as shown in table 1, the control accuracy of the duty cycle can be achieved with a main frequency of 10MHz at 0.1%.
TABLE 1 several comparison of switching cycles of values with the resulting average duty cycle
Wherein, for the first parameter, it can also be set to trigger the comparison value adjustment once every several PWM periods. For the second parameter, the comparison value change may be set to loop at an arbitrary number of times. The first parameter is multiplied by the second parameter to obtain a third parameter, i.e. the number of PWM cycles for the entire cycle.
Specifically, the value of the first parameter (the real-time comparison value adjustment frequency of the timer) is larger, so that the requirement of the MCU computing resource can be reduced (the MCU computing resource is generally set to 1 without being affected by the peripheral scheme), but the instability of the controlled system can be caused. Therefore, in order to save resources and stabilize the system, the value range of the first parameter can be 1-20.
The value of the second parameter (the number of cycle periods) is larger, so that the minimum control unit is smaller, the control precision is higher, but an excessively high value can increase the calculation resource requirement of the MCU or increase the hardware peripheral scale. Therefore, in order to save resources and control precision, the value range of the second parameter can be 2-50.
It should be noted that, in this embodiment, specific values of the first parameter and the second parameter are not specifically limited, as long as refinement and adjustment of the real-time comparison value of the timer can be achieved.
As shown in table 2, the second parameter provided for this embodiment is a "10-fold precision table" when it is equal to 10, and the precision table is a data result calculated and optimized in advance and is fixedly stored in the MCU. In the embodiment, because the table look-up method is used, the MCU can obtain the real-time comparison value (query result) of the timer corresponding to the score value by quickly querying the preset precision table during duty cycle control, and does not need to perform complex multiplication-division calculation during each interrupt, thereby saving a lot of time and computational resources.
As shown in Table 2, the "10-fold precision Table" when the second parameter is equal to 10 is provided for the present embodiment "
It should be noted that any value of the second parameter may generate and apply a precision table, and 0 and 1 in the same "point value" may have different combination manners, which is not specifically limited in this embodiment, as long as the combination of 0 and 1 corresponding to the point value is achieved, all of which belong to the protection range of this embodiment.
In addition, other counter overflow values (reloading values) and comparison values may be set according to actual application requirements, which is not specifically limited in this embodiment.
After the above-mentioned precision table is formed, the method for controlling the duty ratio of the pulse width modulation signal provided by the embodiment of the present application may be executed according to the steps shown in fig. 1, and the method specifically includes the following steps:
and step S1, analyzing the target duty ratio to obtain an integral value and a fraction value of the target duty ratio.
In this embodiment, after receiving the target duty ratio sent by the upper computer (which may be understood as the control device of the wireless charging system or the motor control system), the MCU may first perform analysis calculation on the target duty ratio, and decompose the target duty ratio to obtain an integer value and a fractional value of the target duty ratio. And then performing duty control according to step S2 and step S3 based on the integer value, the fraction value, and the preset precision table. Specifically, steps S2 and S3 may be implemented by the duty cycle control module.
For example, the target duty cycle is to be set to a value of 30.7, i.e., 30+0.7, where the integer value is 30 and the fractional value is 0.7.
In some embodiments of this embodiment, before performing step S1, the pwm signal duty cycle control method may further include the steps of:
and step S01, receiving an enabling signal sent by the upper computer and a clock counter interrupt signal of the timer.
And step S02, when the counter interrupt signal is received and the enable signal is at a high level, executing the pwm signal duty control method.
When the timer works, the reloading value can be set as required, and after an enable signal (high level, which can be understood as writing '1' to a corresponding register address) is received, the whole duty ratio control module can work. After the module starts to operate, a clk clock enables a counter of the timer to be reduced from the reloading value for one time, namely, the counter is reduced from 99 to 0, the counter is interrupted when the reloading value is reduced to 0 each time, a counter interruption signal is generated, the duty ratio control module receives the counter interruption signal and executes the following step S2, the following action of inquiring the preset precision table is performed once when the counter interruption signal is received once, and the real-time comparison value of the timer in one PWM period can be inquired when the preset precision table is inquired each time. And then reloaded 99, thus reloading the cycle according to the reload value.
And step S2, inquiring a preset precision table according to the fraction value, and determining the real-time comparison value of the timer in each PWM period. As described above, the preset precision table is used to describe the corresponding relationship between the fraction value of the target duty ratio and the real-time comparison value of the timer.
When the real-time comparison value of the timer in each PWM period is determined, a preset precision table can be inquired according to the fraction value, and the adjustment frequency number of the real-time comparison value of the timer and the cycle period number of the adjustment frequency of the real-time comparison value of the timer are obtained.
After the adjustment frequency number and the cycle period number are determined, the real-time comparison value of the timer of each PWM period corresponding to the fraction value can be determined according to the adjustment frequency number and the cycle period number.
And each time the clock counter is cycled (namely each counting interruption), the cycle counter in the duty ratio control module is triggered to be added once, then the duty ratio control module inquires the preset precision table once according to the fraction value, and the preset precision table is inquired for many times according to the fraction part of the duty ratio and the cycle counter value (the cycle counting is 0-second parameter) in the software program.
When the real-time comparison value of the timer of each PWM period corresponding to the fractional value is determined, the real-time comparison value of the timer corresponding to each PWM period in the current cycle period may be sequentially determined for each cycle period, and the count value of the cycle counter is incremented by one when each real-time comparison value of the timer is determined until the number of cycle periods is reached.
Some parameter declarations and key functions in this embodiment are as follows:
assigned char duty count
Assigned char duty int// compare value integer portion
Assigned char duty fra// compare value score portion
unsigned char Duty_list[10][10] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //0
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //1
{0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, //2
{0, 0, 1, 0, 0, 0, 1, 0, 0, 1}, //3
{0, 1, 0, 0, 1, 0, 0, 1, 0, 1}, //4
{0, 1, 0, 1, 0, 1, 0, 1, 0, 1}, //5
{1, 0, 1, 1, 0, 1, 1, 0, 1, 0}, //6
{1, 1, 0, 1, 1, 1, 0, 1, 1, 0}, //7
{1, 1, 1, 1, 0, 1, 1, 1, 1, 0}, //8
{1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, //9
A// look-up table
void f _ duty _ set (float percentage)/duty setting function
{
V/calculating integer and fractional parts, ARR being an automatic reload register of a timer
duty_int = ((ARR + 1) * percent / 10) / 10;
duty_fra = ((ARR + 1) * percent / 10) % 10;
}
void TIM1_ IRQHandler (void) interrupt 3// interrupt handling function
{
// duty _ count loop 0 through 9
duty_count ++;
if (duty_count == 10){duty_count = 0;}
V/assigning the table lookup result to a timer comparison value register COMP
COMP = duty_int + Duty_list[duty_fra][duty_count];
}
And step S3, adding the integer values with the real-time comparison values of each timer, and writing the addition results into the comparison registers of the timers respectively so as to enable the duty ratio of the pulse width modulation signals to reach the target duty ratio.
After the timer obtains the query result, the queried value (0 or 1) and the integer value can be added, the addition result is loaded into a comparison value register of the timer, the comparison value of the timer and the preset comparison value of the timer can be compared in real time through an output control module, and a high level or a low level is output according to the comparison result so as to generate a pulse width modulation signal with a certain rule.
It should be noted that the comparison values of the timer implementation corresponding to each PWM period may be the same or different, and are written into the comparison register of the timer regardless of whether they are the same or not.
The following describes the pwm signal duty cycle control process of this embodiment in detail with reference to fig. 2 and fig. 3, taking the target duty cycle 30.7 as an example, wherein the duty cycle control module is increased to the position shown in fig. 2, and writes the output value into the comparison register of the timer triggered by the clock counter overflow. Specifically, after receiving the target duty ratio, the MCU analyzes the target duty ratio to be 30.7, obtains an integer value of 30 and a fraction value of 0.7, and inputs the integer value of 30 and the fraction value of 7 to the timers respectively. The timer then generates a pulse width modulation signal according to the logic shown in fig. 2, loads a reload value (e.g., 99) first, then clocks a counter to count, triggers the duty cycle control module when the counter overflows, and then the duty cycle control module performs duty cycle control according to the logic shown in fig. 3.
As shown in fig. 3, when the duty ratio control module performs duty ratio control, the integer value 30 and the fractional value 7 may be stored in the integer part and the fractional part of the comparison register, respectively, and then the preset precision table is queried based on the fractional value, and in the query process, the cycle counter (5 bit) is self-added every time the query is performed, so that the count is from 0 to 9 until the real-time comparison values of the timers corresponding to all PWM periods of one cycle period are queried. The module enable control register can receive and store an enable signal, and the whole duty ratio control module works when the enable signal is at a high level.
The value ranges and bit widths stored in the integer part of the comparison register, the fractional part of the comparison register and the module enable control register may be, but are not limited to, as shown in table 3 below.
TABLE 3
It should be noted that, the value of the lookup table is the same as the "10-fold precision table" shown above, and the table can be directly designed in a chip as a hardware logic circuit without complicated register read-write operation.
The method for controlling the duty ratio of the pulse width modulation signal provided by this embodiment includes analyzing a target duty ratio to obtain an integer value and a fractional value of the target duty ratio, querying a preset precision table for recording a corresponding relationship between the fractional value of the target duty ratio and a real-time comparison value of a timer according to the fractional value to determine the real-time comparison value of the timer in each PWM period to achieve the target duty ratio, adding the integer value and the real-time comparison value of each timer, and writing an addition result into a comparison register of the timer to enable the duty ratio of the pulse width modulation signal to achieve the target duty ratio. Therefore, different (or same) timer comparison values are set in different PWM periods, and the scheme of subdividing and circularly switching the duty ratio is realized by changing the timer comparison values in real time, so that the purpose of improving the control precision of the duty ratio under low clock frequency is achieved. When the duty ratio control method is realized by the MCU, the integral value and the fractional value of the target duty ratio are respectively written into a timer for executing the method only by calculating the target duty ratio to be set in advance, and the module is enabled (providing high level for the execution main body of the pulse width modulation signal duty ratio control method), so that the execution main body can automatically and continuously output the target duty ratio, and the software program of the MCU can ensure accurate and stable output without any operation. When the duty ratio parameters need to be modified subsequently, the calculation and the operation are only needed once, so that the operation requirement of the MCU software is greatly reduced under the condition of ensuring the performance. Meanwhile, the needed register values are few (only 2 registers are needed), the needed gate circuits are few, and only a tiny area is occupied in a chip, so that the method has higher cost performance.
Based on the same concept of the above pulse width modulation signal duty ratio control method, the present embodiment further provides a pulse width modulation signal generation method, including the following steps:
step c) performing pulse width modulation signal duty ratio control according to the method of any embodiment;
step d) comparing the addition result with a comparison result of a preset comparison value of a timer;
and e) outputting a high level or a low level according to the comparison result to form a pulse width modulation signal with a target duty ratio.
In the process of generating the pulse width modulation signal by the timer, as described above, the reload value may be loaded first, then the clock counter starts counting, when the clock counter overflows, the duty cycle control module is triggered to perform duty cycle control, the duty cycle control module writes a control result (a real-time comparison value of the timer) into a comparison register of the timer, then the output control module of the timer compares the count value with the comparison value (the real-time comparison value of the timer) in real time, and controls the IO port to output a high level or a low level according to the comparison result (the count value is smaller than the real-time comparison value of the timer, the count value is output a high level, otherwise, the count value is output a low level).
In some embodiments of this embodiment, before performing the duty cycle control of the pwm signal, the pwm signal generating method may further include:
step a) acquiring a reloading value of the timer.
And b) counting by the clock counter, interrupting the clock counter when the counting value reaches a reloading value, and triggering and executing the pulse width modulation signal duty ratio control method.
The pwm signal generating method provided in this embodiment is based on the same concept of the pwm signal duty ratio control method, so that at least the beneficial effects that can be achieved by the pwm signal duty ratio control method can be achieved, and details are not repeated herein.
Based on the same concept of the above-mentioned pwm signal duty ratio control method, this embodiment further provides a pwm signal duty ratio control apparatus, which is applied to a timer for generating a pwm signal to implement the above-mentioned pwm signal duty ratio control method, as shown in fig. 4, the apparatus includes:
the analysis module is used for analyzing the target duty ratio to obtain an integral value and a fraction value of the target duty ratio;
the query module is used for querying a preset precision table according to the score value and determining a real-time comparison value of the timer in each PWM period; the preset precision table is used for recording the corresponding relation between the fraction value of the target duty ratio and the real-time comparison value of the timer;
and the adding module is used for adding the integer values with the real-time comparison values of each timer respectively and writing the addition results into the comparison registers of the timers respectively so as to enable the duty ratio of the pulse width modulation signals to reach the target duty ratio.
The query module and the adding module may both be sub-modules of the duty ratio control module, and the duty ratio control module may further include an integer part of the comparison register, a fractional part of the comparison register, and a module enable control register, which are respectively used to store the integer value, the fractional value, and the value of the enable signal.
As shown in fig. 4, the duty ratio control module may further include a cycle counter for counting the number of changes of the real-time comparison value of the timer.
The pwm signal generating apparatus provided in this embodiment is based on the same concept of the pwm signal duty control method, so that at least the beneficial effects that can be achieved by the pwm signal duty control method can be achieved, and details are not repeated herein.
Based on the same concept of the pulse width modulation signal duty ratio control method, the present embodiment further provides a timer, which includes a reloading module, a counter, a comparison register, an output control module, and the pulse width modulation signal duty ratio control device.
Based on the same concept of the above-mentioned pwm signal duty control method, the present embodiment further provides an electronic device to execute the above-mentioned pwm signal duty control method. The electronic device may be the timer, a Micro Control Unit (MCU) including the timer, a chip on which the MCU is formed, the wireless charging system using the chip, a motor control system (or a control device of only the system), or the like.
The electronic device provided by the embodiment of the application and the pulse width modulation signal duty ratio control method provided by the embodiment of the application have the same inventive concept and have the same beneficial effects as the method adopted, operated or realized by the electronic device.
It should be noted that:
in the description provided herein, numerous specific details are set forth. However, it is understood that embodiments of the application may be practiced without these specific details. In some instances, well-known structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the application, various features of the application are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the application and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted to reflect the following schematic: this application is intended to cover such departures from the present disclosure as come within known or customary practice in the art to which this invention pertains. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this application.
Furthermore, those skilled in the art will appreciate that while some embodiments herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the application and form different embodiments. For example, in the following claims, any of the claimed embodiments may be used in any combination.
The above description is only for the preferred embodiment of the present application, but the scope of the present application is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present application should be covered within the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
Claims (12)
1. A duty ratio control method of a pulse width modulation signal is applied to a timer for generating the pulse width modulation signal, and is characterized by comprising the following steps:
analyzing the target duty ratio to obtain an integral value and a fraction value of the target duty ratio;
inquiring a preset precision table according to the fraction value, and determining a real-time comparison value of a timer of each PWM period; the preset precision table is used for recording the corresponding relation between the fraction value of the target duty ratio and the real-time comparison value of the timer;
and adding the integer value with the real-time comparison value of each timer respectively, and writing the addition result into a comparison register of each timer respectively so as to enable the duty ratio of the pulse width modulation signal to reach the target duty ratio.
2. The method of claim 1, wherein prior to querying a preset precision table based on the score value, the method further comprises:
aiming at each fraction value of the duty ratio, calculating a timer real-time comparison value of each PWM period corresponding to the fraction value;
and forming the precision table based on the real-time comparison value of the timer of each PWM period corresponding to all the fraction values.
3. The method of claim 2, wherein calculating, for each fractional value of the duty cycle, a real-time comparison value of the timer for each PWM period for the fractional value comprises:
determining, for each fractional value of a duty cycle, an accuracy of the duty cycle;
respectively determining a first parameter and a second parameter of the precision table according to the score value and the precision; the first parameter is used for representing the number of the adjusting frequencies of the real-time comparison value of the timer, and the second parameter is used for representing the number of the cycle periods of the adjusting frequencies of the real-time comparison value of the timer.
4. The method according to claim 3, wherein the first parameter has a value in a range of 1 to 20, and the first parameter has a value in a range of 2 to 50.
5. The method according to any one of claims 1-4, wherein querying a predetermined precision table based on the fractional value to determine a real-time comparison value of the timer for each PWM cycle, further comprises:
inquiring a preset precision table according to the score value to obtain the number of the adjusting frequencies of the real-time comparison value of the timer and the number of the cycle periods of the adjusting frequencies of the real-time comparison value of the timer;
and determining a timer real-time comparison value of each PWM period corresponding to the fraction value according to the adjustment frequency number and the cycle period number.
6. The method of claim 5, wherein determining the real-time comparison value of the timer for each PWM cycle corresponding to the fractional value according to the number of adjustment frequencies and the number of cycle cycles comprises:
and for each cycle period, sequentially determining the real-time comparison value of the timer corresponding to each PWM period in the current cycle period, and adding one to the count value of the cycle counter when determining the real-time comparison value of one timer until the number of the cycle periods is reached.
7. The method according to any of claims 1-4, wherein before parsing the target duty cycle to obtain integer and fractional values of the target duty cycle, further comprising:
receiving an enabling signal sent by an upper computer and a clock counter interrupt signal of a timer;
and when the counter interrupt signal is received and the enable signal is at a high level, the duty ratio control method of the pulse width modulation signal is executed.
8. A method of generating a pulse width modulated signal, the method comprising:
performing pulse width modulation signal duty cycle control according to the method of any one of claims 1-7;
comparing the addition result with a comparison result of a preset comparison value of a timer;
and outputting a high level or a low level according to the comparison result to form a pulse width modulation signal with the target duty ratio.
9. The method of claim 8, wherein prior to performing the pulse width modulation signal duty cycle control, further comprising:
acquiring a reloading value of the timer;
and the clock counter counts, interrupts the clock counter when the count value reaches the reloading value, and triggers and executes the pulse width modulation signal duty ratio control method.
10. A pwm signal duty ratio control apparatus for a timer for generating a pwm signal, comprising:
the analysis module is used for analyzing the target duty ratio to obtain an integral value and a fraction value of the target duty ratio;
the query module is used for querying a preset precision table according to the score value and determining a real-time comparison value of the timer in each PWM period; the preset precision table is used for recording the corresponding relation between the fraction value of the target duty ratio and the real-time comparison value of the timer;
and the adding module is used for adding the integer values with the real-time comparison values of each timer respectively and writing the addition results into comparison registers of the timers respectively so as to enable the duty ratio of the pulse width modulation signals to reach the target duty ratio.
11. A timer comprising a reloading module, a counter, a comparison register and an output control module, characterized in that the timer further comprises a pwm signal duty cycle control device according to claim 10.
12. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor further comprises the timer of claim 11.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210159333.3A CN114221642B (en) | 2022-02-22 | 2022-02-22 | PWM wave generation and duty ratio control method, device, timer and equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210159333.3A CN114221642B (en) | 2022-02-22 | 2022-02-22 | PWM wave generation and duty ratio control method, device, timer and equipment |
Publications (2)
Publication Number | Publication Date |
---|---|
CN114221642A true CN114221642A (en) | 2022-03-22 |
CN114221642B CN114221642B (en) | 2022-06-17 |
Family
ID=80709158
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210159333.3A Active CN114221642B (en) | 2022-02-22 | 2022-02-22 | PWM wave generation and duty ratio control method, device, timer and equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114221642B (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114500204A (en) * | 2022-03-30 | 2022-05-13 | 浙江地芯引力科技有限公司 | FSK data transmission control device, method, timer, MCU and equipment |
CN115642905A (en) * | 2022-12-22 | 2023-01-24 | 无锡麟聚半导体科技有限公司 | PWM signal anti-interference circuit and chip |
CN117389136A (en) * | 2023-12-13 | 2024-01-12 | 浙江地芯引力科技有限公司 | Power control system and control method |
Citations (19)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6597735B1 (en) * | 1998-11-04 | 2003-07-22 | Nec Electronics Corporation | Timer assembly for generating a PWM signal |
US20030156636A1 (en) * | 2002-02-15 | 2003-08-21 | Klemish Melissa Marie | Generation of multiple independent high resolution pulse width modulations |
US20090292936A1 (en) * | 2008-05-23 | 2009-11-26 | Denso Corporation | Microcomputer having cpu and pwm timer |
US20110310954A1 (en) * | 2010-06-16 | 2011-12-22 | Denso Corporation | Pulse width modulation communication system |
US8362819B1 (en) * | 2011-09-29 | 2013-01-29 | Microchip Technology Incorporated | Synchronizing multi-frequency pulse width modulation generators |
CN103493349A (en) * | 2011-03-28 | 2014-01-01 | 瑞萨电子株式会社 | PWM signal generation circuit and processor system |
CN105429529A (en) * | 2015-12-16 | 2016-03-23 | 四川长虹电器股份有限公司 | Motor control method and electronic equipment |
CN205899423U (en) * | 2016-08-16 | 2017-01-18 | 昆山硕通电子有限公司 | Simple and easy high accuracy digit adjustable power |
CN106712747A (en) * | 2016-12-09 | 2017-05-24 | 深圳市紫光同创电子有限公司 | Frequency dividing clock signal acquisition method and apparatus |
CN108398976A (en) * | 2018-01-30 | 2018-08-14 | 昆明理工大学 | A method of high-accuracy voltage is generated based on pulsewidth modulation |
CN110708045A (en) * | 2019-08-01 | 2020-01-17 | 珠海格力电器股份有限公司 | Waveform phase-shifting control circuit, method and timer |
CN111158291A (en) * | 2020-01-06 | 2020-05-15 | 桂林电子科技大学 | High-precision PWM signal generation and detection system based on edge control |
CN111162762A (en) * | 2020-01-17 | 2020-05-15 | 深圳市驰能创展技术有限公司 | PWM signal generating circuit, method and chip |
CN211127756U (en) * | 2020-01-17 | 2020-07-28 | 深圳市驰能创展技术有限公司 | PWM signal generation circuit and chip |
CN112134561A (en) * | 2020-09-27 | 2020-12-25 | 吉林省广播电视研究所(吉林省广播电视局科技信息中心) | Narrow-band frequency modulation digital precision frequency synthesizer |
CN212459812U (en) * | 2020-06-05 | 2021-02-02 | 镇江英创电力电子有限公司 | Multi-range high-precision high-voltage isolation transmitter |
CN112510975A (en) * | 2020-11-25 | 2021-03-16 | 中国科学院近代物理研究所 | Method and system for improving PWM precision of accelerator power supply |
CN112737549A (en) * | 2020-12-25 | 2021-04-30 | 珠海格力电器股份有限公司 | Signal output frequency adjusting method and device and electronic equipment |
CN112771456A (en) * | 2020-12-30 | 2021-05-07 | 华为技术有限公司 | Digital signal modulation method and device, switching power supply control method and switching power supply |
-
2022
- 2022-02-22 CN CN202210159333.3A patent/CN114221642B/en active Active
Patent Citations (19)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6597735B1 (en) * | 1998-11-04 | 2003-07-22 | Nec Electronics Corporation | Timer assembly for generating a PWM signal |
US20030156636A1 (en) * | 2002-02-15 | 2003-08-21 | Klemish Melissa Marie | Generation of multiple independent high resolution pulse width modulations |
US20090292936A1 (en) * | 2008-05-23 | 2009-11-26 | Denso Corporation | Microcomputer having cpu and pwm timer |
US20110310954A1 (en) * | 2010-06-16 | 2011-12-22 | Denso Corporation | Pulse width modulation communication system |
CN103493349A (en) * | 2011-03-28 | 2014-01-01 | 瑞萨电子株式会社 | PWM signal generation circuit and processor system |
US8362819B1 (en) * | 2011-09-29 | 2013-01-29 | Microchip Technology Incorporated | Synchronizing multi-frequency pulse width modulation generators |
CN105429529A (en) * | 2015-12-16 | 2016-03-23 | 四川长虹电器股份有限公司 | Motor control method and electronic equipment |
CN205899423U (en) * | 2016-08-16 | 2017-01-18 | 昆山硕通电子有限公司 | Simple and easy high accuracy digit adjustable power |
CN106712747A (en) * | 2016-12-09 | 2017-05-24 | 深圳市紫光同创电子有限公司 | Frequency dividing clock signal acquisition method and apparatus |
CN108398976A (en) * | 2018-01-30 | 2018-08-14 | 昆明理工大学 | A method of high-accuracy voltage is generated based on pulsewidth modulation |
CN110708045A (en) * | 2019-08-01 | 2020-01-17 | 珠海格力电器股份有限公司 | Waveform phase-shifting control circuit, method and timer |
CN111158291A (en) * | 2020-01-06 | 2020-05-15 | 桂林电子科技大学 | High-precision PWM signal generation and detection system based on edge control |
CN111162762A (en) * | 2020-01-17 | 2020-05-15 | 深圳市驰能创展技术有限公司 | PWM signal generating circuit, method and chip |
CN211127756U (en) * | 2020-01-17 | 2020-07-28 | 深圳市驰能创展技术有限公司 | PWM signal generation circuit and chip |
CN212459812U (en) * | 2020-06-05 | 2021-02-02 | 镇江英创电力电子有限公司 | Multi-range high-precision high-voltage isolation transmitter |
CN112134561A (en) * | 2020-09-27 | 2020-12-25 | 吉林省广播电视研究所(吉林省广播电视局科技信息中心) | Narrow-band frequency modulation digital precision frequency synthesizer |
CN112510975A (en) * | 2020-11-25 | 2021-03-16 | 中国科学院近代物理研究所 | Method and system for improving PWM precision of accelerator power supply |
CN112737549A (en) * | 2020-12-25 | 2021-04-30 | 珠海格力电器股份有限公司 | Signal output frequency adjusting method and device and electronic equipment |
CN112771456A (en) * | 2020-12-30 | 2021-05-07 | 华为技术有限公司 | Digital signal modulation method and device, switching power supply control method and switching power supply |
Non-Patent Citations (3)
Title |
---|
孟红强: ""基于DSP的无刷直流电机调速系统设计"", 《中国优秀硕士学位论文全文数据库•工程科技Ⅱ辑》 * |
张宣妮等: ""基于FPGA的全数字脉宽调制器"", 《计算机仿真》 * |
虞君锚: ""基于DSP与FPGA的全自主机器人的控制系统的研究"", 《中国优秀硕士学位论文全文数据库•信息科技辑》 * |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114500204A (en) * | 2022-03-30 | 2022-05-13 | 浙江地芯引力科技有限公司 | FSK data transmission control device, method, timer, MCU and equipment |
CN115642905A (en) * | 2022-12-22 | 2023-01-24 | 无锡麟聚半导体科技有限公司 | PWM signal anti-interference circuit and chip |
CN117389136A (en) * | 2023-12-13 | 2024-01-12 | 浙江地芯引力科技有限公司 | Power control system and control method |
CN117389136B (en) * | 2023-12-13 | 2024-03-12 | 浙江地芯引力科技有限公司 | Power control system and control method |
Also Published As
Publication number | Publication date |
---|---|
CN114221642B (en) | 2022-06-17 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN114221642B (en) | PWM wave generation and duty ratio control method, device, timer and equipment | |
US5551044A (en) | Method and apparatus for interrupt/SMI# ordering | |
CN105790738B (en) | Pulse Width Modulation Signal Generating Circuit and Method | |
JP2008059054A (en) | Processor system | |
CN114721908B (en) | On-chip power consumption control circuit, chip and power consumption control method | |
CN110289792A (en) | Scaling method, control method and the bench test control system of permanent magnet synchronous motor | |
KR20120055784A (en) | Apparatus for controlling power of multi core processor and method thereof | |
US6421382B1 (en) | Pulse width modulation signal generator | |
US20160062390A1 (en) | Adjusting Clock Frequency | |
US6597735B1 (en) | Timer assembly for generating a PWM signal | |
CN116974953A (en) | Algorithm processing module, motor control chip and motor | |
CN104076855A (en) | Self adaptive voltage adjuster based on PSM (pulse slope modulation) mode | |
US7327300B1 (en) | System and method for generating a pulse width modulated signal having variable duty cycle resolution | |
WO2024011709A1 (en) | Motor current sampling method, frequency converter, terminal device, and storage medium | |
CN114696623A (en) | Soft switching method and system for charging and discharging of switching power supply | |
JPS60150137A (en) | Microcomputer system | |
CN101518849A (en) | Digital cutting method | |
CN112134503A (en) | Actuator device and driving method thereof | |
US20240333272A1 (en) | Delay time control circuit | |
CN117389136B (en) | Power control system and control method | |
TWI774069B (en) | Actuating apparatus and driving method thereof | |
CN112003455B (en) | Power supply and control method thereof | |
CN116088660A (en) | Method, device, equipment and storage medium for controlling internal voltage of chip | |
CN118885065A (en) | Chip power consumption adjustment method and device, storage medium and chip | |
US20210109559A1 (en) | Bandgap voltage generating apparatus and operation method thereof |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
EE01 | Entry into force of recordation of patent licensing contract |
Application publication date: 20220322 Assignee: SHENZHEN YUANAI ELECTRONIC TECHNOLOGY CO.,LTD. Assignor: Zhejiang core Gravity Technology Co.,Ltd. Contract record no.: X2023980053655 Denomination of invention: PWM wave generation and duty cycle control method, device, timer and equipment Granted publication date: 20220617 License type: Common License Record date: 20231222 |
|
EE01 | Entry into force of recordation of patent licensing contract |