JPH11345033A - Method for controlling modulation of pulse width by microcontroller - Google Patents

Method for controlling modulation of pulse width by microcontroller

Info

Publication number
JPH11345033A
JPH11345033A JP10150103A JP15010398A JPH11345033A JP H11345033 A JPH11345033 A JP H11345033A JP 10150103 A JP10150103 A JP 10150103A JP 15010398 A JP15010398 A JP 15010398A JP H11345033 A JPH11345033 A JP H11345033A
Authority
JP
Japan
Prior art keywords
output
microcontroller
signal
timer
interrupt
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.)
Pending
Application number
JP10150103A
Other languages
Japanese (ja)
Inventor
興治 ▲崎▼山
Koji Sakiyama
Nobumasa Misaki
信正 見崎
Kenji Furuichi
健二 古市
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.)
Fujikura Ltd
Original Assignee
Fujikura 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 Fujikura Ltd filed Critical Fujikura Ltd
Priority to JP10150103A priority Critical patent/JPH11345033A/en
Publication of JPH11345033A publication Critical patent/JPH11345033A/en
Pending legal-status Critical Current

Links

Landscapes

  • Dc-Dc Converters (AREA)
  • Control Of Electrical Variables (AREA)
  • Control Of Ac Motors In General (AREA)

Abstract

PROBLEM TO BE SOLVED: To make it possible to execute high speed and stable control even in the case of using an inexpensive microcontroller by setting up a timer/counter value indicating the time until interruption is generated in a main process and after the lapse of the time, generating the interruption in the main process and inverting an output signal. SOLUTION: First and second control signals TC1 , TC2 are determined based on an input signal and a timer/counter value indicating the time until interruption is generated in a main process, is set up based on the 1st and 2nd control signals TC1 , TC2 . When an interruption request is generated when an output signal is Low, a High signal is outputted (S12a). Then, an interruption request is generated after the lapse of a control variable TC1 determined by a main routine so that the Low signal is outputted (S12b). Further, an interruption signal is generated after the lapse of a control variable TC2 so that the High signal is outputted (S12a). Thereafter, a similar process is repeated up to reaching a prescribed time.

Description

【発明の詳細な説明】DETAILED DESCRIPTION OF THE INVENTION

【0001】[0001]

【発明の属する技術分野】本発明はモータ、ソレノイド
コイル及びブザー等の動作の制御に好適なマイクロコン
トローラによるパルス幅変調制御方法に関し、特に、安
価なマイクロコントローラを使用しても処理の安定性及
び速度を向上させることができるマイクロコントローラ
によるパルス幅変調制御方法に関する。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a pulse width modulation control method using a microcontroller suitable for controlling operations of a motor, a solenoid coil, a buzzer, and the like. The present invention relates to a pulse width modulation control method using a microcontroller capable of improving speed.

【0002】[0002]

【従来の技術】モータ、ソレノイドコイル及びブザー等
の動作を可変に制御する方法として、例えば、パルス幅
変調(PWM)制御方法がある。図8(a)は従来のP
WM制御方法に使用される回路を示すブロック図、
(b)はその際の出力波形を示すタイミングチャートで
ある。従来のPWM制御方法に使用される回路において
は、制御される負荷22の一端子は接地されており、他
の一端子に出力回路23が接続されている。出力回路2
3には、PWM制御を行うマイクロコントローラ21が
接続されている。更に、マイクロコントローラ21に
は、制御される信号が入力される入力装置24が接続さ
れている。また、マイクロコントローラ21には、メイ
ンルーチン及び割込ルーチンを含むプログラムが記憶さ
れ出力信号の制御を行う中央処理装置(CPU)21a
と、このCPU21aに割込要求を発生するタイマ/カ
ウンタ21bとが設けられており、CPU21aと入力
装置24及び出力回路23との間で信号が交信される。
2. Description of the Related Art As a method of variably controlling operations of a motor, a solenoid coil, a buzzer, and the like, there is, for example, a pulse width modulation (PWM) control method. FIG. 8A shows a conventional P
FIG. 2 is a block diagram showing a circuit used in the WM control method;
(B) is a timing chart showing the output waveform at that time. In a circuit used in the conventional PWM control method, one terminal of a load 22 to be controlled is grounded, and an output circuit 23 is connected to another terminal. Output circuit 2
3 is connected to a microcontroller 21 that performs PWM control. Further, an input device 24 to which a signal to be controlled is input is connected to the microcontroller 21. In the microcontroller 21, a program including a main routine and an interrupt routine is stored, and a central processing unit (CPU) 21a that controls an output signal.
The CPU 21a is provided with a timer / counter 21b for generating an interrupt request, and signals are exchanged between the CPU 21a, the input device 24, and the output circuit 23.

【0003】なお、タイマ/カウンタ21bには、制御
変数であるタイマ/カウンタ値(TC値)として、例え
ば、100msがCPU21aから書き込まれ、このT
C値(100ms)の周期でタイマ/カウンタ21bか
らCPU21aに対して割込要求が発生される。そし
て、CPU21a内ではこの割込要求によりソフトウェ
アカウンタ(以下、Sカウンタという)と呼ばれるカウ
ンタがカウントアップされる。マイクロコントローラ2
1から出力回路23に出力される信号の波形は、図8
(b)に示すように、パルス波形であるが、そのパルス
周期T及びパルス幅T1はSカウンタに基づいて制御さ
れている。そして、そのパルス周期Tに対するパルス幅
1の比であるデューティ比(T1/T×100(%))
がマイクロコントローラ21により0乃至100%の間
で可変に制御される。
In addition, for example, 100 ms is written into the timer / counter 21b as a timer / counter value (TC value) as a control variable from the CPU 21a.
An interrupt request is issued from the timer / counter 21b to the CPU 21a at a cycle of the C value (100 ms). In the CPU 21a, a counter called a software counter (hereinafter, referred to as an S counter) is counted up by the interrupt request. Microcontroller 2
The waveform of the signal output from the output circuit 1 to the output circuit 23 is shown in FIG.
(B), the is a pulse waveform, the pulse period T and pulse width T 1 is controlled on the basis of the S counter. Then, a duty ratio (T 1 / T × 100 (%)) which is a ratio of the pulse width T 1 to the pulse period T
Is variably controlled by the microcontroller 21 between 0% and 100%.

【0004】このように構成された従来のPWM制御用
の回路においては、アナログ信号等の入力信号が入力装
置24に入力され、マイクロコントローラ21によりそ
の入力信号が図8(b)に示すようなパルス波に変換さ
れる。そして、出力回路23を介して負荷22に出力さ
れる。
In the conventional PWM control circuit configured as described above, an input signal such as an analog signal is input to the input device 24, and the input signal is input by the microcontroller 21 as shown in FIG. It is converted into a pulse wave. Then, it is output to the load 22 via the output circuit 23.

【0005】次に、従来のPWM制御方法によるデュー
ティ比の具体的な制御方法について説明する。図9は従
来のPWM制御方法におけるメインルーチンを示すフロ
ーチャート、図10は同じく割込ルーチンを示すフロー
チャートである。
Next, a specific method of controlling the duty ratio by the conventional PWM control method will be described. FIG. 9 is a flowchart showing a main routine in a conventional PWM control method, and FIG. 10 is a flowchart showing an interrupt routine similarly.

【0006】メインルーチンでは、図9に示すように、
入力装置24から入力信号が入力されると、この入力信
号がCPU21aに読み込まれる(ステップS51)。
次に、この入力信号に基づいてパルス幅T1が決定され
る(ステップS52)。次いで、Sカウンタの値がパル
ス幅T1より大きいか判断される(ステップS53)。
そして、Sカウンタの値がパルス幅T1より大きい場合
にはHighの信号が出力され(ステップS54a)、
それ以外の場合にはLowの信号が出力される(ステッ
プS54b)。次に、Sカウンタの値がパルス周期Tよ
り大きいか判断される(ステップS55)。Sカウンタ
の値がパルス周期Tより大きい場合には、Sカウンタの
値が0に(クリア)され(ステップS56)、それ以外
の場合にはそのまま、工程がステップS51へと工程が
戻る。
In the main routine, as shown in FIG.
When an input signal is input from the input device 24, the input signal is read by the CPU 21a (step S51).
Then, the pulse width T 1 is determined on the basis of the input signal (step S52). Then, the value of the S counter is determined whether the pulse width greater than T 1 (step S53).
Then, the signal of High is output when the value of the S counter is greater than the pulse width T 1 (step S54a),
Otherwise, a Low signal is output (step S54b). Next, it is determined whether the value of the S counter is greater than the pulse period T (step S55). If the value of the S counter is larger than the pulse period T, the value of the S counter is cleared (cleared) to 0 (step S56). Otherwise, the process returns to step S51 as it is.

【0007】一方、割込ルーチンでは、TC値の周期で
タイマ/カウンタ21bから割込要求が発生されると、
図10に示すように、タイマ/カウンタ21bにTC値
がセットされる(ステップS61)。次に、Sカウンタ
の値がインクリメント(+1)され(ステップS6
2)、割込ルーチンでの工程が終了する。つまり、TC
値が、例えば、100msである場合、100ms毎に
割込がかかってプログラムがメインルーチンから割込ル
ーチンへと遷移し、Sカウンタは100msの分解能で
100ms、200ms、300ms、400ms・・
・とカウントアップされる。
On the other hand, in the interrupt routine, when an interrupt request is generated from the timer / counter 21b at the cycle of the TC value,
As shown in FIG. 10, the TC value is set in the timer / counter 21b (step S61). Next, the value of the S counter is incremented (+1) (step S6).
2) The steps in the interrupt routine are completed. That is, TC
If the value is, for example, 100 ms, an interrupt occurs every 100 ms and the program transitions from the main routine to the interrupt routine, and the S counter has 100 ms, 200 ms, 300 ms, 400 ms,.
・ It is counted up.

【0008】このように、従来の電子部品のPWM制御
方法においては、一定周期(TC値)の割込によりSカ
ウンタがカウントアップされ、このSカウンタに基づい
てデューティ比の制御が行われている。
As described above, in the conventional PWM control method for electronic components, the S counter is counted up by interruption at a constant period (TC value), and the duty ratio is controlled based on the S counter. .

【0009】[0009]

【発明が解決しようとする課題】しかしながら、上述の
従来のPWM制御方法では、安価なマイクロコントロー
ラを使用して高い分解能を得ようと割込の周期を小さく
設定すると、全体に占める割込時間の割合が大きくなっ
て処理が遅くなるという問題点がある。図11(a)は
従来のPWM制御方法における割込タイミングを示すタ
イミングチャート、(b)はこれを時間軸方向に拡大し
たタイミングチャートである。Sカウンタの最小時間で
ある割込の周期をTi、Sカウンタをカウントアップす
るために必要な割込ルーチンの所要時間をtiとする
と、制御全体に占める割込処理時間の割合Rは下記数式
1で示される。
However, in the above-described conventional PWM control method, if an interrupt cycle is set to be small in order to obtain a high resolution using an inexpensive microcontroller, the entire interrupt time is reduced. There is a problem that the ratio becomes large and the processing becomes slow. FIG. 11A is a timing chart showing an interrupt timing in the conventional PWM control method, and FIG. 11B is a timing chart in which this is enlarged in the time axis direction. Assuming that the interrupt cycle, which is the minimum time of the S counter, is T i , and the time required for the interrupt routine required to count up the S counter is t i , the ratio R of the interrupt processing time to the entire control is as follows. It is shown by Equation 1.

【0010】[0010]

【数1】R=ti/Ti×100(%)## EQU1 ## R = t i / T i × 100 (%)

【0011】従って、例えば、割込周期Tiが100μ
s、所要時間tiが30μsの場合、制御全体の30%
が割込処理に費やされることになる。これにより、PW
M制御の他に制御ルーチンを含むメインルーチンによる
制御全体の処理は割込ルーチンがない場合と比して30
%遅れることになる。
Therefore, for example, if the interrupt cycle T i is 100 μm
s, when the required time t i is 30 μs, 30% of the entire control
Will be spent on interrupt processing. Thereby, PW
The entire control processing by the main routine including the control routine in addition to the M control is 30 times more than when there is no interrupt routine.
% Delay.

【0012】また、メインルーチンが1周するために必
要な所要時間をTmとしたとき、割込の周期Tiが所要時
間Tmより小さいと、メインルーチンが1周する間に割
込が2回かかり、メインルーチンのn周目でSカウンタ
の値がTS、メインルーチンのn+1周目でSカウンタ
の値がTS+2となることがある。この場合、出力波形
の立ち上がり又は立ち下がりのエッジのタイミングに誤
差が生じて制御が不安定なものとなってしまう。
Further, when the necessary time required for the main routine one cycle and T m, the period T i of the interruption is less than the required time T m, interruption while the main routine is one round It may take two times, and the value of the S counter may be T S at the n-th cycle of the main routine, and T S +2 at the (n + 1) -th cycle of the main routine. In this case, an error occurs in the timing of the rising or falling edge of the output waveform, and the control becomes unstable.

【0013】更に、割込の周期Tiが割込ルーチンの所
要時間tiより小さく設定された場合、割込処理中に再
度割込要求が発生されて無限ループに陥ってしまう。こ
れにより、プログラムの暴走が引き起こされてしまう。
Further, if the interrupt cycle T i is set smaller than the required time t i of the interrupt routine, an interrupt request is issued again during the interrupt processing, and an infinite loop occurs. This causes a program runaway.

【0014】一方、高速のマイクロコントローラを使用
すれば、高い分解能で出力のデューティ比を安定して制
御することは可能であるが、高速のマイクロコントロー
ラは極めて高価である。
On the other hand, if a high-speed microcontroller is used, it is possible to stably control the output duty ratio with high resolution, but the high-speed microcontroller is extremely expensive.

【0015】本発明はかかる問題点に鑑みてなされたも
のであって、安価なマイクロコントローラを使用しても
高速で安定した制御を行うことができるマイクロコント
ローラによるパルス幅変調制御方法を提供することを目
的とする。
The present invention has been made in view of such a problem, and provides a pulse width modulation control method using a microcontroller capable of performing high-speed and stable control even if an inexpensive microcontroller is used. With the goal.

【0016】[0016]

【課題を解決するための手段】本発明に係るマイクロコ
ントローラによるパルス幅変調制御方法は、マイクロコ
ントローラに入力された入力信号に基づいて前記マイク
ロコントローラから出力される出力信号のデューティ比
を制御するマイクロコントローラによるパルス幅変調制
御方法において、前記入力信号に基づいて第1の制御変
数及び第2の制御変数を決定する工程を繰り返す主工程
と、前記第1の制御変数及び前記第2の制御変数に基づ
いて前記主工程に割込を発生させるまでの時間を示すタ
イマ/カウンタ値を設定するタイマ/カウンタ値設定工
程と、前記タイマ/カウンタ値が示す時間が経過したと
きに前記主工程に割込を発生させて前記出力信号を反転
させる出力反転工程とを有することを特徴とする。
According to the present invention, there is provided a pulse width modulation control method using a microcontroller, which controls a duty ratio of an output signal output from the microcontroller based on an input signal input to the microcontroller. In the pulse width modulation control method by the controller, a main step of repeating a step of determining a first control variable and a second control variable based on the input signal; and the first control variable and the second control variable A timer / counter value setting step of setting a timer / counter value indicating a time until an interrupt is generated in the main step based on the timer; And an output inverting step of inverting the output signal.

【0017】本発明においては、割込が発生されるの
は、出力信号が反転されるときのみであるので、Sカウ
ンタが不必要であり、Sカウンタを原因として従来生じ
ていた処理の遅れが防止される。
In the present invention, since an interrupt is generated only when the output signal is inverted, the S counter is unnecessary, and the processing delay conventionally caused by the S counter is delayed. Is prevented.

【0018】前記主工程において繰り返される各工程間
の前記第1の制御変数と前記第2の制御変数との和は一
定とすることができる。
The sum of the first control variable and the second control variable during each step repeated in the main step may be constant.

【0019】[0019]

【発明の実施の形態】以下、本発明の実施例に係る電子
部品のPWM制御方法について、添付の図面を参照して
具体的に説明する。本実施例においては、割込要求が発
生される間隔を可変としている。つまり、割込要求は従
来のように一定周期では発生されない。図1は本発明の
第1の実施例に係るPWM制御方法におけるメインルー
チンを示すフローチャート、図2は同じく割込ルーチン
を示すフローチャートである。なお、本実施例に使用さ
れるPWM制御用の回路は図8(a)に示す従来のもの
と同様のものである。
DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS Hereinafter, a method for controlling a PWM of an electronic component according to an embodiment of the present invention will be specifically described with reference to the accompanying drawings. In this embodiment, the interval at which an interrupt request is generated is variable. That is, the interrupt request is not generated in a fixed cycle as in the related art. FIG. 1 is a flowchart showing a main routine in a PWM control method according to a first embodiment of the present invention, and FIG. 2 is a flowchart showing an interrupt routine similarly. The PWM control circuit used in this embodiment is the same as the conventional one shown in FIG.

【0020】本実施例に係るPWM制御方法のメインル
ーチンでは、図1に示すように、入力装置から入力信号
が入力されると、この入力信号がCPUに読み込まれる
(ステップS1)。次に、この入力信号に基づいて制御
変数TC1(>0)が決定され(ステップS2)、制御
変数TC2(>0)が決定される(ステップS3)。な
お、同一のメインルーチンにより決定された制御変数T
1と制御変数TC2との和は、常に、出力パルスの周期
Tと一致するように設定される。そして、ステップS1
へと工程が戻る。
In the main routine of the PWM control method according to the present embodiment, as shown in FIG. 1, when an input signal is input from an input device, the input signal is read by the CPU (step S1). Next, the control variable TC 1 (> 0) is determined based on the input signal (step S2), and the control variable TC 2 (> 0) is determined (step S3). The control variable T determined by the same main routine
The sum of the C 1 and the control variable TC 2 is always set to match the cycle T of the output pulse. Then, step S1
The process returns to.

【0021】一方、本実施例に係るPWM制御方法の割
込ルーチンでは、タイマ/カウンタから割込要求が発生
されると、図2に示すように、その時点での出力がLo
wであるか判断される(ステップS11)。そして、出
力がLowである場合には、出力にHighの信号が設
定され(ステップS12a)た後、TC値に制御変数T
1が設定される(ステップS13a)。一方、ステッ
プS11で出力がLowでない場合には、出力にLow
の信号が設定され(ステップ12b)た後、TC値に制
御変数TC2が設定される(ステップS13b)。そし
て、割込ルーチンでの工程が終了する。
On the other hand, in the interrupt routine of the PWM control method according to the present embodiment, when an interrupt request is generated from the timer / counter, as shown in FIG.
It is determined whether it is w (step S11). If the output is low, a high signal is set for the output (step S12a), and then the TC value is set to the control variable T.
C 1 is set (step S13a). On the other hand, if the output is not Low in step S11, the output is Low.
The signal is set after was (step 12b), the control variable TC 2 is set to the TC value (step S13b). Then, the process in the interrupt routine ends.

【0022】このようにして、マイクロコントローラに
より制御されて出力される信号は図3のようになる。図
3は本発明の第1の実施例に係るPWM制御方法におけ
る出力波形を示すタイミングチャートである。つまり、
出力信号がLowの時点で割込要求が発生されると、H
ighの信号が出力されるようになる。そして、メイン
ルーチンにより決定された制御変数TC1を経過したと
き、割込要求が発生される。そして、Lowの信号が出
力されるようになる。更に、同一のメインルーチンによ
り決定された制御変数TC2を経過したとき、割込要求
が発生される。そして、Highの信号が出力されるよ
うになる。以降、同様の工程が所定の時間に達するまで
繰り返される。
The signals controlled and output by the microcontroller in this manner are as shown in FIG. FIG. 3 is a timing chart showing output waveforms in the PWM control method according to the first embodiment of the present invention. That is,
If an interrupt request is issued when the output signal is low, H
high signal is output. Then, when the elapsed controlled variable TC 1 determined by the main routine, the interrupt request is generated. Then, a Low signal is output. Further, when the elapsed controlled variable TC 2 determined by the same main routine, the interrupt request is generated. Then, a High signal is output. Thereafter, the same process is repeated until a predetermined time is reached.

【0023】このように、本実施例においては、割込要
求がタイマ/カウンタから発生されるのは、出力される
信号のHighとLowとが反転されるときのみであ
る。このため、従来、Sカウンタをカウントアップする
ために一定の周期で割込要求が発生されて他の制御に遅
れが生じていたが、本実施例では、そのような遅れは生
じない。
As described above, in this embodiment, the interrupt request is generated from the timer / counter only when High and Low of the output signal are inverted. For this reason, conventionally, an interrupt request is generated at a constant cycle to count up the S counter, and a delay occurs in other control. However, in the present embodiment, such a delay does not occur.

【0024】また、タイマ/カウンタとCPUとは相互
に独立して動作するので、制御変数TC1及びTC2によ
り規定される割込要求の発生の間隔は安定している。こ
のため、出力の立ち上がり及び立ち下がりのエッジのタ
イミングに誤差が生じることがなく、安定した波形を有
する信号がPWM制御により出力される。
Further, since the timer / counter and the CPU operate independently of each other, the interval between the generations of the interrupt requests defined by the control variables TC 1 and TC 2 is stable. Therefore, no error occurs in the timing of the rising edge and the falling edge of the output, and a signal having a stable waveform is output by the PWM control.

【0025】更に、制御変数TC1及びTC2を、タイマ
/カウンタの性能が十分に発揮される程度まで著しく小
さく設定しても割込処理で無限ループに陥ることがない
ので、出力信号のデューティ比を極めて細かく制御する
ことが可能である。つまり、制御分解能を高めてもプロ
グラムの暴走は生じない。なお、制御分解能は、タイマ
/カウンタの分解能で決まる。
Further, even if the control variables TC 1 and TC 2 are set extremely small to such an extent that the performance of the timer / counter is sufficiently exhibited, the interruption processing does not fall into an infinite loop. It is possible to control the ratio very finely. That is, even if the control resolution is increased, the program does not run away. The control resolution is determined by the resolution of the timer / counter.

【0026】従って、本実施例によれば、短い周期のS
カウンタを使用しなくても、制御の遅れ、制御の不安定
性及びプログラムの暴走という従来のPWM制御方法で
生じていた問題点は解決されるので、高価なマイクロコ
ントローラは必要なく低速で安価なマイクロコントロー
ラを使用することで十分に適応することができる。
Therefore, according to the present embodiment, short period S
Even if the counter is not used, the problems caused by the conventional PWM control method such as control delay, control instability, and program runaway can be solved. The use of a controller can be fully adapted.

【0027】つまり、従来と同程度の性能を有するマイ
クロコントローラを使用した場合には、より繊細な制御
分解能及びより高い安定性でPWM制御が行われる。ま
た、従来と同程度の制御性能を得ようとする場合には、
より安価で低速のマイクロコントローラで適応可能であ
る。
That is, when a microcontroller having the same level of performance as the conventional one is used, PWM control is performed with finer control resolution and higher stability. Also, when trying to obtain the same level of control performance as before,
It can be adapted with cheaper and slower microcontrollers.

【0028】なお、PWM専用の出力ポートを内蔵する
マイクロコントローラも存在するが、本発明はPWM専
用の出力ポートを使用しなくても汎用の出力ポートで十
分に適応することが可能である。更に、汎用の出力ポー
トを使用した場合には、PWM専用の出力ポートを使用
した場合と比して、制御分解能及び出力信号のパルス周
期の設定自由度が高くなる。
Although some microcontrollers have a built-in PWM-dedicated output port, the present invention can be sufficiently applied to a general-purpose output port without using a PWM-dedicated output port. Furthermore, when a general-purpose output port is used, the degree of freedom in setting the control resolution and the pulse period of the output signal is higher than when a dedicated output port for PWM is used.

【0029】次に、本発明の第2の実施例について説明
する。本実施例は警報音等に使用されるブザーの断続減
衰音のPWM制御に適応された例である。図4は本発明
の第2の実施例に係るPWM制御方法に使用される回路
を示すブロック図である。
Next, a second embodiment of the present invention will be described. This embodiment is an example applied to PWM control of an intermittent attenuation sound of a buzzer used for an alarm sound or the like. FIG. 4 is a block diagram showing a circuit used in the PWM control method according to the second embodiment of the present invention.

【0030】第2の実施例に係るPWM制御方法に使用
される回路においては、制御されるブザー2の一端子は
接地されており、他の一端子にブザー出力ドライバ3が
接続されている。ブザー出力ドライバ3には、PWM制
御を行うマイクロコントローラ1が接続されている。更
に、マイクロコントローラ1には、制御される信号が入
力される入力スイッチ(SW)4が接続されている。ま
た、マイクロコントローラ1には、メインルーチン及び
割込ルーチンを含むプログラムが記憶され出力信号の制
御を行う中央処理装置(CPU)1aと、このCPU1
aに割込要求を発生するタイマ/カウンタ1bとが設け
られており、CPU1aと入力SW4及びブザー出力ド
ライバ3との間で信号が交信される。
In the circuit used in the PWM control method according to the second embodiment, one terminal of the buzzer 2 to be controlled is grounded, and a buzzer output driver 3 is connected to the other terminal. The buzzer output driver 3 is connected to a microcontroller 1 that performs PWM control. Further, the microcontroller 1 is connected to an input switch (SW) 4 to which a signal to be controlled is input. Further, the microcontroller 1 stores a program including a main routine and an interrupt routine and controls an output signal.
A is provided with a timer / counter 1b for generating an interrupt request, and signals are exchanged between the CPU 1a, the input SW 4 and the buzzer output driver 3.

【0031】図5は本発明の第2の実施例に係るPWM
制御方法におけるメインルーチンを示すフローチャー
ト、図6は同じく割込ルーチンを示すフローチャートで
ある。
FIG. 5 shows a PWM according to a second embodiment of the present invention.
FIG. 6 is a flowchart showing a main routine in the control method, and FIG. 6 is a flowchart showing an interrupt routine in the same manner.

【0032】メインルーチンでは、図5に示すように、
入力SW4からの信号が読み込まれる(ステップS2
1)。次に、この信号から入力SW4がオンにされてい
るか判断される(ステップS22)。そして、入力SW
4がオンにされていない場合には、タイマ/カウンタ1
bが停止される(ステップS23b)。更に、制御変数
TC1及びTC2に定数αが設定される(ステップS3
1、S32)。なお、定数αの2倍の値がブザー2の基
本発振周期と一致し、定数αによりブザー2の音色が決
定される。その後、減衰率を制御するタイマがクリアさ
れる(ステップS33)。
In the main routine, as shown in FIG.
The signal from the input SW4 is read (Step S2
1). Next, it is determined from this signal whether the input SW4 is turned on (step S22). And the input SW
4 is not turned on, the timer / counter 1
b is stopped (step S23b). Furthermore, the constant α is set to the control variable TC 1 and TC 2 (step S3
1, S32). Note that the value twice as large as the constant α matches the fundamental oscillation period of the buzzer 2, and the tone of the buzzer 2 is determined by the constant α. Thereafter, the timer for controlling the attenuation rate is cleared (step S33).

【0033】また、ステップS22において、入力SW
4がオンにされている場合には、タイマ/カウンタ1b
が駆動される(ステップS23a)。そして、前回にタ
イマがクリアされてからt(秒)経過したか判断される
(ステップS24)。前回にタイマがクリアされてから
t(秒)経過している場合には、タイマがクリアされる
(ステップS25)。次いで、制御変数TC1がディク
リメント(−1)され(ステップS26)、制御変数T
2がインクリメント(+1)される(ステップS2
7)。その後、制御変数TC1が0であるか判断される
(ステップS28)。制御変数TC1が0である場合に
は、制御変数TC1及びTC2に定数αが設定される(ス
テップS29、S30)。本実施例においては、制御変
数TC1と制御変数TC2との和の初期値は2αであり、
その後、制御変数TC1はディクリメントされ、制御変
数TC2はインクリメントされるが、その変化量の絶対
値は等しいので、制御変数TC1と制御変数TC2との和
は常時2αとなっている。そして、制御変数TC1と制
御変数TC2との和(2α)がパルス周期Tとなってい
る。
In step S22, the input SW
4 is turned on, the timer / counter 1b
Is driven (step S23a). Then, it is determined whether t (second) has elapsed since the last time the timer was cleared (step S24). If t (second) has elapsed since the last time the timer was cleared, the timer is cleared (step S25). Then, the control variable TC 1 is decremented (-1) (step S26), the control variable T
C 2 is incremented (+1) (step S2
7). Thereafter, it is determined whether the control variable TC 1 is 0 (step S28). If the control variable TC 1 is 0, constant α is set to the control variable TC 1 and TC 2 (step S29, S30). In the present embodiment, the initial value of the sum of the control variables TC 1 and the control variable TC 2 is 2.alpha,
Thereafter, the control variable TC 1 is decremented, the control variable TC 2 is being incremented, since the absolute value of the change amount is equal to the sum of the control variables TC 1 and the control variable TC 2 has a constantly 2α . The sum (2α) of the control variable TC 1 and the control variable TC 2 is the pulse period T.

【0034】なお、ステップS24でt(秒)経過して
いない場合、ステップS28で制御変数TC1が0でな
い場合及びステップS30又はステップS33の後に
は、工程がステップS21へと戻る。
[0034] Note that when not elapsed t (in seconds) at step S24, after when the control variable TC 1 at step S28 is not zero and step S30 or step S33, step returns to step S21.

【0035】一方、割込ルーチンでは、タイマ/カウン
タ1bから割込要求が発生されると、図6に示すよう
に、その時点での出力信号がLowであるか判断される
(ステップS41)。そして、出力信号がLowである
場合には、出力にHighの信号が設定され(ステップ
S42a)た後、TC値に制御変数TC1が設定される
(ステップS43a)。一方、ステップS41で出力信
号がLowでない場合には、出力にLowの信号が設定
され(ステップ42b)た後、TC値に制御変数TC2
が設定される(ステップS43b)。そして、割込ルー
チンでの工程が終了する。
On the other hand, in the interrupt routine, when an interrupt request is issued from the timer / counter 1b, as shown in FIG. 6, it is determined whether the output signal at that time is low (step S41). When the output signal is Low, the signal of High is set to the output after was (step S42a), the control variable TC 1 is set to the TC value (step S43a). On the other hand, if the output signal is not low in step S41, a low signal is set to the output (step 42b), and then the TC value is set to the control variable TC 2.
Is set (step S43b). Then, the process in the interrupt routine ends.

【0036】このようにして、マイクロコントローラに
より制御されて出力される信号は図7のようになる。図
7は本発明の第2の実施例に係るPWM制御方法におけ
る出力波形を示すタイミングチャートである。つまり、
出力信号がLowの時点で割込要求が発生されると、H
ighの信号が出力されるようになる。そして、メイン
ルーチンにより決定された制御変数TC1を経過したと
き、割込要求が発生される。そして、Lowの信号が出
力されるようになる。更に、同一のメインルーチンによ
り決定された制御変数TC2を経過したとき、割込要求
が発生される。そして、Highの信号が出力されるよ
うになる。次いで、新たなメインルーチンにより決定さ
れディクリメントされた制御変数TC1を経過したと
き、割込要求が発生される。以降、同様の工程が制御変
数TC1が0になるまで繰り返される。従って、デュー
ティ比は50%から徐々に0%まで減少する。つまり、
入力SW4がオンにされている間、断続的にポーンポー
ンという減衰音がブザー2から発せられる。
The signals controlled and output by the microcontroller are as shown in FIG. FIG. 7 is a timing chart showing output waveforms in the PWM control method according to the second embodiment of the present invention. That is,
If an interrupt request is issued when the output signal is low, H
high signal is output. Then, when the elapsed controlled variable TC 1 determined by the main routine, the interrupt request is generated. Then, a Low signal is output. Further, when the elapsed controlled variable TC 2 determined by the same main routine, the interrupt request is generated. Then, a High signal is output. Then, when the elapsed is determined by the new main routine is decremented controlled variable TC 1, an interrupt request is generated. Thereafter, the same process is repeated until the control variable TC 1 becomes 0. Therefore, the duty ratio gradually decreases from 50% to 0%. That is,
While the input SW4 is turned on, the buzzer 2 emits an intermittent buzzing sound.

【0037】本実施例においても、割込要求がタイマ/
カウンタから発生されるのは出力される信号のHigh
とLowとが反転されるときのみであるので、第1の実
施例と同様に、高価なマイクロコントローラを使用しな
くても制御の遅延防止等の効果が得られる。
Also in the present embodiment, the interrupt request
What is generated from the counter is the High of the output signal.
And Low are inverted only. Therefore, similarly to the first embodiment, effects such as prevention of control delay can be obtained without using an expensive microcontroller.

【0038】[0038]

【発明の効果】以上詳述したように、本発明によれば、
割込が発生されるのは出力信号が反転されるときのみと
なるので、割込によって他の制御が阻害されることを防
止することができる。また、割込間隔をより短く設定し
ても、エッジのタイミングに誤差が生じず安定した出力
波形が得られ制御の安定性は低下しないので、デューテ
ィ比の制御分解能をより小さくすることができる。更
に、割込間隔をより短く設定しても、プログラムが暴走
する虞がないので、制御の信頼性が向上される。そし
て、高速のマイクロコントローラを使用しなくても、上
記の効果が得られるので、コストの低減が可能である。
更に、マイクロコントローラには、PWM専用出力ポー
トではなく汎用の出力ポートが具備されていれば適応可
能であるので、選択の自由度が高い。
As described in detail above, according to the present invention,
Since the interrupt is generated only when the output signal is inverted, it is possible to prevent other controls from being disturbed by the interrupt. Even if the interrupt interval is set shorter, a stable output waveform is obtained without any error in the edge timing, and the stability of control is not reduced. Therefore, the control resolution of the duty ratio can be further reduced. Furthermore, even if the interrupt interval is set shorter, the program does not run out of control, so that the reliability of control is improved. The above-described effects can be obtained without using a high-speed microcontroller, so that cost can be reduced.
Further, since the microcontroller can be adapted as long as it has a general-purpose output port instead of a PWM-dedicated output port, the degree of freedom of selection is high.

【図面の簡単な説明】[Brief description of the drawings]

【図1】本発明の第1の実施例に係るPWM制御方法に
おけるメインルーチンを示すフローチャートである。
FIG. 1 is a flowchart showing a main routine in a PWM control method according to a first embodiment of the present invention.

【図2】同じく割込ルーチンを示すフローチャートであ
る。
FIG. 2 is a flowchart showing an interrupt routine.

【図3】本発明の第1の実施例に係るPWM制御方法に
おける出力波形を示すタイミングチャートである。
FIG. 3 is a timing chart showing output waveforms in the PWM control method according to the first embodiment of the present invention.

【図4】本発明の第2の実施例に係るPWM制御方法に
使用される回路を示すブロック図である。
FIG. 4 is a block diagram showing a circuit used for a PWM control method according to a second embodiment of the present invention.

【図5】本発明の第2の実施例に係るPWM制御方法に
おけるメインルーチンを示すフローチャートである。
FIG. 5 is a flowchart illustrating a main routine in a PWM control method according to a second embodiment of the present invention.

【図6】同じく割込ルーチンを示すフローチャートであ
る。
FIG. 6 is a flowchart showing an interrupt routine.

【図7】本発明の第2の実施例に係るPWM制御方法に
おける出力波形を示すタイミングチャートである。
FIG. 7 is a timing chart showing output waveforms in a PWM control method according to a second embodiment of the present invention.

【図8】(a)は従来のPWM制御方法に使用される回
路を示すブロック図、(b)はその際の出力波形を示す
タイミングチャートである。
8A is a block diagram showing a circuit used in a conventional PWM control method, and FIG. 8B is a timing chart showing an output waveform at that time.

【図9】従来のPWM制御方法におけるメインルーチン
を示すフローチャートである。
FIG. 9 is a flowchart showing a main routine in a conventional PWM control method.

【図10】同じく割込ルーチンを示すフローチャートで
ある。
FIG. 10 is a flowchart showing an interrupt routine.

【図11】(a)は従来のPWM制御方法における割込
タイミングを示すタイミングチャート、(b)はこれを
時間軸方向に拡大したタイミングチャートである。
FIG. 11A is a timing chart showing an interrupt timing in the conventional PWM control method, and FIG. 11B is a timing chart in which this is enlarged in the time axis direction.

【符号の説明】[Explanation of symbols]

1、21;マイクロコントローラ 1a、21a;中央処理装置(CPU) 1b、21b;タイマ/カウンタ 2;ブザー 3;ブザー出力ドライバ 4;入力スイッチ 22;負荷 23;出力回路 24;入力装置 1, 21; microcontroller 1a, 21a; central processing unit (CPU) 1b, 21b; timer / counter 2: buzzer 3: buzzer output driver 4: input switch 22; load 23; output circuit 24;

Claims (2)

【特許請求の範囲】[Claims] 【請求項1】 マイクロコントローラに入力された入力
信号に基づいて前記マイクロコントローラから出力され
る出力信号のデューティ比を制御するマイクロコントロ
ーラによるパルス幅変調制御方法において、前記入力信
号に基づいて第1の制御変数及び第2の制御変数を決定
する工程を繰り返す主工程と、前記第1の制御変数及び
前記第2の制御変数に基づいて前記主工程に割込を発生
させるまでの時間を示すタイマ/カウンタ値を設定する
タイマ/カウンタ値設定工程と、前記タイマ/カウンタ
値が示す時間が経過したときに前記主工程に割込を発生
させて前記出力信号を反転させる出力反転工程とを有す
ることを特徴とするマイクロコントローラによるパルス
幅変調制御方法。
1. A pulse width modulation control method by a microcontroller that controls a duty ratio of an output signal output from the microcontroller based on an input signal input to the microcontroller. A main step of repeating a step of determining a control variable and a second control variable; and a timer / a timer indicating a time until an interrupt is generated in the main step based on the first control variable and the second control variable. A timer / counter value setting step of setting a counter value; and an output inverting step of inverting the output signal by generating an interrupt in the main step when a time indicated by the timer / counter value elapses. Characteristic pulse width modulation control method by a microcontroller.
【請求項2】 前記主工程において繰り返される各工程
間の前記第1の制御変数と前記第2の制御変数との和は
一定であることを特徴とする請求項1に記載のマイクロ
コントローラによるパルス幅変調制御方法。
2. The pulse according to claim 1, wherein the sum of the first control variable and the second control variable during each step repeated in the main step is constant. Width modulation control method.
JP10150103A 1998-05-29 1998-05-29 Method for controlling modulation of pulse width by microcontroller Pending JPH11345033A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP10150103A JPH11345033A (en) 1998-05-29 1998-05-29 Method for controlling modulation of pulse width by microcontroller

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP10150103A JPH11345033A (en) 1998-05-29 1998-05-29 Method for controlling modulation of pulse width by microcontroller

Publications (1)

Publication Number Publication Date
JPH11345033A true JPH11345033A (en) 1999-12-14

Family

ID=15489579

Family Applications (1)

Application Number Title Priority Date Filing Date
JP10150103A Pending JPH11345033A (en) 1998-05-29 1998-05-29 Method for controlling modulation of pulse width by microcontroller

Country Status (1)

Country Link
JP (1) JPH11345033A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2004054104A1 (en) * 2002-12-10 2004-06-24 Koninklijke Philips Electronics N.V. Hardware/software implementation of a pwm with enhanced features using a standard microprocessor
KR101136436B1 (en) 2004-12-15 2012-04-19 에스에무케이 가부시키가이샤 Apparatus for generating a pulse width modulation signal and method of generating the same

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2004054104A1 (en) * 2002-12-10 2004-06-24 Koninklijke Philips Electronics N.V. Hardware/software implementation of a pwm with enhanced features using a standard microprocessor
KR101136436B1 (en) 2004-12-15 2012-04-19 에스에무케이 가부시키가이샤 Apparatus for generating a pulse width modulation signal and method of generating the same

Similar Documents

Publication Publication Date Title
TW200933371A (en) Variably delayed wakeup transition
JPH11345033A (en) Method for controlling modulation of pulse width by microcontroller
JP3005865B2 (en) Ultrasonic motor drive circuit
JPS6232486B2 (en)
JP2773546B2 (en) Pulse generation circuit
JP2002323894A (en) Buzzer driving device
JP3266675B2 (en) controller
JP3546449B2 (en) Method and apparatus for switching pulse period of pulse generating circuit
JP3284317B2 (en) Pulse width modulator
JP2689778B2 (en) Runaway detection device for electronic control unit
JP2001109484A (en) Warning sound generation device
JPS6364588A (en) Digital controller for motor
JPS60190197A (en) Control circuit of pulse motor
JP2831151B2 (en) Pulse generator
JP2819973B2 (en) Noise removal circuit
KR940027300A (en) Circuit and Method for Generating Stretch Clock
KR930011432A (en) Sub-step control signal generation circuit using step pulse interval
JPH04321102A (en) Pulse cycle controller
JPH07255192A (en) Motor control circuit
JPH07129272A (en) Clock speed control circuit
JPH0457096A (en) Electronic apparatus with notice function
JPS63148298A (en) Electronic siren
JPH07142944A (en) Sound volume control circuit
JPH03280722A (en) Digital analog conversion circuit
JPH11112295A (en) Pulse generator