CN104702251A - Timer-based PWM (Pulse Width Modulation) wave generation method - Google Patents

Timer-based PWM (Pulse Width Modulation) wave generation method Download PDF

Info

Publication number
CN104702251A
CN104702251A CN201510089189.0A CN201510089189A CN104702251A CN 104702251 A CN104702251 A CN 104702251A CN 201510089189 A CN201510089189 A CN 201510089189A CN 104702251 A CN104702251 A CN 104702251A
Authority
CN
China
Prior art keywords
timer
count
cycle
pwm ripple
pwm
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
Application number
CN201510089189.0A
Other languages
Chinese (zh)
Other versions
CN104702251B (en
Inventor
周尧明
蒙志君
王凯鹏
赵文龙
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beihang University
Original Assignee
Beihang University
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Beihang University filed Critical Beihang University
Priority to CN201510089189.0A priority Critical patent/CN104702251B/en
Publication of CN104702251A publication Critical patent/CN104702251A/en
Application granted granted Critical
Publication of CN104702251B publication Critical patent/CN104702251B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The invention discloses a timer-based PWM (Pulse Width Modulation) wave generation method. The method comprises the following steps: I, setting one timer in a cycle count working mode, wherein one clock interrupt is triggered and one negative pulse is output in each cycle; an output end of the cycle count timer is connected with an input end of a PWM wave generation timer; II, setting the timer for generating the PWM wave in the working mode of high level reductional count trigger, rising edge count heavy load trigger, low level output when the count value is not zero and high level output after the count value is reduced to be zero, wherein the output end of the PWM wave generation timer can generate the PWM wave; III, writing an interruption service function, and responding clock interruption after the count of each cycle is ended. According to the timer-based PWM wave generation method, since the timer is loaded in next interruption after the initial value is written, the pulse width and the cycle accuracy of the generated PWM wave are not affected even though the interruption response of the cycle count timer has time delay.

Description

A kind of PWM ripple generation method based on timer
Technical field
The invention provides a kind of PWM ripple generation method based on timer, it relates to a kind of generation method of the pulsewidth length modulated signal PWM ripple based on timer, proposes a kind of timer that utilizes to realize the method for the generation of PWM ripple.The generation method of this PWM ripple based on timer, can be generalized to the generation realizing pwm signal in various types of timer, is applicable to multiple industrial control field.Carry out example explanation with CDT2000 board for example in the present invention, the PWM ripple generated is used to the 14ms cycle PWM ripple of the motor-driven work of control flaps, pulsewidth length range 1.1 ~ 1.9ms.
Background technology
PWM ripple (PWM, i.e. Pulse Width Modulation, pulse width modulation) be a kind of industry control message of technology maturation, being widely used in the Industry Control aspects such as motor speed control, actuator Stroke Control, is utilize numeral to export the very effective technology of one controlled analog circuit.
The oscillogram of PWM ripple is shown in Fig. 1, t cfor the pulse period, t 1, t 2for characterizing the pulsewidth length of PWM ripple effective information.PWM ripple of the present invention derives from the demand that steering wheel start controls, and needs to generate a kind of cycle 14ms, the pulsewidth length modulated signal of the scope 1.1 ~ 1.9ms of pulsewidth length.
Carry out the generation of PWM ripple, utilize the pulsewidth length modulated signal that some equipment produces this fixed cycle, pulsewidth length can carry out artificial setting exactly.
Traditional PWM ripple generation method, adopt in sheet carry system clock, alternately export high level and low level by I/O equipment according to certain clock length, this method is easily subject to other software in system, on the impact of system resource occupancy, can cause PWM period of wave or effective pulsewidth length instability.
PWM ripple generating mode used in the present invention, adopts break in service function to mate, strictly can control, and can generate the PWM ripple of various different cycles easily, have very strong versatility and operability to PWM accuracy wave period.
Summary of the invention
<1> goal of the invention
The object of the invention is to design a kind of PWM ripple method of generationing based on timer, take timer as main hardware equipment, and by the coding of certain physical connection and break in service function, realization is applicable to the generation of the PWM ripple of various different cycles and pulsewidth.
<2> technical scheme
A kind of PWM ripple generation method based on timer of the present invention, its step is as follows:
Step one: arranging a timer is cycle count mode of operation, each cycle triggers a tick interrupt, exports a negative pulse, and the input that output and the PWM ripple of cycle count timer generate timer is connected;
Step 2: arrange be used for timer that PWM ripple generates be high level when triggering subtrahend counting, rising edge flip-flop number heavy duty, count value non-zero output low level, count value be kept to the mode of operation exporting high level after zero, the output that PWM ripple generates timer can generate PWM ripple;
Step 3: write break in service function, responds tick interrupt after each cycle count terminates.
Wherein, " cycle count mode of operation " described in step one, it is a kind of mode of operation of carrying out arranging of timer, a given set point, it can from this value from reducing to zero, and then get back to the continuation of this value from subtracting, and go round and begin again, cycle count period=set point/timer clock frequency.Cycle count period must divide exactly PWM period of wave and be greater than the maximum of pulsewidth length, the accuracy of such guarantee PWM period of wave, ensures that each probable value of PWM ripple pulsewidth can be generated.
Wherein, " when high level triggering subtrahend counting, rising edge flip-flop number heavy duty, count value non-zero, output low level, count value are kept to the mode of operation exporting high level after zero " described in step 2, it is the mode of operation that the another kind of timer can be arranged, its function is: at the end of each cycle count period, the negative pulse that the input that PWM ripple generates timer all can receive from cycle count timer output end makes count value that heavy duty occur, and the high level continued makes subtrahend counting work on.
Wherein, " break in service function " described in step 3, it is the function that triggered interrupts calls at the end of each cycle count period, its function is: carry out cycle count in function inside, the inner loop count cycle is just in time the quotient of PWM period of wave and cycle count timer period, / timer clock frequency that the count value of the timer that PWM ripple generates by the one-period of each inner loop is rewritten as (cycle count timer period-generate PWM ripple pulsewidth length), within this cycle, timer will inevitably count end like this, thus produce the high level with pulsewidth length equal time, other process is not done within ensuing several cycle of inner loop.
The sequential chart of PWM ripple is generated as shown in Figure 2 with timer.
<3> advantage effect
Based on the PWM ripple generation method of timer, because timer is writing loading in the upper once interruption after initial value, even if therefore the interrupt response of cycle count timer has time delay also can not affect pulsewidth and the cycle accuracy of the PWM ripple of generation.
Accompanying drawing explanation
Below in conjunction with accompanying drawing, the present invention is further described.
Fig. 1 is a kind of waveform schematic diagram of PWM ripple;
Fig. 2 is the sequential chart generating PWM ripple with timer, has the explanation explanation of correlated variables in remarks;
Fig. 3 is the circuit and the signal connection layout that utilize the timer function of CDT2000 to realize the generation of PWM ripple in application example;
Fig. 4 is the sequential chart utilizing the timer function of CDT2000 to carry out the generation of PWM ripple in application example;
Fig. 5 the method for the invention FB(flow block)
Concrete implementation step
As Figure 1-5, a kind of PWM ripple generation method based on timer of the present invention, as shown in Figure 5, its step is as follows:
Step one: arranging a timer is cycle count mode of operation, each cycle triggers a tick interrupt, exports a negative pulse, and the input that output and the PWM ripple of cycle count timer generate timer is connected; Cycle count period must be divided exactly and be greater than the maximum of pulsewidth length by PWM period of wave.
Step 2: arranging the timer being used for the generation of PWM ripple is the mode of operation that high level triggers output low level in subtrahend counting, rising edge flip-flop number heavy duty, gate time, counting terminates rear output high level, and the output of PWM ripple generation timer can generate PWM ripple.
Step 3: write break in service function, tick interrupt is responded after each cycle count terminates, break in service function carries out inner loop counting, count cycle is just in time the quotient of PWM period of wave and cycle count timer period, / timer clock frequency that the count value of the timer that PWM ripple generates by each circulation one-period is rewritten as (cycle count timer period-generate PWM ripple pulsewidth length), within this cycle, timer will inevitably count the high level terminating generation and pulsewidth length equal time like this, be left intact within each circulation following several cycle.
Application example
The example explained below comes from actual application case, with CDT2000 board for timer device, realizes the response of break in service function with PC/104 embedded computer.In this case, generation 5 road PWM ripple is needed.The 5 road PWM ripple signals generated produce action for driving steering wheel actuator.
The PWM ripple that needs generate is the pulsewidth length modulated signal of a kind of cycle 14ms, pulsewidth length range 1.1 ~ 1.9ms.
Specific practice is as follows:
1, runs pattern is arranged
Four 82C54 timing controllers of CDT2000 board, each have three independent timer, altogether obtains 12 independently timers, and wherein six timers have only been used in the generation carrying out PWM ripple, as shown in Figure 3.The connection of each timer and the setting of working method are expressed as follows:
Timer 1-0: be that loop cycle counts with 2ms, and produce interruption, OUT mouth produces negative pulse in each count cycle.
Timer 1-1 ~ timer 2-2:GATE mouth rising edge input makes timer heavy duty, and OUT mouth is low when counting, for high after counting terminates.
Wherein, timer 1-0 the shot timers as break in service function, arranging the work period is 2ms, and namely each cycle initial count value is set as 16000.
2, break in service function performance describes
The principle generated about PWM ripple in break in service function is expressed as follows (sequential chart of PWM ripple collection is shown in Fig. 4):
1) generating period is wanted to be that the PWM ripple of 14ms needs 7 interrupt cycles of experience;
2) the 1st cycle, generate timer to PWM and be loaded into T1=(2ms-t0)/(8 × 10 6) count value, t0 expects the PWM ripple pulsewidth that obtains, and so in first 2ms, PWM generates timer can produce t0 length after (2ms-t0) counting terminates pulse at OUT mouth;
3) ensuing continuous 6 cycles, PWM generates timer and is again loaded into maximum (65535), the OUT mouth output low level of timer, and 6 2ms cycles all keep low level afterwards.

Claims (4)

1. one kind based on the PWM ripple generation method of timer, it is characterized in that: its step is as follows:
Step one: arranging a timer is cycle count mode of operation, each cycle triggers a tick interrupt, exports a negative pulse, and the input that output and the PWM ripple of cycle count timer generate timer is connected;
Step 2: arrange be used for timer that PWM ripple generates be high level when triggering subtrahend counting, rising edge flip-flop number heavy duty, count value non-zero output low level, count value be kept to the mode of operation exporting high level after zero, the output that PWM ripple generates timer can generate PWM ripple;
Step 3: write break in service function, responds tick interrupt after each cycle count terminates.
2. a kind of PWM ripple generation method based on timer according to claim 1, it is characterized in that: " cycle count mode of operation " described in step one, it is a kind of mode of operation carrying out arranging of timer, a given set point, it can from this value from reducing to zero, and then get back to the continuation of this value from subtracting, and go round and begin again, cycle count period=set point/timer clock frequency; Cycle count period must divide exactly PWM period of wave and be greater than the maximum of pulsewidth length, the accuracy of such guarantee PWM period of wave, ensures that each probable value of PWM ripple pulsewidth can both be generated.
3. a kind of PWM ripple generation method based on timer according to claim 1, it is characterized in that: " the high level triggering subtrahend counting described in step 2, rising edge flip-flop number heavy duty, output low level during count value non-zero, count value is kept to the mode of operation exporting high level after zero ", it is the mode of operation that the another kind of timer can be arranged, its function is: at the end of each cycle count period, the negative pulse that the input that PWM ripple generates timer all can receive from cycle count timer output end makes count value that heavy duty occur, and the high level continued makes subtrahend counting work on.
4. a kind of PWM ripple generation method based on timer according to claim 1, it is characterized in that: " break in service function " described in step 3, it is the function that triggered interrupts calls at the end of each cycle count period, its function is: carry out cycle count in function inside, the inner loop count cycle is just in time the quotient of PWM period of wave and cycle count timer period, / timer clock frequency that the count value of the timer that PWM ripple generates by the one-period of each inner loop is rewritten as (cycle count timer period-generate PWM ripple pulsewidth length), within this cycle, timer will inevitably count end like this, thus produce the high level with pulsewidth length equal time, other process is not done within ensuing several cycle of inner loop.
CN201510089189.0A 2014-07-24 2015-02-27 Timer-based PWM (Pulse Width Modulation) wave generation method Active CN104702251B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510089189.0A CN104702251B (en) 2014-07-24 2015-02-27 Timer-based PWM (Pulse Width Modulation) wave generation method

Applications Claiming Priority (3)

Application Number Priority Date Filing Date Title
CN2014103556156 2014-07-24
CN201410355615 2014-07-24
CN201510089189.0A CN104702251B (en) 2014-07-24 2015-02-27 Timer-based PWM (Pulse Width Modulation) wave generation method

Publications (2)

Publication Number Publication Date
CN104702251A true CN104702251A (en) 2015-06-10
CN104702251B CN104702251B (en) 2017-04-19

Family

ID=53349072

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510089189.0A Active CN104702251B (en) 2014-07-24 2015-02-27 Timer-based PWM (Pulse Width Modulation) wave generation method

Country Status (1)

Country Link
CN (1) CN104702251B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113552843A (en) * 2021-07-08 2021-10-26 武汉雄韬氢雄燃料电池科技有限公司 High-precision fixed-point output method for numerical control machine tool
CN115001325A (en) * 2022-04-20 2022-09-02 北京瑞祺皓迪技术股份有限公司 Timed interrupt control method and multi-step motor synchronous control system and method

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102103168A (en) * 2009-12-22 2011-06-22 比亚迪股份有限公司 PWM (Pulse-Width Modulation) wave detecting method and device
US20130191428A1 (en) * 2012-01-19 2013-07-25 Makita Corporation Random number generating device
CN103873035A (en) * 2014-03-07 2014-06-18 电子科技大学 Timer-based PWM (Pulse-Width Modulation) control signal system for generating adjustable dead zone

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102103168A (en) * 2009-12-22 2011-06-22 比亚迪股份有限公司 PWM (Pulse-Width Modulation) wave detecting method and device
US20130191428A1 (en) * 2012-01-19 2013-07-25 Makita Corporation Random number generating device
CN103873035A (en) * 2014-03-07 2014-06-18 电子科技大学 Timer-based PWM (Pulse-Width Modulation) control signal system for generating adjustable dead zone

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
李宁等: "利用单片机定时器实现信号采样和PWM控制", 《微型机与应用》 *
梁伟等: "采用单片机定时器设计PWM实现廉价的高分辨率D/A 转换器", 《吉林化工学院学报》 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113552843A (en) * 2021-07-08 2021-10-26 武汉雄韬氢雄燃料电池科技有限公司 High-precision fixed-point output method for numerical control machine tool
CN115001325A (en) * 2022-04-20 2022-09-02 北京瑞祺皓迪技术股份有限公司 Timed interrupt control method and multi-step motor synchronous control system and method

Also Published As

Publication number Publication date
CN104702251B (en) 2017-04-19

Similar Documents

Publication Publication Date Title
EP2005589B1 (en) Allowing immediate update of pulse width modulation values
CN1022865C (en) High Resolution pulse width modulation
CN100550631C (en) Pulse width modulation device
CN104702251A (en) Timer-based PWM (Pulse Width Modulation) wave generation method
US20220014123A1 (en) Linear resonant device, and braking method for same
CN104698286B (en) A kind of PWM ripple acquisition methods based on timer
CN103560783A (en) Digital event generator, comparator, switched mode energy converter and method
CN104796048A (en) Alternating-current motor current loop parallelism digital control implementation method
CN103828237B (en) Maintain pulse width modulation data set coherence
CN106598034A (en) Motor drive control strategy test system and method
CN103855928A (en) Multifunctional digital pulse width modulation controller
CN101335494B (en) Method and apparatus for controlling asynchronous motors
CN104767431A (en) Control method, device and system for direct current brushless motor pulse width modulation
CN103675373A (en) Digital signal generation method achieved in FPGA
KR20140137416A (en) Method and circuit arrangement for limiting peak currents and pitch of current flanks
CN101122787A (en) Method and apparatus for positioning the object
US20140001992A1 (en) Control Circuit with Frequency Hopping for Permanent Magnet Motor Control
CN106933535B (en) A method of realizing that high-precision is delayed in SCM system
CN108107777A (en) A kind of pulse sending method and system
CN105375904B (en) It is a kind of to generate rapid exponential type pulse output method with ARM single-chip microcontroller
CN107053169B (en) Bus type intelligent servo driving system, robot and method
CN104205634A (en) High resolution pulse width modulator
CN103166496B (en) Inversion control device and method
CN107046382B (en) A kind of iteration speed control method based on trigonometric function
KR20110132640A (en) Input shaper for non-linear actuators and input shaping method thereof

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant