CN104796118A - Method for breaking through limited pwm (pulse width modulation) output of MCU (micro control unit) hardware - Google Patents

Method for breaking through limited pwm (pulse width modulation) output of MCU (micro control unit) hardware Download PDF

Info

Publication number
CN104796118A
CN104796118A CN201510211221.8A CN201510211221A CN104796118A CN 104796118 A CN104796118 A CN 104796118A CN 201510211221 A CN201510211221 A CN 201510211221A CN 104796118 A CN104796118 A CN 104796118A
Authority
CN
China
Prior art keywords
pwm
mcu
formula
output
time
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
CN201510211221.8A
Other languages
Chinese (zh)
Other versions
CN104796118B (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.)
Shenzhen Zhenbang intelligent Polytron Technologies Inc
Original Assignee
SHENZHEN ZHENBANG INTELLIGENT TECHNOLOGY Co Ltd
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 SHENZHEN ZHENBANG INTELLIGENT TECHNOLOGY Co Ltd filed Critical SHENZHEN ZHENBANG INTELLIGENT TECHNOLOGY Co Ltd
Priority to CN201510211221.8A priority Critical patent/CN104796118B/en
Publication of CN104796118A publication Critical patent/CN104796118A/en
Application granted granted Critical
Publication of CN104796118B publication Critical patent/CN104796118B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The invention discloses a method for breaking through limited pwm (pulse width modulation) output of MCU (micro control unit) hardware. The method is characterized by including the following steps: S1, initializing clock configuration, and configuring an 8-bit continuous clock overflow interrupt in the MCU; S2, performing normal operation for set time prior to appearing of one interrupt; S3, judging whether an I/O (input/output) output flag is true or not, if yes, reloading low-level time in pwm to a clock timer, setting the I/O output flag as false, outputting low level by an I/O port, and then repeating the step S2; if the I/O output flag is false, reloading high-level time in the pwm to the clock timer, setting the I/O output flag as true, outputting high level by the I/O port, and then repeating the step S2. Product upgrade and development cycle is short, change of a hardware circuit, addition of a high-speed external crystal oscillator or replacement for a high-speed MCU is not needed, and cost is lowered.

Description

A kind of restriction breaking through MCU hardware exports the method for pwm
Technical field
The present invention relates to pulse-width modulation field, particularly relate to a kind of method that restriction breaking through MCU hardware exports pwm.
Background technology
In current various electronic equipment, the perfect in shape and function of MCU, wherein just comprises pwm output function; The output function of its MCU hardware supports pwm, only needs to carry out pwm configuration to current MCU, and the pwm that can obtain corresponding frequency exports.
But the crystal oscillator selected for this MCU and electronic circuit limit the frequency that this MCU hardware pwm exports, and in order to improve the frequency of the output of pwm, existing technology has three kinds:
(1) change hardware circuit, pwm delivery outlet is changed to the outlet of other pwm function numbers.Defect is: product up-gradation change circuit and software carry out simultaneously, and the upgrading construction cycle is long, and negative value is many;
(2) add high speed outer crystal oscillator, pwm output frequency is increased.Defect is: need upgrade circuit and most of software merit rating, and the upgrading construction cycle is long, and product cost raises, and negative value is many;
(3) more high speed MCU is changed.Defect is: product cost raises, and software is developed again, and the cycle is long.
Summary of the invention
The object of this invention is to provide a kind of method that restriction breaking through MCU hardware exports pwm, promoting pwm output frequency when increasing hardware unit and circuit structure.
Technical scheme of the present invention is a kind of method that restriction breaking through MCU hardware exports pwm, comprises the steps:
S1, initialization clock configure, and the continuous print clock configuring 8 in MCU overflows interruption;
S2, normally to run, after the time of setting, occur an interruption; And
S3, judge whether I/O output identification is true, when I/O output identification is true time, in heavily loaded pwm, low level time is to clock timer, and I/O output identification is set to vacation, I/O mouth output low level, then repeats step S2; When I/O output identification is fictitious time, in heavily loaded pwm, high level time is to clock timer, and I/O output identification is set to very, and I/O mouth exports high level, then repeats step S2.
The technical program adopts 8 bit clock timers to carry out simulation pwm output function, makes it possible to I/O mouth adjustable duty cycle number Dc in MCU to set arbitrarily.As by Dc=100, so Dc<255; Frequency is raised, breaches the pwm output function of original MCU hardware.The product up-gradation construction cycle is short, does not need change hardware circuit, adds high speed outer crystal oscillator or change high speed MCU, reduce cost.
Further, in step S2, the time of described setting meets following formula:
Tx=255*t
In formula, Tx represents the distance next time of interrupting, and t represents the instruction cycle of MCU.When program runs to time Tx, there is an interruption; When off-duty is to Tx, continue to run.
Further, in step S3, in heavily loaded pwm, low level time meets following formula:
Tl=(255-Dc+Dd)*t
In formula, Tl represents low level time in pwm, and t represents the instruction cycle of MCU, and Dc represents adjustable duty cycle number, and Dd represents the numerical value that duty ratio is corresponding.
Further, in step S3, in heavily loaded pwm, high level time meets following formula:
Th=(255-Dd)*t
In formula, Th represents high level time in pwm, and t represents the instruction cycle of MCU, and Dd represents the numerical value that duty ratio is corresponding.
Further, the cycle of the final stable output of I/O mouth of MCU is the pwm waveform of T, and described cycle T meets formula:
T=Th+Tl=Dc*t (1)
In formula, T represents the cycle of pwm, and t represents the MCU instruction cycle, and Dc represents adjustable duty cycle number;
The duty ratio of described pwm waveform is (Dd/Dc) * 100%;
Can draw according to formula (1), the frequency that the I/O mouth of MCU finally exports pwm waveform meets formula:
Fpwm=1/T=1/(Dc*t)
In formula, Dc represents adjustable duty cycle number, and t represents the instruction cycle of MCU
Beneficial effect: by adopting 8 bit clock timers to carry out simulation pwm output function, makes it possible to I/O mouth adjustable duty cycle number Dc in MCU to set arbitrarily, frequency is raised, breaches the pwm output function of original MCU hardware.The product up-gradation construction cycle is short, does not need change hardware circuit, adds high speed outer crystal oscillator or change high speed MCU, reduce cost.
Accompanying drawing explanation
Fig. 1 is the workflow diagram of an embodiment of the present invention.
Embodiment
Below in conjunction with accompanying drawing, preferably embodiment of the present invention is described in further detail:
See Fig. 1, a kind of restriction breaking through MCU hardware exports the method for pwm, comprises the steps:
S1, initialization clock configure, and the continuous print clock configuring 8 in MCU overflows interruption;
S2, normally to run, after the time of setting, occur an interruption; And
S3, judge whether I/O output identification is true, when I/O output identification is true time, in heavily loaded pwm, low level time is to clock timer, and I/O output identification is set to vacation, I/O mouth output low level, then repeats step S2; When I/O output identification is fictitious time, in heavily loaded pwm, high level time is to clock timer, and I/O output identification is set to very, and I/O mouth exports high level, then repeats step S2.
In step S2, the time of described setting meets following formula:
Tx=255*t
In formula, Tx represents the distance next time of interrupting, and t represents the instruction cycle of MCU.When program runs to time Tx, there is an interruption; When off-duty is to Tx, continue to run.
In step S3, in heavily loaded pwm, low level time meets following formula:
Tl=(255-Dc+Dd)*t
In formula, Tl represents low level time in pwm, and t represents the instruction cycle of MCU, and Dc represents adjustable duty cycle number, and Dd represents the numerical value that duty ratio is corresponding.
In step S3, in heavily loaded pwm, high level time meets following formula:
Th=(255-Dd)*t
In formula, Th represents high level time in pwm, and t represents the instruction cycle of MCU, and Dd represents the numerical value that duty ratio is corresponding.
The cycle of the final stable output of I/O mouth of MCU is the pwm waveform of T, and described cycle T meets formula:
T=Th+Tl=Dc*t (1)
In formula, T represents the cycle of pwm, and t represents the MCU instruction cycle, and Dc represents adjustable duty cycle number;
The duty ratio of described pwm waveform is (Dd/Dc) * 100%;
Can draw according to formula (1), the frequency that the I/O mouth of MCU finally exports pwm waveform meets formula:
Fpwm=1/T=1/(Dc*t)
In formula, Dc represents adjustable duty cycle number, and t represents the instruction cycle of MCU.
In the present embodiment, MCU model is MB95F564K, t=0.25, supposes Dd=50, Dc=100, and so the duty ratio of pwm waveform is:
50/100*100=50%,
The frequency that the I/O mouth of MCU finally exports pwm waveform is:
(1/100*0.25)MHz=40KHz。
Therefore, in software by 50 assignment to Dd, the duty ratio that this MCU just can be made to export a 40KHz is the pwm waveform of 50%.
The present embodiment adopts 8 bit clock timers to carry out simulation pwm output function, makes it possible to I/O mouth adjustable duty cycle number Dc in MCU to set arbitrarily.As by Dc=100, so Dc<255; Frequency is raised, breaches the pwm output function of original MCU hardware.The product up-gradation construction cycle is short, does not need change hardware circuit, adds high speed outer crystal oscillator or change high speed MCU, reduce cost.
Above content is in conjunction with concrete preferred implementation further description made for the present invention, can not assert that specific embodiment of the invention is confined to these explanations.For general technical staff of the technical field of the invention, without departing from the inventive concept of the premise, some simple deduction or replace can also be made, all should be considered as belonging to protection scope of the present invention.

Claims (5)

1. the restriction breaking through MCU hardware exports a method of pwm, it is characterized in that, comprises the steps:
S1, initialization clock configure, and the continuous print clock configuring 8 in MCU overflows interruption;
S2, normally to run, after the time of setting, occur an interruption; And
S3, judge whether I/O output identification is true, when I/O output identification is true time, in heavily loaded pwm, low level time is to clock timer, and I/O output identification is set to vacation, I/O mouth output low level, then repeats step S2; When I/O output identification is fictitious time, in heavily loaded pwm, high level time is to clock timer, and I/O output identification is set to very, and I/O mouth exports high level, then repeats step S2.
2. the restriction of breakthrough MCU hardware according to claim 1 exports the method for pwm, and it is characterized in that, in step S2, the time of described setting meets following formula:
Tx=255*t
In formula, Tx represents the distance next time of interrupting, and t represents the instruction cycle of MCU.
3. the restriction of breakthrough MCU hardware according to claim 2 exports the method for pwm, and it is characterized in that, in step S3, in heavily loaded pwm, low level time meets following formula:
Tl=(255-Dc+Dd)*t
In formula, Tl represents low level time in pwm, and t represents the instruction cycle of MCU, and Dc represents adjustable duty cycle number, and Dd represents the numerical value that duty ratio is corresponding.
4. the restriction of breakthrough MCU hardware according to claim 3 exports the method for pwm, and it is characterized in that, in step S3, in heavily loaded pwm, high level time meets following formula:
Th=(255-Dd)*t
In formula, Th represents high level time in pwm, and t represents the instruction cycle of MCU, and Dd represents the numerical value that duty ratio is corresponding.
5. the restriction of breakthrough MCU hardware according to claim 4 exports the method for pwm, and it is characterized in that, the cycle of the final stable output of I/O mouth of MCU is the pwm waveform of T, and described cycle T meets formula:
T=Th+Tl=Dc*t (1)
In formula, T represents the cycle of pwm, and t represents the MCU instruction cycle, and Dc represents adjustable duty cycle number;
The duty ratio of described pwm waveform is (Dd/Dc) * 100%;
Can draw according to formula (1), the frequency that the I/O mouth of MCU finally exports pwm waveform meets formula:
Fpwm=1/T=1/(Dc*t)
In formula, Dc represents adjustable duty cycle number, and t represents the instruction cycle of MCU.
CN201510211221.8A 2015-04-29 2015-04-29 A kind of limitation output pwm of breakthrough MCU hardware method Active CN104796118B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510211221.8A CN104796118B (en) 2015-04-29 2015-04-29 A kind of limitation output pwm of breakthrough MCU hardware method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510211221.8A CN104796118B (en) 2015-04-29 2015-04-29 A kind of limitation output pwm of breakthrough MCU hardware method

Publications (2)

Publication Number Publication Date
CN104796118A true CN104796118A (en) 2015-07-22
CN104796118B CN104796118B (en) 2017-09-26

Family

ID=53560678

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510211221.8A Active CN104796118B (en) 2015-04-29 2015-04-29 A kind of limitation output pwm of breakthrough MCU hardware method

Country Status (1)

Country Link
CN (1) CN104796118B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105446417A (en) * 2014-08-21 2016-03-30 Tcl集团股份有限公司 Method and system for acquiring high-precision timing signal

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6995592B2 (en) * 2003-11-06 2006-02-07 Stmicroelectronics Pvt. Ltd. Method and system for generating variable frequency cyclic waveforms using pulse width modulation
US20060104343A1 (en) * 2004-10-29 2006-05-18 Stmicroelectronics Pvt. Ltd. PWM generator providing improved duty cycle resolution
CN1996729A (en) * 2006-12-23 2007-07-11 深圳市拓邦电子科技股份有限公司 Multi-channel PWM generation system and method
US7348755B2 (en) * 2003-12-18 2008-03-25 The Boeing Company Time sliced DSP operation for very high frequency pulse width modulated controllers
CN103312300A (en) * 2013-06-24 2013-09-18 哈尔滨工业大学 Pulse-width modulation (PWM) signal generator based on field programmable gate array (FPGA)

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6995592B2 (en) * 2003-11-06 2006-02-07 Stmicroelectronics Pvt. Ltd. Method and system for generating variable frequency cyclic waveforms using pulse width modulation
US7348755B2 (en) * 2003-12-18 2008-03-25 The Boeing Company Time sliced DSP operation for very high frequency pulse width modulated controllers
US20060104343A1 (en) * 2004-10-29 2006-05-18 Stmicroelectronics Pvt. Ltd. PWM generator providing improved duty cycle resolution
CN1996729A (en) * 2006-12-23 2007-07-11 深圳市拓邦电子科技股份有限公司 Multi-channel PWM generation system and method
CN103312300A (en) * 2013-06-24 2013-09-18 哈尔滨工业大学 Pulse-width modulation (PWM) signal generator based on field programmable gate array (FPGA)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105446417A (en) * 2014-08-21 2016-03-30 Tcl集团股份有限公司 Method and system for acquiring high-precision timing signal
CN105446417B (en) * 2014-08-21 2018-07-27 Tcl集团股份有限公司 A kind of method and system obtaining high precision timing signal

Also Published As

Publication number Publication date
CN104796118B (en) 2017-09-26

Similar Documents

Publication Publication Date Title
ATE554443T1 (en) INSTRUCTION-DRIVEN DATA PROCESSING DEVICE AND METHOD
CN103324546B (en) A kind of method and device of watchdog service delay
CN104571444A (en) Method for controlling power state of server through BIOS
CN106227293A (en) A kind of system clock
CN105528208A (en) TCON-less screen parameter separation control method
WO2022135440A1 (en) Llc resonant circuit control method and control apparatus, and terminal device
CN104796118A (en) Method for breaking through limited pwm (pulse width modulation) output of MCU (micro control unit) hardware
CN103838183A (en) Numerical control system and output control method thereof
EP3333680B1 (en) Drive unit, method and circuit for touch control drive electrode, and touch control display panel
CN103970255A (en) Information processing method and electronic equipment
CN202111899U (en) LED (Light-emitting Diode) decorating tube and integrated drive circuit thereof comprising 24V numerical control overvoltage protection circuit
CN202600428U (en) Intelligent control cabinet in communication with high-voltage frequency converter
CN105652813B (en) A method of embedded real-time EtherCAT main websites are built based on AM335X processors
CN104104367A (en) Multi-waveform signal generator
CN102662780B (en) Protection method and protection device for power supply in multiple-programmable-device system
CN204613603U (en) The synchro system of clock information and air conditioner
CN102402270A (en) Method and system for regulating frequency of central processing unit
CN105487597A (en) Clock management method and device of central processing unit
CN106569879B (en) Method for awakening peripheral and mobile terminal
CN110192183A (en) Computer installation, task start method and task start program
CN106774788A (en) A kind of SOC and its kernel Cooperation controlling unit based on MCU
CN106059400B (en) A kind of motor HALL rate smoothing processing method
CN105093996A (en) I/O port expansion control device and control method
CN102323903B (en) SOC (system-on-chip) chip simulation system and method
CN105159708A (en) Information processing method and electronic device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
EXSB Decision made by sipo to initiate substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP03 Change of name, title or address

Address after: 518000 Guangdong province Shenzhen Guangming New District Gongming street Gongming South Avenue Geya Technology Building 3 building 1-4 layer

Patentee after: Shenzhen Zhenbang intelligent Polytron Technologies Inc

Address before: 518000 Guangdong, Nanshan District, Taoyuan, Longjing street, industrial zone, building A, building 2, building A, building on the ground floor, building B, building, building 6, building C, block B, building, building No. 3

Patentee before: SHENZHEN ZHENBANG INTELLIGENT TECHNOLOGY CO., LTD.

CP03 Change of name, title or address