JP2004171040A - Timer circuit - Google Patents

Timer circuit Download PDF

Info

Publication number
JP2004171040A
JP2004171040A JP2002332483A JP2002332483A JP2004171040A JP 2004171040 A JP2004171040 A JP 2004171040A JP 2002332483 A JP2002332483 A JP 2002332483A JP 2002332483 A JP2002332483 A JP 2002332483A JP 2004171040 A JP2004171040 A JP 2004171040A
Authority
JP
Japan
Prior art keywords
value
compare
register
timer
compare register
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.)
Withdrawn
Application number
JP2002332483A
Other languages
Japanese (ja)
Inventor
Motoo Akasaka
元雄 赤坂
Yasuhiro Takada
泰寛 高田
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.)
Renesas Micro Systems Co Ltd
Original Assignee
Renesas Micro Systems Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Renesas Micro Systems Co Ltd filed Critical Renesas Micro Systems Co Ltd
Priority to JP2002332483A priority Critical patent/JP2004171040A/en
Publication of JP2004171040A publication Critical patent/JP2004171040A/en
Withdrawn legal-status Critical Current

Links

Images

Landscapes

  • Microcomputers (AREA)

Abstract

<P>PROBLEM TO BE SOLVED: To provide a timer circuit which operates as an interval timer for setting a plurality of pieces of interval time and does not cause a software bug. <P>SOLUTION: In the timer circuit in which the interval timer is realized by a general purpose timer counter and a comparison register, a width register to which a value indicating an interval time is set and an adder which adds the value of the timer counter and the value of the width register are additionally provided. When the value of the timer counter agrees with the value of the comparison register, the added value of the adder is furnished to the comparison register to be set as a new comparison register value. By this, the value of the comparison register is set without software processing. <P>COPYRIGHT: (C)2004,JPO

Description

【0001】
【発明の属する技術分野】
本発明は、マイクロコンピュータ等に内蔵されているタイマ回路に関し、特に一定間隔で割り込みを入れるインターバルタイマを実現するタイマ回路に関する。
【0002】
【従来の技術】
ひとつのタイマカウンタと複数のコンペアレジスタを搭載している汎用タイマにて、インターバルタイマを実現する場合、一般的に、コンペアレジスタ及び汎用タイマカウンタはバスを介して中央処理装置(CPU)と接続されており、ソフトウェア処理によってこれらをインターバルタイマとして動作させている。(例えば、特許文献1参照。)特許文献1では、タイマカウンタのカウント値とコンペアレジスタのコンペア値が一致し一致信号が出力されると、CPUは一致信号に応じてタイマ回路の割り込みルーチンを起動する。このタイマ回路の割り込みルーチンにおいて、コンペアレジスタに設定されていた値にインターバル時間を加算したものを新たなコンペアレジスタの値として設定し、割り込みルーチンを終了するものが開示されている。このようにソフトウェアで処理することによりインターバルタイマとして動作することになる。
【0003】
ところが、汎用タイマカウンタのカウント値とコンペア値が一致したときに、他の優先順位の高い処理が行なわれており、一致信号が出力されたときに割り込みルーチンが起動できない場合が考えられる。このような状態を図5を参照して説明する。
【0004】
このインターバルタイマにおいて、コンペアレジスタに値Aがコンペア値として設定されているとする。また、このインターバルタイマによって、タイマカウンタのカウント値の間隔Aごとに割り込み信号が発生されるものとする。また、タイマカウンタは、複数のインターバル時間の割り込みを入れるタイマ回路として動作させるために、間隔Aよりも大きい値までカウントできるもので構成されている。
【0005】
まず、タイマカウンタがカウントアップし、カウンタ値がコンペア値Aと等しくなる(ア)の時点にて、当該インターバルタイマからの割り込み信号が発生する。CPUはこの割り込み信号に応答してタイマ回路の割り込みルーチンを起動する。ところが、(ア)の時点で、CPUが他の優先順位の高い処理を実行している場合には、この割り込みルーチンを起動することができない。かくして、(ア)の時点で生じた割り込み信号に対する割り込みルーチンは該優先順位の高い処理の終了後に行なれることとなる。すなわち、該優先順位の高い処理が(イ)にて終了したとすると、その後、(ア)の時点で生じた割り込み信号に対するタイマ回路の割り込みルーチンが行なわれ、それまで設定されていたコンペア値に間隔Aを加算した値をコンペア値として更新する処理が行なわれるのである。しかし、この時点でタイマカウンタの値が更新されたコンペア値(2A)を上回っていた場合、インターバルタイマによって入れられる割り込み信号は、タイマカウンタがオーバーフローし再びカウンタ値がコンペア値と等しい値2Aを示すまで発生しないこととなってしまう。これにより、インターバルタイマによる割り込みの間隔が大きくずれることとなり、結果、ソフトバグが引き起こされる可能性がある。
【0006】
このような状態を回避するために、割り込みルーチンが起動された時点のタイマカウンタ値を読み出し、読み出されたタイマカウンタ値に対してインターバル時間を加算し、この加算値を新たなコンペアレジスタ値として更新することが考えられる。しかし、このために読出、加算、更新の最低3命令を処理することになり、ソフトウェアの処理時間が長くなってしまう。その結果、ソフトウェアでの処理能力が低下するという問題点が生じる。また、CPUでの処理速度に比べタイマカウンタのカウントアップ動作が速い場合には、カウント値を読み出すタイミングが遅くなりインターバルの間隔がずれてしまうという問題が生じる。
【0007】
特許文献1には、タイマカウンタの値とコンペアレジスタに設定されたインターバル時間の値とを比較し一致すると、一致検出回路から一致信号が出力され、この一致信号によりタイマカウンタがクリアされる技術が開示されている。これにより、タイマカウンタの値がコンペアレジスタに設定されたインターバル時間の値だけ歩進するたびにクリアされるため、CPUの割り込みルーチンが不要となり、ソフトウェアの実行時間の短縮を図ることができる。しかしながら、インターバル時間を複数設定するインターバルタイマとして利用することはできない。
【0008】
【特許文献1】
特開平11−95864号公報
【0009】
【発明が解決しようとする課題】
以上のように、インターバルタイマをソフトウェア処理で実現すると、インターバルタイマのための割り込みルーチンよりも優先度の高い処理が行なわれていた場合に、インターバルタイマによる割り込みの間隔が大きくずれることによるソフトバグを引き起こすという課題が存在する。
【0010】
また、割り込みルーチンにおいて、割り込みルーチンが起動された時点でタイマカウンタ値を読み出し、読み出されたタイマカウンタ値に割り込み間隔を加算し、加算した値をコンペアレジスタに更新するという処理を行なうことにすると、割り込みルーチンでの処理時間が長くなり、そのためにソフトウェアでの処理時間が長くなり、インターバルタイマを設けたことによりソフトウェア処理能力が低下するという課題が存在する。また、ソフトウェアでの処理時間が長くなることによって、インターバル時間にばらつきが生じるという課題が存在する。
【0011】
本発明の目的は、複数のインターバル時間を設定することができるインターバルタイマとして動作するタイマ回路において、ソフトバグを引き起こさないタイマ回路を提供することにある。また、ソフトウェア処理能力を低下させないタイマ回路を提供することにある。また、インターバル時間のばらつきが少ないインターバルタイマを実現するタイマ回路を提供することにある。
【0012】
【課題を解決するための手段】
本発明によるタイマ回路は、クロック信号に応じてカウントするタイマカウンタと、コンペアレジスタと、タイマカウンタの値とコンペアレジスタに設定された値とを比較し一致したときに一致信号を出力する比較器と、インターバル時間を示す値が設定される幅レジスタと、タイマカウンタの値と幅レジスタの値とを加算する加算器と、一致信号に応じて加算器から出力される加算値をコンペアレジスタに設定することを特徴とする。
【0013】
すなわち、本発明によるデータ処理装置は、CPUと、CPUとバスを介して接続されたタイマ回路とを備え、タイマ回路は、クロック信号に応じてカウントするタイマカウンタと、コンペアレジスタと、タイマカウンタの値とコンペアレジスタに設定された値とを比較し一致したときに一致信号を出力する比較器と、インターバル時間を示す値が設定される幅レジスタと、タイマカウンタの値と幅レジスタの値とを加算する加算器とを有し、一致信号に応答してCPUが処理を行なっているか否かにかかわらず加算器の出力をコンペアレジスタに設定することを特徴とする。
【0014】
以上のように、本発明によれば、タイマカウンタ値とインターバル時間とが加算された値が一致信号に応じてCPUが処理を行なっているか否かにかかわらずコンペアレジスタに供給される。すなわち、コンペアレジスタの値は一致信号に応答して自動的に設定することができる。よって、コンペアレジスタの値はソフトウェア処理を介することなく設定することができる。
【0015】
【発明の実施の形態】
本発明の好適な実施の形態について、図1〜図4を用いて説明する。
【0016】
(第1の実施の形態)
図1を参照して、第1の実施の形態について説明する。
【0017】
図1は、データ処理装置に含まれる複数の割り込み間隔で割り込みを入れるインターバルタイマを実現するタイマ回路であり、データ処理装置に含まれる図示しない中央処理装置(CPU)とバスを介して接続されている。タイマ回路100は、CPUにバス10を介して接続されており、タイマカウンタ11と、コンペアレジスタ12a、12bと、それぞれ異なるインターバル時間でコンペアレジスタのコンペア値を設定する第1及び第2のコンペアレジスタ設定回路13a、13bと、コンペアレジスタに設定された値とタイマカウンタの値とを比較し両者が一致したときに一致信号を出力する比較器14と割り込み制御回路15とで構成されている。
【0018】
タイマカウンタ11は、図示されていない入力クロック信号に応じてカウントアップし、CPUによりバス10を介して初期値が設定される。コンペアレジスタ12a、12bは、入力クロック信号に応じて供給されたデータを格納するレジスタであって、バスを介して初期値が設定される。
【0019】
コンペアレジスタ設定回路13a、13bの構成は実質同一であるので、第1のコンペアレジスタ設定回路13aについて説明する。なお、図1において同一の構成要素は同一の参照番号で示す。
【0020】
第1のコンペアレジスタ設定回路13aは、インターバル時間を示す値が設定された幅レジスタ16と、幅レジスタ16に設定された値とタイマカウント値とを加算する加算器17と、加算器17の加算結果をコンペアレジスタ12に供給するタイミングを発生するタイミング生成回路とで構成される。幅レジスタ16は、コンペアレジスタ12と同様にバスを介して初期値が設定される。
【0021】
タイミング生成回路は、選択器18及び選択器19とからなる。選択器18は、比較器から出力される一致信号に応じて選択信号を出力し、選択器19は、選択信号に応じて加算器17の加算結果及びコンペアレジスタ12に設定されているコンペア値のいずれかの値を選択しコンペアレジスタ12に供給する。すなわち、選択信号が活性状態のときには加算器17の加算結果をコンペアレジスタ12に供給し、選択信号が非活性状態ときにはコンペアレジスタに設定されているコンペア値を供給する。
【0022】
ここで、コンペアレジスタ12に供給する値を選択するものとしたが、コンペアレジスタに設定されている値をフィードバックすることなく加算器17の加算結果のみを供給し、選択信号に応じてコンペアレジスタに入力されるクロック信号をマスクしてもよい。すなわち、選択信号が活性状態のときにはクロック信号を供給し加算結果をコンペアレジスタに書き込み、選択信号が非選択状態のときにはコンペアレジスタに供給されるべきクロック信号をマスクするものとしてもよい。
【0023】
割り込み制御回路15は、比較器14から出力される一致信号に応じて割り込み制御信号INT1(又はINT2)を発生する。また、割り込み制御回路15はバス10に接続され、割り込み制御信号INT1(又はINT2)に基づき図示しない周辺回路の割り込み処理を行なう。
【0024】
次に、図1及び図2を参照して、本タイマ回路のインターバルタイマとしての動作を説明する。例として、第1の割り込みタイミング設定回路によって実現されるインターバルタイマの動作を説明する。ここで、コンペアレジスタにはバスを介してAという初期値が設定されているとする。
【0025】
タイマカウンタ11は、入力クロックによって順次カウントアップされる。比較器14は、カウントアップするタイマカウンタの値とコンペアレジスタ12に設定されている値とを比較し、入力クロック信号に応じてカウントアップされたタイマカウンタの値とコンペアレジスタの値が一致した(ア)のタイミングで、一致信号を出力する。すなわち、一致信号は入力クロック信号に同期して出力されることとなる。この一致信号に応じて選択器18から出力される選択信号が活性化され、この選択信号に応じてタイマカウンタ値と幅レジスタ16に設定されている値との加算値が選択されコンペアレジスタ12に供給される。このような動作によりコンペアレジスタの値は2Aとなる。したがって、次の割り込みタイミングはタイマカウンタ値が2Aを示す(イ)のタイミングとすることができる。つまり、CPUが処理を行なっているか否かにかかわらずタイマカウンタとコンペアレジスタの値が一致したときに自動的にコンペアレジスタ12に設定される値が更新される。(イ)のタイミングにおいても、(ア)のタイミングと同じように、一致信号に応じてコンペアレジスタの値が更新されることにより、コンペアレジスタの値は3Aとなる。このようにして、タイマ回路はインターバル時間Aで一致信号を出力することができる。
【0026】
したがって、CPUが他の優先順位の高い割り込み処理を行なっていたとしても、タイマ回路のコンペアレジスタの値を更新することができる。また、ソフトウェア処理を介していないため、ソフトウェア処理能力が低下することもない。さらに、入力クロック信号に同期して出力される一致信号に応じてコンペアレジスタにデータが供給され、コンペアレジスタは入力クロック信号に同期してデータを格納するため、コンペアレジスタに設定されるインターバル時間の間隔のばらつきを低減することができる。
【0027】
なお、図1に示されるタイマ回路は、CPUアクセス制御回路20と外部エッジ検出制御回路21をさらに備えていてもよい。
【0028】
CPUアクセス制御回路20は、CPUからのインターバル開始アクセス命令を受け取り、割り込み制御回路15にて対象となる割り込み処理を許可すると共に、タイマカウンタ値と幅レジスタに設定されている値との加算値をコンペアレジスタに再設定するためのCPUアクセス制御信号を発生する。
【0029】
また、外部エッジ検出制御回路21は、外部信号のエッジを検出し、割り込み制御回路15にて対象となる割り込み処理を許可すると共に、タイマカウンタ値と幅レジスタに設定されている値との加算値をコンペアレジスタに再設定するための外部エッジ制御信号を発生する。
【0030】
このとき、選択器18は、これらCPUアクセス制御信号、外部エッジ制御信号及び一致信号を供給し、いずれかが活性状態となった場合に選択信号を出力するように構成すればよい。
【0031】
このようにCPUアクセス制御回路20をさらに備えることによって、通常のインターバルタイマとしての動作のみならず、CPUアクセスによるコンペアレジスタの更新が可能である。すなわち、CPUアクセスからインターバル時間経たタイミングを容易に得ることができる。これにより、CPUがソフトウェア処理を実行し、その処理からあるインターバル時間をもって割り込み処理を行なう場合には、ソフトウェア処理であれば、タイマカウンタ値を読み出し、タイマカウンタ値にインターバル時間を加算し、加算したものを新たなコンペアレジスタ値として更新する、という処理を行わなければならないところ、CPUからのインターバル開始アクセスのみで実現可能となる。この結果、CPUへの負荷が削減できるとともに、CPUで処理することによって生じていた割り込みタイミング発生に対する誤差を低減することができる。
【0032】
また、外部エッジ検出制御回路21を有することによって、外部トリガ入力からのインターバル時間計測機能をも実現することができる。すなわち、外部信号のレベル変化を検出し、検出したタイミングからインターバル時間を計測して割り込み制御信号を発行することができる。このような処理をソフトウェアで実行した場合には、外部信号を受け取り、割り込み分岐命令によって、タイマカウンタ値の読み出し、タイマカウント値にインターバル時間を加算し、加算値を新たなコンペアレジスタ値として更新する、という一連の処理を行なわなければならない。しかしながら、本発明ではこのような処理を行なわずに、外部信号のレベル変化を検出するのみで実現可能となる。したがって、CPUへの負荷が削減できるとともに、CPUで処理することによって生じていた割り込みタイミング発生に対する誤差を低減することができる。
【0033】
(第2の実施の形態)
次に、第2の実施の形態について図3を参照して説明する。なお、図1と同一の構成要素は同一の参照番号で示し、その説明を省略する。
【0034】
第2の実施の形態によるタイマ回路は、図1に示す第1の実施例と比較して、タイマカウンタ値と幅レジスタの値を加算するための加算器の構成が異なる。図3に示されるタイマ回路101は、回路規模を削減するために、複数のインターバル時間を設定するためにそれぞれ設けられていた加算器をまとめた加算回路22としている。加算回路22は、加算器23と、タイマカウンタ値にいずれの幅レジスタの値を加算すべきかを選択するために選択信号に応じて幅レジスタの値を選択する選択回路24が追加されている。
【0035】
図3のような回路構成にした場合には、複数のコンペアレジスタへの書換えタイミングが同一タイミングとなった場合に誤動作してしまうため、そのための制御がさらに必要となる。この制御方法として、書換えタイミングが重なった場合に、書き換えタイミングをずらし優先順位の高いコンペアから設定する方法と、1カウントアップ毎にクロックを複数個発するように設計し、クロック毎に対応するコンペアを分けて制御する方法とがある。
【0036】
(第3の実施の形態)
図4は、3つの割り込み間隔で割り込みを入れるインターバルタイマを実現するタイマ回路を構成した本発明の第3の実施の形態である。図1と同一の構成要素は同一の参照番号で示し、その説明を省略する。
【0037】
すなわち、タイマ回路102は、幅レジスタ、加算器、タイミング生成回路及びコンペアレジスタからなる割り込み設定回路25が3種類ずつ設けられいる。比較ユニット25には、タイマカウンタとそれぞれのコンペアレジスタ値とを比較するべく比較回路が3つ内蔵されており、それぞれのコンペアレジスタ値とタイマカウンタ値が一致したときに一致信号を出力する。このように割り込み設定回路を複数設けることによって異なる割り込み間隔で割り込みを入れるインターバルタイマを実現することができる。
【0038】
【発明の効果】
上述のとおり、本発明によれば、CPUがインターバルタイマによる割り込み処理よりも優先順位の高い処理を行なっていたとしても、自動的にコンペアレジスタが更新することができるため、ソフトバグを発生することがない。また、複数のインターバル時間でもって割り込みを入れるインターバルタイマとして動作させても、コンペアレジスタの値はソフトウェア処理を介することなく更新することができるため、ソフトウェア処理能力を低下させることがない。また、コンペアレジスタの値がソフトウェア処理を介することなく自動的に更新されるためインターバル時間のばらつきを低減することができる。
【図面の簡単な説明】
【図1】本発明によるタイマ回路の第1の実施の形態の構成図である。
【図2】図1のタイマ回路の動作を示すタイミング図である。
【図3】本発明によるタイマ回路の第2の実施の形態の構成図である。
【図4】本発明によるタイマ回路の第3の実施の形態の構成図である。
【図5】従来のタイマ回路の動作を示すタイミング図である。
【符号の説明】
10 バス
11 タイマカウンタ
12 コンペアレジスタ
14 比較器
15 割り込み制御回路
16 幅レジスタ
17、23 加算器
18、19、24 選択器
20 CPUアクセス制御回路
21 外部エッジ検出制御回路
[0001]
TECHNICAL FIELD OF THE INVENTION
The present invention relates to a timer circuit built in a microcomputer or the like, and more particularly to a timer circuit that realizes an interval timer that interrupts at a constant interval.
[0002]
[Prior art]
When an interval timer is realized by a general-purpose timer having one timer counter and a plurality of compare registers, the compare register and the general-purpose timer counter are generally connected to a central processing unit (CPU) via a bus. These are operated as an interval timer by software processing. In Patent Document 1, when the count value of the timer counter matches the compare value of the compare register and a match signal is output, the CPU starts an interrupt routine of the timer circuit in accordance with the match signal. I do. In this interrupt routine of the timer circuit, there is disclosed an interrupt routine in which a value obtained by adding an interval time to a value set in a compare register is set as a new compare register value and the interrupt routine is terminated. By performing the processing by software in this manner, the apparatus operates as an interval timer.
[0003]
However, when the count value of the general-purpose timer counter matches the compare value, another high-priority process is being performed, and the interrupt routine may not be activated when the match signal is output. Such a state will be described with reference to FIG.
[0004]
In this interval timer, the value A is set in the compare register as a compare value. It is also assumed that an interrupt signal is generated by the interval timer at each interval A of the count value of the timer counter. Further, the timer counter is configured to be able to count up to a value larger than the interval A in order to operate as a timer circuit for interrupting a plurality of interval times.
[0005]
First, when the timer counter counts up and the counter value becomes equal to the compare value A (A), an interrupt signal from the interval timer is generated. The CPU starts an interrupt routine of the timer circuit in response to the interrupt signal. However, if the CPU is executing another high-priority process at the time (a), the interrupt routine cannot be started. Thus, the interrupt routine for the interrupt signal generated at the time (a) can be executed after the processing of the higher priority is completed. That is, assuming that the processing with the higher priority is completed in (A), an interrupt routine of the timer circuit for the interrupt signal generated at the time of (A) is thereafter performed, and the compare value set up to that time is restored. The process of updating the value obtained by adding the interval A as the compare value is performed. However, if the value of the timer counter exceeds the updated compare value (2A) at this time, the interrupt signal input by the interval timer indicates the value 2A in which the timer counter overflows and the counter value is equal to the compare value again. Will not occur until now. As a result, the interval between interruptions by the interval timer is greatly shifted, and as a result, a soft bug may be caused.
[0006]
In order to avoid such a state, the timer counter value at the time when the interrupt routine was started is read, an interval time is added to the read timer counter value, and this added value is used as a new compare register value. It is possible to update. However, for this reason, at least three instructions of reading, adding, and updating are processed, and the processing time of the software becomes longer. As a result, there arises a problem that the processing capability of software is reduced. Further, when the count-up operation of the timer counter is faster than the processing speed of the CPU, there is a problem that the timing of reading the count value is delayed and the interval of the interval is shifted.
[0007]
Patent Literature 1 discloses a technology in which a match detection circuit outputs a match signal when a value of a timer counter is compared with a value of an interval time set in a compare register, and the match signal is used to clear the timer counter. It has been disclosed. As a result, the value of the timer counter is cleared each time the value is incremented by the value of the interval time set in the compare register, so that an interrupt routine of the CPU becomes unnecessary and the execution time of software can be reduced. However, it cannot be used as an interval timer for setting a plurality of interval times.
[0008]
[Patent Document 1]
Japanese Patent Application Laid-Open No. H11-95864
[Problems to be solved by the invention]
As described above, if the interval timer is implemented by software processing, a software bug caused by a large shift in the interval between interrupts by the interval timer will occur when processing with higher priority than the interrupt routine for the interval timer is performed. There is a problem of causing.
[0010]
Further, in the interrupt routine, it is assumed that the timer counter value is read when the interrupt routine is activated, an interrupt interval is added to the read timer counter value, and the added value is updated in the compare register. However, there is a problem that the processing time in the interrupt routine becomes longer, the processing time in the software becomes longer, and the provision of the interval timer lowers the software processing capability. In addition, there is a problem that the interval time varies due to an increase in software processing time.
[0011]
An object of the present invention is to provide a timer circuit that operates as an interval timer that can set a plurality of interval times and that does not cause a soft bug. Another object of the present invention is to provide a timer circuit that does not reduce software processing capability. It is another object of the present invention to provide a timer circuit that realizes an interval timer with less variation in interval time.
[0012]
[Means for Solving the Problems]
A timer circuit according to the present invention includes a timer counter that counts according to a clock signal, a compare register, and a comparator that compares a value of the timer counter with a value set in the compare register and outputs a match signal when the values match. , A width register in which a value indicating the interval time is set, an adder for adding the value of the timer counter and the value of the width register, and an addition value output from the adder in response to the coincidence signal are set in the compare register. It is characterized by the following.
[0013]
That is, a data processing device according to the present invention includes a CPU, and a timer circuit connected to the CPU via a bus. The timer circuit includes a timer counter that counts according to a clock signal, a compare register, and a timer counter. The comparator compares the value with the value set in the compare register and outputs a match signal when the values match, a width register in which a value indicating an interval time is set, and a timer counter value and a width register value. And an adder for adding, and the output of the adder is set in the compare register regardless of whether or not the CPU is performing processing in response to the coincidence signal.
[0014]
As described above, according to the present invention, the value obtained by adding the timer counter value and the interval time is supplied to the compare register irrespective of whether or not the CPU is performing processing in accordance with the coincidence signal. That is, the value of the compare register can be automatically set in response to the match signal. Therefore, the value of the compare register can be set without going through software processing.
[0015]
BEST MODE FOR CARRYING OUT THE INVENTION
A preferred embodiment of the present invention will be described with reference to FIGS.
[0016]
(First Embodiment)
The first embodiment will be described with reference to FIG.
[0017]
FIG. 1 shows a timer circuit for realizing an interval timer for interrupting at a plurality of interrupt intervals included in the data processing device, which is connected via a bus to a central processing unit (CPU) not shown included in the data processing device. I have. The timer circuit 100 is connected to the CPU via the bus 10, and includes a timer counter 11, compare registers 12a and 12b, and first and second compare registers for setting compare values of the compare registers at different interval times. It comprises setting circuits 13a and 13b, a comparator 14 for comparing the value set in the compare register with the value of the timer counter, and outputting a match signal when the values match, and an interrupt control circuit 15.
[0018]
The timer counter 11 counts up in response to an input clock signal (not shown), and an initial value is set via the bus 10 by the CPU. The compare registers 12a and 12b are registers for storing data supplied according to an input clock signal, and have initial values set via a bus.
[0019]
Since the configurations of the compare register setting circuits 13a and 13b are substantially the same, the first compare register setting circuit 13a will be described. In FIG. 1, the same components are denoted by the same reference numerals.
[0020]
The first compare register setting circuit 13a includes a width register 16 in which a value indicating the interval time is set, an adder 17 that adds the value set in the width register 16 and the timer count value, and an adder 17 And a timing generation circuit for generating a timing for supplying the result to the compare register 12. The initial value of the width register 16 is set via the bus similarly to the compare register 12.
[0021]
The timing generation circuit includes a selector 18 and a selector 19. The selector 18 outputs a selection signal according to the coincidence signal output from the comparator, and the selector 19 outputs the addition result of the adder 17 and the comparison value set in the compare register 12 according to the selection signal. One of the values is selected and supplied to the compare register 12. That is, when the selection signal is active, the addition result of the adder 17 is supplied to the compare register 12, and when the selection signal is inactive, the compare value set in the compare register is supplied.
[0022]
Here, the value supplied to the compare register 12 is selected. However, only the addition result of the adder 17 is supplied without feeding back the value set in the compare register, and the value is supplied to the compare register according to the selection signal. The input clock signal may be masked. That is, when the selection signal is in the active state, the clock signal is supplied and the addition result is written in the compare register. When the selection signal is in the non-selected state, the clock signal to be supplied to the compare register may be masked.
[0023]
The interrupt control circuit 15 generates an interrupt control signal INT1 (or INT2) according to the coincidence signal output from the comparator 14. The interrupt control circuit 15 is connected to the bus 10, and performs an interrupt process for a peripheral circuit (not shown) based on the interrupt control signal INT1 (or INT2).
[0024]
Next, the operation of the present timer circuit as an interval timer will be described with reference to FIGS. As an example, the operation of the interval timer realized by the first interrupt timing setting circuit will be described. Here, it is assumed that an initial value A is set in the compare register via the bus.
[0025]
The timer counter 11 is sequentially counted up by the input clock. The comparator 14 compares the value of the timer counter to be counted up with the value set in the compare register 12, and the value of the timer counter counted up according to the input clock signal matches the value of the compare register ( A match signal is output at the timing of a). That is, the coincidence signal is output in synchronization with the input clock signal. The selection signal output from the selector 18 is activated in response to the coincidence signal, and the added value of the timer counter value and the value set in the width register 16 is selected in accordance with the selection signal. Supplied. By such an operation, the value of the compare register becomes 2A. Therefore, the next interrupt timing can be the timing (a) at which the timer counter value indicates 2A. That is, the value set in the compare register 12 is automatically updated when the value of the timer counter matches the value of the compare register regardless of whether or not the CPU is performing processing. At the timing of (a), similarly to the timing of (a), the value of the compare register is updated to 3A by updating the value of the compare register according to the match signal. Thus, the timer circuit can output the coincidence signal at the interval time A.
[0026]
Therefore, the value of the compare register of the timer circuit can be updated even if the CPU performs another high-priority interrupt processing. Further, since the processing is not performed through software processing, the software processing capacity does not decrease. Further, data is supplied to the compare register in response to the match signal output in synchronization with the input clock signal, and the compare register stores the data in synchronization with the input clock signal. Variations in intervals can be reduced.
[0027]
The timer circuit shown in FIG. 1 may further include a CPU access control circuit 20 and an external edge detection control circuit 21.
[0028]
The CPU access control circuit 20 receives the interval start access command from the CPU, permits the target interrupt processing in the interrupt control circuit 15, and adds the value of the timer counter value to the value set in the width register. A CPU access control signal for resetting the compare register is generated.
[0029]
Further, the external edge detection control circuit 21 detects the edge of the external signal, enables the target interrupt processing in the interrupt control circuit 15, and adds the timer counter value to the value set in the width register. Is generated in the compare register.
[0030]
At this time, the selector 18 may be configured to supply the CPU access control signal, the external edge control signal, and the coincidence signal, and to output the selection signal when any one of them is activated.
[0031]
By further providing the CPU access control circuit 20 as described above, not only the operation as a normal interval timer but also the update of the compare register by CPU access is possible. That is, it is possible to easily obtain the timing after the interval time from the CPU access. Thereby, when the CPU executes the software processing and performs the interrupt processing with a certain interval time from the processing, if the processing is the software processing, the CPU reads the timer counter value, adds the interval time to the timer counter value, and adds the timer counter value. In this case, the process of updating a new register value as a new compare register value must be performed, but this can be realized only by the interval start access from the CPU. As a result, the load on the CPU can be reduced, and an error with respect to the occurrence of the interrupt timing caused by processing by the CPU can be reduced.
[0032]
Further, by having the external edge detection control circuit 21, a function of measuring an interval time from an external trigger input can be realized. That is, it is possible to detect the level change of the external signal, measure the interval time from the detected timing, and issue the interrupt control signal. When such processing is executed by software, an external signal is received, a timer counter value is read by an interrupt branch instruction, an interval time is added to the timer count value, and the added value is updated as a new compare register value. , Must be performed. However, the present invention can be realized only by detecting a level change of an external signal without performing such processing. Therefore, the load on the CPU can be reduced, and the error caused by the processing performed by the CPU with respect to the occurrence of the interrupt timing can be reduced.
[0033]
(Second embodiment)
Next, a second embodiment will be described with reference to FIG. Note that the same components as those in FIG. 1 are denoted by the same reference numerals, and description thereof will be omitted.
[0034]
The timer circuit according to the second embodiment differs from the first embodiment shown in FIG. 1 in the configuration of the adder for adding the timer counter value and the value of the width register. The timer circuit 101 shown in FIG. 3 is an adder circuit 22 in which adders provided for setting a plurality of interval times are combined in order to reduce the circuit scale. The addition circuit 22 includes an adder 23 and a selection circuit 24 for selecting a value of the width register according to a selection signal in order to select which value of the width register should be added to the timer counter value.
[0035]
In the case of the circuit configuration as shown in FIG. 3, a malfunction occurs when the rewrite timings for a plurality of compare registers are the same, so that further control is required. As the control method, when the rewrite timing is overlapped, the rewrite timing is shifted to set from the higher priority compare. There is a method of controlling separately.
[0036]
(Third embodiment)
FIG. 4 shows a third embodiment of the present invention in which a timer circuit for realizing an interval timer for interrupting at three interrupt intervals is configured. The same components as those in FIG. 1 are denoted by the same reference numerals, and description thereof will be omitted.
[0037]
That is, the timer circuit 102 is provided with three types of interrupt setting circuits 25 each including a width register, an adder, a timing generation circuit, and a compare register. The comparison unit 25 has three built-in comparison circuits for comparing the timer counter with the respective compare register values, and outputs a match signal when the respective compare register values match the timer counter value. By providing a plurality of interrupt setting circuits in this way, it is possible to realize an interval timer that inserts interrupts at different interrupt intervals.
[0038]
【The invention's effect】
As described above, according to the present invention, even if the CPU performs a process having a higher priority than the interrupt process by the interval timer, the compare register can be automatically updated, thereby causing a software bug. There is no. Further, even when the timer is operated as an interval timer for interrupting at a plurality of interval times, the value of the compare register can be updated without software processing, so that the software processing capacity is not reduced. Further, since the value of the compare register is automatically updated without going through software processing, it is possible to reduce variation in the interval time.
[Brief description of the drawings]
FIG. 1 is a configuration diagram of a first embodiment of a timer circuit according to the present invention.
FIG. 2 is a timing chart showing an operation of the timer circuit of FIG. 1;
FIG. 3 is a configuration diagram of a second embodiment of a timer circuit according to the present invention.
FIG. 4 is a configuration diagram of a third embodiment of a timer circuit according to the present invention.
FIG. 5 is a timing chart showing an operation of a conventional timer circuit.
[Explanation of symbols]
Reference Signs List 10 Bus 11 Timer counter 12 Compare register 14 Comparator 15 Interrupt control circuit 16 Width registers 17, 23 Adders 18, 19, 24 Selector 20 CPU access control circuit 21 External edge detection control circuit

Claims (8)

クロック信号に応じてカウントするタイマカウンタと、コンペアレジスタと、前記タイマカウンタの値と前記コンペアレジスタに設定された値とを比較し一致したときに一致信号を出力する比較器と、インターバル時間を示す値が設定された幅レジスタと、前記タイマカウンタの値と幅レジスタに設定された値とを加算する加算器とを有し、前記一致信号に応じて前記加算器から出力される加算値を前記コンペアレジスタに設定することを特徴とするタイマ回路。A timer counter that counts according to a clock signal, a compare register, a comparator that compares a value of the timer counter with a value set in the compare register and outputs a match signal when they match, and an interval time. A width register in which a value is set, and an adder for adding the value of the timer counter and the value set in the width register, and the added value output from the adder in response to the coincidence signal. A timer circuit set in a compare register. 前記タイマ回路は、前記加算器から出力される加算値と前記コンペアレジスタに設定されている値とが供給されており、前記一致信号が活性化されているときには前記加算値を前記コンペアレジスタに供給し、前記一致信号が活性化されていないときには前記コンペアレジスタに設定されている値を前記コンペアレジスタに供給する選択回路をさらに有することを特徴とする請求項1記載のタイマ回路。The timer circuit is supplied with an addition value output from the adder and a value set in the compare register, and supplies the addition value to the compare register when the match signal is activated. 2. The timer circuit according to claim 1, further comprising a selection circuit that supplies a value set in the compare register to the compare register when the match signal is not activated. 前記コンペアレジスタはクロック信号に応じて前記選択回路から供給された値が設定されることを特徴とする請求項2記載のタイマ回路。3. The timer circuit according to claim 2, wherein a value supplied from the selection circuit is set in the compare register according to a clock signal. 前記タイマ回路は、CPUからのアクセス命令を受け取るCPUアクセス制御回路をさらに備え、前記コンペアレジスタ設定回路は、前記アクセス命令に応じて前記加算器から出力される加算値を前記コンペアレジスタに設定することを特徴とする請求項1記載のタイマ回路。The timer circuit further includes a CPU access control circuit that receives an access instruction from a CPU, and the compare register setting circuit sets an addition value output from the adder in the compare register according to the access instruction. The timer circuit according to claim 1, wherein 前記タイマ回路は、外部トリガ信号を受け取り前記外部トリガ信号のエッジを検出する外部エッジ検出回路をさらに備え、前記コンペアレジスタ設定回路は、前記外部エッジ検出回路の検出結果に応じて前記加算器から出力される加算値を前記コンペアレジスタに設定することを特徴とする請求項1記載のタイマ回路。The timer circuit further includes an external edge detection circuit that receives an external trigger signal and detects an edge of the external trigger signal, and the compare register setting circuit outputs an output from the adder according to a detection result of the external edge detection circuit. 2. The timer circuit according to claim 1, wherein the added value is set in the compare register. クロック信号に応じてカウントするタイマカウンタと、比較器と、複数のコンペアレジスタと、前記複数のコンペアレジスタに対応して設けられた複数のコンペアレジスタ設定回路とからなるタイマ回路であって、前記コンペアレジスタ設定回路それぞれは、インターバル時間を示す値が設定された幅レジスタと、前記タイマカウンタのカウント値と前記幅レジスタの値とを加算する加算器と,前記比較器により前記タイマカウンタのカウント値と前記コンペアレジスタに設定されたコンペア値とが比較され一致したときに出力される一致信号に応答して前記加算器の出力を前記コンペアレジスタに設定することを特徴とするタイマ回路。A timer circuit comprising: a timer counter that counts in accordance with a clock signal; a comparator; a plurality of compare registers; and a plurality of compare register setting circuits provided in correspondence with the plurality of compare registers. Each of the register setting circuits includes a width register in which a value indicating an interval time is set, an adder for adding the count value of the timer counter and the value of the width register, and a count value of the timer counter by the comparator. A timer circuit, wherein the output of the adder is set in the compare register in response to a match signal output when the compare value set in the compare register is compared and matched. 前記複数のコンペアレジスタ設定回路に設けられた幅レジスタのそれぞれは異なるインターバル時間を示す値が設定されていることを特徴とする請求項6記載のタイマ回路。7. The timer circuit according to claim 6, wherein a value indicating a different interval time is set in each of the width registers provided in the plurality of compare register setting circuits. クロック信号に応じてカウントするタイマカウンタと、複数のコンペアレジスタと、前記タイマカウンタの値と前記複数のコンペアレジスタのそれぞれの値とを比較し一致したときにそれぞれ一致信号を出力する比較器と、前記複数のコンペアレジスタに対応して設けられた複数の幅レジスタと、前記タイマカウンタの値と一致した値が格納されたコンペアレジスタに対応して設けられた幅レジスタの値を選択し前記タイマカウンタの値に加算する加算器と、前記複数のコンペアレジスタに対応して設けられ前記一致信号に応じて前記加算器の出力を前記コンペアレジスタに設定する複数のコンペアレジスタ設定回路とを有することを特徴とするタイマ回路。A timer counter that counts in accordance with a clock signal, a plurality of compare registers, and a comparator that compares a value of the timer counter with a value of each of the plurality of compare registers and outputs a match signal when they match, Selecting a plurality of width registers provided corresponding to the plurality of compare registers and a value of the width register provided corresponding to the compare register storing a value corresponding to the value of the timer counter; And a plurality of compare register setting circuits provided corresponding to the plurality of compare registers and configured to set the output of the adder to the compare register according to the coincidence signal. Timer circuit.
JP2002332483A 2002-11-15 2002-11-15 Timer circuit Withdrawn JP2004171040A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2002332483A JP2004171040A (en) 2002-11-15 2002-11-15 Timer circuit

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2002332483A JP2004171040A (en) 2002-11-15 2002-11-15 Timer circuit

Publications (1)

Publication Number Publication Date
JP2004171040A true JP2004171040A (en) 2004-06-17

Family

ID=32697492

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2002332483A Withdrawn JP2004171040A (en) 2002-11-15 2002-11-15 Timer circuit

Country Status (1)

Country Link
JP (1) JP2004171040A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR101100754B1 (en) 2004-12-30 2011-12-30 매그나칩 반도체 유한회사 Timer circuit with double buffer structure
CN106292256A (en) * 2016-08-10 2017-01-04 北京空间飞行器总体设计部 The correction device that a kind of second interrupt interval is controlled

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR101100754B1 (en) 2004-12-30 2011-12-30 매그나칩 반도체 유한회사 Timer circuit with double buffer structure
CN106292256A (en) * 2016-08-10 2017-01-04 北京空间飞行器总体设计部 The correction device that a kind of second interrupt interval is controlled
CN106292256B (en) * 2016-08-10 2018-12-18 北京空间飞行器总体设计部 The controllable correction device of a kind of second interrupt interval

Similar Documents

Publication Publication Date Title
JP4393954B2 (en) Microcomputer
KR100521110B1 (en) Event handling
US20160103704A1 (en) Data processing device and method of controlling the same
US5928348A (en) Method of processing interrupt requests and information processing apparatus using the method
JP2004171040A (en) Timer circuit
JP2003058381A (en) Processor realizing exception processing setting by program
EP3428799A1 (en) Data access device and access error notification method
JP6918267B2 (en) Bottleneck detection device and bottleneck detection program
JPH0573296A (en) Microcomputer
JP3729250B2 (en) Information processing apparatus and electronic apparatus
JP2968749B2 (en) Microprogram speed control circuit
JPH03246603A (en) Rapid counter
JP3366235B2 (en) Data read control device
JPS6118045A (en) Detecting system of program runaway
JP2006099654A (en) Semiconductor circuit apparatus
JP2006236233A (en) Interrupt level selecting circuit
JP2004157662A (en) Dynamic stack overwrite monitoring method
JPH0764822A (en) Microcomputer
JP2000250786A (en) Watchdog timer
JP3308670B2 (en) Event-driven processing equipment failure detection device
JPS59206957A (en) Device for supervising execution of instruction
JP2003050750A (en) Microcomputer
JP2004118669A (en) Control device, control method, and control software
JPH0676083A (en) Timer circuit
JPH10161887A (en) Method and device for interruption signal synchronization

Legal Events

Date Code Title Description
A300 Withdrawal of application because of no request for examination

Free format text: JAPANESE INTERMEDIATE CODE: A300

Effective date: 20060207