JP2013080432A - Microcomputer - Google Patents
Microcomputer Download PDFInfo
- Publication number
- JP2013080432A JP2013080432A JP2011221121A JP2011221121A JP2013080432A JP 2013080432 A JP2013080432 A JP 2013080432A JP 2011221121 A JP2011221121 A JP 2011221121A JP 2011221121 A JP2011221121 A JP 2011221121A JP 2013080432 A JP2013080432 A JP 2013080432A
- Authority
- JP
- Japan
- Prior art keywords
- time
- edge
- register
- value
- capture
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 230000000630 rising effect Effects 0.000 claims description 178
- 238000000034 method Methods 0.000 claims description 142
- 238000012544 monitoring process Methods 0.000 abstract description 19
- 238000001514 detection method Methods 0.000 abstract 1
- 238000003708 edge detection Methods 0.000 description 34
- 230000000737 periodic effect Effects 0.000 description 28
- 238000004364 calculation method Methods 0.000 description 9
- 230000007274 generation of a signal involved in cell-cell signaling Effects 0.000 description 9
- 230000000694 effects Effects 0.000 description 3
- 241000287462 Phalacrocorax carbo Species 0.000 description 1
- 238000009795 derivation Methods 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 230000006870 function Effects 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
Images
Landscapes
- Microcomputers (AREA)
Abstract
Description
本発明は、入力信号に特定方向のエッジが発生すると、その時の時刻を示す時刻情報を記憶するレジスタを備えたマイクロコンピュータに関する。 The present invention relates to a microcomputer provided with a register for storing time information indicating the time when an edge in a specific direction occurs in an input signal.
マイクロコンピュータ(以下、マイコンともいう)としては、特定の端子への入力信号に特定方向のエッジ(レベル変化エッジ)が発生すると、その時の時刻情報としてフリーランニングタイマ(フリーランニングカウンタとも呼ばれる)のカウント値をラッチする、インプットキャプチャレジスタ(以下、キャプチャレジスタという)を備えたものが知られている(例えば、特許文献1参照)。そして、このようなマイコンにおいて、CPUは、キャプチャレジスタの値(時刻情報)を読み込むことで、入力信号に特定方向のエッジが発生した時刻を検出することができる。 As a microcomputer (hereinafter also referred to as a microcomputer), when an edge in a specific direction (level change edge) occurs in an input signal to a specific terminal, a free running timer (also referred to as a free running counter) is counted as time information at that time. A device having an input capture register (hereinafter referred to as a capture register) that latches a value is known (for example, see Patent Document 1). In such a microcomputer, the CPU can detect the time when the edge in the specific direction occurs in the input signal by reading the value (time information) of the capture register.
更に、特定の端子への入力信号に特定方向のエッジが発生すると、割り込み要求が発生してCPUが割り込み処理を実行するマイコンも知られている(例えば、特許文献2参照)。 Furthermore, there is also known a microcomputer in which when an edge in a specific direction occurs in an input signal to a specific terminal, an interrupt request is generated and the CPU executes an interrupt process (for example, see Patent Document 2).
また、キャプチャレジスタに関して、そのキャプチャレジスタにフリーランニングタイマのカウント値をラッチさせるようにする方のエッジを、有効エッジと言うことにすると、有効エッジが立ち上がりエッジであるキャプチャレジスタ(以下、立ち上がりエッジキャプチャレジスタという)と、有効エッジが立ち下がりエッジであるキャプチャレジスタ(以下、立ち下がりエッジキャプチャレジスタという)との、各々を備えたマイコンも周知である。そのマイコンでは、特定の端子への入力信号に立ち上がりエッジが発生すると、立ち上がりエッジキャプチャレジスタが、その立ち上がりエッジ発生時の時刻を示す時刻情報として、フリーランニングタイマのカウント値をラッチし、また、上記入力信号に立ち下がりエッジが発生すると、立ち下がりエッジキャプチャレジスタが、その立ち下がりエッジ発生時の時刻を示す時刻情報として、フリーランニングタイマのカウント値をラッチすることとなる。 In addition, regarding the capture register, if the edge that causes the capture register to latch the count value of the free running timer is referred to as a valid edge, a capture register whose rising edge is a rising edge (hereinafter, rising edge capture). A microcomputer including a register and a capture register whose effective edge is a falling edge (hereinafter referred to as a falling edge capture register) is also well known. In the microcomputer, when a rising edge occurs in the input signal to a specific terminal, the rising edge capture register latches the count value of the free running timer as time information indicating the time when the rising edge occurs. When a falling edge occurs in the input signal, the falling edge capture register latches the count value of the free running timer as time information indicating the time when the falling edge occurs.
ここで、立ち上がりエッジキャプチャレジスタと立ち下がりエッジキャプチャレジスタとを備えたマイコンの使用例について、図10を用い説明する。
図10は、立ち下がりエッジの発生周期(図10におけるT)が一定であるPWM(パルス幅変調)信号のデューティ比を計測する場合の使用例を表している。そして、この例では、PWM信号の立ち下がりエッジから次の立ち上がりエッジまでのローレベル時間(図10におけるW)が、可変のパルス幅である。
Here, an example of use of a microcomputer provided with a rising edge capture register and a falling edge capture register will be described with reference to FIG.
FIG. 10 shows a usage example in the case of measuring the duty ratio of a PWM (pulse width modulation) signal in which the falling edge generation period (T in FIG. 10) is constant. In this example, the low level time (W in FIG. 10) from the falling edge of the PWM signal to the next rising edge is a variable pulse width.
図10に示す使用例では、PWM信号がマイコンに入力され、そのPWM信号に立ち下がりエッジが発生する毎に、マイコンの内部において、割り込み要求が発生し、CPUが割り込み処理を実行する。つまり、割り込み要求に関しての有効エッジは立ち下がりエッジになっている。 In the usage example shown in FIG. 10, every time a PWM signal is input to the microcomputer and a falling edge occurs in the PWM signal, an interrupt request is generated inside the microcomputer, and the CPU executes an interrupt process. That is, the valid edge for the interrupt request is a falling edge.
そして、マイコンのCPUは、PWM信号の立ち下がりエッジに伴う割り込み処理において、下記[S1]〜[S4]の処理を行う。
[S1]立ち下がりエッジキャプチャレジスタの値を読み込むと共に、その読み込んだ値(即ち、PWM信号に立ち下がりエッジが今回発生した時のフリーランニングタイマのカウント値)Naと、当該割り込み処理を前回実行した際に立ち下がりエッジキャプチャレジスタから読み込んでRAMに記憶しておいた値(即ち、PWM信号に立ち下がりエッジが前回発生した時のフリーランニングタイマのカウント値)Nbとの差分から、PWM信号の周期(即ち、立ち下がりエッジが前回発生してから今回発生するまでの1周期時間)を算出する。
Then, the CPU of the microcomputer performs the following processes [S1] to [S4] in the interrupt process associated with the falling edge of the PWM signal.
[S1] The value of the falling edge capture register is read, and the read value (that is, the count value of the free-running timer when the falling edge occurs in the PWM signal this time) Na and the interrupt processing are executed last time. The period of the PWM signal is calculated from the difference from the value Nb read from the falling edge capture register and stored in the RAM (that is, the count value of the free running timer when the falling edge occurred in the PWM signal last time) Nb. (That is, one cycle time from the last occurrence of the falling edge to the current occurrence) is calculated.
[S2]立ち上がりエッジキャプチャレジスタの値を読み込むと共に、その読み込んだ値(即ち、PWM信号に立ち上がりエッジが発生した時のフリーランニングタイマのカウント値)Ncと、上記値Nbとの差分から、PWM信号のパルス幅(即ち、立ち下がりエッジが前回発生してから立ち上がりエッジが発生するまでのパルス幅時間)を算出する。 [S2] The value of the rising edge capture register is read, and the PWM signal is calculated from the difference between the read value (that is, the count value of the free running timer when the rising edge occurs in the PWM signal) Nc and the value Nb. Pulse width (that is, the pulse width time from the occurrence of the falling edge to the occurrence of the rising edge) is calculated.
[S3]上記[S2]で算出したパルス幅を、上記[S1]で算出した周期で割ることにより、PWM信号のデューティ比を算出する。
[S4]少なくとも上記[S1],[S2]の処理を行った後に、上記[S1]で読み込んだ立ち下がりエッジキャプチャレジスタの値Naを、RAMに新たな上記値Nbとして更新記憶する。尚、この[S4]の処理でRAMに記憶した値Nbが、次回の割り込み処理における上記[S1],[S2]の各処理で用いられる。
[S3] The PWM signal duty ratio is calculated by dividing the pulse width calculated in [S2] by the period calculated in [S1].
[S4] After at least the processes of [S1] and [S2], the value Na of the falling edge capture register read in [S1] is updated and stored in the RAM as the new value Nb. Note that the value Nb stored in the RAM in the process [S4] is used in the processes [S1] and [S2] in the next interrupt process.
このため、図10に示すように、PWM信号に、時刻t1で立ち下がりエッジが発生し、時刻t2で立ち上がりエッジが発生し、時刻t3で立ち下がりエッジが発生したとすると、時刻t1では、その時刻t1でのフリーランニングタイマのカウント値(C1)が立ち下がりエッジキャプチャレジスタに記憶され、時刻t2では、その時刻t2でのフリーランニングタイマのカウント値(C2)が立ち上がりエッジキャプチャレジスタに記憶され、時刻t3では、その時刻t3でのフリーランニングタイマのカウント値(C3)が立ち下がりエッジキャプチャレジスタに記憶される。 For this reason, as shown in FIG. 10, if a falling edge occurs in the PWM signal at time t1, a rising edge occurs at time t2, and a falling edge occurs at time t3, at time t1, the falling edge The count value (C1) of the free running timer at time t1 is stored in the falling edge capture register, and at time t2, the count value (C2) of the free running timer at time t2 is stored in the rising edge capture register. At time t3, the count value (C3) of the free running timer at time t3 is stored in the falling edge capture register.
そして、時刻t3の立ち下がりエッジに伴う割り込み処理では、時刻t1から時刻t3までの時間(詳しくは、時刻t1から時刻t3までのフリーランニングタイマのカウント数(=C3−C1))を周期Tとして算出すると共に、時刻t1から時刻t2までの時間(詳しくは、時刻t1から時刻t2までのフリーランニングタイマのカウント数(=C2−C1))をパルス幅Wとして算出し、更に、算出した周期Tに対するパルス幅Wの比を、デューティ比として算出することとなる。 In the interrupt process associated with the falling edge at time t3, the period from time t1 to time t3 (specifically, the count number of the free running timer from time t1 to time t3 (= C3-C1)) is set as a period T. In addition to calculation, the time from time t1 to time t2 (specifically, the count number of the free running timer from time t1 to time t2 (= C2-C1)) is calculated as the pulse width W, and the calculated period T The ratio of the pulse width W to is calculated as the duty ratio.
ところで、上記従来のマイコンにおいて、キャプチャレジスタの値は、そのキャプチャレジスタにとっての有効エッジが発生する毎に、自動的に(つまり、ソフトウェアに従いCPUが行う処理とは関係なく)更新される。 In the conventional microcomputer, the value of the capture register is automatically updated every time a valid edge for the capture register occurs (that is, regardless of the processing performed by the CPU according to software).
このため、所定のモニタ開始時から、CPUがキャプチャレジスタの値を読み込む読込処理を行う時までの期間を、有効エッジのモニタ期間とすると共に、そのモニタ期間中に有効エッジが最初に発生した時の時刻情報を上記読込処理で取得したい場合に、下記の不具合が生じる。 For this reason, the period from the start of a predetermined monitor to the time when the CPU performs the reading process for reading the value of the capture register is set as the valid edge monitor period, and the valid edge is first generated during the monitor period. The following problems occur when it is desired to acquire the time information in the above reading process.
即ち、モニタ期間中に有効エッジが2回以上発生してしまうと、CPUが上記読込処理を行った時点で、キャプチャレジスタの値は、有効エッジが最初に発生した時の時刻情報ではない時刻情報に更新されてしまっていることとなり、有効エッジが最初に発生した時の時刻情報を失ってしまう(有効エッジが最初に発生した時の時刻を検出することができない)、という不都合が生じる。 That is, if a valid edge occurs twice or more during the monitoring period, the capture register value is not the time information when the valid edge is first generated when the CPU performs the above reading process. As a result, the time information when the valid edge first occurs is lost (the time when the valid edge first occurs cannot be detected).
例えば、立ち上がりエッジキャプチャレジスタと立ち下がりエッジキャプチャレジスタとを備えたマイコンの前述した使用例(図10に示した)に関して説明すると、図11に例示するように、時刻t3でPWM信号に立ち下がりエッジが発生してから、CPUが割り込み処理を開始するまで(より詳しくは、割り込み処理において立ち上がりエッジキャプチャレジスタの値を読み込むまで)の、処理開始遅れ期間中の時刻t4にて、ノイズによりPWM信号に不要な(余分な)立ち上がりエッジが発生したとする。 For example, the above-described use example (shown in FIG. 10) of the microcomputer including the rising edge capture register and the falling edge capture register will be described. As illustrated in FIG. 11, the falling edge is added to the PWM signal at time t3. Until the CPU starts interrupt processing (more specifically, until the value of the rising edge capture register is read in the interrupt processing), at time t4 during the processing start delay period, the PWM signal is caused by noise. Assume that an unnecessary (extra) rising edge occurs.
すると、その時刻t4でのフリーランニングタイマのカウント値(C4)が、立ち上がりエッジキャプチャレジスタに更新記憶されることとなり、PWM信号が前回立ち下がってから最初に立ち上がった時刻t2でのカウント値(C2)が失われてしまう。 Then, the count value (C4) of the free running timer at the time t4 is updated and stored in the rising edge capture register, and the count value (C2) at the time t2 when the PWM signal first rises after the previous fall. ) Will be lost.
このため、CPUは、その時刻t2でのカウント値(C2)を取得することができず(時刻t2を検出することができず)、延いては、PWM信号のパルス幅及びデューティ比を正しく算出することができなくなる。この図11の例では、時刻t1から時刻t4までのフリーランニングタイマのカウント数(=C4−C1)であって、周期Tよりも長い時間を、パルス幅Wとして算出してしまうこととなる。 For this reason, the CPU cannot acquire the count value (C2) at the time t2 (cannot detect the time t2), and thus correctly calculates the pulse width and duty ratio of the PWM signal. Can not do. In the example of FIG. 11, the free running timer count number (= C4−C1) from time t1 to time t4, which is longer than the period T, is calculated as the pulse width W.
尚、図10及び図11の例では、割り込み処理において立ち上がりエッジキャプチャレジスタの値を読み込んだ時が、立ち上がりエッジについての前回のモニタ期間の終了時であり、次回のモニタ期間の開始時(モニタ開始時点)でもある。 In the example of FIGS. 10 and 11, the value of the rising edge capture register is read in the interrupt processing is the end of the previous monitoring period for the rising edge, and the start of the next monitoring period (monitoring start). Time).
本発明は、こうした問題に鑑みなされたものであり、入力信号に特定方向の有効エッジが発生すると、その時の時刻情報を記憶する時刻記憶レジスタを備えたマイコンにおいて、所定のモニタ開始時からCPUが時刻記憶レジスタの値を読み込む処理を行う時までのモニタ期間中に、有効エッジが複数回発生したとしても、その有効エッジが最初に発生した時の時刻情報をCPUが取得できるようにすること、を目的としている。 The present invention has been made in view of such a problem. When a valid edge in a specific direction occurs in an input signal, the microcomputer having a time storage register for storing time information at that time, the CPU starts from a predetermined monitor start time. Even when a valid edge occurs a plurality of times during the monitoring period until the time of reading the value of the time storage register, the CPU can acquire time information when the valid edge first occurs, It is an object.
請求項1のマイコン(マイクロコンピュータ)は、入力信号に特定方向のエッジである有効エッジが発生すると、その時の時刻を示す時刻情報を記憶する時刻記憶レジスタと、プログラムを実行するCPUとを備えており、更に、更新制御手段を備えている。
When a valid edge that is an edge in a specific direction occurs in an input signal, the microcomputer according to
そして、更新制御手段は、時刻記憶レジスタが時刻情報を記憶すると、CPUから出力される許可信号を受けるまでは、時刻記憶レジスタが時刻情報を更新して記憶するのを禁止する。 Then, when the time storage register stores the time information, the update control means prohibits the time storage register from updating and storing the time information until receiving a permission signal output from the CPU.
このマイコンでは、入力信号に有効エッジが発生して時刻記憶レジスタが時刻情報を記憶すると、CPUがソフトウェアの処理によって更新制御手段に許可信号を与えるまでは、入力信号に再び有効エッジが発生しても時刻記憶レジスタの記憶値は更新されない。 In this microcomputer, when a valid edge occurs in the input signal and the time storage register stores the time information, the valid edge occurs again in the input signal until the CPU gives a permission signal to the update control means by software processing. However, the stored value of the time storage register is not updated.
よって、このマイコンによれば、所定のモニタ開始時からCPUが時刻記憶レジスタの値を読み込む処理を行う時までのモニタ期間において、有効エッジが複数回発生したとしても、有効エッジが最初に発生した時の時刻情報をCPUに取得させたい場合には、CPUがモニタ開始時に更新制御手段へ許可信号を与えるようにしておけば良い。 Therefore, according to this microcomputer, even if the valid edge occurs a plurality of times in the monitoring period from the start of the predetermined monitoring to the time when the CPU reads the value of the time storage register, the valid edge occurs first. If the CPU wants to acquire the time information of the hour, the CPU should give a permission signal to the update control means at the start of monitoring.
そのようにすれば、時刻記憶レジスタは、モニタ開始時から、時刻情報を更新記憶できる状態となり、その後、入力信号に有効エッジが複数回発生したとしても、最初に有効エッジが発生した時にだけ時刻情報を更新記憶することとなる。よって、モニタ期間中に有効エッジが複数回発生したとしても、CPUは、時刻記憶レジスタの値を読み込むことにより、有効エッジが最初に発生した時の時刻情報を取得することができ、延いては、有効エッジが最初に発生した時刻を検出することができる。 By doing so, the time storage register is in a state in which the time information can be updated and stored from the start of monitoring, and even after that, even if the valid edge occurs multiple times in the input signal, Information is updated and stored. Therefore, even if the valid edge occurs multiple times during the monitoring period, the CPU can acquire the time information when the valid edge first occurs by reading the value of the time storage register. The time when the valid edge first occurs can be detected.
次に、請求項2のマイコンでは、請求項1のマイコンにおいて、前記時刻記憶レジスタを、第1の時刻記憶レジスタとして備えると共に、入力信号は、立ち上がりエッジと立ち下がりエッジとのうちの一方である基準エッジが複数回発生する信号である。 According to a second aspect of the present invention, in the microcomputer of the first aspect, the time storage register is provided as a first time storage register, and the input signal is one of a rising edge and a falling edge. This is a signal in which the reference edge is generated a plurality of times.
そして、第1の時刻記憶レジスタは、入力信号に、有効エッジとして、基準エッジとは反対方向の非基準エッジが発生すると、その時の時刻を示す時刻情報を記憶するようになっている。 The first time storage register stores time information indicating the current time when a non-reference edge in the direction opposite to the reference edge is generated as a valid edge in the input signal.
更に、請求項2のマイコンは、入力信号に基準エッジが発生すると、その時の時刻を示す時刻情報を記憶する第2の時刻記憶レジスタと、入力信号に基準エッジが発生すると、割り込み要求を発生する割り込み発生手段とを備えている。
The microcomputer according to
そして、このマイコンにおいて、CPUは、割り込み発生手段による割り込み要求が発生すると(即ち、入力信号に基準エッジが発生すると)実行を開始する割り込み処理において、下記の第1〜第6の処理を行う。 In this microcomputer, the CPU performs the following first to sixth processes in the interrupt process that starts execution when an interrupt request is generated by the interrupt generation means (that is, when a reference edge occurs in the input signal).
即ち、CPUは、割り込み処理において、「第1の時刻記憶レジスタに記憶されている時刻情報を読み込む第1の処理」と、「第2の時刻記憶レジスタに記憶されている時刻情報を読み込む第2の処理」と、「第2の処理で読み込んだ時刻情報の値と、当該割り込み処理を前回実行した際に第2の処理で読み込んでメモリに記憶しておいた時刻情報である基準エッジ前回発生時刻情報の値との差分から、入力信号に基準エッジが前回発生してから今回発生するまでの時間である1周期時間を算出する第3の処理」と、「第1の処理で読み込んだ時刻情報の値と、前記基準エッジ前回発生時刻情報の値との差分から、入力信号に基準エッジが前回発生してから非基準エッジが発生するまでの時間であるパルス幅時間を算出する第4の処理」とを行う。そして、第3の処理と第4の処理よりも後に、「第2の処理で読み込んだ時刻情報を前記メモリに新たな基準エッジ前回発生時刻情報として更新記憶する第5の処理」を行い、更に第1の処理よりも後に、「更新制御手段に許可信号を与えて第1の時刻記憶レジスタが時刻情報を更新して記憶するのを許可する第6の処理」を行う。 That is, in the interrupt processing, the CPU performs “first processing for reading time information stored in the first time storage register” and “second processing for reading time information stored in the second time storage register”. ”And“ time information value read in the second process, and the previous occurrence of the reference edge, which is the time information read in the second process and stored in the memory when the interrupt process was executed last time From the difference from the value of the time information, the third process for calculating one cycle time, which is the time from the last occurrence of the reference edge to the input signal to the current occurrence, and the time read in the first process A pulse width time that is a time from when the reference edge is generated in the input signal to when the non-reference edge is generated is calculated from the difference between the information value and the value of the reference edge previous generation time information. Processing Cormorant. Then, after the third process and the fourth process, a “fifth process for updating and storing the time information read in the second process as new reference edge previous occurrence time information in the memory” is performed. After the first process, a “sixth process for giving a permission signal to the update control unit and allowing the first time storage register to update and store time information” is performed.
このようなマイコンによれば、基準エッジの発生に伴う割り込み処理により、入力信号の1周期時間(基準エッジが前回発生してから今回発生するまでの時間)と、入力信号のパルス幅時間(基準エッジが前回発生してから非基準エッジが発生するまでの時間)とを算出することができる。また、算出した周期とパルス幅時間から、入力信号の1周期時間に対するパルス幅時間の比を算出することもでき、基準エッジの発生周期が一定のPWM信号が入力信号であるならば、その比として、PWM信号のデューティ比を算出するこができる。 According to such a microcomputer, due to the interrupt processing accompanying the generation of the reference edge, one cycle time of the input signal (the time from when the reference edge is generated to the current generation) and the pulse width time of the input signal (the reference edge) The time from when the edge occurs last time until the non-reference edge occurs) can be calculated. Further, the ratio of the pulse width time to one cycle time of the input signal can be calculated from the calculated cycle and the pulse width time. If a PWM signal having a constant reference edge generation cycle is an input signal, the ratio As a result, the duty ratio of the PWM signal can be calculated.
そして特に、割り込み処理では、第1の時刻記憶レジスタの値(時刻情報)を読み込む第1の処理より後の第6の処理により、更新制御手段に許可信号を与えるため、入力信号に基準エッジが発生してから割り込み処理が開始されるまで(より詳しくは、割り込み処理における第1の処理が行われるまで)の間に、ノイズによって入力信号に不要な非基準エッジ(即ち、第1の時刻記憶レジスタにとっての有効エッジ)が発生したとしても、第1の時刻記憶レジスタの値は更新されない。このため、割り込み処理における第1の処理で第1の時刻記憶レジスタの値を読み込む時に、その第1の時刻記憶レジスタには、入力信号に基準エッジが前回発生してから最初に非基準エッジが発生した時の時刻情報が記憶されていることとなる。 In particular, in the interrupt processing, the permission signal is given to the update control means by the sixth processing after the first processing for reading the value (time information) of the first time storage register, so that the input signal has a reference edge. A non-reference edge (that is, a first time memory that is unnecessary for an input signal due to noise) between occurrence of the interrupt signal and start of interrupt processing (more specifically, until the first processing in the interrupt processing is performed). Even if a valid edge for the register occurs, the value of the first time storage register is not updated. For this reason, when the value of the first time storage register is read in the first processing in the interrupt processing, the first time storage register has a non-reference edge first in the input signal after the previous occurrence of the reference edge. Time information at the time of occurrence is stored.
よって、上記ノイズによる不要な非基準エッジが発生しても、割り込み処理では、入力信号に基準エッジが前回発生してから最初に非基準エッジが発生した時の時刻情報を取得することができ、誤ったパルス幅時間を算出してしまうことを回避することができる。つまり、入力信号に基準エッジが前回発生してから最初に非基準エッジが発生した時までの時間を、パルス幅時間として算出することができ、ノイズによるパルス幅時間の誤算出を回避することができる。 Therefore, even if an unnecessary non-reference edge due to the noise occurs, the interrupt process can acquire time information when the non-reference edge first occurs after the reference edge occurred in the input signal last time. It is possible to avoid calculating an incorrect pulse width time. In other words, the time from when the reference edge occurs in the input signal to the time when the first non-reference edge occurs can be calculated as the pulse width time, thus avoiding erroneous calculation of the pulse width time due to noise. it can.
尚、このマイコンでは、割り込み処理における第1の処理で第1の時刻記憶レジスタの値を読み込んだ時が、前回のモニタ期間の終了時であり、次回のモニタ期間の開始時(モニタ開始時点)にも相当するが、モニタ開始時点については、厳密には、第6の処理で更新制御手段に許可信号を与えた時となる。 In this microcomputer, the time when the value of the first time storage register is read in the first process of the interrupt process is the end of the previous monitor period, and the start of the next monitor period (monitor start time) Strictly speaking, the monitoring start time is strictly when the permission signal is given to the update control means in the sixth process.
次に、請求項3のマイコンでは、請求項2のマイコンにおいて、入力信号は、基準エッジの発生周期が一定のPWM(パルス幅変調)信号である。そして、CPUは、前記割り込み処理において、「第3の処理で算出した1周期時間と第4の処理で算出したパルス幅時間とからPWM信号のデューティ比を算出する第7の処理」を行う。 According to a third aspect of the present invention, in the microcomputer according to the second aspect, the input signal is a PWM (pulse width modulation) signal having a constant reference edge generation period. Then, in the interrupt process, the CPU performs “seventh process for calculating the duty ratio of the PWM signal from one cycle time calculated in the third process and the pulse width time calculated in the fourth process”.
このマイコンによれば、入力信号としてのPWM信号に基準エッジが発生してから割り込み処理における第1の処理が行われるまでの間に、ノイズによってPWM信号に不要な非基準エッジが発生したとしても、誤ったデューティ比を算出してしまうことを回避することができる。 According to this microcomputer, even if an unnecessary non-reference edge occurs in the PWM signal due to noise between the occurrence of the reference edge in the PWM signal as the input signal and the execution of the first process in the interrupt process. It is possible to avoid calculating an incorrect duty ratio.
次に、請求項4のマイコンでは、請求項3のマイコンにおいて、CPUは、前記割り込み処理において、「第3の処理で算出した1周期時間が所定の正常範囲内であるか否かを判定する第8の処理」を行うと共に、その第8の処理により1周期時間が正常範囲内ではないと判定した場合には、第7の処理をスキップするようになっている。
Next, in the microcomputer according to claim 4, in the microcomputer according to
つまり、割り込み処理では、今回算出した1周期時間が正常範囲内でなければ、今回算出した1周期時間とパルス幅時間を用いてデューティ比を算出しないようになっている。尚、正常範囲は、PWM信号の周期(基準エッジの発生周期)の正常許容範囲(正常と考えられる許容範囲)に設定しておけば良い。 That is, in the interrupt process, if the one cycle time calculated this time is not within the normal range, the duty ratio is not calculated using the one cycle time calculated this time and the pulse width time. Note that the normal range may be set to a normal permissible range (permissible range considered normal) of the PWM signal cycle (reference edge generation cycle).
このマイコンによれば、PWM信号に正規の基準エッジが発生してから次の正規の基準エッジが発生するまでの間に、ノイズによる不要な基準エッジが発生して、基準エッジの発生間隔が正常範囲よりも短くなった場合には、割り込み処理における第3の処理で算出される1周期時間が正常範囲よりも短くなり、そのことが第8の処理で判定されて、第7の処理がスキップされることとなる。 According to this microcomputer, between the occurrence of a regular reference edge in the PWM signal and the occurrence of the next regular reference edge, an unnecessary reference edge is generated due to noise, and the reference edge generation interval is normal. When it becomes shorter than the range, the one cycle time calculated in the third process in the interrupt process becomes shorter than the normal range, and this is determined in the eighth process, and the seventh process is skipped. Will be.
このため、ノイズによってPWM信号に不要な基準エッジが発生した場合(基準エッジの発生間隔が正常範囲よりも短くなった場合)に、誤ったデューティ比を算出してしまうことを回避することができる。 For this reason, when an unnecessary reference edge is generated in the PWM signal due to noise (when the generation interval of the reference edge is shorter than the normal range), it is possible to avoid calculating an incorrect duty ratio. .
次に、請求項5のマイコンでは、請求項4のマイコンにおいて、CPUは、前記割り込み処理において、第8の処理により1周期時間が前記正常範囲内ではないと判定した場合には、第5の処理もスキップするようになっている。つまり、割り込み処理では、今回算出した1周期時間が正常範囲内でなければ、デューティ比の算出だけではく、基準エッジ前回発生時刻情報の更新記憶も止めるようになっている。 Next, in the microcomputer of claim 5, in the microcomputer of claim 4, if the CPU determines that one cycle time is not within the normal range by the eighth process in the interrupt process, Processing is also skipped. That is, in the interrupt process, if the one cycle time calculated this time is not within the normal range, the update storage of the reference edge previous occurrence time information is stopped as well as the duty ratio calculation.
このマイコンによれば、PWM信号に正規の基準エッジが発生してから次の正規の基準エッジが発生するまでの間に、ノイズによる不要な基準エッジが発生した場合でも、PWM信号に次の正規の基準エッジが発生して割り込み処理が実行されれば、その回の割り込み処理により、正しい1周期時間(PWM信号の周期)が算出されることとなる。その回の割り込み処理における第3及び第4の処理で用いられる基準エッジ前回発生時刻情報は、ノイズによる基準エッジが発生した時の時刻情報ではなく、前回の正規の基準エッジが発生した時の時刻情報になっているからである。 According to this microcomputer, even if an unnecessary reference edge is generated due to noise between the occurrence of a normal reference edge in the PWM signal and the generation of the next normal reference edge, the next normal signal is generated in the PWM signal. When the reference edge is generated and interrupt processing is executed, the correct one cycle time (PWM signal cycle) is calculated by the interrupt processing at that time. The reference edge previous occurrence time information used in the third and fourth processes in the interrupt process at that time is not the time information when the reference edge due to noise occurs, but the time when the last regular reference edge occurs Because it is information.
また、PWM信号に正規の基準エッジが発生してから次の正規の基準エッジが発生するまでの間に、ノイズによる不要な基準エッジが発生した場合には、その不要な基準エッジの直近に不要な非基準エッジも発生することとなるが、その場合でも、PWM信号に次の正規の基準エッジが発生して割り込み処理が実行されれば、その回の割り込み処理により、正しいパルス幅時間が算出されることとなり、延いては、正しいデューティ比が算出されることとなる。 In addition, if an unnecessary reference edge is generated due to noise between the occurrence of a regular reference edge in the PWM signal and the occurrence of the next regular reference edge, it is unnecessary in the immediate vicinity of the unnecessary reference edge. In this case, if the next regular reference edge occurs in the PWM signal and interrupt processing is executed, the correct pulse width time is calculated by the interrupt processing of that time. As a result, the correct duty ratio is calculated.
このことについて説明すると、まず、PWM信号に正規の基準エッジが発生してから次の正規の基準エッジが発生するまでの間に、ノイズによる不要な基準エッジ及び非基準エッジが発生するパターンとしては、下記の第1パターンと第2パターンとがある。 To explain this, first, as a pattern in which an unnecessary reference edge and a non-reference edge are generated due to noise between the generation of a normal reference edge in the PWM signal and the generation of the next normal reference edge. There are the following first pattern and second pattern.
第1パターンは、「PWM信号に正規の基準エッジが発生してから正規の非基準エッジが発生するまでの期間であるパルス幅期間中に、ノイズによって、非基準エッジと基準エッジとがその順に発生する」というパターンである。 The first pattern is: “Non-reference edge and reference edge in that order due to noise during the pulse width period, which is the period from the generation of the normal reference edge to the PWM signal until the generation of the normal non-reference edge. It occurs.
第2パターンは、「PWM信号に正規の非基準エッジが発生してから次の正規の基準エッジが発生するまでの期間である反パルス幅期間中に、ノイズによって、基準エッジと非基準エッジとがその順に発生する」というパターンである。 The second pattern is “a reference edge and a non-reference edge due to noise during an anti-pulse width period, which is a period from when a normal non-reference edge occurs in the PWM signal until the next normal reference edge occurs. Are generated in that order. "
そして、第1パターンの場合、ノイズによる非基準エッジが発生した時の時刻情報が第1の時刻記憶に記憶されてしまうが、その直後のノイズによる基準エッジに伴う割り込み処理においては、その第1の時刻記憶レジスタの値は無視されることとなる。第8の処理により1周期時間が正常範囲内ではないと判定されて、第7の処理がスキップされるからである。 In the case of the first pattern, the time information when the non-reference edge due to noise occurs is stored in the first time memory, but in the interrupt processing accompanying the reference edge due to noise immediately after that, the first information is stored. The value of the time storage register is ignored. This is because it is determined by the eighth process that one cycle time is not within the normal range, and the seventh process is skipped.
また、ノイズによる基準エッジに伴う割り込み処理においても、第6の処理により更新制御手段に許可信号を与えることとなる。よって、その後に正規の非基準エッジが発生すれば、その時の時刻情報が第1の時刻記憶レジスタに更新記憶される。 Also, in the interrupt processing accompanying the reference edge due to noise, the permission signal is given to the update control means by the sixth processing. Therefore, if a normal non-reference edge occurs thereafter, the time information at that time is updated and stored in the first time storage register.
そして、その後に正規の基準エッジが発生して、割り込み処理が実行されれば、その回の割り込み処理により、PWM信号の正しい1周期時間とパルス幅時間とが算出されることとなり、延いては、正しいデューティ比が算出されることとなる。 Then, if a normal reference edge occurs after that and interrupt processing is executed, the correct one cycle time and pulse width time of the PWM signal are calculated by the interrupt processing of that time. Thus, the correct duty ratio is calculated.
一方、第2パターンの場合、ノイズによる基準エッジが発生した時点では、既に第1の時刻記憶レジスタには正規の非基準エッジが発生した時刻の時刻情報が記憶されており、第1の時刻記憶レジスタは更新記憶禁止状態になっている。このため、ノイズによる基準エッジが発生してから該基準エッジに伴う割り込み処理が開始されるまで(より詳しくは第6の処理が行われるまで)に同ノイズによる非基準エッジが発生しても、第1の時刻記憶レジスタの値が更新されない。また、第2パターンの場合にも、ノイズによる基準エッジに伴う割り込み処理においては、第8の処理により1周期時間が正常範囲内ではないと判定されて、第7の処理がスキップされる。 On the other hand, in the case of the second pattern, when the reference edge due to noise occurs, the time information of the time when the normal non-reference edge occurs is already stored in the first time storage register. The register is in an update storage prohibition state. For this reason, even if a non-reference edge due to the noise occurs from when the reference edge due to noise occurs until interrupt processing associated with the reference edge starts (more specifically, until the sixth process is performed), The value of the first time storage register is not updated. Also in the case of the second pattern, in the interrupt processing accompanying the reference edge due to noise, it is determined by the eighth processing that one cycle time is not within the normal range, and the seventh processing is skipped.
よって、その後に正規の基準エッジが発生して、割り込み処理が実行されれば、その回の割り込み処理により、PWM信号の正しい1周期時間とパルス幅時間とが算出されることとなり、延いては、正しいデューティ比が算出されることとなる。 Therefore, if a normal reference edge occurs after that and interrupt processing is executed, the correct one cycle time and pulse width time of the PWM signal are calculated by the interrupt processing of that time, Thus, the correct duty ratio is calculated.
以上のことから、請求項5のマイコンによれば、ノイズによるデューティ比誤算出の回避性能を一層向上させることができる。 From the above, according to the microcomputer of the fifth aspect, it is possible to further improve the avoidance performance of erroneous calculation of the duty ratio due to noise.
以下に、本発明が適用された実施形態のマイコンについて説明する。
図1に示すように、本実施形態のマイコン1は、プログラムを実行するCPU3と、実行対象のプログラムが記憶されたROM5と、プログラムの一部やCPU3による演算結果等が記憶されるRAM7と、当該マイコン1への入力信号にエッジが発生した時の時刻情報を記憶する機能を有したタイマユニット9と、それらを接続するバス11と、CPU3に割込み要求信号を出力する割り込みコントローラ(INTC)13と、エッジ検出ポート15とを備えている。
The microcomputer of the embodiment to which the present invention is applied will be described below.
As shown in FIG. 1, the
エッジ検出ポート15は、当該マイコン1の特定の端子17に入力される入力信号に立ち上がりエッジ(ローからハイへのレベル変化エッジ)が発生すると、立ち上がりエッジ検出信号を出力し、上記入力信号に立ち下がりエッジ(ハイからローへのレベル変化エッジ)が発生すると、立ち下がりエッジ検出信号を出力する。尚、立ち上がりエッジ検出信号と立ち下がりエッジ検出信号の各々は、例えば、当該マイコン1における内部クロックの所定周期分(例えば半周期分や1周期分)のパルス幅を有したパルス信号である。
The
また、タイマユニット9は、当該マイコン1における内部クロックによってカウントアップされるフリーランニングタイマ19と、立ち上がりエッジキャプチャレジスタ21と、立ち上がりエッジキャプチャモードレジスタ23と、立ち上がりエッジキャプチャイネーブルレジスタ25と、立ち上がりエッジキャプチャ制御回路27と、立ち下がりエッジキャプチャレジスタ31と、立ち下がりエッジキャプチャモードレジスタ33と、立ち下がりエッジキャプチャイネーブルレジスタ35と、立ち下がりエッジキャプチャ制御回路37と、割り込み要求信号生成部41と、割り込み要求有効エッジ設定レジスタ43とを備えている。
The timer unit 9 includes a
そして、エッジ検出ポート15から出力される立ち上がりエッジ検出信号が、立ち上がりエッジキャプチャ制御回路27と割り込み要求信号生成部41とに入力され、また、エッジ検出ポート15から出力される立ち下がりエッジ検出信号が、立ち下がりエッジキャプチャ制御回路37と割り込み要求信号生成部41とに入力されるようになっている。
The rising edge detection signal output from the
立ち上がりエッジキャプチャレジスタ21は、フリーランニングタイマ19と同じビット数のレジスタであり、上記立ち上がりエッジ検出信号が立ち上がりエッジキャプチャ制御回路27を介して入力されると、その時のフリーランニングタイマ19のカウント値(以下、タイマ値という)をラッチする(記憶する)。そして、立ち上がりエッジキャプチャレジスタ21は、CPU3からのリードアクセスが可能である。
The rising
立ち上がりエッジキャプチャモードレジスタ23は、立ち上がりエッジキャプチャ制御回路27の動作モードを設定するための1ビットのレジスタであり、CPU3によって“1”か“0”が書き込まれる。
The rising edge
立ち上がりエッジキャプチャイネーブルレジスタ25は、立ち上がりエッジキャプチャレジスタ21がタイマ値をラッチする毎(即ち、更新記憶する毎)に“1”がセットされる1ビットのレジスタである。そして、この立ち上がりエッジキャプチャイネーブルレジスタ25の値は、CPU3によって“0”に書き換えることができるようになっている。
The rising edge capture enable
立ち上がりエッジキャプチャ制御回路27は、立ち上がりエッジキャプチャモードレジスタ23の値が“0”である場合には、動作モードがノーマルモードとなり、立ち上がりエッジキャプチャモードレジスタ23の値が“1”である場合には、動作モードがワンショットモードとなる。尚、この対応関係とは逆に、立ち上がりエッジキャプチャモードレジスタ23の値は、“0”がワンショットモードに対応し、“1”がノーマルモードに対応するようになっていても良い。また、このことは、後述する立ち下がりエッジキャプチャモードレジスタ33の値についても同様である。
When the value of the rising edge
そして、立ち上がりエッジキャプチャ制御回路27は、ノーマルモードの場合には、エッジ検出ポート15からの立ち上がりエッジ検出信号を、立ち上がりエッジキャプチャレジスタ21に、そのまま出力する。
In the normal mode, the rising edge
よって、立ち上がりエッジキャプチャ制御回路27の動作モードがノーマルモードに設定された場合には、立ち上がりエッジについてのタイマユニット9での処理形態がノーマルモードとなり、そのノーマルモードでは、端子17への入力信号に立ち上がりエッジが発生する毎に、立ち上がりエッジキャプチャレジスタ21がタイマ値を更新記憶することとなる。
Therefore, when the operation mode of the rising edge
また、立ち上がりエッジキャプチャ制御回路27は、ワンショットモードの場合には、立ち上がりエッジキャプチャイネーブルレジスタ25の値が“0”ならば、エッジ検出ポート15からの立ち上がりエッジ検出信号を立ち上がりエッジキャプチャレジスタ21に出力するが、立ち上がりエッジキャプチャイネーブルレジスタ25の値が“1”ならば、立ち上がりエッジ検出信号を立ち上がりエッジキャプチャレジスタ21に出力しなくなる。このため、立ち上がりエッジキャプチャレジスタ21は、立ち上がりエッジキャプチャイネーブルレジスタ25の値が“0”の場合にだけ、タイマ値を更新記憶することとなる。
In the one-shot mode, the rising edge
よって、立ち上がりエッジキャプチャ制御回路27の動作モードがワンショットモードに設定された場合には、立ち上がりエッジについてのタイマユニット9での処理形態がワンショットモードとなり、そのワンショットモードでは、CPU3によって立ち上がりエッジキャプチャイネーブルレジスタ25の値が“0”に設定されてから、端子17への入力信号に立ち上がりエッジが最初に発生すると、立ち上がりエッジキャプチャレジスタ21がタイマ値を更新記憶するが、その更新記憶時点からCPU3によって立ち上がりエッジキャプチャイネーブルレジスタ25の値が“1”から“0”に書き換えられるまでの間は、入力信号に立ち上がりエッジが発生しても、立ち上がりエッジキャプチャレジスタ21がタイマ値を更新記憶することが、禁止されることとなる。
Therefore, when the operation mode of the rising edge
また、立ち下がりエッジキャプチャレジスタ31、立ち下がりエッジキャプチャモードレジスタ33、立ち下がりエッジキャプチャイネーブルレジスタ35及び立ち下がりエッジキャプチャ制御回路37の各々も、上記立ち上がりエッジキャプチャレジスタ21、立ち上がりエッジキャプチャモードレジスタ23、立ち上がりエッジキャプチャイネーブルレジスタ25及び立ち上がりエッジキャプチャ制御回路27の各々と同様のものである。
In addition, the falling
即ち、立ち下がりエッジキャプチャレジスタ31も、フリーランニングタイマ19と同じビット数のレジスタであり、上記立ち下がりエッジ検出信号が立ち下がりエッジキャプチャ制御回路37を介して入力されると、その時のタイマ値をラッチする(記憶する)。そして、立ち下がりエッジキャプチャレジスタ31も、CPU3からのリードアクセスが可能である。
That is, the falling
立ち下がりエッジキャプチャモードレジスタ33は、立ち下がりエッジキャプチャ制御回路37の動作モードを設定するための1ビットのレジスタであり、CPU3によって“1”か“0”が書き込まれる。
The falling edge
立ち下がりエッジキャプチャイネーブルレジスタ35は、立ち下がりエッジキャプチャレジスタ31がタイマ値をラッチする毎(即ち、更新記憶する毎)に“1”がセットされる1ビットのレジスタである。そして、この立ち下がりエッジキャプチャイネーブルレジスタ35の値は、CPU3によって“0”に書き換えることができるようになっている。
The falling edge capture enable
立ち下がりエッジキャプチャ制御回路37は、立ち下がりエッジキャプチャモードレジスタ33の値が“0”である場合には、動作モードがノーマルモードとなり、立ち下がりエッジキャプチャモードレジスタ33の値が“1”である場合には、動作モードがワンショットモードとなる。
When the value of the falling edge
そして、立ち下がりエッジキャプチャ制御回路37は、ノーマルモードの場合には、エッジ検出ポート15からの立ち下がりエッジ検出信号を、立ち下がりエッジキャプチャレジスタ31に、そのまま出力する。
In the normal mode, the falling edge
よって、立ち下がりエッジキャプチャ制御回路37の動作モードがノーマルモードに設定された場合には、立ち下がりエッジについてのタイマユニット9での処理形態がノーマルモードとなり、そのノーマルモードでは、端子17への入力信号に立ち下がりエッジが発生する毎に、立ち下がりエッジキャプチャレジスタ31がタイマ値を更新記憶することとなる。
Therefore, when the operation mode of the falling edge
また、立ち下がりエッジキャプチャ制御回路37は、ワンショットモードの場合には、立ち下がりエッジキャプチャイネーブルレジスタ35の値が“0”ならば、エッジ検出ポート15からの立ち下がりエッジ検出信号を立ち下がりエッジキャプチャレジスタ31に出力するが、立ち下がりエッジキャプチャイネーブルレジスタ35の値が“1”ならば、立ち下がりエッジ検出信号を立ち下がりエッジキャプチャレジスタ31に出力しなくなる。
In the one-shot mode, the falling edge
よって、立ち下がりエッジキャプチャ制御回路37の動作モードがワンショットモードに設定された場合には、立ち下がりエッジについてのタイマユニット9での処理形態がワンショットモードとなり、そのワンショットモードでは、CPU3によって立ち下がりエッジキャプチャイネーブルレジスタ35の値が“0”に設定されてから、端子17への入力信号に立ち下がりエッジが最初に発生すると、立ち下がりエッジキャプチャレジスタ31がタイマ値を更新記憶するが、その更新記憶時点からCPU3によって立ち下がりエッジキャプチャイネーブルレジスタ35の値が“1”から“0”に書き換えられるまでの間は、入力信号に立ち下がりエッジが発生しても、立ち下がりエッジキャプチャレジスタ31がタイマ値を更新記憶することが、禁止されることとなる。
Therefore, when the operation mode of the falling edge
一方、タイマユニット9において、割り込み要求有効エッジ設定レジスタ43は、CPU3によってライトアクセスが可能な1ビットのレジスタである。
そして、割り込み要求信号生成部41は、エッジ検出ポート15からの立ち上がりエッジ検出信号と立ち下がりエッジ検出信号とのうち、割り込み要求有効エッジ設定レジスタ43の値によって指示される方の信号が入力されると、割り込みコントローラ13へ割り込み要求信号を出力する。
On the other hand, in the timer unit 9, the interrupt request valid
Then, the interrupt request
本実施形態では、例えば、割り込み要求信号生成部41は、割り込み要求有効エッジ設定レジスタ43の値が“1”の場合には、立ち上がりエッジ検出信号が入力されると割り込み要求信号を出力し、逆に、割り込み要求有効エッジ設定レジスタ43の値が“0”の場合には、立ち下がりエッジ検出信号が入力されると割り込み要求信号を出力する。
In this embodiment, for example, when the value of the interrupt request valid
そして、割り込み要求信号生成部41から出力される割り込み要求信号は、割り込みコントローラ13からCPU3へ、外部割り込みに対応する割り込み要求信号(即ち、外部割り込み要求信号)として出力される。すると、CPU3は、その外部割り込み要求信号に対応する割り込み処理(即ち、外部割り込み処理)を実行することとなる。
The interrupt request signal output from the interrupt request
つまり、割り込み要求有効エッジ設定レジスタ43は、割り込み要求の有効エッジ(詳しくは、割り込み要求を発生させることとなる入力信号のエッジ)を任意に設定するためのレジスタであり、そのレジスタ43の値を“1”にすれば、立ち上がりエッジが割り込み要求の有効エッジとなり、そのレジスタ43の値を“0”にすれば、立ち下がりエッジが割り込み要求の有効エッジとなる。
That is, the interrupt request valid
尚、割り込み要求有効エッジ設定レジスタ43を複数ビットのレジスタにして、割り込み要求信号生成部41が、立ち上がりエッジ検出信号と立ち下がりエッジ検出信号との何れが入力されても割り込み要求信号を出力するモードと、立ち上がりエッジ検出信号が入力された時にだけ割り込み要求信号を出力するモードと、立ち下がりエッジ検出信号が入力された時にだけ割り込み要求信号を出力するモードと、立ち上がりエッジ検出信号と立ち下がりエッジ検出信号との何れが入力されても割り込み要求信号を出力しないモードとの、4つのモードに切り替わるように構成しても良い。
A mode in which the interrupt request valid
以上のことから、タイマユニット9の動作内容をまとめると、図2に示すフローチャートのようになる。尚、ここでは、端子17への入力信号に立ち上がりエッジが発生した場合を例に挙げて説明するが、入力信号に立ち下がりエッジが発生した場合にも同様の動作となる。 From the above, the operation contents of the timer unit 9 are summarized as shown in the flowchart of FIG. Here, a case where a rising edge occurs in the input signal to the terminal 17 will be described as an example, but the same operation is performed when a falling edge occurs in the input signal.
図2に示すように、例えば、入力信号に立ち上がりエッジが発生した時に、立ち上がりエッジキャプチャモードレジスタ23の値が“0”であれば(S101:NO)、立ち上がりエッジキャプチャイネーブルレジスタ25の値に拘わらず、立ち上がりエッジキャプチャレジスタ21がタイマ値を更新記憶し(S102)、その更新記憶が行われることに伴って、立ち上がりエッジキャプチャイネーブルレジスタ25に“1”がセットされる(S103)。
As shown in FIG. 2, for example, when the rising edge occurs in the input signal, if the value of the rising edge
また、入力信号に立ち上がりエッジが発生した時に、立ち上がりエッジキャプチャモードレジスタ23の値が“1”であれば(S101:YES)、立ち上がりエッジキャプチャイネーブルレジスタ25の値が“0”の場合にだけ(S104:YES)、立ち上がりエッジキャプチャレジスタ21がタイマ値を更新記憶し(S102)、その更新記憶が行われることに伴って、立ち上がりエッジキャプチャイネーブルレジスタ25に“1”がセットされる(S103)。
If the value of the rising edge
このため、入力信号に立ち上がりエッジが発生した時に、立ち上がりエッジキャプチャモードレジスタ23の値が“1”であり(S101:YES)、且つ、立ち上がりエッジキャプチャイネーブルレジスタ25の値が“1”であれば(S104:NO)、立ち上がりエッジキャプチャレジスタ21はタイマ値を更新記憶しない。
Therefore, when the rising edge occurs in the input signal, the value of the rising edge
一方、入力信号に立ち上がりエッジが発生した時に、割り込み要求有効エッジ設定レジスタ43によって、立ち上がりエッジが割り込み要求の有効エッジに設定されているならば(S150:YES)、割り込み要求信号生成部41が割り込みコントローラ13へ割り込み要求信号を出力する(S106)。逆に、立ち上がりエッジが割り込み要求の有効エッジに設定されていなければ(S105:NO)、割り込み要求信号生成部41は割り込み要求信号を出力しない。
On the other hand, when the rising edge is generated in the input signal, if the rising edge is set to the valid edge of the interrupt request by the interrupt request valid edge setting register 43 (S150: YES), the interrupt request
尚、端子17への入力信号に立ち下がりエッジが発生した場合のタイマユニット9の動作は、上記図2に関する説明において、「立ち上がりエッジ」を「立ち下がりエッジ」と読み替え、「レジスタ21」を「レジスタ31」と読み替え、「レジスタ23」を「レジスタ33」と読み替え、「レジスタ25」を「レジスタ35」と読み替えた動作になる。
Note that the operation of the timer unit 9 when a falling edge occurs in the input signal to the terminal 17 in the description related to FIG. 2 above is to read “rising edge” as “falling edge” and “register 21” as “ The operation is performed by replacing “register 31”, “register 23” with “
次に、以上のようなマイコン1の使用例について説明する。
本実施形態において、マイコン1の端子17には、立ち下がりエッジの発生周期が一定であるPWM信号が入力される。そして、マイコン1では、CPU3が、図3及び図4の処理を実行することにより、PWM信号のデューティ比を算出する。
Next, a usage example of the
In the present embodiment, a PWM signal having a constant falling edge generation cycle is input to the
尚、以下の説明において、「周期エッジ」とは、PWM信号のエッジのうち、該PWM信号の1周期毎に発生する方のエッジ(この例では、立ち下がりエッジ)のことであり、「非周期エッジ」とは、周期エッジとは反対方向のエッジ(この例では、立ち上がりエッジ)のことである。そして、本実施形態では、PWM信号における周期エッジ(立ち下がりエッジ)の発生間隔を、PWM信号の1周期時間(以下、単に「周期」という)として検出すると共に、周期エッジ(立ち下がりエッジ)が発生してから非周期エッジ(立ち上がりエッジ)が発生するまでの時間を、パルス幅時間(以下、単に「パルス幅」という)として検出し、その検出した周期に対するパルス幅の比を、PWM信号のデューティ比として算出する。 In the following description, “periodic edge” refers to an edge (a falling edge in this example) that occurs every one period of the PWM signal among the edges of the PWM signal. “Periodic edge” means an edge in the opposite direction to the periodic edge (in this example, a rising edge). In this embodiment, the occurrence interval of the periodic edge (falling edge) in the PWM signal is detected as one period time (hereinafter simply referred to as “period”) of the PWM signal, and the periodic edge (falling edge) is detected. The time from occurrence to the occurrence of a non-periodic edge (rising edge) is detected as the pulse width time (hereinafter simply referred to as “pulse width”), and the ratio of the pulse width to the detected period is determined as the PWM signal. Calculated as the duty ratio.
まず、図3は、マイコン1が起動した直後にCPU3が実行する初期化処理を表すフローチャートである。
図3に示すように、CPU3は、初期化処理の実行を開始すると、まずS110にて、割り込み要求有効エッジ設定レジスタ43に“0”を書き込むことにより、周期エッジである立ち下がりエッジを、割り込み要求の有効エッジに設定する。
First, FIG. 3 is a flowchart showing an initialization process executed by the
As shown in FIG. 3, when the
そして、次のS120にて、立ち上がりエッジキャプチャモードレジスタ23に“1”を書き込むことにより、立ち上がりエッジキャプチャ制御回路27の動作モードをワンショットモードに設定する。また、次のS130にて、立ち下がりエッジキャプチャモードレジスタ33に“0”を書き込むことにより、立ち下がりエッジキャプチャ制御回路37の動作モードをノーマルモードに設定する。つまり、本実施形態では、PWM信号の立ち上がりエッジについては、タイマユニット9での処理形態をワンショットモードに設定し、PWM信号の立ち下がりエッジについては、タイマユニット9での処理形態をノーマルモードに設定している。
Then, in the next S120, “1” is written to the rising edge
次に、S140にて、立ち上がりエッジキャプチャイネーブルレジスタ25に、初期値としての“0”を書き込み、続くS150にて、立ち下がりエッジキャプチャイネーブルレジスタ35にも、初期値としての“0”を書き込む。
Next, “0” as an initial value is written in the rising edge capture enable
そして、その後、当該初期化処理を終了する。
次に、図4は、CPU3が、割り込みコントローラ13からの外部割り込み要求信号(即ち、割り込み要求信号生成部41からの割り込み要求信号)を受けると実行する割り込み処理を表すフローチャートである。このため、図4の割り込み処理は、端子17へのPWM信号に立ち下がりエッジが発生する毎に実行される。
Then, the initialization process ends.
Next, FIG. 4 is a flowchart showing an interrupt process executed when the
図4に示すように、CPU3は、割り込み処理の実行を開始すると、まずS210にて、立ち下がりエッジキャプチャレジスタ31の値を読み込み、その読み込んだ値を、周期エッジ今回発生時刻としてRAM7に記憶する。尚、周期エッジ今回発生時刻とは、「周期エッジが今回発生した時刻」のことである。
As shown in FIG. 4, when the
次に、S215にて、今回の当該割り込み処理が初回の処理(詳しくは、当該マイコン1が起動してから最初に実行する処理)であるか否かを判定する。そして、今回の当該割り込み処理が初回の処理でなければ(即ち、2回目以降の処理であれば)、S220に進む。
Next, in S215, it is determined whether or not the current interrupt process is the first process (specifically, the process executed first after the
S220では、立ち上がりエッジキャプチャレジスタ21の値を読み込み、その読み込んだ値を、非周期エッジ発生時刻としてRAM7に記憶する。尚、非周期エッジ派生時刻とは、「非周期エッジが発生した時刻」のことである。
In S220, the value of the rising
そして、次のS230にて、上記S210でRAM7に記憶した周期エッジ今回発生時刻から、RAM7に記憶されている周期エッジ前回発生時刻を引くことにより、PWM信号の周期(詳しくは、PWM信号に周期エッジが前回発生してから今回発生するまでの時間)を算出する。尚、周期エッジ前回発生時刻は、「周期エッジが前回発生した時刻」のことであり、当該割り込み処理が前回実行された際に、S210で立ち下がりエッジキャプチャレジスタ31から読み込んで、後述のS270でRAM7に記憶しておいた値である。 In the next S230, the period of the PWM signal (specifically, the period of the PWM signal is determined by subtracting the period edge previous generation time stored in the RAM 7 from the current generation time of the periodic edge stored in the RAM 7 in S210). The time from the last occurrence of the edge to the current occurrence) is calculated. Note that the previous occurrence time of the periodic edge is the “time when the periodic edge occurred last time”, and when the interrupt processing was executed last time, it was read from the falling edge capture register 31 in S210, and in S270 described later. This is the value stored in the RAM 7.
そして、続くS240にて、上記S220でRAM7に記憶した非周期エッジ発生時刻から、周期エッジ前回発生時刻を引くことにより、PWM信号のパルス幅(詳しくは、PWM信号に周期エッジが前回発生してから非周期エッジが発生するまでの時間)を算出する。 In subsequent S240, by subtracting the previous periodic edge generation time from the non-periodic edge generation time stored in the RAM 7 in S220, the pulse width of the PWM signal (specifically, the periodic edge is generated in the PWM signal last time). To the time from when the non-periodic edge occurs).
尚、本実施形態では、エッジの発生時刻を示す時刻情報がタイマ値であるため、S230で算出される周期の値は、実際には、周期の時間をフリーランニングタイマ19の1カウント分の時間(即ち、内部クロックの1周期)で割った値となり、同様に、S240で算出されるパルス幅の値は、実際には、パルス幅の時間を上記1カウント分の時間で割った値となる。
In the present embodiment, since the time information indicating the occurrence time of the edge is a timer value, the period value calculated in S230 is actually the period time equal to one count of the
次に、S250にて、上記S230で算出した周期が正常範囲内であるか否かを判定する。尚、この正常範囲は、周期の値として正常と考えられる許容範囲に設定されている。
上記S250にて、周期が正常範囲内であると判定した場合には、S260に進み、S230で算出した周期と、S240で算出したパルス幅とから、PWM信号のデューティ比を算出する。具体的には、周期に対するパルス幅の比(=パルス幅/周期)を、デューティ比として算出する。
Next, in S250, it is determined whether or not the cycle calculated in S230 is within the normal range. This normal range is set to an allowable range that is considered normal as a cycle value.
If it is determined in S250 that the cycle is within the normal range, the process proceeds to S260, and the duty ratio of the PWM signal is calculated from the cycle calculated in S230 and the pulse width calculated in S240. Specifically, the ratio of the pulse width to the cycle (= pulse width / cycle) is calculated as the duty ratio.
そして、次のS270にて、周期エッジ今回発生時刻を、RAM7に、新たな周期エッジ前回発生時刻として更新記憶する。
そして更に、次のS280にて、立ち上がりエッジキャプチャイネーブルレジスタ35に“0”を書き込むことにより、立ち上がりエッジキャプチャレジスタ21がタイマ値を更新記憶するのを許可し、その後、当該割り込み処理を終了する。
In next S270, the periodic edge current occurrence time is updated and stored in the RAM 7 as a new periodic edge previous occurrence time.
Further, in the next S280, “0” is written to the rising edge capture enable
また、上記S250にて、周期が正常範囲内ではないと判定した場合には、S260とS270をスキップして、S280に進み、立ち上がりエッジキャプチャイネーブルレジスタ35に“0”を書き込んだ後、当該割り込み処理を終了する。
If it is determined in S250 that the cycle is not within the normal range, S260 and S270 are skipped, the process proceeds to S280, “0” is written in the rising edge capture enable
一方、上記S215にて、今回の当該割り込み処理が初回の処理であると判定した場合には、そのままS270に移行する。つまり、初回の割り込み処理では、周期とデューティ比を算出することができないため、次回の割り込み処理に備えるために、立ち下がりエッジキャプチャレジスタ31の値を周期エッジ前回発生時刻としてRAM7に記憶する処理(S210及びS270)と、立ち上がりエッジキャプチャイネーブルレジスタ35に“0”を書き込む処理(S280)だけを行う。
On the other hand, if it is determined in S215 that the current interrupt process is the first process, the process proceeds to S270. In other words, since the cycle and duty ratio cannot be calculated in the first interrupt processing, the value stored in the falling
次に、マイコン1の作用及び効果について、図5〜図9を用い説明する。
まず図5は、PWM信号にノイズが乗らない場合の動作を表すタイムチャートである。
図5に示すように、マイコン1では、PWM信号に立ち下がりエッジが発生する毎に、CPU3が図4の割り込み処理を実行する。
Next, the operation and effect of the
First, FIG. 5 is a time chart showing the operation when noise is not applied to the PWM signal.
As shown in FIG. 5, in the
そして、前述したように、PWM信号の立ち下がりエッジについては、タイマユニット9での処理形態をノーマルモードに設定している(図3のS130)。また、PWM信号の立ち上がりエッジについては、タイマユニット9での処理形態をワンショットモードに設定している(図3のS120)が、CPU3は、割り込み処理において、立ち上がりエッジキャプチャイネーブルレジスタ35に“0”を書き込むようになっている(図4のS280)。
As described above, the processing mode in the timer unit 9 is set to the normal mode for the falling edge of the PWM signal (S130 in FIG. 3). As for the rising edge of the PWM signal, the processing mode in the timer unit 9 is set to the one-shot mode (S120 in FIG. 3), but the
このため、図5に示すように、PWM信号に、時刻t1で立ち下がりエッジが発生し、時刻t2で立ち上がりエッジが発生し、時刻t3で立ち下がりエッジが発生したとすると、時刻t1では、その時刻t1でのタイマ値(C1)が立ち下がりエッジキャプチャレジスタ31に記憶され、時刻t2では、その時刻t2でのタイマ値(C2)が立ち上がりエッジキャプチャレジスタ21に記憶され、時刻t3では、その時刻t3でのタイマ値(C3)が立ち下がりエッジキャプチャレジスタ31に記憶される。
Therefore, as shown in FIG. 5, if a falling edge occurs in the PWM signal at time t1, a rising edge occurs at time t2, and a falling edge occurs at time t3, at time t1, the falling edge The timer value (C1) at time t1 is stored in the falling
そして、時刻t3の立ち下がりエッジに伴う割り込み処理では、時刻t1から時刻t3までの時間(詳しくは、時刻t1から時刻t3までのフリーランニングタイマのカウント数(=C3−C1))を周期Tとして算出する(S230)と共に、時刻t1から時刻t2までの時間(詳しくは、時刻t1から時刻t2までのフリーランニングタイマのカウント数(=C2−C1))をパルス幅Wとして算出し(S240)、更に、算出した周期Tに対するパルス幅Wの比(=W/T)を、デューティ比として算出する(S260)こととなる。 In the interrupt process associated with the falling edge at time t3, the period from time t1 to time t3 (specifically, the count number of the free running timer from time t1 to time t3 (= C3-C1)) is set as a period T. Along with the calculation (S230), the time from time t1 to time t2 (specifically, the count number of the free running timer from time t1 to time t2 (= C2-C1)) is calculated as the pulse width W (S240), Further, the ratio of the pulse width W to the calculated period T (= W / T) is calculated as the duty ratio (S260).
次に、図6は、PWM信号にノイズが乗った場合の動作を表す第1のタイムチャートであり、詳しくは、PWM信号に正規の立ち下がりエッジが発生してからCPU3が割り込み処理を開始するまでの処理開始遅れ期間中に、PWM信号にノイズによる不要な立ち上がりエッジが発生した場合の動作を表すタイムチャートである。尚、正規の立ち下がりエッジとは、発生間隔がPWM信号の周期として正常な立ち下がりエッジであり、換言すれば、発生間隔が図4のS250での判定に用いられる正常範囲に入っている立ち下がりエッジである。
Next, FIG. 6 is a first time chart showing the operation when noise is added to the PWM signal. Specifically, the
図6に示すように、図5と同じ時刻t3でPWM信号に正規の立ち下がりエッジが発生してから、CPU3が割り込み処理(時刻t3の立ち下がりエッジに伴う割り込み処理)を開始するまでの処理開始遅れ期間中の時刻t4にて、PWM信号にノイズによる不要な立ち上がりエッジが発生したとする。
As shown in FIG. 6, the process from when the regular falling edge occurs in the PWM signal at the same time t3 as in FIG. 5 until the
この場合、時刻t3よりも前の時刻t2にて、PWM信号に正規の立ち下がりエッジ後の最初の立ち上がりエッジが発生しており、その時刻t2で、立ち上がりエッジキャプチャレジスタ21がタイマ値(C2)を記憶したことにより、立ち上がりエッジキャプチャイネーブルレジスタ35の値が“1”になっている。そして、立ち上がりエッジキャプチャイネーブルレジスタ35の値が“1”になっている状態は、時刻t3の立ち下がりエッジに伴う割り込み処理(図6において、時刻t3より後の最初の割り込み処理)におけるS280が実行されるまで継続する。
In this case, the first rising edge after the normal falling edge occurs in the PWM signal at time t2 before time t3, and at the time t2, the rising edge capture register 21 sets the timer value (C2). Is stored, the value of the rising edge capture enable
このため、時刻t4でPWM信号に立ち上がりエッジが発生しても、立ち上がりエッジキャプチャレジスタ21の値は、更新されず、PWM信号に正規の立ち下がりエッジが前回発生してから最初に立ち上がりエッジが発生した時刻t2でのタイマ値(C2)のままになる。
For this reason, even if a rising edge occurs in the PWM signal at time t4, the value of the rising
よって、時刻t3の立ち下がりエッジに伴う割り込み処理において、S220では、立ち上がりエッジキャプチャレジスタ21から、時刻t4でのタイマ値ではなく、時刻t2でのタイマ値(C2)を取得することができ、その結果、S240で誤ったパルス幅を算出してしまうことを回避することができる。つまり、時刻t3の立ち下がりエッジに伴う割り込み処理では、図5の場合と同様に、立ち下がりエッジが前回発生してから最初に立ち上がりエッジが発生した時までの時間(時刻t1から時刻t2までのフリーランニングタイマのカウント数(=C2−C1))をパルス幅Wとして算出することができ、ノイズによるパルス幅の誤算出を回避することができる。そして、このため、デューティ比も正しく算出することができる。 Therefore, in the interrupt process associated with the falling edge at time t3, in S220, the timer value (C2) at time t2 can be acquired from the rising edge capture register 21 instead of the timer value at time t4. As a result, it is possible to avoid calculating an incorrect pulse width in S240. That is, in the interrupt processing associated with the falling edge at time t3, as in the case of FIG. 5, the time from the time when the falling edge was last generated until the time when the rising edge was first generated (from time t1 to time t2). The count number (= C2-C1) of the free running timer can be calculated as the pulse width W, and an erroneous calculation of the pulse width due to noise can be avoided. For this reason, the duty ratio can also be calculated correctly.
尚、図6の例では、時刻t4の後の時刻t5にて、PWM信号にノイズによる立ち下がりエッジが発生しているが、その時刻t5は、時刻t3の立ち下がりエッジに伴う割り込み処理において、立ち下がりエッジキャプチャレジスタ31の値を読み込む処理(S210)が行われた後である。このため、時刻t3の立ち下がりエッジに伴う割り込み処理において、S210では、立ち下がりエッジキャプチャレジスタ31から、時刻t3でのタイマ値(C3)を読み込むこととなる。また、図6では、時刻t1から時刻t3までの時間を「T1」と記載している。そして、図6の例において、時刻t3の立ち下がりエッジに伴う割り込み処理のS230では、その時間T1に相当するフリーランニングタイマのカウント数(=C3−C1)が、周期として算出され、その回の割り込み処理のS260では、「パルス幅W/時間T1」の値が、デューティ比として算出されることとなる。 In the example of FIG. 6, a falling edge due to noise occurs in the PWM signal at time t5 after time t4. At the time t5, in the interrupt processing accompanying the falling edge at time t3, This is after the process of reading the value of the falling edge capture register 31 (S210). For this reason, in the interrupt processing accompanying the falling edge at time t3, the timer value (C3) at time t3 is read from the falling edge capture register 31 in S210. In FIG. 6, the time from time t1 to time t3 is described as “T1”. In the example of FIG. 6, in S230 of the interrupt process associated with the falling edge at time t3, the count number (= C3-C1) of the free running timer corresponding to the time T1 is calculated as the cycle. In S260 of the interrupt process, the value of “pulse width W / time T1” is calculated as the duty ratio.
次に、図7は、PWM信号にノイズが乗った場合の動作を表す第2のタイムチャートであり、詳しくは、PWM信号に正規の立ち下がりエッジが発生してからCPU3が割り込み処理を開始するまでの処理開始遅れ期間中に、PWM信号にノイズによる不要な立ち上がりエッジと立ち下がりエッジとの両方が発生し、更に、前回の正規の立ち下がりエッジから不要な立ち下がりエッジまでの間隔(図7におけるT1)も、PWM信号の周期として正常と考えられる許容範囲内であった場合の動作を表すタイムチャートである。
Next, FIG. 7 is a second time chart showing the operation when noise is added to the PWM signal. Specifically, the
図7に示すように、図5と同じ時刻t3でPWM信号に正規の立ち下がりエッジが発生してから、CPU3が割り込み処理(時刻t3の立ち下がりエッジに伴う割り込み処理)を開始するまでの処理開始遅れ期間中の時刻t4にて、PWM信号にノイズによる不要な立ち上がりエッジが発生すると共に、その処理開始遅れ期間中の時刻t5にて、PWM信号にノイズによる不要な立ち下がりエッジが発生し、更に、正規の立ち下がりエッジが前回発生した時刻t1から時刻t5までの時間T1も、PWM信号の周期として正常と考えられる許容範囲内であったとする。
As shown in FIG. 7, the process from when a regular falling edge occurs in the PWM signal at the same time t3 as in FIG. 5 until the
この場合も、図6の場合と同様に、時刻t3よりも前の時刻t2にて、PWM信号に正規の立ち下がりエッジ後の最初の立ち上がりエッジが発生しており、その時刻t2で、立ち上がりエッジキャプチャレジスタ21がタイマ値(C2)を記憶したことにより、立ち上がりエッジキャプチャイネーブルレジスタ35の値が“1”になっている。そして、立ち上がりエッジキャプチャイネーブルレジスタ35の値が“1”になっている状態は、時刻t3の立ち下がりエッジに伴う割り込み処理(図7において、時刻t3より後の最初の割り込み処理)におけるS280が実行されるまで継続する。このため、時刻t4でPWM信号に立ち上がりエッジが発生しても、立ち上がりエッジキャプチャレジスタ21の値は、更新されず、PWM信号に正規の立ち下がりエッジが前回発生してから最初に立ち上がりエッジが発生した時刻t2でのタイマ値(C2)のままになる。
Also in this case, as in the case of FIG. 6, the first rising edge after the normal falling edge occurs in the PWM signal at time t2 before time t3, and at the time t2, the rising edge Since the capture register 21 stores the timer value (C2), the value of the rising edge capture enable
よって、時刻t3の立ち下がりエッジに伴う割り込み処理において、S220では、立ち上がりエッジキャプチャレジスタ21から、時刻t4でのタイマ値ではなく、時刻t2でのタイマ値(C2)を取得することができ、その結果、S240では、時刻t1から時刻t2までのフリーランニングタイマのカウント数(=C2−C1)をパルス幅Wとして算出することができる。このため、ノイズによるパルス幅の誤算出を回避することができる。 Therefore, in the interrupt process associated with the falling edge at time t3, in S220, the timer value (C2) at time t2 can be acquired from the rising edge capture register 21 instead of the timer value at time t4. As a result, in S240, the count number (= C2-C1) of the free running timer from time t1 to time t2 can be calculated as the pulse width W. For this reason, erroneous calculation of the pulse width due to noise can be avoided.
また、立ち下がりエッジについては、タイマユニット9での処理形態をノーマルモードに設定しているため、時刻t5で立ち下がりエッジが発生すると、立ち上がりエッジキャプチャレジスタ21の値が、時刻t3でのタイマ値(C3)から、時刻t5でのタイマ値(C5)に更新される。このため、時刻t3の立ち下がりエッジに伴う割り込み処理において、S210では、立ち下がりエッジキャプチャレジスタ31から、時刻t5でのタイマ値(C5)を取得することとなり、S230では、時刻t1から時刻t5までの時間T1に相当するフリーランニングタイマのカウント数(=C5−C1)を周期として算出することとなる。そして、この例では、時刻t3から時刻t5までの時間が微小であって、時刻t1から時刻t5までの時間T1もPWM信号の周期の許容範囲内であるため、時刻t3の立ち下がりエッジに伴う割り込み処理において、S250では、S230で算出した周期が正常範囲内であると判定することとなり、S260では、「パルス幅W/時間T1」の値であって、正しいと見なすことのできるデューティ比が算出されることとなる。
As for the falling edge, since the processing mode in the timer unit 9 is set to the normal mode, when the falling edge occurs at time t5, the value of the rising
尚、図7に関する上記説明では、時刻t3の立ち下がりエッジが正規の立ち下がりエッジで、時刻t5の立ち下がりエッジがノイズによる不要な立ち下がりエッジであると説明したが、それとは逆に、時刻t5の立ち下がりエッジが正規の立ち下がりエッジで、時刻t3の立ち下がりエッジがノイズによる不要な立ち下がりエッジであると見なしても、時刻t3の立ち下がりエッジに伴う割り込み処理による算出結果は実質的に同じになる。つまり、図7の例において、時刻t1から時刻t3までの時間と、時刻t1から時刻t5までの時間とが、両方共にPWM信号の周期として許容範囲内であれば、時刻t3と時刻t5のどちらの立ち下がりエッジが正規の立ち下がりエッジであっても処理結果は実質的に変わらない。 In the above description regarding FIG. 7, it has been described that the falling edge at time t3 is a regular falling edge, and the falling edge at time t5 is an unnecessary falling edge due to noise. Even if the falling edge at t5 is a regular falling edge and the falling edge at time t3 is an unnecessary falling edge due to noise, the calculation result by the interrupt processing associated with the falling edge at time t3 is practical. Will be the same. That is, in the example of FIG. 7, if both the time from time t1 to time t3 and the time from time t1 to time t5 are within the allowable range as the period of the PWM signal, either time t3 or time t5 Even if the falling edge is a regular falling edge, the processing result is not substantially changed.
次に、図8は、PWM信号にノイズが乗った場合の動作を表す第3のタイムチャートであり、詳しくは、PWM信号に正規の立ち下がりエッジが発生してから正規の立ち上がりエッジが発生するまでのパルス幅期間(本実施形態ではローレベル期間)中に、ノイズによって、立ち上がりエッジと立ち下がりエッジとがその順に発生した場合の動作を表すタイムチャートである。 Next, FIG. 8 is a third time chart showing the operation when noise is added to the PWM signal. Specifically, after the normal falling edge occurs in the PWM signal, the normal rising edge occurs. 6 is a time chart showing an operation when a rising edge and a falling edge occur in that order due to noise during a pulse width period up to (low level period in this embodiment).
図8に示すように、図5と同じ時刻t1から時刻t2までのパルス幅期間(ローレベル期間)において、CPU3が時刻t1の立ち下がりエッジに伴う割り込み処理(図8において、時刻t1より後の最初の割り込み処理)を行った後の時刻taで、PWM信号にノイズによる不要な立ち上がりエッジが発生すると共に、その直後の時刻tbで、PWM信号にノイズによる不要な立ち下がりエッジが発生したとする。
As shown in FIG. 8, in the same pulse width period (low level period) from time t1 to time t2 as in FIG. 5, the
この場合、時刻taの前に、立ち上がりエッジキャプチャイネーブルレジスタ25の値が“0”に戻されているため、時刻taでノイズによる立ち上がりエッジが発生すると、その時刻taでのタイマ値(Ca)が、立ち上がりエッジキャプチャレジスタ21に記憶される。そして、時刻tbでノイズによる立ち下がりエッジが発生すると、その時刻tbでのタイマ値(Cb)が、立ち下がりエッジキャプチャレジスタ31に記憶される。
In this case, since the value of the rising edge capture enable
しかし、時刻tbの立ち下がりエッジに伴う割り込み処理においては、両キャプチャレジスタ21,31から読み込んだ値が無効になり、誤ったデューティ比を算出してしまうことが防止される。その回の割り込み処理において、S250では、S230で算出した周期(即ち、図8において、時刻t1から時刻tbまでの時間T1に相当する値)が正常範囲内ではないと判定することとなり、S260とS270がスキップされるからである。 However, in the interrupt process associated with the falling edge at time tb, the values read from both capture registers 21 and 31 are invalidated, and it is possible to prevent an erroneous duty ratio from being calculated. In the interrupt processing of that time, in S250, it is determined that the cycle calculated in S230 (that is, a value corresponding to time T1 from time t1 to time tb in FIG. 8) is not within the normal range. This is because S270 is skipped.
また、時刻tbの立ち下がりエッジに伴う割り込み処理においても、S280により、立ち上がりエッジキャプチャイネーブルレジスタ25の値を“0”にするため、その後の時刻t2にて、PWM信号に正規の立ち上がりエッジが発生すると、その時刻t2でのタイマ値(C2)が立ち上がりエッジキャプチャレジスタ21に更新記憶される。
Also, in the interrupt processing associated with the falling edge at time tb, the value of the rising edge capture enable
そして、その後の時刻t3にて、PWM信号に正規の立ち下がりエッジが発生すると、その時刻t3でのタイマ値(C3)が立ち下がりエッジキャプチャレジスタ31に更新記憶される。
Then, when a regular falling edge occurs in the PWM signal at a subsequent time t3, the timer value (C3) at that time t3 is updated and stored in the falling
更に、時刻t3の立ち下がりエッジに伴う割り込み処理が開始される時点において、RAM7内の周期エッジ前回発生時刻は、ノイズによる立ち下がりエッジが発生した時刻tbでのタイマ値(Cb)ではなく、前回の正規の立ち下がりエッジが発生した時刻t1でのタイマ値(C1)になっている。時刻tbの立ち下がりエッジに伴う割り込み処理においては、デューティ比を算出するS260だけでなく、周期エッジ前回発生時刻を更新するS270もスキップされているからである。 Furthermore, at the time when the interrupt processing associated with the falling edge at time t3 is started, the previous generation time of the periodic edge in the RAM 7 is not the timer value (Cb) at the time tb at which the falling edge due to noise occurred, but the previous time. The timer value (C1) at the time t1 when the regular falling edge is generated. This is because, in the interrupt processing accompanying the falling edge at time tb, not only S260 for calculating the duty ratio but also S270 for updating the previous occurrence time of the periodic edge is skipped.
よって、時刻t3の立ち下がりエッジに伴う割り込み処理が実行されれば、その回の割り込み処理により、正しい周期(即ち、図8において、時刻t1から時刻tbまでの時間T1と、時刻tbから時刻t3までの時間T2とを加算した時間(=T1+T2)に相当する値)と、正しいパルス幅(即ち、図8において、時刻t1から時刻t2までの時間Wに相当する値)とが算出され、延いては、正しいデューティ比(図8における「W/(T1+T2」)が算出されることとなる。 Therefore, if the interrupt process associated with the falling edge at time t3 is executed, the interrupt process at that time causes the correct period (that is, time T1 from time t1 to time tb and time tb to time t3 in FIG. 8). And a correct pulse width (that is, a value corresponding to time W from time t1 to time t2 in FIG. 8) is calculated and extended. Therefore, the correct duty ratio (“W / (T1 + T2” in FIG. 8) is calculated.
次に、図9は、PWM信号にノイズが乗った場合の動作を表す第4のタイムチャートであり、詳しくは、PWM信号に正規の立ち上がりエッジが発生してから次の正規の立ち下がりエッジが発生するまでの反パルス幅期間(本実施形態ではハイレベル期間)中に、ノイズによって、立ち下がりエッジと立ち上がりエッジとがその順に発生した場合の動作を表すタイムチャートである。 Next, FIG. 9 is a fourth time chart showing the operation when noise is added to the PWM signal. Specifically, after the normal rising edge occurs in the PWM signal, the next normal falling edge is detected. 6 is a time chart showing an operation when a falling edge and a rising edge are generated in that order due to noise during an anti-pulse width period (high level period in the present embodiment) until they occur.
図9に示すように、図5と同じ時刻t2から時刻t3までの反パルス幅期間(ハイレベル期間)において、時刻tcでPWM信号にノイズによる不要な立ち下がりエッジが発生し、その時刻tcの立ち下がりエッジに伴う割り込み処理が開始されるよりも前の時刻tdで、PWM信号にノイズによる不要な立ち上がりエッジが発生したとする。 As shown in FIG. 9, in the same anti-pulse width period (high level period) from time t2 to time t3 as in FIG. 5, an unnecessary falling edge due to noise occurs in the PWM signal at time tc. It is assumed that an unnecessary rising edge due to noise occurs in the PWM signal at time td before the interrupt processing associated with the falling edge is started.
この場合、時刻tcでは、既に、立ち上がりエッジキャプチャレジスタ21には正規の立ち上がりエッジが発生した時刻t2でのタイマ値(C2)が記憶されていると共に、立ち上がりエッジキャプチャイネーブルレジスタ25の値が“1”になっている。
In this case, at the time tc, the rising edge capture register 21 already stores the timer value (C2) at the time t2 when the normal rising edge occurs, and the value of the rising edge capture enable
このため、時刻tcの立ち下がりエッジに伴う割り込み処理が開始される前の時刻tdでノイズによる立ち上がりエッジが発生しても、立ち上がりエッジキャプチャレジスタ21の値は更新されずにタイマ値(C2)のままである。
For this reason, even if a rising edge due to noise occurs at time td before the interrupt processing associated with the falling edge at time tc is started, the value of the rising
また、時刻tcでノイズによる立ち下がりエッジが発生すると、その時刻tcでのタイマ値(Cc)が、立ち下がりエッジキャプチャレジスタ31に更新記憶されるが、その時刻tcの立ち下がりエッジに伴う割り込み処理において、S250では、S230で算出した周期(即ち、図9において、時刻t1から時刻tcまでの時間T1に相当する値)が正常範囲内ではないと判定することとなり、S260とS270がスキップされる。よって、両キャプチャレジスタ21,31から読み込んだ値が無効になり、誤ったデューティ比を算出してしまうことが防止される。
When a falling edge due to noise occurs at time tc, the timer value (Cc) at that time tc is updated and stored in the falling
そして、その後の時刻t3にて、PWM信号に正規の立ち下がりエッジが発生すると、その時刻t3でのタイマ値(C3)が立ち下がりエッジキャプチャレジスタ31に更新記憶される。また、その時点において、立ち上がりエッジキャプチャレジスタ21の値は、時刻t2でのタイマ値(C2)のままになっている。
Then, when a regular falling edge occurs in the PWM signal at a subsequent time t3, the timer value (C3) at that time t3 is updated and stored in the falling
更に、時刻t3の立ち下がりエッジに伴う割り込み処理が開始される時点において、RAM7内の周期エッジ前回発生時刻は、ノイズによる立ち下がりエッジが発生した時刻tcでのタイマ値(Cc)ではなく、前回の正規の立ち下がりエッジが発生した時刻t1でのタイマ値(C1)になっている。前述したように、時刻tcの立ち下がりエッジに伴う割り込み処理においては、S270がスキップされているからである。 Furthermore, at the time when the interrupt processing associated with the falling edge at time t3 is started, the previous generation time of the periodic edge in the RAM 7 is not the timer value (Cc) at the time tc when the falling edge due to noise occurs, but the previous time. The timer value (C1) at the time t1 when the regular falling edge is generated. This is because S270 is skipped in the interrupt processing accompanying the falling edge at time tc as described above.
よって、時刻t3の立ち下がりエッジに伴う割り込み処理が実行されれば、その回の割り込み処理により、正しい周期(即ち、図9において、時刻t1から時刻tcまでの時間T1と、時刻tcから時刻t3までの時間T2とを加算した時間(=T1+T2)に相当する値)と、正しいパルス幅(即ち、図9において、時刻t1から時刻t2までの時間Wに相当する値)とが算出され、延いては、正しいデューティ比(図9における「W/(T1+T2」)が算出されることとなる。 Therefore, if the interrupt process associated with the falling edge at time t3 is executed, the interrupt process at that time causes the correct period (ie, time T1 from time t1 to time tc and time tc to time t3 in FIG. 9). And a correct pulse width (that is, a value corresponding to time W from time t1 to time t2 in FIG. 9) is calculated. In this case, the correct duty ratio (“W / (T1 + T2” in FIG. 9) is calculated.
一方、前述した図6の例において、時刻t5の立ち下がりエッジに伴う割り込み処理(図6において一番右側に示している割り込み処理)では、S210にて、立ち下がりエッジキャプチャレジスタ31から時刻t5でのタイマ値(C5)を読み込むこととなり、S230では、時刻t3から時刻t5までの時間T2に相当するフリーランニングタイマのカウント数(=C5−C3)を、周期として算出することとなるが、S250では、そのS230で算出した周期(時間T2に相当する値)が正常範囲内ではないと判定することとなり、S260とS270がスキップされる。 On the other hand, in the example of FIG. 6 described above, in the interrupt process associated with the falling edge at time t5 (interrupt process shown on the rightmost side in FIG. 6), in S210, from the falling edge capture register 31 at time t5. The timer value (C5) is read, and in S230, the count number (= C5-C3) of the free running timer corresponding to the time T2 from the time t3 to the time t5 is calculated as a cycle. Then, it is determined that the period (value corresponding to time T2) calculated in S230 is not within the normal range, and S260 and S270 are skipped.
つまり、図6の例において、時刻t5の立ち下がりエッジに伴う割り込み処理では、図8における時刻tbの立ち下がりエッジに伴う割り込み処理と同様の処理結果となる。よって、その後、PWM信号に正規の立ち上がりエッジが発生してから正規の立ち下がりエッジが発生すれば、その正規の立ち下がりエッジに伴う割り込み処理により、正しい周期、パルス幅及びデューティ比が算出されることとなる。 That is, in the example of FIG. 6, the interrupt process associated with the falling edge at time t5 has the same processing result as the interrupt process associated with the falling edge at time tb in FIG. Therefore, if a normal falling edge occurs after a normal rising edge occurs in the PWM signal, the correct period, pulse width, and duty ratio are calculated by an interrupt process associated with the normal falling edge. It will be.
また同様に、前述した図7の例においても、時刻t5の立ち下がりエッジに伴う割り込み処理(図7において一番右側に示している割り込み処理)では、S210にて、立ち下がりエッジキャプチャレジスタ31から時刻t5でのタイマ値(C5)を読み込むこととなる。そして、その回の割り込み処理において、S230で周期を算出する際には、周期エッジ前回発生時刻の値が、前回の割り込み処理(即ち、時刻t3の立ち下がりエッジに伴う割り込み処理)のS270により時刻t5でのタイマ値(C5)に設定されているため、0(=C5−C5)を周期として算出することとなり、S250では、そのS230で算出した周期(=0)が正常範囲内ではないと判定することとなる。よって、S260とS270がスキップされる。 Similarly, also in the example of FIG. 7 described above, in the interrupt process (interrupt process shown on the rightmost side in FIG. 7) associated with the falling edge at time t5, the falling edge capture register 31 starts from S210. The timer value (C5) at time t5 is read. In the interrupt processing of that time, when calculating the cycle in S230, the value of the previous occurrence time of the cycle edge is set to the time by S270 of the previous interrupt processing (that is, the interrupt processing associated with the falling edge at time t3). Since the timer value (C5) at t5 is set, 0 (= C5-C5) is calculated as a cycle. In S250, the cycle (= 0) calculated in S230 is not within the normal range. It will be judged. Therefore, S260 and S270 are skipped.
このため、図7の例において、時刻t5の立ち下がりエッジに伴う割り込み処理でも、図8における時刻tbの立ち下がりエッジに伴う割り込み処理と同様の処理結果となる。よって、その後、PWM信号に正規の立ち上がりエッジが発生してから正規の立ち下がりエッジが発生すれば、その正規の立ち下がりエッジに伴う割り込み処理により、正しい周期、パルス幅及びデューティ比が算出されることとなる。 For this reason, in the example of FIG. 7, the interrupt process associated with the falling edge at time t5 has the same processing result as the interrupt process associated with the falling edge at time tb in FIG. Therefore, if a normal falling edge occurs after a normal rising edge occurs in the PWM signal, the correct period, pulse width, and duty ratio are calculated by an interrupt process associated with the normal falling edge. It will be.
以上のようなマイコン1によれば、立ち上がりエッジキャプチャモードレジスタ23に“1”を書き込めば、入力信号の立ち上がりエッジについて、タイマユニット9での処理形態をワンショットモードに設定することができ、また、立ち下がりエッジキャプチャモードレジスタ33に“1”を書き込めば、入力信号の立ち下がりエッジについて、タイマユニット9での処理形態をワンショットモードに設定することができる。
According to the
そして、例えば、立ち上がりエッジについてワンショットモードに設定すれば、任意のモニタ開始時からCPU3が立ち上がりエッジキャプチャレジスタ21の値を読み込む処理を行う時までのモニタ期間において、入力信号に立ち上がりエッジが複数回発生したとしても、立ち上がりエッジが最初に発生した時の時刻情報としてのタイマ値をCPU3に取得させることができる。
For example, if the one-shot mode is set for the rising edge, the input signal has a plurality of rising edges in the monitoring period from the start of arbitrary monitoring to the time when the
そして更に、CPU3が図3の初期化処理と図4の割り込み処理を行うことで、PWM信号の周期、パルス幅及びデューティ比を算出することができると共に、PWM信号にノイズが乗った場合に誤った算出結果を出してしてしまうことを回避することができる。
Furthermore, the
尚、前述したマイコン1の使用例(PWM信号のデューティ比を算出するための使用例)では、図4の割り込み処理におけるS220で立ち上がりエッジキャプチャレジスタ21の値を読み込んだ時が、立ち上がりエッジについての前回のモニタ期間の終了時であり、次回のモニタ期間の開始時(モニタ開始時点)にも相当するが、モニタ開始時点については、厳密には、S280で立ち上がりエッジキャプチャイネーブルレジスタ25に“0”を書き込んだ時となる。
In the use example of the
一方、上記実施形態のマイコン1では、立ち上がりエッジキャプチャレジスタ21と、立ち下がりエッジキャプチャレジスタ31とが、時刻記憶レジスタの一例に相当している。
On the other hand, in the
そして、立ち上がりエッジを有効エッジとする立ち上がりエッジキャプチャレジスタ21については、動作モードがワンショットモードに設定された立ち上がりエッジキャプチャ制御回路27と、立ち上がりエッジキャプチャイネーブルレジスタ25とが、更新制御手段の一例に相当しており、CPU3が立ち上がりエッジキャプチャイネーブルレジスタ25に“0”を書き込む信号が、許可信号の一例に相当している。
For the rising edge capture register 21 having the rising edge as an effective edge, the rising edge
同様に、立ち下がりエッジを有効エッジとする立ち下がりエッジキャプチャレジスタ31については、動作モードがワンショットモードに設定された立ち下がりエッジキャプチャ制御回路37と、立ち下がりエッジキャプチャイネーブルレジスタ35とが、更新制御手段の一例に相当しており、CPU3が立ち下がりエッジキャプチャイネーブルレジスタ35に“0”を書き込む信号が、許可信号の一例に相当している。
Similarly, for the falling edge capture register 31 having the falling edge as an effective edge, the falling edge
また、マイコン1の使用例においては、PMW信号の立ち下がりエッジ(周期エッジ)が、基準エッジの一例に相当し、PMW信号の立ち上がりエッジ(非周期エッジ)が、非基準エッジの一例に相当し、立ち上がりエッジキャプチャレジスタ21が、第1の時刻記憶レジスタの一例に相当し、立ち下がりエッジキャプチャレジスタ31が、第2の時刻記憶レジスタの一例に相当し、割り込み要求信号生成部41が、割り込み発生手段の一例に相当し、RAM7が、メモリの一例に相当している。そして、図4のS220が、第1の処理の一例に相当し、図4のS210が、第2の処理の一例に相当し、図4のS230が、第3の処理の一例に相当し、周期エッジ前回発生時刻が、基準エッジ前回発生時刻情報の一例に相当し、図4のS240が、第4の処理の一例に相当し、図4のS270が、第5の処理の一例に相当し、図4のS280が、第6の処理の一例に相当し、図4のS260が、第7の処理の一例に相当し、図4のS250が、第8の処理の一例に相当している。
In the usage example of the
以上、本発明の一実施形態について説明したが、本発明はこうした実施形態に何等限定されるものではなく、本発明の要旨を逸脱しない範囲において、種々なる態様で実施し得ることは勿論である。 As mentioned above, although one Embodiment of this invention was described, this invention is not limited to such Embodiment at all, Of course, in the range which does not deviate from the summary of this invention, it can implement in a various aspect. .
例えば、変形例として、図3のS130では、立ち下がりエッジキャプチャモードレジスタ33に“1”を書き込むことにより、立ち下がりエッジについても、タイマユニット9での処理形態をワンショットモードに設定し(即ち、立ち下がりエッジキャプチャ制御回路37の動作モードをワンショットモードに設定し)、図4のS280では、立ち上がりエッジキャプチャイネーブルレジスタ35だけでなく、立ち下がりエッジキャプチャイネーブルレジスタ25にも“0”を書き込むように変形しても良い。そして、このように変形しても、図6〜図9を用いて説明した効果と同じ効果が得られる。
For example, as a modification, in S130 of FIG. 3, by writing “1” into the falling edge
また、立ち上がりエッジと立ち下がりエッジとの各々について、タイマユニット9での処理形態は、ワンショットモードに固定されていても良い。
また、CPU3に図4の割り込み処理を実行させてPWM信号のデューティ比を算出する使用例の場合、立ち上がりエッジについては、タイマユニット9での処理形態がワンショットモードに固定されており、立ち下がりエッジについては、タイマユニット9での処理形態がノーマルモードに固定されていても良い。
Further, for each of the rising edge and the falling edge, the processing mode in the timer unit 9 may be fixed to the one-shot mode.
In the example of use in which the
また逆に、PWM信号の周期エッジが立ち上がりエッジであるならば、立ち上がりエッジについては、タイマユニット9での処理形態がノーマルモードに固定されており、立ち下がりエッジについては、タイマユニット9での処理形態がワンショットモードに固定されていても良い。 Conversely, if the periodic edge of the PWM signal is a rising edge, the processing mode in the timer unit 9 is fixed to the normal mode for the rising edge, and the processing in the timer unit 9 is performed for the falling edge. The form may be fixed to the one-shot mode.
1…マイコン(マイクロコンピュータ)、3…CPU、5…ROM、7…RAM、9…タイマユニット、11…バス、13…割り込みコントローラ、15…エッジ検出ポート、17…端子、19…フリーランニングタイマ、21…立ち上がりエッジキャプチャレジスタ、23…立ち上がりエッジキャプチャモードレジスタ、25…立ち上がりエッジキャプチャイネーブルレジスタ、27…立ち上がりエッジキャプチャ制御回路、31…立ち下がりエッジキャプチャレジスタ、33…立ち下がりエッジキャプチャモードレジスタ、35…立ち下がりエッジキャプチャイネーブルレジスタ、37…立ち下がりエッジキャプチャ制御回路、41…割り込み要求信号生成部、43…割り込み要求有効エッジ設定レジスタ
DESCRIPTION OF
Claims (5)
前記時刻記憶レジスタが前記時刻情報を記憶すると、前記CPUから出力される許可信号を受けるまでは、前記時刻記憶レジスタが前記時刻情報を更新して記憶するのを禁止する更新制御手段を備えていること、
特徴とするマイクロコンピュータ。 When a valid edge that is an edge in a specific direction occurs in an input signal, the microcomputer has a time storage register that stores time information indicating the time at that time, and a CPU that executes a program,
When the time storage register stores the time information, update control means for prohibiting the time storage register from updating and storing the time information until receiving a permission signal output from the CPU is provided. about,
A featured microcomputer.
前記時刻記憶レジスタを、第1の時刻記憶レジスタとして備えると共に、
前記入力信号は、立ち上がりエッジと立ち下がりエッジとのうちの一方である基準エッジが複数回発生する信号であり、
前記第1の時刻記憶レジスタは、前記入力信号に、前記有効エッジとして、前記基準エッジとは反対方向の非基準エッジが発生すると、その時の時刻を示す時刻情報を記憶するようになっており、
更に当該マイクロコンピュータは、
前記入力信号に前記基準エッジが発生すると、その時の時刻を示す時刻情報を記憶する第2の時刻記憶レジスタと、
前記入力信号に前記基準エッジが発生すると、割り込み要求を発生する割り込み発生手段とを備え、
前記CPUは、前記割り込み要求が発生すると実行を開始する割り込み処理において、
前記第1の時刻記憶レジスタに記憶されている時刻情報を読み込む第1の処理と、
前記第2の時刻記憶レジスタに記憶されている時刻情報を読み込む第2の処理と、
前記第2の処理で読み込んだ時刻情報の値と、当該割り込み処理を前回実行した際に前記第2の処理で読み込んでメモリに記憶しておいた時刻情報である基準エッジ前回発生時刻情報の値との差分から、前記入力信号に前記基準エッジが前回発生してから今回発生するまでの時間である1周期時間を算出する第3の処理と、
前記第1の処理で読み込んだ時刻情報の値と、前記基準エッジ前回発生時刻情報の値との差分から、前記入力信号に前記基準エッジが前回発生してから前記非基準エッジが発生するまでの時間であるパルス幅時間を算出する第4の処理と、を行うと共に、
前記第3の処理と前記第4の処理よりも後に、前記第2の処理で読み込んだ時刻情報を前記メモリに新たな前記基準エッジ前回発生時刻情報として更新記憶する第5の処理を行い、
更に前記第1の処理よりも後に、前記更新制御手段に前記許可信号を与えて前記第1の時刻記憶レジスタが前記時刻情報を更新して記憶するのを許可する第6の処理を行うこと、
を特徴とするマイクロコンピュータ。 The microcomputer according to claim 1,
The time storage register is provided as a first time storage register,
The input signal is a signal in which a reference edge that is one of a rising edge and a falling edge is generated a plurality of times,
The first time storage register is configured to store time information indicating a time at that time when a non-reference edge in a direction opposite to the reference edge occurs as the effective edge in the input signal,
Furthermore, the microcomputer
When the reference edge occurs in the input signal, a second time storage register for storing time information indicating a time at that time;
An interrupt generating means for generating an interrupt request when the reference edge occurs in the input signal;
In the interrupt processing that starts execution when the interrupt request is generated,
A first process of reading time information stored in the first time storage register;
A second process of reading time information stored in the second time storage register;
The value of the time information read in the second process and the value of the reference edge previous occurrence time information which is the time information read in the second process and stored in the memory when the interrupt process was executed last time A third process for calculating one cycle time, which is a time from the occurrence of the reference edge in the input signal to the current occurrence, from the difference between
From the difference between the value of the time information read in the first process and the value of the reference edge previous occurrence time information, from the previous occurrence of the reference edge to the input signal until the non-reference edge occurs A fourth process for calculating a pulse width time, which is a time, and
After the third process and the fourth process, perform a fifth process of updating and storing the time information read in the second process as new reference edge previous occurrence time information in the memory,
Further, after the first process, performing a sixth process for giving the permission signal to the update control means and allowing the first time storage register to update and store the time information,
A microcomputer characterized by.
前記入力信号は、前記基準エッジの発生周期が一定のPWM信号であり、
前記CPUは、前記割り込み処理において、前記第3の処理で算出した前記1周期時間と前記第4の処理で算出した前記パルス幅時間とから前記PWM信号のデューティ比を算出する第7の処理を行うこと、
を特徴とするマイクロコンピュータ。 The microcomputer according to claim 2,
The input signal is a PWM signal having a constant generation period of the reference edge,
In the interrupt process, the CPU performs a seventh process of calculating a duty ratio of the PWM signal from the one cycle time calculated in the third process and the pulse width time calculated in the fourth process. What to do,
A microcomputer characterized by.
前記CPUは、前記割り込み処理において、前記第3の処理で算出した前記1周期時間が所定の正常範囲内であるか否かを判定する第8の処理を行うと共に、該第8の処理により前記1周期時間が前記正常範囲内ではないと判定した場合には、前記第7の処理をスキップすること、
を特徴とするマイクロコンピュータ。 The microcomputer according to claim 3,
In the interrupt process, the CPU performs an eighth process for determining whether or not the one cycle time calculated in the third process is within a predetermined normal range. If it is determined that one cycle time is not within the normal range, skipping the seventh process;
A microcomputer characterized by.
前記CPUは、前記割り込み処理において、前記第8の処理により前記1周期時間が前記正常範囲内ではないと判定した場合には、前記第5の処理もスキップすること、
を特徴とするマイクロコンピュータ。 The microcomputer according to claim 4,
When the CPU determines that the one cycle time is not within the normal range by the eighth process in the interrupt process, the CPU also skips the fifth process.
A microcomputer characterized by.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2011221121A JP5652367B2 (en) | 2011-10-05 | 2011-10-05 | Microcomputer |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2011221121A JP5652367B2 (en) | 2011-10-05 | 2011-10-05 | Microcomputer |
Publications (2)
Publication Number | Publication Date |
---|---|
JP2013080432A true JP2013080432A (en) | 2013-05-02 |
JP5652367B2 JP5652367B2 (en) | 2015-01-14 |
Family
ID=48526743
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2011221121A Active JP5652367B2 (en) | 2011-10-05 | 2011-10-05 | Microcomputer |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP5652367B2 (en) |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPS6424170A (en) * | 1987-07-15 | 1989-01-26 | Hitachi Ltd | Combustion control circuit of internal combustion engine |
EP0592165A2 (en) * | 1992-10-03 | 1994-04-13 | Motorola, Inc. | Pulse generation/sensing arrangement for use in a microprocessor system |
JP2005332097A (en) * | 2004-05-19 | 2005-12-02 | Oki Electric Ind Co Ltd | Microcomputer |
JP2009121397A (en) * | 2007-11-16 | 2009-06-04 | Mitsubishi Electric Corp | Rotor position sensing method and its device, and controller of internal-combustion engine |
-
2011
- 2011-10-05 JP JP2011221121A patent/JP5652367B2/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPS6424170A (en) * | 1987-07-15 | 1989-01-26 | Hitachi Ltd | Combustion control circuit of internal combustion engine |
EP0592165A2 (en) * | 1992-10-03 | 1994-04-13 | Motorola, Inc. | Pulse generation/sensing arrangement for use in a microprocessor system |
JP2005332097A (en) * | 2004-05-19 | 2005-12-02 | Oki Electric Ind Co Ltd | Microcomputer |
JP2009121397A (en) * | 2007-11-16 | 2009-06-04 | Mitsubishi Electric Corp | Rotor position sensing method and its device, and controller of internal-combustion engine |
Also Published As
Publication number | Publication date |
---|---|
JP5652367B2 (en) | 2015-01-14 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
JP5739290B2 (en) | Electronic control unit | |
JP2006338605A (en) | Program failure monitoring method and program failure monitoring device | |
JP5531679B2 (en) | Power consumption reduction method, power consumption reduction device, and power consumption reduction program for information processing apparatus having SMT compatible CPU | |
JP5962697B2 (en) | Electronic control unit | |
JP5652367B2 (en) | Microcomputer | |
JP6009518B2 (en) | Electronic control unit | |
JP7435182B2 (en) | electronic control unit | |
JP5982845B2 (en) | Trace control apparatus and trace control method | |
JP6172040B2 (en) | Electronic control unit | |
JP2016162330A (en) | Electronic controller | |
JP5157697B2 (en) | Electronic control unit | |
JP5987723B2 (en) | Slave for communication | |
JP5541201B2 (en) | Program execution status monitoring apparatus and execution status monitoring program | |
JP2009230425A (en) | Information processor | |
JP7413749B2 (en) | Monitoring equipment and electronic control equipment | |
JP2021004587A (en) | Electronic control unit and vehicle control system | |
JP6332091B2 (en) | Electronic control unit | |
JP6447442B2 (en) | Electronic control unit | |
JP2019080242A (en) | Data acquisition method and data acquisition device | |
JP2015121953A (en) | Microcomputer and electronic control device | |
JP6130735B2 (en) | Microcontroller and error detection method | |
JP5942904B2 (en) | Processing equipment | |
JP2009294823A (en) | Data processor and data processing method | |
JP2016184366A (en) | Timer correction device, timer correction method, and timer correction program | |
CN113030567A (en) | Frequency measurement method and device based on single chip microcomputer |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
A621 | Written request for application examination |
Free format text: JAPANESE INTERMEDIATE CODE: A621 Effective date: 20131118 |
|
A977 | Report on retrieval |
Free format text: JAPANESE INTERMEDIATE CODE: A971007 Effective date: 20140822 |
|
A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20140902 |
|
A521 | Request for written amendment filed |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20140929 |
|
TRDD | Decision of grant or rejection written | ||
A01 | Written decision to grant a patent or to grant a registration (utility model) |
Free format text: JAPANESE INTERMEDIATE CODE: A01 Effective date: 20141021 |
|
A61 | First payment of annual fees (during grant procedure) |
Free format text: JAPANESE INTERMEDIATE CODE: A61 Effective date: 20141103 |
|
R151 | Written notification of patent or utility model registration |
Ref document number: 5652367 Country of ref document: JP Free format text: JAPANESE INTERMEDIATE CODE: R151 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |