JP2013080432A - Microcomputer - Google Patents

Microcomputer Download PDF

Info

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
Application number
JP2011221121A
Other languages
Japanese (ja)
Other versions
JP5652367B2 (en
Inventor
Risa Ozawa
理沙 小澤
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.)
Denso Corp
Original Assignee
Denso Corp
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 Denso Corp filed Critical Denso Corp
Priority to JP2011221121A priority Critical patent/JP5652367B2/en
Publication of JP2013080432A publication Critical patent/JP2013080432A/en
Application granted granted Critical
Publication of JP5652367B2 publication Critical patent/JP5652367B2/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Microcomputers (AREA)

Abstract

PROBLEM TO BE SOLVED: To enable a CPU to acquire time information when a valid edge occurs first, even if valid edges occur multiple times during a monitoring period from start of prescribed monitoring to the time when the CPU performs read processing of a value of a time storage register, in a microcomputer including the time storage register which stores the time information when a valid edge of a specific direction occurs in an input signal.SOLUTION: In a microcomputer, when a value of a capture mode register is set to "1" by a CPU (S101:Y), the capture register updates and stores a value of a free running timer (S102), only if a value of a capture enable register is set to "0" (S104:Y) when an edge of a detection target occurs in an input signal, and the value of the capture enable register changes to "1" from "0" (S103) regardless of software processing, when the update and storage are performed. Also, the value of the capture enable register is rewritable to "0" by software processing of the CPU.

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.

特開平8−258694号公報JP-A-8-258694 特開昭57−49040号公報JP 57-49040 A

ところで、上記従来のマイコンにおいて、キャプチャレジスタの値は、そのキャプチャレジスタにとっての有効エッジが発生する毎に、自動的に(つまり、ソフトウェアに従い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 claim 1 includes a time storage register that stores time information indicating a time at that time, and a CPU that executes a program. In addition, update control means is provided.

そして、更新制御手段は、時刻記憶レジスタが時刻情報を記憶すると、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 claim 2 generates an interrupt request when a reference edge occurs in the input signal and a second time storage register for storing time information indicating the time at the time when the reference edge occurs in the input signal. Interrupt generating means.

そして、このマイコンにおいて、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 claim 3, in the interrupt process, the CPU determines “whether or not one cycle time calculated in the third process is within a predetermined normal range. When the eighth process is performed and it is determined by the eighth process that one cycle time is not within the normal range, the seventh process is skipped.

つまり、割り込み処理では、今回算出した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.

実施形態のマイコンの構成を表す構成図である。It is a block diagram showing the structure of the microcomputer of embodiment. タイマユニットの動作を説明するフローチャートである。It is a flowchart explaining operation | movement of a timer unit. 初期化処理を表すフローチャートである。It is a flowchart showing an initialization process. 割り込み処理を表すフローチャートである。It is a flowchart showing an interruption process. PWM信号にノイズが乗らない場合の動作を表すタイムチャートである。It is a time chart showing operation when noise does not ride on a PWM signal. PWM信号にノイズが乗った場合の動作を表す第1のタイムチャートである。It is the 1st time chart showing operation when noise gets on a PWM signal. PWM信号にノイズが乗った場合の動作を表す第2のタイムチャートである。It is the 2nd time chart showing operation when noise gets on a PWM signal. PWM信号にノイズが乗った場合の動作を表す第3のタイムチャートである。It is a 3rd time chart showing operation | movement when a noise gets on a PWM signal. PWM信号にノイズが乗った場合の動作を表す第4のタイムチャートである。It is a 4th time chart showing operation when noise gets on a PWM signal. 従来のマイコンの使用例を説明する説明図である。It is explanatory drawing explaining the usage example of the conventional microcomputer. 従来技術の問題を説明する説明図である。It is explanatory drawing explaining the problem of a prior art.

以下に、本発明が適用された実施形態のマイコンについて説明する。
図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 microcomputer 1 of the present embodiment includes a CPU 3 that executes a program, a ROM 5 that stores a program to be executed, a RAM 7 that stores a part of the program, a calculation result by the CPU 3, and the like. A timer unit 9 having a function of storing time information when an edge occurs in an input signal to the microcomputer 1, a bus 11 for connecting them, and an interrupt controller (INTC) 13 for outputting an interrupt request signal to the CPU 3 And an edge detection port 15.

エッジ検出ポート15は、当該マイコン1の特定の端子17に入力される入力信号に立ち上がりエッジ(ローからハイへのレベル変化エッジ)が発生すると、立ち上がりエッジ検出信号を出力し、上記入力信号に立ち下がりエッジ(ハイからローへのレベル変化エッジ)が発生すると、立ち下がりエッジ検出信号を出力する。尚、立ち上がりエッジ検出信号と立ち下がりエッジ検出信号の各々は、例えば、当該マイコン1における内部クロックの所定周期分(例えば半周期分や1周期分)のパルス幅を有したパルス信号である。   The edge detection port 15 outputs a rising edge detection signal when a rising edge (level change edge from low to high) occurs in the input signal input to the specific terminal 17 of the microcomputer 1, and the rising edge is detected by the input signal. When a falling edge (level change edge from high to low) occurs, a falling edge detection signal is output. Each of the rising edge detection signal and the falling edge detection signal is, for example, a pulse signal having a pulse width corresponding to a predetermined period (for example, half period or one period) of the internal clock in the microcomputer 1.

また、タイマユニット9は、当該マイコン1における内部クロックによってカウントアップされるフリーランニングタイマ19と、立ち上がりエッジキャプチャレジスタ21と、立ち上がりエッジキャプチャモードレジスタ23と、立ち上がりエッジキャプチャイネーブルレジスタ25と、立ち上がりエッジキャプチャ制御回路27と、立ち下がりエッジキャプチャレジスタ31と、立ち下がりエッジキャプチャモードレジスタ33と、立ち下がりエッジキャプチャイネーブルレジスタ35と、立ち下がりエッジキャプチャ制御回路37と、割り込み要求信号生成部41と、割り込み要求有効エッジ設定レジスタ43とを備えている。   The timer unit 9 includes a free running timer 19 that is counted up by an internal clock in the microcomputer 1, a rising edge capture register 21, a rising edge capture mode register 23, a rising edge capture enable register 25, and a rising edge capture. Control circuit 27, falling edge capture register 31, falling edge capture mode register 33, falling edge capture enable register 35, falling edge capture control circuit 37, interrupt request signal generator 41, interrupt request And an effective edge setting register 43.

そして、エッジ検出ポート15から出力される立ち上がりエッジ検出信号が、立ち上がりエッジキャプチャ制御回路27と割り込み要求信号生成部41とに入力され、また、エッジ検出ポート15から出力される立ち下がりエッジ検出信号が、立ち下がりエッジキャプチャ制御回路37と割り込み要求信号生成部41とに入力されるようになっている。   The rising edge detection signal output from the edge detection port 15 is input to the rising edge capture control circuit 27 and the interrupt request signal generation unit 41, and the falling edge detection signal output from the edge detection port 15 is The falling edge capture control circuit 37 and the interrupt request signal generator 41 are inputted.

立ち上がりエッジキャプチャレジスタ21は、フリーランニングタイマ19と同じビット数のレジスタであり、上記立ち上がりエッジ検出信号が立ち上がりエッジキャプチャ制御回路27を介して入力されると、その時のフリーランニングタイマ19のカウント値(以下、タイマ値という)をラッチする(記憶する)。そして、立ち上がりエッジキャプチャレジスタ21は、CPU3からのリードアクセスが可能である。   The rising edge capture register 21 is a register having the same number of bits as the free running timer 19. When the rising edge detection signal is input via the rising edge capture control circuit 27, the count value of the free running timer 19 at that time ( The timer value is latched (stored). The rising edge capture register 21 can be read from the CPU 3.

立ち上がりエッジキャプチャモードレジスタ23は、立ち上がりエッジキャプチャ制御回路27の動作モードを設定するための1ビットのレジスタであり、CPU3によって“1”か“0”が書き込まれる。   The rising edge capture mode register 23 is a 1-bit register for setting the operation mode of the rising edge capture control circuit 27, and “1” or “0” is written by the CPU 3.

立ち上がりエッジキャプチャイネーブルレジスタ25は、立ち上がりエッジキャプチャレジスタ21がタイマ値をラッチする毎(即ち、更新記憶する毎)に“1”がセットされる1ビットのレジスタである。そして、この立ち上がりエッジキャプチャイネーブルレジスタ25の値は、CPU3によって“0”に書き換えることができるようになっている。   The rising edge capture enable register 25 is a 1-bit register that is set to “1” every time the rising edge capture register 21 latches a timer value (that is, every time it is updated and stored). The value of the rising edge capture enable register 25 can be rewritten to “0” by the CPU 3.

立ち上がりエッジキャプチャ制御回路27は、立ち上がりエッジキャプチャモードレジスタ23の値が“0”である場合には、動作モードがノーマルモードとなり、立ち上がりエッジキャプチャモードレジスタ23の値が“1”である場合には、動作モードがワンショットモードとなる。尚、この対応関係とは逆に、立ち上がりエッジキャプチャモードレジスタ23の値は、“0”がワンショットモードに対応し、“1”がノーマルモードに対応するようになっていても良い。また、このことは、後述する立ち下がりエッジキャプチャモードレジスタ33の値についても同様である。   When the value of the rising edge capture mode register 23 is “0”, the rising edge capture control circuit 27 is in the normal mode, and when the value of the rising edge capture mode register 23 is “1”. The operation mode becomes the one-shot mode. Contrary to this correspondence, the value of the rising edge capture mode register 23 may be such that “0” corresponds to the one-shot mode and “1” corresponds to the normal mode. This also applies to the value of the falling edge capture mode register 33 described later.

そして、立ち上がりエッジキャプチャ制御回路27は、ノーマルモードの場合には、エッジ検出ポート15からの立ち上がりエッジ検出信号を、立ち上がりエッジキャプチャレジスタ21に、そのまま出力する。   In the normal mode, the rising edge capture control circuit 27 outputs the rising edge detection signal from the edge detection port 15 to the rising edge capture register 21 as it is.

よって、立ち上がりエッジキャプチャ制御回路27の動作モードがノーマルモードに設定された場合には、立ち上がりエッジについてのタイマユニット9での処理形態がノーマルモードとなり、そのノーマルモードでは、端子17への入力信号に立ち上がりエッジが発生する毎に、立ち上がりエッジキャプチャレジスタ21がタイマ値を更新記憶することとなる。   Therefore, when the operation mode of the rising edge capture control circuit 27 is set to the normal mode, the processing mode in the timer unit 9 for the rising edge is the normal mode. In the normal mode, the input signal to the terminal 17 is Each time a rising edge occurs, the rising edge capture register 21 updates and stores the timer value.

また、立ち上がりエッジキャプチャ制御回路27は、ワンショットモードの場合には、立ち上がりエッジキャプチャイネーブルレジスタ25の値が“0”ならば、エッジ検出ポート15からの立ち上がりエッジ検出信号を立ち上がりエッジキャプチャレジスタ21に出力するが、立ち上がりエッジキャプチャイネーブルレジスタ25の値が“1”ならば、立ち上がりエッジ検出信号を立ち上がりエッジキャプチャレジスタ21に出力しなくなる。このため、立ち上がりエッジキャプチャレジスタ21は、立ち上がりエッジキャプチャイネーブルレジスタ25の値が“0”の場合にだけ、タイマ値を更新記憶することとなる。   In the one-shot mode, the rising edge capture control circuit 27 sends the rising edge detection signal from the edge detection port 15 to the rising edge capture register 21 if the value of the rising edge capture enable register 25 is “0”. However, if the value of the rising edge capture enable register 25 is “1”, the rising edge detection signal is not output to the rising edge capture register 21. Therefore, the rising edge capture register 21 updates and stores the timer value only when the value of the rising edge capture enable register 25 is “0”.

よって、立ち上がりエッジキャプチャ制御回路27の動作モードがワンショットモードに設定された場合には、立ち上がりエッジについてのタイマユニット9での処理形態がワンショットモードとなり、そのワンショットモードでは、CPU3によって立ち上がりエッジキャプチャイネーブルレジスタ25の値が“0”に設定されてから、端子17への入力信号に立ち上がりエッジが最初に発生すると、立ち上がりエッジキャプチャレジスタ21がタイマ値を更新記憶するが、その更新記憶時点からCPU3によって立ち上がりエッジキャプチャイネーブルレジスタ25の値が“1”から“0”に書き換えられるまでの間は、入力信号に立ち上がりエッジが発生しても、立ち上がりエッジキャプチャレジスタ21がタイマ値を更新記憶することが、禁止されることとなる。   Therefore, when the operation mode of the rising edge capture control circuit 27 is set to the one-shot mode, the processing mode in the timer unit 9 for the rising edge is set to the one-shot mode. When the rising edge first occurs in the input signal to the terminal 17 after the value of the capture enable register 25 is set to “0”, the rising edge capture register 21 updates and stores the timer value. Until the value of the rising edge capture enable register 25 is rewritten from “1” to “0” by the CPU 3, even if a rising edge occurs in the input signal, the rising edge capture register 21 updates and stores the timer value. But, so that is prohibited.

また、立ち下がりエッジキャプチャレジスタ31、立ち下がりエッジキャプチャモードレジスタ33、立ち下がりエッジキャプチャイネーブルレジスタ35及び立ち下がりエッジキャプチャ制御回路37の各々も、上記立ち上がりエッジキャプチャレジスタ21、立ち上がりエッジキャプチャモードレジスタ23、立ち上がりエッジキャプチャイネーブルレジスタ25及び立ち上がりエッジキャプチャ制御回路27の各々と同様のものである。   In addition, the falling edge capture register 31, the falling edge capture mode register 33, the falling edge capture enable register 35, and the falling edge capture control circuit 37 are respectively the rising edge capture register 21, the rising edge capture mode register 23, This is the same as each of the rising edge capture enable register 25 and the rising edge capture control circuit 27.

即ち、立ち下がりエッジキャプチャレジスタ31も、フリーランニングタイマ19と同じビット数のレジスタであり、上記立ち下がりエッジ検出信号が立ち下がりエッジキャプチャ制御回路37を介して入力されると、その時のタイマ値をラッチする(記憶する)。そして、立ち下がりエッジキャプチャレジスタ31も、CPU3からのリードアクセスが可能である。   That is, the falling edge capture register 31 is also a register having the same number of bits as the free-running timer 19, and when the falling edge detection signal is input via the falling edge capture control circuit 37, the timer value at that time is set. Latch (store). The falling edge capture register 31 can also be read-accessed from the CPU 3.

立ち下がりエッジキャプチャモードレジスタ33は、立ち下がりエッジキャプチャ制御回路37の動作モードを設定するための1ビットのレジスタであり、CPU3によって“1”か“0”が書き込まれる。   The falling edge capture mode register 33 is a 1-bit register for setting the operation mode of the falling edge capture control circuit 37, and “1” or “0” is written by the CPU 3.

立ち下がりエッジキャプチャイネーブルレジスタ35は、立ち下がりエッジキャプチャレジスタ31がタイマ値をラッチする毎(即ち、更新記憶する毎)に“1”がセットされる1ビットのレジスタである。そして、この立ち下がりエッジキャプチャイネーブルレジスタ35の値は、CPU3によって“0”に書き換えることができるようになっている。   The falling edge capture enable register 35 is a 1-bit register that is set to “1” every time the falling edge capture register 31 latches the timer value (that is, every time it is updated and stored). The value of the falling edge capture enable register 35 can be rewritten to “0” by the CPU 3.

立ち下がりエッジキャプチャ制御回路37は、立ち下がりエッジキャプチャモードレジスタ33の値が“0”である場合には、動作モードがノーマルモードとなり、立ち下がりエッジキャプチャモードレジスタ33の値が“1”である場合には、動作モードがワンショットモードとなる。   When the value of the falling edge capture mode register 33 is “0”, the falling edge capture control circuit 37 is in the normal mode and the value of the falling edge capture mode register 33 is “1”. In this case, the operation mode is the one-shot mode.

そして、立ち下がりエッジキャプチャ制御回路37は、ノーマルモードの場合には、エッジ検出ポート15からの立ち下がりエッジ検出信号を、立ち下がりエッジキャプチャレジスタ31に、そのまま出力する。   In the normal mode, the falling edge capture control circuit 37 outputs the falling edge detection signal from the edge detection port 15 to the falling edge capture register 31 as it is.

よって、立ち下がりエッジキャプチャ制御回路37の動作モードがノーマルモードに設定された場合には、立ち下がりエッジについてのタイマユニット9での処理形態がノーマルモードとなり、そのノーマルモードでは、端子17への入力信号に立ち下がりエッジが発生する毎に、立ち下がりエッジキャプチャレジスタ31がタイマ値を更新記憶することとなる。   Therefore, when the operation mode of the falling edge capture control circuit 37 is set to the normal mode, the processing mode in the timer unit 9 for the falling edge is the normal mode. In the normal mode, the input to the terminal 17 is performed. Each time a falling edge occurs in the signal, the falling edge capture register 31 updates and stores the timer value.

また、立ち下がりエッジキャプチャ制御回路37は、ワンショットモードの場合には、立ち下がりエッジキャプチャイネーブルレジスタ35の値が“0”ならば、エッジ検出ポート15からの立ち下がりエッジ検出信号を立ち下がりエッジキャプチャレジスタ31に出力するが、立ち下がりエッジキャプチャイネーブルレジスタ35の値が“1”ならば、立ち下がりエッジ検出信号を立ち下がりエッジキャプチャレジスタ31に出力しなくなる。   In the one-shot mode, the falling edge capture control circuit 37 outputs a falling edge detection signal from the edge detection port 15 as a falling edge if the value of the falling edge capture enable register 35 is “0”. Although it is output to the capture register 31, if the value of the falling edge capture enable register 35 is “1”, the falling edge detection signal is not output to the falling edge capture register 31.

よって、立ち下がりエッジキャプチャ制御回路37の動作モードがワンショットモードに設定された場合には、立ち下がりエッジについてのタイマユニット9での処理形態がワンショットモードとなり、そのワンショットモードでは、CPU3によって立ち下がりエッジキャプチャイネーブルレジスタ35の値が“0”に設定されてから、端子17への入力信号に立ち下がりエッジが最初に発生すると、立ち下がりエッジキャプチャレジスタ31がタイマ値を更新記憶するが、その更新記憶時点からCPU3によって立ち下がりエッジキャプチャイネーブルレジスタ35の値が“1”から“0”に書き換えられるまでの間は、入力信号に立ち下がりエッジが発生しても、立ち下がりエッジキャプチャレジスタ31がタイマ値を更新記憶することが、禁止されることとなる。   Therefore, when the operation mode of the falling edge capture control circuit 37 is set to the one-shot mode, the processing mode in the timer unit 9 for the falling edge is the one-shot mode. When the falling edge is first generated in the input signal to the terminal 17 after the value of the falling edge capture enable register 35 is set to “0”, the falling edge capture register 31 updates and stores the timer value. Even if a falling edge occurs in the input signal from the update storage time until the value of the falling edge capture enable register 35 is rewritten from “1” to “0” by the CPU 3, the falling edge capture register 31. Stores the timer value updated. But, so that is prohibited.

一方、タイマユニット9において、割り込み要求有効エッジ設定レジスタ43は、CPU3によってライトアクセスが可能な1ビットのレジスタである。
そして、割り込み要求信号生成部41は、エッジ検出ポート15からの立ち上がりエッジ検出信号と立ち下がりエッジ検出信号とのうち、割り込み要求有効エッジ設定レジスタ43の値によって指示される方の信号が入力されると、割り込みコントローラ13へ割り込み要求信号を出力する。
On the other hand, in the timer unit 9, the interrupt request valid edge setting register 43 is a 1-bit register that can be write-accessed by the CPU 3.
Then, the interrupt request signal generation unit 41 receives the signal indicated by the value of the interrupt request valid edge setting register 43 among the rising edge detection signal and the falling edge detection signal from the edge detection port 15. Then, an interrupt request signal is output to the interrupt controller 13.

本実施形態では、例えば、割り込み要求信号生成部41は、割り込み要求有効エッジ設定レジスタ43の値が“1”の場合には、立ち上がりエッジ検出信号が入力されると割り込み要求信号を出力し、逆に、割り込み要求有効エッジ設定レジスタ43の値が“0”の場合には、立ち下がりエッジ検出信号が入力されると割り込み要求信号を出力する。   In this embodiment, for example, when the value of the interrupt request valid edge setting register 43 is “1”, the interrupt request signal generation unit 41 outputs an interrupt request signal when a rising edge detection signal is input, and reversely In addition, when the value of the interrupt request valid edge setting register 43 is “0”, an interrupt request signal is output when a falling edge detection signal is input.

そして、割り込み要求信号生成部41から出力される割り込み要求信号は、割り込みコントローラ13からCPU3へ、外部割り込みに対応する割り込み要求信号(即ち、外部割り込み要求信号)として出力される。すると、CPU3は、その外部割り込み要求信号に対応する割り込み処理(即ち、外部割り込み処理)を実行することとなる。   The interrupt request signal output from the interrupt request signal generation unit 41 is output from the interrupt controller 13 to the CPU 3 as an interrupt request signal corresponding to an external interrupt (that is, an external interrupt request signal). Then, the CPU 3 executes an interrupt process (that is, an external interrupt process) corresponding to the external interrupt request signal.

つまり、割り込み要求有効エッジ設定レジスタ43は、割り込み要求の有効エッジ(詳しくは、割り込み要求を発生させることとなる入力信号のエッジ)を任意に設定するためのレジスタであり、そのレジスタ43の値を“1”にすれば、立ち上がりエッジが割り込み要求の有効エッジとなり、そのレジスタ43の値を“0”にすれば、立ち下がりエッジが割り込み要求の有効エッジとなる。   That is, the interrupt request valid edge setting register 43 is a register for arbitrarily setting the valid edge of the interrupt request (specifically, the edge of the input signal that generates the interrupt request). If it is set to “1”, the rising edge becomes the effective edge of the interrupt request, and if the value of the register 43 is set to “0”, the falling edge becomes the effective edge of the interrupt request.

尚、割り込み要求有効エッジ設定レジスタ43を複数ビットのレジスタにして、割り込み要求信号生成部41が、立ち上がりエッジ検出信号と立ち下がりエッジ検出信号との何れが入力されても割り込み要求信号を出力するモードと、立ち上がりエッジ検出信号が入力された時にだけ割り込み要求信号を出力するモードと、立ち下がりエッジ検出信号が入力された時にだけ割り込み要求信号を出力するモードと、立ち上がりエッジ検出信号と立ち下がりエッジ検出信号との何れが入力されても割り込み要求信号を出力しないモードとの、4つのモードに切り替わるように構成しても良い。   A mode in which the interrupt request valid edge setting register 43 is a multi-bit register and the interrupt request signal generation unit 41 outputs an interrupt request signal regardless of which of the rising edge detection signal and the falling edge detection signal is input. A mode that outputs an interrupt request signal only when a rising edge detection signal is input, a mode that outputs an interrupt request signal only when a falling edge detection signal is input, and a rising edge detection signal and a falling edge detection It may be configured to switch to four modes, a mode in which no interrupt request signal is output regardless of which signal is input.

以上のことから、タイマユニット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 capture mode register 23 is “0” (S101: NO), the value is related to the value of the rising edge capture enable register 25. First, the rising edge capture register 21 updates and stores the timer value (S102), and "1" is set in the rising edge capture enable register 25 as the update storage is performed (S103).

また、入力信号に立ち上がりエッジが発生した時に、立ち上がりエッジキャプチャモードレジスタ23の値が“1”であれば(S101:YES)、立ち上がりエッジキャプチャイネーブルレジスタ25の値が“0”の場合にだけ(S104:YES)、立ち上がりエッジキャプチャレジスタ21がタイマ値を更新記憶し(S102)、その更新記憶が行われることに伴って、立ち上がりエッジキャプチャイネーブルレジスタ25に“1”がセットされる(S103)。   If the value of the rising edge capture mode register 23 is “1” when the rising edge occurs in the input signal (S101: YES), only when the value of the rising edge capture enable register 25 is “0” (S101: YES) (S104: YES), the rising edge capture register 21 updates and stores the timer value (S102), and "1" is set in the rising edge capture enable register 25 as the update storage is performed (S103).

このため、入力信号に立ち上がりエッジが発生した時に、立ち上がりエッジキャプチャモードレジスタ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 capture mode register 23 is “1” (S101: YES), and the value of the rising edge capture enable register 25 is “1”. (S104: NO), the rising edge capture register 21 does not update and store the timer value.

一方、入力信号に立ち上がりエッジが発生した時に、割り込み要求有効エッジ設定レジスタ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 signal generation unit 41 interrupts. An interrupt request signal is output to the controller 13 (S106). On the contrary, if the rising edge is not set to the valid edge of the interrupt request (S105: NO), the interrupt request signal generation unit 41 does not output the interrupt request signal.

尚、端子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 “register 33”, and “register 25” with “register 35”.

次に、以上のようなマイコン1の使用例について説明する。
本実施形態において、マイコン1の端子17には、立ち下がりエッジの発生周期が一定であるPWM信号が入力される。そして、マイコン1では、CPU3が、図3及び図4の処理を実行することにより、PWM信号のデューティ比を算出する。
Next, a usage example of the microcomputer 1 as described above will be described.
In the present embodiment, a PWM signal having a constant falling edge generation cycle is input to the terminal 17 of the microcomputer 1. In the microcomputer 1, the CPU 3 calculates the duty ratio of the PWM signal by executing the processing of FIGS. 3 and 4.

尚、以下の説明において、「周期エッジ」とは、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 CPU 3 immediately after the microcomputer 1 is activated.
As shown in FIG. 3, when the CPU 3 starts to execute the initialization process, first, in S110, “0” is written in the interrupt request valid edge setting register 43, so that the falling edge, which is a periodic edge, is interrupted. Set to valid edge of request.

そして、次のS120にて、立ち上がりエッジキャプチャモードレジスタ23に“1”を書き込むことにより、立ち上がりエッジキャプチャ制御回路27の動作モードをワンショットモードに設定する。また、次のS130にて、立ち下がりエッジキャプチャモードレジスタ33に“0”を書き込むことにより、立ち下がりエッジキャプチャ制御回路37の動作モードをノーマルモードに設定する。つまり、本実施形態では、PWM信号の立ち上がりエッジについては、タイマユニット9での処理形態をワンショットモードに設定し、PWM信号の立ち下がりエッジについては、タイマユニット9での処理形態をノーマルモードに設定している。   Then, in the next S120, “1” is written to the rising edge capture mode register 23 to set the operation mode of the rising edge capture control circuit 27 to the one-shot mode. In the next S 130, “0” is written to the falling edge capture mode register 33 to set the operation mode of the falling edge capture control circuit 37 to the normal mode. That is, in the present embodiment, the processing form in the timer unit 9 is set to the one-shot mode for the rising edge of the PWM signal, and the processing form in the timer unit 9 is set to the normal mode for the falling edge of the PWM signal. It is set.

次に、S140にて、立ち上がりエッジキャプチャイネーブルレジスタ25に、初期値としての“0”を書き込み、続くS150にて、立ち下がりエッジキャプチャイネーブルレジスタ35にも、初期値としての“0”を書き込む。   Next, “0” as an initial value is written in the rising edge capture enable register 25 in S140, and “0” as an initial value is also written in the falling edge capture enable register 35 in S150.

そして、その後、当該初期化処理を終了する。
次に、図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 CPU 3 receives an external interrupt request signal from the interrupt controller 13 (that is, an interrupt request signal from the interrupt request signal generation unit 41). Therefore, the interrupt process in FIG. 4 is executed every time a falling edge occurs in the PWM signal to the terminal 17.

図4に示すように、CPU3は、割り込み処理の実行を開始すると、まずS210にて、立ち下がりエッジキャプチャレジスタ31の値を読み込み、その読み込んだ値を、周期エッジ今回発生時刻としてRAM7に記憶する。尚、周期エッジ今回発生時刻とは、「周期エッジが今回発生した時刻」のことである。   As shown in FIG. 4, when the CPU 3 starts executing the interrupt process, first, in S210, the value of the falling edge capture register 31 is read, and the read value is stored in the RAM 7 as the periodic edge current occurrence time. . Note that the current occurrence time of the periodic edge is the “time when the periodic edge occurs this time”.

次に、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 microcomputer 1 is activated). If the current interrupt process is not the first process (that is, if it is the second or subsequent process), the process proceeds to S220.

S220では、立ち上がりエッジキャプチャレジスタ21の値を読み込み、その読み込んだ値を、非周期エッジ発生時刻としてRAM7に記憶する。尚、非周期エッジ派生時刻とは、「非周期エッジが発生した時刻」のことである。   In S220, the value of the rising edge capture register 21 is read, and the read value is stored in the RAM 7 as the aperiodic edge occurrence time. The non-periodic edge derivation time is “the time when the non-periodic edge occurs”.

そして、次の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 free running timer 19. Similarly, the value of the pulse width calculated in S240 is actually a value obtained by dividing the time of the pulse width by the time of one count. .

次に、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 register 35 to allow the rising edge capture register 21 to update and store the timer value, and then the interrupt processing is ended.

また、上記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 register 35, and the interrupt is performed. The process ends.

一方、上記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 edge capture register 31 is stored in the RAM 7 as the previous cycle edge occurrence time in preparation for the next interrupt processing ( Only S210 and S270) and a process of writing “0” in the rising edge capture enable register 35 (S280) are performed.

次に、マイコン1の作用及び効果について、図5〜図9を用い説明する。
まず図5は、PWM信号にノイズが乗らない場合の動作を表すタイムチャートである。
図5に示すように、マイコン1では、PWM信号に立ち下がりエッジが発生する毎に、CPU3が図4の割り込み処理を実行する。
Next, the operation and effect of the microcomputer 1 will be described with reference to FIGS.
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 microcomputer 1, the CPU 3 executes the interrupt process of FIG. 4 every time a falling edge occurs in the PWM signal.

そして、前述したように、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 CPU 3 stores “0” in the rising edge capture enable register 35 in the interrupt processing. "Is written (S280 in FIG. 4).

このため、図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 edge capture register 31, and at time t2, the timer value (C2) at time t2 is stored in the rising edge capture register 21, and at time t3, the time The timer value (C3) at t3 is stored in the falling edge capture register 31.

そして、時刻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 CPU 3 starts interrupt processing after a normal falling edge occurs in the PWM signal. 6 is a time chart showing an operation when an unnecessary rising edge due to noise occurs in the PWM signal during the processing start delay period until. The regular falling edge is a normal falling edge whose generation interval is normal as the period of the PWM signal. In other words, the normal falling edge is within the normal range used for the determination in S250 of FIG. It is a falling edge.

図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 CPU 3 starts the interrupt process (interrupt process associated with the falling edge at time t3). It is assumed that an unnecessary rising edge due to noise occurs in the PWM signal at time t4 during the start delay period.

この場合、時刻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 register 35 is “1”. When the value of the rising edge capture enable register 35 is “1”, S280 in the interrupt processing (first interrupt processing after time t3 in FIG. 6) associated with the falling edge at time t3 is executed. Continue until

このため、時刻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 edge capture register 21 is not updated, and the first rising edge occurs after the last normal falling edge occurs in the PWM signal. The timer value (C2) at the time t2 remains unchanged.

よって、時刻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 CPU 3 starts interrupt processing after a normal falling edge occurs in the PWM signal. During the processing start delay period until the time point, both unnecessary rising edge and falling edge due to noise occur in the PWM signal, and further, the interval from the last regular falling edge to the unnecessary falling edge (FIG. 7). T1) in FIG. 6 is also a time chart showing the operation when the PWM signal cycle is within an allowable range considered normal.

図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 CPU 3 starts an interrupt process (interrupt process associated with the falling edge at time t3). At time t4 during the start delay period, an unnecessary rising edge due to noise occurs in the PWM signal, and at time t5 during the processing start delay period, an unnecessary falling edge due to noise occurs at the PWM signal, Furthermore, it is assumed that the time T1 from the time t1 to the time t5 at which the regular falling edge was previously generated is also within an allowable range that is considered normal as the period of the PWM signal.

この場合も、図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 register 35 is “1”. When the value of the rising edge capture enable register 35 is “1”, S280 in the interrupt processing (first interrupt processing after time t3 in FIG. 7) associated with the falling edge at time t3 is executed. Continue until For this reason, even if a rising edge occurs in the PWM signal at time t4, the value of the rising edge capture register 21 is not updated, and the first rising edge occurs after the last normal falling edge occurs in the PWM signal. The timer value (C2) at the time t2 remains unchanged.

よって、時刻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 edge capture register 21 becomes the timer value at time t3. The timer value (C5) at time t5 is updated from (C3). Therefore, in the interrupt processing associated with the falling edge at time t3, the timer value (C5) at time t5 is acquired from the falling edge capture register 31 at S210, and from time t1 to time t5 at S230. The count number (= C5-C1) of the free running timer corresponding to the time T1 is calculated as a cycle. In this example, the time from the time t3 to the time t5 is very small, and the time T1 from the time t1 to the time t5 is also within the allowable range of the period of the PWM signal. In the interrupt processing, in S250, it is determined that the cycle calculated in S230 is within the normal range. In S260, the value of “pulse width W / time T1”, which is a duty ratio that can be regarded as correct, is determined. Will be calculated.

尚、図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 CPU 3 performs interrupt processing accompanying the falling edge of time t1 (in FIG. 8, after time t1). It is assumed that an unnecessary rising edge due to noise occurs in the PWM signal at time ta after the first interrupt processing), and an unnecessary falling edge due to noise occurs in the PWM signal immediately after time tb. .

この場合、時刻taの前に、立ち上がりエッジキャプチャイネーブルレジスタ25の値が“0”に戻されているため、時刻taでノイズによる立ち上がりエッジが発生すると、その時刻taでのタイマ値(Ca)が、立ち上がりエッジキャプチャレジスタ21に記憶される。そして、時刻tbでノイズによる立ち下がりエッジが発生すると、その時刻tbでのタイマ値(Cb)が、立ち下がりエッジキャプチャレジスタ31に記憶される。   In this case, since the value of the rising edge capture enable register 25 is returned to “0” before the time ta, when a rising edge due to noise occurs at the time ta, the timer value (Ca) at the time ta is set. And stored in the rising edge capture register 21. When a falling edge due to noise occurs at time tb, the timer value (Cb) at that time tb is stored in the falling edge capture register 31.

しかし、時刻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 register 25 is set to “0” in S280, so that a normal rising edge is generated in the PWM signal at time t2. Then, the timer value (C2) at the time t2 is updated and stored in the rising edge capture register 21.

そして、その後の時刻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 edge capture register 31.

更に、時刻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 register 25 is “1”. "It has become.

このため、時刻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 edge capture register 21 is not updated and the timer value (C2) It remains.

また、時刻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 edge capture register 31, but interrupt processing associated with the falling edge at time tc is performed. In S250, it is determined that the cycle calculated in S230 (that is, a value corresponding to time T1 from time t1 to time tc in FIG. 9) is not within the normal range, and S260 and S270 are skipped. . Therefore, it is possible to prevent the values read from both capture registers 21 and 31 from being invalid and calculating an incorrect duty ratio.

そして、その後の時刻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 edge capture register 31. At that time, the value of the rising edge capture register 21 remains the timer value (C2) at time t2.

更に、時刻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 microcomputer 1 as described above, if “1” is written in the rising edge capture mode register 23, the processing mode in the timer unit 9 can be set to the one-shot mode for the rising edge of the input signal. If “1” is written in the falling edge capture mode register 33, the processing mode in the timer unit 9 can be set to the one-shot mode for the falling edge of the input signal.

そして、例えば、立ち上がりエッジについてワンショットモードに設定すれば、任意のモニタ開始時から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 CPU 3 performs the process of reading the value of the rising edge capture register 21. Even if it occurs, the CPU 3 can acquire the timer value as time information when the rising edge first occurs.

そして更に、CPU3が図3の初期化処理と図4の割り込み処理を行うことで、PWM信号の周期、パルス幅及びデューティ比を算出することができると共に、PWM信号にノイズが乗った場合に誤った算出結果を出してしてしまうことを回避することができる。   Furthermore, the CPU 3 can calculate the period, pulse width, and duty ratio of the PWM signal by performing the initialization process of FIG. 3 and the interrupt process of FIG. It is possible to avoid giving the calculated result.

尚、前述したマイコン1の使用例(PWM信号のデューティ比を算出するための使用例)では、図4の割り込み処理におけるS220で立ち上がりエッジキャプチャレジスタ21の値を読み込んだ時が、立ち上がりエッジについての前回のモニタ期間の終了時であり、次回のモニタ期間の開始時(モニタ開始時点)にも相当するが、モニタ開始時点については、厳密には、S280で立ち上がりエッジキャプチャイネーブルレジスタ25に“0”を書き込んだ時となる。   In the use example of the microcomputer 1 described above (use example for calculating the duty ratio of the PWM signal), when the value of the rising edge capture register 21 is read in S220 in the interrupt processing of FIG. At the end of the previous monitoring period, which corresponds to the start of the next monitoring period (monitoring start time), strictly speaking, the monitoring start time is set to “0” in the rising edge capture enable register 25 in S280. Will be written.

一方、上記実施形態のマイコン1では、立ち上がりエッジキャプチャレジスタ21と、立ち下がりエッジキャプチャレジスタ31とが、時刻記憶レジスタの一例に相当している。   On the other hand, in the microcomputer 1 of the above embodiment, the rising edge capture register 21 and the falling edge capture register 31 correspond to an example of a time storage register.

そして、立ち上がりエッジを有効エッジとする立ち上がりエッジキャプチャレジスタ21については、動作モードがワンショットモードに設定された立ち上がりエッジキャプチャ制御回路27と、立ち上がりエッジキャプチャイネーブルレジスタ25とが、更新制御手段の一例に相当しており、CPU3が立ち上がりエッジキャプチャイネーブルレジスタ25に“0”を書き込む信号が、許可信号の一例に相当している。   For the rising edge capture register 21 having the rising edge as an effective edge, the rising edge capture control circuit 27 in which the operation mode is set to the one-shot mode and the rising edge capture enable register 25 are examples of the update control means. A signal in which the CPU 3 writes “0” in the rising edge capture enable register 25 corresponds to an example of a permission signal.

同様に、立ち下がりエッジを有効エッジとする立ち下がりエッジキャプチャレジスタ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 capture control circuit 37 in which the operation mode is set to the one-shot mode and the falling edge capture enable register 35 are updated. A signal corresponding to an example of a control means, and a signal that the CPU 3 writes “0” in the falling edge capture enable register 35 corresponds to an example of a permission signal.

また、マイコン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 microcomputer 1, the falling edge (periodic edge) of the PMW signal corresponds to an example of a reference edge, and the rising edge (non-periodic edge) of the PMW signal corresponds to an example of a non-reference edge. The rising edge capture register 21 corresponds to an example of a first time storage register, the falling edge capture register 31 corresponds to an example of a second time storage register, and the interrupt request signal generation unit 41 generates an interrupt. The RAM 7 corresponds to an example of a means, and the RAM 7 corresponds to an example of a memory. 4 corresponds to an example of the first process, S210 of FIG. 4 corresponds to an example of the second process, S230 of FIG. 4 corresponds to an example of the third process, The previous occurrence time of the periodic edge corresponds to an example of reference edge previous occurrence time information, S240 of FIG. 4 corresponds to an example of the fourth process, and S270 of FIG. 4 corresponds to an example of the fifth process. 4 corresponds to an example of the sixth process, S260 of FIG. 4 corresponds to an example of the seventh process, and S250 of FIG. 4 corresponds to an example of the eighth process. .

以上、本発明の一実施形態について説明したが、本発明はこうした実施形態に何等限定されるものではなく、本発明の要旨を逸脱しない範囲において、種々なる態様で実施し得ることは勿論である。   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 capture mode register 33, the processing mode in the timer unit 9 is also set to the one-shot mode for the falling edge (that is, The operation mode of the falling edge capture control circuit 37 is set to the one-shot mode). In S280 of FIG. 4, “0” is written not only to the rising edge capture enable register 35 but also to the falling edge capture enable register 25. You may deform | transform. And even if it deform | transforms in this way, the same effect as the effect demonstrated using FIGS. 6-9 is acquired.

また、立ち上がりエッジと立ち下がりエッジとの各々について、タイマユニット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 CPU 3 executes the interrupt process of FIG. 4 and calculates the duty ratio of the PWM signal, the processing mode in the timer unit 9 is fixed to the one-shot mode for the rising edge, and the falling edge For the edge, the processing mode in the timer unit 9 may be fixed to the normal mode.

また逆に、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 SYMBOLS 1 ... Microcomputer (microcomputer), 3 ... CPU, 5 ... ROM, 7 ... RAM, 9 ... Timer unit, 11 ... Bus, 13 ... Interrupt controller, 15 ... Edge detection port, 17 ... Terminal, 19 ... Free running timer, 21 ... Rising edge capture register, 23 ... Rising edge capture mode register, 25 ... Rising edge capture enable register, 27 ... Rising edge capture control circuit, 31 ... Falling edge capture register, 33 ... Falling edge capture mode register, 35 ... Falling edge capture enable register 37: Falling edge capture control circuit 41: Interrupt request signal generator 43: Interrupt request valid edge setting register

Claims (5)

入力信号に特定方向のエッジである有効エッジが発生すると、その時の時刻を示す時刻情報を記憶する時刻記憶レジスタと、プログラムを実行するCPUと、を有したマイクロコンピュータであって、
前記時刻記憶レジスタが前記時刻情報を記憶すると、前記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の時刻記憶レジスタとして備えると共に、
前記入力信号は、立ち上がりエッジと立ち下がりエッジとのうちの一方である基準エッジが複数回発生する信号であり、
前記第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.
請求項2に記載のマイクロコンピュータにおいて、
前記入力信号は、前記基準エッジの発生周期が一定の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.
請求項3に記載のマイクロコンピュータにおいて、
前記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.
請求項4に記載のマイクロコンピュータにおいて、
前記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.
JP2011221121A 2011-10-05 2011-10-05 Microcomputer Active JP5652367B2 (en)

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)

* Cited by examiner, † Cited by third party
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

Patent Citations (4)

* Cited by examiner, † Cited by third party
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
JP7435182B2 (en) electronic control unit
JP5982845B2 (en) Trace control apparatus and trace control method
KR20120003088A (en) Apparatus and method for thread progress tracking using deterministic progress index
JP6009518B2 (en) Electronic control unit
JP6172040B2 (en) Electronic control unit
JP5157697B2 (en) Electronic control unit
JP5541201B2 (en) Program execution status monitoring apparatus and execution status monitoring program
JP2016162330A (en) Electronic controller
JP7413749B2 (en) Monitoring equipment and electronic control equipment
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
JP6477032B2 (en) Processor and control method thereof
JP6332091B2 (en) Electronic control unit
JP2009294823A (en) Data processor and data processing method
CN113030567A (en) Frequency measurement method and device based on single chip microcomputer
KR20130060984A (en) Method for managing stack of memory
JP5362856B2 (en) Error generation instruction circuit, storage device, information processing apparatus, and error generation instruction circuit control method

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