CN107117321B - Method and device for outputting complementary pulse modulation waves by single chip microcomputer and single chip microcomputer - Google Patents

Method and device for outputting complementary pulse modulation waves by single chip microcomputer and single chip microcomputer Download PDF

Info

Publication number
CN107117321B
CN107117321B CN201710138208.3A CN201710138208A CN107117321B CN 107117321 B CN107117321 B CN 107117321B CN 201710138208 A CN201710138208 A CN 201710138208A CN 107117321 B CN107117321 B CN 107117321B
Authority
CN
China
Prior art keywords
output
timer
configuring
gpio
pwm wave
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.)
Active
Application number
CN201710138208.3A
Other languages
Chinese (zh)
Other versions
CN107117321A (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.)
Beijing Yuandu Internet Technology Co ltd
Original Assignee
Tianjin Yuanyu 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 Tianjin Yuanyu Technology Co ltd filed Critical Tianjin Yuanyu Technology Co ltd
Priority to CN201710138208.3A priority Critical patent/CN107117321B/en
Publication of CN107117321A publication Critical patent/CN107117321A/en
Application granted granted Critical
Publication of CN107117321B publication Critical patent/CN107117321B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • BPERFORMING OPERATIONS; TRANSPORTING
    • B64AIRCRAFT; AVIATION; COSMONAUTICS
    • B64DEQUIPMENT FOR FITTING IN OR TO AIRCRAFT; FLIGHT SUITS; PARACHUTES; ARRANGEMENTS OR MOUNTING OF POWER PLANTS OR PROPULSION TRANSMISSIONS IN AIRCRAFT
    • B64D27/00Arrangement or mounting of power plant in aircraft; Aircraft characterised thereby
    • B64D27/02Aircraft characterised by the type or position of power plant
    • B64D27/24Aircraft characterised by the type or position of power plant using steam, electricity, or spring force
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/14Handling requests for interconnection or transfer
    • G06F13/20Handling requests for interconnection or transfer for access to input/output bus
    • G06F13/28Handling requests for interconnection or transfer for access to input/output bus using burst mode transfer, e.g. direct memory access DMA, cycle steal
    • HELECTRICITY
    • H02GENERATION; CONVERSION OR DISTRIBUTION OF ELECTRIC POWER
    • H02PCONTROL OR REGULATION OF ELECTRIC MOTORS, ELECTRIC GENERATORS OR DYNAMO-ELECTRIC CONVERTERS; CONTROLLING TRANSFORMERS, REACTORS OR CHOKE COILS
    • H02P27/00Arrangements or methods for the control of AC motors characterised by the kind of supply voltage
    • H02P27/04Arrangements or methods for the control of AC motors characterised by the kind of supply voltage using variable-frequency supply voltage, e.g. inverter or converter supply voltage

Abstract

The invention relates to a method for outputting complementary PWM waves by a singlechip, wherein the method comprises the following steps: selecting a general timer and an even number of GPIO interfaces connected with the general timer; configuring working parameters of the general timer and the GPIO interface; enabling a clock of the general timer and a clock of the GPIO interface; and starting the general timer to work according to the configured working parameters, so that every two interfaces of the even number of GPIO interfaces output complementary PWM waves. The invention also relates to an output device of the complementary PWM waves, a single chip microcomputer and an unmanned aerial vehicle. The invention can drive more circuit elements by configuring more universal timers, so that the invention is not limited by the number of the advanced timers.

Description

Method and device for outputting complementary pulse modulation waves by single chip microcomputer and single chip microcomputer
Technical Field
The invention relates to the technical field of single-chip microcomputers, in particular to a method and a device for outputting complementary pulse modulation waves by a single-chip microcomputer, the single-chip microcomputer and an unmanned aerial vehicle.
Background
The general single chip microcomputer internally comprises a high-level timer, and because the high-level timer is configured with a plurality of parameters, complementary Pulse Width Modulation (PWM) waves can be output through simple configuration. Each advanced timer can output three groups of complementary PWM waves, and the three groups of complementary PWM waves can drive one motor. Because the number of high-level timers contained in the singlechip is limited, the number of output complementary PWM wave channels is also limited. For example, the current STM32 single chip microcomputer only comprises two high-level timers, and only can output six groups of complementary PWM waves, so that one STM32 single chip microcomputer can only drive two paths of motors at most.
Therefore, the current single chip microcomputer has the problem that the number of output complementary PWM wave channels is limited by the number of advanced timers.
Disclosure of Invention
Based on this, the application provides a method, device, singlechip and unmanned aerial vehicle of singlechip output complementary PWM ripples is used for solving above-mentioned singlechip output complementary PWM ripples passageway number and receives the problem of senior timer number restriction.
On one hand, the application provides a method for outputting complementary PWM waves by a singlechip, wherein the method comprises the following steps:
selecting a general timer and an even number of GPIO interfaces connected with the general timer;
configuring working parameters of the general timer and the GPIO interface;
enabling a clock of the general timer and a clock of the GPIO interface;
and starting the general timer to work according to the configured working parameters, so that every two interfaces in the even number of GPIO interfaces output complementary PWM waves.
According to the method for outputting the complementary PWM waves by the single chip microcomputer, the complementary PWM waves can be output by the single chip microcomputer through the universal timer by configuring the working parameters of the universal timer and the GPIO interface. Therefore, in order to output multiple sets of complementary PWM waves, the complementary PWM waves can be realized by configuring more universal timers to drive more circuit elements, so that the number of channels of the complementary PWM waves output by the single chip microcomputer is not limited by the number of high-level timers.
In one embodiment, selecting an even number of GPIO interfaces for the general purpose timer comprises:
and selecting GPIO interfaces with twice number of channels according to the number of channels of the complementary PWM waves to be output.
In one embodiment, configuring the operating parameters of the general-purpose timer and the GPIO interface includes:
configuring a clock frequency at which the universal timer operates;
configuring the counting mode of the universal timer to be an up-down counting mode;
configuring the output mode of the universal timer to be a PWM mode;
configuring the operating mode of the GPIO interface to be push-pull multiplexing;
configuring the output polarity of the GPIO interfaces to make two paths of PWM waves output by the GPIO interfaces in one group, wherein each group of PWM waves are complementary; and
the reload value of each PWM wave is set according to the configured clock frequency.
In one embodiment, the configuring the clock frequency at which the universal timer operates includes: the presorting value and the clock division value of the general timer are configured.
In one embodiment, the configuring the output polarity of the GPIO interfaces so that two sets of the GPIO interfaces output two PWM waves complementarily includes:
configuring the polarity of a first GPIO interface in each group of GPIO interfaces to be high so as to output an upper bridge PWM wave;
and configuring the polarity of a second GPIO interface in each group of GPIO interfaces to be low so as to output a lower bridge PWM wave, wherein the level of the upper bridge PWM wave is opposite to that of the lower bridge PWM wave.
In one embodiment, the step of setting the reload value of each PWM wave according to the configured clock frequency comprises:
and according to the working clock frequency of the universal timer, setting the reloading value of the upper bridge PWM wave and the reloading value of the lower bridge PWM wave, enabling the reloading values of the upper bridge PWM wave and the lower bridge PWM wave to be different by a preset value, and enabling the starting time interval of the upper bridge PWM wave and the lower bridge PWM wave to be preset in duration.
On the other hand, this application still provides a singlechip output complementary PWM ripples method, the method is applied to unmanned aerial vehicle, wherein, the method includes:
outputting complementary PWM waves by the method;
and selecting the three paths of complementary PWM waves to be used for driving a motor of the unmanned aerial vehicle.
In one embodiment, the single chip microcomputer is an STM32 single chip microcomputer.
In one embodiment, the motor comprises any one of the following functions:
a drive motor of the propeller;
the driving motor of cloud platform.
On the other hand, this application still provides complementary PWM ripples output device of singlechip, wherein, the device includes:
the selection module is used for selecting the general timer and an even number of GPIO interfaces connected with the general timer;
the working parameter configuration module is used for configuring the working parameters of the general timer and the GPIO interface;
the clock enabling module is used for enabling a clock of the general timer and a clock of the GPIO interface;
and the starting module is used for starting the general timer to work according to the configured working parameters, so that every two interfaces of the even number of GPIO interfaces output complementary PWM waves.
The device for outputting the complementary PWM waves by the single chip microcomputer enables the single chip microcomputer to output the complementary PWM waves by configuring the working parameters of the general timer and the GPIO interface. Therefore, in order to output multiple sets of complementary PWM waves, the complementary PWM waves can be realized by configuring more universal timers to drive more circuit elements, so that the number of channels of the complementary PWM waves output by the single chip microcomputer is not limited by the number of high-level timers.
In one embodiment, the selection module is further configured to select, according to the number of channels of the complementary PWM wave that needs to be output, GPIO interfaces twice as many as the number of the channels.
As one embodiment, the operating parameter configuration module includes:
the clock frequency configuration module is used for configuring the clock frequency of the work of the universal timer;
a counting mode configuration module, configured to configure the counting mode of the general timer to be an up-down counting mode;
the output mode configuration module is used for configuring the output mode of the universal timer to be a PWM mode;
the working mode configuration module is used for configuring the working mode of the GPIO interface to be push-pull multiplexing;
the output polarity configuration module is used for configuring the output polarity of the GPIO interfaces to make two paths of PWM waves output by the GPIO interfaces in one group and the GPIO interfaces in each group complement each other; and
and the reloading value setting module is used for setting the reloading value of each PWM wave according to the set clock frequency.
As one embodiment, the clock frequency configuration module includes:
the pre-frequency division value configuration module is used for configuring the pre-frequency division value of the universal timer;
and the clock division value configuration module is used for configuring the clock division value of the universal timer.
As one embodiment, the output polarity configuration module includes:
the first interface configuration module is used for configuring the polarity of a first GPIO interface in each group of GPIO interfaces to be high so as to output an upper bridge PWM wave;
and the second interface configuration module is used for configuring the polarity of the second GPIO interface in each group of GPIO interfaces to be low so as to output a lower bridge PWM wave, and the level of the upper bridge PWM wave is opposite to that of the lower bridge PWM wave.
As one embodiment, the reload value setting module is further configured to:
and according to the working clock frequency of the universal timer, setting the reloading value of the upper bridge PWM wave and the reloading value of the lower bridge PWM wave, enabling the reloading values of the upper bridge PWM wave and the lower bridge PWM wave to be different by a preset value, and enabling the starting time interval of the upper bridge PWM wave and the lower bridge PWM wave to be preset in duration.
On the other hand, the application also provides a single chip microcomputer, wherein the complementary PWM wave output device of the single chip microcomputer is included.
On the other hand, the application also provides an unmanned aerial vehicle, which comprises a motor and a single chip microcomputer, wherein the single chip microcomputer comprises a complementary PWM wave output device of the single chip microcomputer;
the motor is connected with the device, and the complementary PWM waves output by every three paths of the devices are used for driving a motor of the unmanned aerial vehicle.
As one embodiment, the single chip microcomputer is an STM32 single chip microcomputer.
As one embodiment, the motor includes a motor having any one of the following functions:
a drive motor of the propeller;
the driving motor of cloud platform.
The single chip microcomputer and the unmanned aerial vehicle can output complementary PWM waves by configuring the universal timer in the single chip microcomputer and the working parameters of the GPIO interface. Therefore, in order to output multiple sets of complementary PWM waves, the complementary PWM waves can be realized by configuring more universal timers to drive more circuit elements, so that the number of channels of the complementary PWM waves output by the single chip microcomputer is not limited by the number of high-level timers.
Drawings
FIG. 1 is a schematic structural diagram of a minimum system of an STM32 single chip microcomputer provided by the embodiment of the invention;
fig. 2 is a block flow diagram of a method for outputting complementary PWM waves by a single chip microcomputer according to an embodiment of the present invention;
fig. 3 is a flowchart of a method for configuring operating parameters of a general timer and a GPIO interface according to an embodiment of the present invention;
fig. 4 is a schematic waveform diagram of outputting two sets of complementary PWM waves by using a single chip microcomputer according to an embodiment of the present invention;
fig. 5 is a waveform diagram illustrating a dead zone D in the complementary PWM wave shown in fig. 4;
fig. 6 is a schematic structural diagram of a complementary PWM wave output device of a single chip microcomputer according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of an operating parameter configuration module according to an embodiment of the present invention;
fig. 8 is a schematic structural diagram of a driving motor using a single chip according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
It will be understood that, as used herein, the terms "first," "second," and the like may be used herein to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish one element from another.
For convenience of description, the following embodiments of the present application only use an STM32 single chip microcomputer as an example to illustrate the technical solution of the present application, and it should be understood that the present application is not limited thereto.
Referring to fig. 1, fig. 1 is a schematic structural diagram of an STM32 monolithic computer adopted in an embodiment of the present invention, where the STM32 monolithic computer includes two advanced timers (TIM1, TIM8) and a plurality of general timers (TIM2-TIM5), each general timer may be connected to four general purpose input/output (GPIO) interfaces, and each GPIO interface corresponds to one pin of PA0-PA15 and PB0-PB 15. By configuring the parameters of the general timer and the GPIO interface, the complementary PWM waves can be output by utilizing the general timer. In addition, by configuring a plurality of general timers and selecting a plurality of GPIO interfaces, a plurality of groups of complementary PWM waves can be output to drive different circuit elements.
Referring to fig. 2, the method for outputting complementary PWM waves by using a single chip microcomputer according to the present embodiment includes:
and step S10, selecting the general timer and an even number of GPIO interfaces connected with the general timer.
In the single chip microcomputer, one general timer can be connected with a plurality of GPIO interfaces, and each GPIO interface can output one path of PWM wave, so that at least two GPIO interfaces are needed for generating a group of complementary PWM waves. Therefore, multiple groups of GPIO interfaces can be selected as required, each group of GPIO interfaces comprises two GPIO interfaces so as to output multiple groups of complementary PWM waves, and the number of the selected GPIO interfaces is always even.
And step S20, configuring the general timer and the working parameters of the GPIO interface.
In order to output the complementary PWM wave, it is necessary to configure the operating parameters of the general-purpose timer and the GPIO interface, including the clock frequency, the counting mode, the output mode, etc. required by the general-purpose timer, and the operating mode, the output polarity, etc. of the GPIO interface. Meanwhile, the reloading value of the universal timer needs to be set according to the clock frequency of the universal timer.
In step S30, the clock of the general-purpose timer and the clock of the GPIO interface are enabled.
The clock for enabling the GPIO interface is a precondition that the GPIO interface can be used, and the enabling of the clock of the general timer is a precondition that the general timer works normally, and provides a basic clock signal for the general timer.
The general timers share the same clock source, so that the output PWM clocks are synchronous, and if the general timers do not share the same clock source, the clocks of the general timers need to be made into a synchronous mode through external signals.
And step S40, starting the general timer to work according to the configured working parameters, and enabling every two interfaces of the even number of GPIO interfaces to output complementary PWM waves.
After the configuration of the working parameters of the general timer and the GPIO interfaces connected with the general timer is completed, the general timer is started, so that every two GPIO interfaces output complementary PWM waves.
According to the method for outputting the complementary PWM waves by the single chip microcomputer, provided by the embodiment of the invention, the complementary PWM waves can be output by utilizing the general timer through configuring the working parameters of the general timer and the GPIO interface. Therefore, in order to output multiple groups of complementary PWM waves, the complementary PWM waves can be realized by configuring more universal timers to drive more circuit elements, so that the number of complementary PWM wave channels output by the singlechip is not limited by the number of high-level timers in the singlechip any more.
As one example, in step S10, selecting an even number of GPIO interfaces of the general-purpose timer includes: and selecting GPIO interfaces with twice number of channels according to the number of channels of complementary PWM waves to be output.
Specifically, a general timer in the STM32 singlechip is generally connected with four GPIO interfaces. When a plurality of groups of complementary PWM waves are required to be generated by using a general timer, a GPIO interface with the number being twice that of the channels of the PWM waves can be selected according to the number of the channels of the complementary PWM waves required to be output by circuit elements required to be driven. And each two selected GPIO interfaces output a group of complementary PWM waves.
In an STM32 singlechip, one general timer is generally connected with four GPIO interfaces, so that at most four groups of complementary PWM waves can be output by every two general timers. If the generated complementary PWM is used for driving the motors, each motor needs six paths of PWM waves to form three groups of complementary PWM waves, namely six GPIO interfaces are selected, so that at least two universal timers are required to be configured. As an alternative, three GPIO interfaces connected to one general-purpose timer may be selected, and then three GPIO interfaces connected to another general-purpose timer may be selected to implement six-way PWM wave output. In addition, as another alternative, four GPIO interfaces connected to one general-purpose timer may be selected, and then two GPIO interfaces connected to another general-purpose timer may be selected to implement six-channel PWM wave output, so that the two general-purpose timers may generate six channels of complementary PWM waves for driving the motor.
Referring to fig. 3, as an embodiment, in step S20, the configuring the operating parameters of the general-purpose timer and the GPIO interface includes the following steps:
step S21, configuring the working clock frequency of the universal timer;
step S22, configuring the counting mode of the universal timer as an up-down counting mode;
step S23, configuring the output mode of the universal timer as a PWM mode;
step S24, configuring the operating mode of the GPIO interface as push-pull multiplexing;
step S25, configuring the output polarity of the GPIO interfaces to make two paths of PWM waves output by the GPIO interfaces in one group, wherein each group of the two paths of PWM waves are complementary; and
step S26, a reload value for each PWM wave is set according to the configured clock frequency.
It should be noted that, the above steps are only used to describe parameter items for configuring the general-purpose timer and the GPIO interface, and do not limit the specific setting sequence.
In step S21, the clock frequency at which the general-purpose timer operates may be set according to the requirements of the circuit elements to be driven. Because the universal timers in the STM32 singlechip can share one clock source, such as an APB1 clock source, the universal timers can have the same clock frequency, and the output PWM waves are also in a synchronous mode. It will be appreciated that if the universal timers in the STM32 single chip microcomputer do not share the same clock source, the universal timers can be configured to be in a synchronous mode by external signals.
In step S22, the output of the complementary PWM wave can be realized by configuring the count mode of the general-purpose timer to be the up-down count mode, with centering in the PWM wave output appearance.
In step S24, the two PWM waves output by the at least two selected GPIO interfaces may be complemented by configuring the output polarities of the at least two selected GPIO interfaces.
In step S25, by turning on the general timer reload function, the reload value of each PWM wave is set, and the complementary PWM waves can be output.
According to the method for outputting the complementary PWM waves by using the STM32 single chip microcomputer, provided by the embodiment of the invention, the complementary PWM waves can be output by using the universal timer in the STM32 single chip microcomputer through configuring the universal timer and the GPIO interface; meanwhile, by configuring more universal timers, a plurality of sets of complementary PWM waves can be output, so that more circuit elements can be driven, and the limitation of the number of advanced timers is avoided.
As one example, in step S21, the step of setting the clock frequency at which the universal timer operates includes: the prescaled value and the clock split value of the universal timer are configured to set a clock frequency at which the universal timer operates.
Specifically, by configuring the prescaled value and the clock split value of the universal timer, the clock frequency at which the universal timer operates can be determined. The clock division value is obtained by dividing the clock source initially from APB1, then the actual action of the pre-division value is consistent with the clock division value, but the pre-division value can only be divided by 1, 2 and 4, namely the clock source is divided by 1, 2 and 4; the clock division value can be any integer from 0 to 65535. The configuration of the output clock frequency of the universal timer is realized through the combined action of the two timers. For example, in an STM32F103 single chip microcomputer, the APB1 clock source is 72MHz, and if the clock division value is selected to be 0, that is, 1 division, it is equivalent to maintaining the clock frequency.
As one embodiment, in step S25, configuring the polarity of the selected GPIO interface, and configuring the output polarity of the GPIO interface to make two groups of GPIO interfaces, where two PWM waves output by each group of GPIO interfaces are complementary to each other, includes:
configuring the polarity of a first GPIO interface in each group of GPIO interfaces to be high so as to output an upper bridge PWM wave;
and configuring the polarity of a second GPIO interface in each group of GPIO interfaces to be low so as to output a lower bridge PWM wave, wherein the level of the upper bridge PWM wave is opposite to that of the lower bridge PWM wave.
The configuration of the output polarities of the first GPIO interface and the second GPIO interface is high or low, which can be understood as that the level corresponding to the pre-output PWM duty ratio is high or low. For example: setting the polarity to be high, wherein the output duty ratio of the PWM wave is 20%, 20% of the output waveform is high level, and 80% of the output waveform is low level; the polarity is set to be low, the output duty ratio of the PWM wave is 20%, 20% of the output waveform is low level, and 80% of the output waveform is high level. Referring to fig. 4, in the first set of complementary PWM waves, the high level duty ratio is 20%, and in the second set of complementary PWM waves, the high level duty ratio is 60%.
As one embodiment, in step S26, the step of setting the reload value of each PWM wave according to the configured clock frequency includes:
and according to the working clock frequency of the universal timer, setting the reloading value of the upper bridge PWM wave and the reloading value of the lower bridge PWM wave, enabling the reloading values of the upper bridge PWM wave and the lower bridge PWM wave to be different by a preset value, and enabling the starting time interval of the upper bridge PWM wave and the lower bridge PWM wave to be preset in duration.
Referring to fig. 5, the preset duration of the configured interval is a dead zone D, where the dead zone D is that, in the complementary PWM wave, after the upper half-bridge is turned off, the lower half-bridge is turned on after a certain time delay; or after the lower half-bridge is switched off, the upper half-bridge is switched on after a period of time is delayed, so that the power element is prevented from being burnt or the power supply is prevented from being damaged due to the direct connection of the anode and the cathode of the power supply, and the delay time is a dead zone. Specifically, the reload value of the lower bridge PWM may be higher than a preset threshold of the reload value of the upper bridge PWM, the preset threshold is a preset time length added for preventing the power supply short circuit caused by the simultaneous conduction of the upper and lower MOS transistors in the application of the motor, the preset time length may be any value in 0.5us-1.5us, such as 500ns, 1us and the like, and may be selected according to the clock frequency of the timer.
Further, an embodiment of the present invention further provides a driving method for an unmanned aerial vehicle, where a method for outputting complementary PWM waves by a singlechip is applied to the unmanned aerial vehicle, and the method includes:
outputting complementary PWM waves by using the method of outputting complementary PWM waves by the singlechip;
and selecting the three paths of complementary PWM waves for output, and driving a motor in the unmanned aerial vehicle.
STM32 singlechip can be adopted in unmanned aerial vehicle. The complementary PWM ripples of output can be used to drive the driving motor who is arranged in driving the screw among the unmanned aerial vehicle, also can be used to drive the driving motor of cloud platform, still can be used to drive other driving motor etc. among the unmanned aerial vehicle.
Referring to fig. 6, the present invention further provides a device 1000 for outputting complementary PWM waves by a single chip microcomputer corresponding to the method for outputting complementary PWM waves by a single chip microcomputer, the device comprising:
the selection module 100 is used for selecting a general timer and an even number of GPIO interfaces connected with the general timer;
a working parameter configuration module 200, configured to configure working parameters of the general timer and the GPIO interface;
the clock enabling module 300 is used for enabling the clock of the general timer and the clock of the GPIO interface; and
and the starting module 400 is configured to start the general timer to operate according to the configured operating parameters, so that every two interfaces of the even number of GPIO interfaces output complementary PWM waves.
Specifically, the selection module 100 is configured to select multiple groups of GPIO interfaces as needed, where each group of GPIO interfaces includes two GPIO interfaces to output multiple complementary PWM waves, and the number of the selected GPIO interfaces is always an even number.
The work configuration module 200 is configured to configure the work parameters of the general-purpose timer and the GPIO interface, including a clock frequency, a counting mode, an output mode, etc. required by the general-purpose timer, and a work mode, an output polarity, etc. of the GPIO interface. Meanwhile, the reloading value of the universal timer needs to be set according to the clock frequency of the universal timer.
The always-on module 300 is configured to enable the clock of the general-purpose timer and the clock of the GPIO interface, and provide a basic clock signal for the general-purpose timer.
The starting module 400 is configured to start the general-purpose timer after the configuration of the operating parameters of the general-purpose timer and the GPIO interfaces connected to the general-purpose timer is completed, so that every two GPIO interfaces output complementary PWM waves.
According to the complementary PWM wave output device of the single chip microcomputer, the complementary PWM waves can be output by utilizing the universal timer of the single chip microcomputer through the configuration of the selection module, the working parameter configuration module, the clock enabling module and the starting module. Therefore, in order to output multiple sets of complementary PWM waves, more universal timers can be configured to drive more circuit elements, so that the number of advanced timers is not limited, and the driving manner is more flexible.
As one embodiment, the selection module 100 is further configured to select, according to the number of channels of the complementary PWM waves that need to be output, GPIO interfaces with twice the number of the channels.
Referring to fig. 7, as an embodiment, the working parameter configuration module 200 may further include:
a clock frequency configuration module 210, configured to configure a clock frequency at which the universal timer operates;
a counting mode configuration module 220, configured to configure the counting mode of the general timer to be an up-down counting mode;
an output mode configuration module 230, configured to configure the output mode of the general timer to be a PWM mode;
a working mode configuration module 240, configured to configure the working mode of the GPIO interface to be push-pull multiplexing;
an output polarity configuration module 250, configured to configure the output polarities of the GPIO interfaces, so that two paths of PWM waves output by two groups of GPIO interfaces are complementary; and
and a reload value setting module 260 for setting a reload value of each PWM wave according to the set clock frequency.
The clock frequency configuration module 210 can set the clock frequency of the general timer according to the requirement of the circuit element to be driven. Because the universal timers in the STM32 singlechip can share one clock source, such as an APB1 clock source, the universal timers can have the same clock frequency, and the output PWM waves are also in a synchronous mode.
The output polarity configuration module 240 may be configured to configure the output polarities of the selected at least two GPIO interfaces, so that the two PWM waves output by the selected at least two GPIO interfaces are complementary to each other.
The reloading value setting module 260 can be used for setting the reloading value of each PWM wave according to the set clock frequency, so as to avoid the power element from being burnt or the power supply from being damaged due to the direct connection of the anode and the cathode of the power supply, and improve the safety performance of the device.
As an embodiment, the clock frequency configuration module 210 further includes:
a prescaler value configuration module 211, configured to configure a prescaler value of the universal timer; and
a clock division value configuration module 213, configured to configure the clock division value of the universal timer.
The pre-divided value configuration module 211 and the clock divided value configuration module 213 can be used to configure the pre-divided value and the clock divided value of the universal timer to determine the clock frequency at which the universal timer operates.
For one embodiment, the output polarity configuration module 250 includes:
a first interface configuration module 251, configured to configure the polarity of the first GPIO interface in each group of GPIO interfaces to be high, so as to output an upper bridge PWM wave; and
and a second interface configuration module 253, configured to configure the polarity of the second GPIO interface in each group of GPIO interfaces to be low, so as to output a lower bridge PWM wave, where the level of the upper bridge PWM wave is opposite to that of the lower bridge PWM wave.
The first interface configuration module 251 and the second interface configuration module 253 configure the polarities of the GPIO interfaces to output different complementary PWM waves, so that the complementary PWM waves can be used to drive different types of circuit elements as needed, and the complementary PWM wave output device can drive different types of circuit elements simultaneously, thereby expanding the application range.
As one embodiment, the reload value setting module 260 is further configured to set a reload value of the upper bridge PWM wave and a reload value of the lower bridge PWM wave according to a clock frequency of the universal timer, so that the reload values of the upper bridge PWM wave and the lower bridge PWM wave are different by a preset value, and an on time interval between the upper bridge PWM wave and the lower bridge PWM wave is preset.
The reload value setting module 260 may be configured to configure a reload value to implement the configuration of a dead zone, so that the lower half-bridge is turned on after the upper half-bridge is turned off in the complementary PWM wave; or after the lower half-bridge is switched off, the upper half-bridge is switched on after a period of time is delayed, so that the power element is prevented from being burnt or the power supply is prevented from being damaged due to the direct connection of the anode and the cathode of the power supply.
The embodiment of the invention also provides the singlechip, which comprises a complementary PWM wave output device for outputting complementary PWM waves. Specifically, the single chip microcomputer may include the complementary PWM wave output device described in any one of the above embodiments. The single chip microcomputer can output complementary PWM waves through the universal timer, and the single chip microcomputer comprises a plurality of universal timers, so that the single chip microcomputer can be used for driving a plurality of elements.
Fig. 8 is a schematic diagram of driving a motor by using an STM32 single chip microcomputer. The adopted singlechip is specifically an STM32F103c8t6 singlechip, a Cortex-M3 kernel F1 series small memory processor is adopted, and a power supply, a clock and a reset circuit are added to realize a minimum working circuit system. The general timer TIM2 is used as the output of the upper bridge PWM wave, the corresponding pins of the general timer TIM2 are four GPIO ports of PA0, PA1, PA2 and PA3, and the adopted GPIO ports are PA0, PA1 and PA 2; a general timer TIM4 is used as the output of the lower bridge PWM wave, corresponding pins of the general timer TIM4 are four GPIO ports PB6, PB7, PB8 and PB9, and adopted GPIO ports are PB6, PB7 and PB 8. Meanwhile, TIM2 and TIM4 share the same clock source and are 72MHz, so that the clocks are synchronous; two timers are configured, the reloading value is 1000, the frequency division value is 36 clocks, and PWM waves with the frequency of 1K (72M/36/1000 is 2K and is 1K due to counting up and down) are output; the reloading value of the universal timer TIM4 as the lower bridge is numerically 2 more than that of the universal timer TIM2, the clock frequency is 2MHz, 2 × 1/2M is 1us, and the dead zone is found to be 1 μ s by calculation.
The embodiment of the invention also provides the unmanned aerial vehicle which comprises the complementary PWM wave output device and the motor, wherein the motor is connected with the complementary PWM wave output device, and the complementary PWM waves output by every three paths of complementary PWM wave output devices are used for driving the motor of the unmanned aerial vehicle. Specifically, can include a plurality of motors among the unmanned aerial vehicle, this complementary PWM ripples output device can be used to drive each motor among the unmanned aerial vehicle, and motor among the unmanned aerial vehicle is connected with this complementary PWM ripples output device, and the complementary PWM ripples of three routes that this complementary PWM ripples output device exported for drive a motor among the unmanned aerial vehicle. This complementary PWM ripples output device can be arranged in driving unmanned aerial vehicle, and the driving motor of any function in the driving motor of screw, the driving motor of cloud platform etc. also can be used to the driving motor of drive screw and the driving motor of cloud platform simultaneously, can select according to actual need for drive mode flexibility more.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a non-volatile computer-readable storage medium, and can include the processes of the embodiments of the methods described above when executed. The non-volatile storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), or the like.
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above examples only show some embodiments of the present invention, and the description thereof is specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (17)

1. A method for outputting complementary PWM waves by a singlechip is characterized by comprising the following steps:
selecting a general timer and an even number of GPIO interfaces connected with the general timer;
configuring working parameters of the general timer and the GPIO interface;
enabling a clock of the general timer and a clock of the GPIO interface;
starting the general timer to work according to the configured working parameters, so that every two interfaces in the even number of GPIO interfaces output complementary PWM waves;
wherein, configuring the working parameters of the general timer and the GPIO interface comprises:
configuring a clock frequency at which the universal timer operates;
configuring the counting mode of the universal timer to be an up-down counting mode;
configuring the output mode of the universal timer to be a PWM mode;
configuring the operating mode of the GPIO interface to be push-pull multiplexing;
configuring the output polarity of the GPIO interfaces to make two paths of PWM waves output by the GPIO interfaces in one group, wherein each group of PWM waves are complementary; and
the reload value of each PWM wave is set according to the configured clock frequency.
2. The method of claim 1, wherein selecting an even number of GPIO interfaces for the general purpose timer comprises:
and selecting GPIO interfaces with twice number of channels according to the number of channels of the complementary PWM waves to be output.
3. The method of claim 1, wherein configuring the clock frequency at which the universal timer operates comprises: the presorting value and the clock division value of the general timer are configured.
4. The method of claim 1, wherein the configuring the output polarity of the GPIO interfaces such that two PWM waves output by each group of GPIO interfaces are complementary comprises:
configuring the polarity of a first GPIO interface in each group of GPIO interfaces to be high so as to output an upper bridge PWM wave;
and configuring the polarity of a second GPIO interface in each group of GPIO interfaces to be low so as to output a lower bridge PWM wave, wherein the level of the upper bridge PWM wave is opposite to that of the lower bridge PWM wave.
5. The method of claim 4, wherein the step of setting the reload value for each PWM wave according to the configured clock frequency comprises:
and according to the working clock frequency of the universal timer, setting the reloading value of the upper bridge PWM wave and the reloading value of the lower bridge PWM wave, enabling the reloading values of the upper bridge PWM wave and the lower bridge PWM wave to be different by a preset value, and enabling the starting time interval of the upper bridge PWM wave and the lower bridge PWM wave to be preset in duration.
6. A method for outputting complementary PWM waves by a single chip microcomputer is applied to an unmanned aerial vehicle, and is characterized by comprising the following steps:
outputting complementary PWM waves using the method of any one of claims 1 to 5;
and selecting the three paths of complementary PWM waves to be used for driving a motor of the unmanned aerial vehicle.
7. The method of claim 6, wherein the single chip microcomputer is an STM32 single chip microcomputer.
8. The method according to claim 6 or 7, wherein the electric machine comprises an electric machine of any one of the following functions:
a drive motor of the propeller;
the driving motor of cloud platform.
9. A complementary PWM ripples output device of singlechip, its characterized in that, the device includes:
the selection module is used for selecting the general timer and an even number of GPIO interfaces connected with the general timer;
the working parameter configuration module is used for configuring the working parameters of the general timer and the GPIO interface;
the clock enabling module is used for enabling a clock of the general timer and a clock of the GPIO interface;
the starting module is used for starting the general timer to work according to the configured working parameters, so that every two interfaces in the even number of GPIO interfaces output complementary PWM waves; wherein the content of the first and second substances,
the working parameter configuration module comprises:
the clock frequency configuration module is used for configuring the clock frequency of the work of the universal timer;
a counting mode configuration module, configured to configure the counting mode of the general timer to be an up-down counting mode;
the output mode configuration module is used for configuring the output mode of the universal timer to be a PWM mode;
the working mode configuration module is used for configuring the working mode of the GPIO interface to be push-pull multiplexing;
the output polarity configuration module is used for configuring the output polarity of the GPIO interfaces to make two paths of PWM waves output by the GPIO interfaces in one group and the GPIO interfaces in each group complement each other; and
and the reloading value setting module is used for setting the reloading value of each PWM wave according to the set clock frequency.
10. The device according to claim 9, wherein the selection module is further configured to select, according to the number of channels of the complementary PWM waves to be output, GPIO interfaces twice as many as the number of channels.
11. The apparatus of claim 9, wherein the clock frequency configuration module comprises:
the pre-frequency division value configuration module is used for configuring the pre-frequency division value of the universal timer;
and the clock division value configuration module is used for configuring the clock division value of the universal timer.
12. The apparatus of claim 9, wherein the output polarity configuration module comprises:
the first interface configuration module is used for configuring the polarity of a first GPIO interface in each group of GPIO interfaces to be high so as to output an upper bridge PWM wave;
and the second interface configuration module is used for configuring the polarity of the second GPIO interface in each group of GPIO interfaces to be low so as to output a lower bridge PWM wave, and the level of the upper bridge PWM wave is opposite to that of the lower bridge PWM wave.
13. The apparatus of claim 12, wherein the reload value setting module is further configured to:
and according to the working clock frequency of the universal timer, setting the reloading value of the upper bridge PWM wave and the reloading value of the lower bridge PWM wave, enabling the reloading values of the upper bridge PWM wave and the lower bridge PWM wave to be different by a preset value, and enabling the starting time interval of the upper bridge PWM wave and the lower bridge PWM wave to be preset in duration.
14. A one-chip microcomputer characterized by comprising the complementary PWM wave output device of the one-chip microcomputer according to any one of claims 9 to 13.
15. An unmanned aerial vehicle comprises a motor and a singlechip, and is characterized in that,
the single chip microcomputer comprises a complementary PWM wave output device of the single chip microcomputer of any one of claims 9 to 13;
the motor is connected with the device, and the complementary PWM waves output by every three paths of the devices are used for driving a motor of the unmanned aerial vehicle.
16. An unmanned aerial vehicle as claimed in claim 15, wherein the single-chip microcomputer is an STM32 single-chip microcomputer.
17. A drone according to claim 15 or 16, characterised in that the motor comprises a motor of any one of the following functions:
a drive motor of the propeller;
the driving motor of cloud platform.
CN201710138208.3A 2017-03-09 2017-03-09 Method and device for outputting complementary pulse modulation waves by single chip microcomputer and single chip microcomputer Active CN107117321B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710138208.3A CN107117321B (en) 2017-03-09 2017-03-09 Method and device for outputting complementary pulse modulation waves by single chip microcomputer and single chip microcomputer

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710138208.3A CN107117321B (en) 2017-03-09 2017-03-09 Method and device for outputting complementary pulse modulation waves by single chip microcomputer and single chip microcomputer

Publications (2)

Publication Number Publication Date
CN107117321A CN107117321A (en) 2017-09-01
CN107117321B true CN107117321B (en) 2020-11-06

Family

ID=59718187

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710138208.3A Active CN107117321B (en) 2017-03-09 2017-03-09 Method and device for outputting complementary pulse modulation waves by single chip microcomputer and single chip microcomputer

Country Status (1)

Country Link
CN (1) CN107117321B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116885955B (en) * 2023-07-14 2024-01-26 山东艾诺智能仪器有限公司 Driving control method of three-phase bidirectional resonant converter

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP6029433B2 (en) * 2012-11-26 2016-11-24 ルネサスエレクトロニクス株式会社 Microcomputer
JP6170455B2 (en) * 2014-03-20 2017-07-26 日立オートモティブシステムズ株式会社 Brushless motor control device and control method
CN104898520B (en) * 2015-05-22 2018-09-11 上海晟矽微电子股份有限公司 A kind of microcontroller for motor control
CN205345346U (en) * 2016-01-26 2016-06-29 深圳市大疆创新科技有限公司 Unmanned vehicles and motor control chip , electronic governor thereof

Also Published As

Publication number Publication date
CN107117321A (en) 2017-09-01

Similar Documents

Publication Publication Date Title
CN110707982B (en) Control method, device and equipment of electronic equipment and storage medium
CN107117321B (en) Method and device for outputting complementary pulse modulation waves by single chip microcomputer and single chip microcomputer
RU2013157942A (en) DIGITAL SCALING OF VOLTAGE AND FREQUENCY
JP6039643B2 (en) Parallel connection inverter control method
CN103607183A (en) Multi-channel separation function signal generator and signal generating method
TW200629731A (en) Oscillator and charge pump circuit using the same
US11264864B2 (en) Flat-motor driving method and drive circuit, and electronic device
JP5180620B2 (en) DC-DC converter control circuit
US10964501B2 (en) Single coil magnetic latching relay control circuit and method
US8957614B2 (en) Modularized control circuit with signal-capturing function for fan motor and controlling method
CN107431481B (en) Combined/sequential pulse width modulation
JP7119681B2 (en) Signal transmission device and drive device
CN108429585B (en) Optical module control method and device and optical module
CN205304663U (en) Multichannel stepper motor control circuit
CN105513584A (en) Buzz output method and device
CN104660224A (en) Pulse shaping circuit and on-off keying (ook) transmitter including pulse shaping circuit
CN111064452A (en) Enabling signal generating circuit
US10243360B2 (en) Power supply apparatus for setting target times of control signals
CN113325766B (en) Drive control chip and heating ventilation equipment
KR20210068905A (en) Relaxation oscillator and method for controlling the same
CN107565800B (en) Gate driving circuit and gate driving method
CN111988021B (en) PWM generation method and device, motor controller and vehicle
KR101167799B1 (en) Electrical apparatus for controlling of driving injector
KR101005128B1 (en) Charge pump circuit of Semiconductor device
CN107846140B (en) Power supply circuit of auxiliary power supply

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20180212

Address after: No. 309-9, service center, Chen Tong, Hexi District, Dongting Road, Hexi District, Tianjin, Tianjin

Applicant after: Tianjin Yuanyu Technology Co.,Ltd.

Address before: 401121 Chongqing Yubei City Longxing Street Ying Long Road No. 19

Applicant before: CHONGQING ZERO INTELLIGENT CONTROL TECHNOLOGY CO.,LTD.

SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP01 Change in the name or title of a patent holder
CP01 Change in the name or title of a patent holder

Address after: No. 309-9, service center, Chen Tong, Hexi District, Dongting Road, Hexi District, Tianjin, Tianjin

Patentee after: Tianjin Yuandu Technology Co.,Ltd.

Address before: No. 309-9, service center, Chen Tong, Hexi District, Dongting Road, Hexi District, Tianjin, Tianjin

Patentee before: Tianjin Yuanyu Technology Co.,Ltd.

CP03 Change of name, title or address
CP03 Change of name, title or address

Address after: 0701600 A102, No. 67, tourism East Road, Anxin County, Baoding City, Hebei Province

Patentee after: Hebei xiong'an Yuandu Technology Co.,Ltd.

Address before: No. 309-9, service center, Chen Tong, Hexi District, Dongting Road, Hexi District, Tianjin, Tianjin

Patentee before: Tianjin Yuandu Technology Co.,Ltd.

TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20210910

Address after: 102100 1916, building 27, yard 8, Fenggu 4th Road, Yanqing garden, Zhongguancun, Yanqing District, Beijing

Patentee after: Beijing Yuandu Internet Technology Co.,Ltd.

Address before: 0701600 A102, No. 67, tourism East Road, Anxin County, Baoding City, Hebei Province

Patentee before: Hebei xiong'an Yuandu Technology Co.,Ltd.