JP2022064701A - Rotary encoder rotation detection method - Google Patents

Rotary encoder rotation detection method Download PDF

Info

Publication number
JP2022064701A
JP2022064701A JP2020173490A JP2020173490A JP2022064701A JP 2022064701 A JP2022064701 A JP 2022064701A JP 2020173490 A JP2020173490 A JP 2020173490A JP 2020173490 A JP2020173490 A JP 2020173490A JP 2022064701 A JP2022064701 A JP 2022064701A
Authority
JP
Japan
Prior art keywords
phase
interrupt
signal level
rotation
rotary encoder
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
JP2020173490A
Other languages
Japanese (ja)
Other versions
JP7468901B2 (en
Inventor
新平 齋藤
Shimpei Saito
仁宏 中村
Hitohiro Nakamura
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.)
Sigma Corp
Original Assignee
Sigma 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 Sigma Corp filed Critical Sigma Corp
Priority to JP2020173490A priority Critical patent/JP7468901B2/en
Publication of JP2022064701A publication Critical patent/JP2022064701A/en
Application granted granted Critical
Publication of JP7468901B2 publication Critical patent/JP7468901B2/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

To provide a rotary encoder rotation detection method that suppresses a computation load of a control device such as a CPU and the like, and prevents wrong detection of rotation detection due to chattering and the like.SOLUTION: A rotary encoder rotation detection method according to the present invention is configured to: detect an interruption based on a change in a signal level of an A-phase or a B-phase; and start interruption processing as to one phase having the interruption detected. The starting interruption processing for the one phase has: a signal level acquisition step of acquiring a signal level of other phase different from the one phase; an interruption detection flag acquisition step of acquiring presence or absence of an interruption detection flag of the other phase; and a rotation detection step of performing rotation detection of a rotary encoder when the signal level of the A-phase and the signal level of the B-phase are identical, and the interruption detection flag of the other phase is present.SELECTED DRAWING: Figure 2

Description

本発明はロータリーエンコーダーの回転検出方法に関する。特に、チャタリングなどによるロータリーエンコーダーの回転方向の誤検出を防止し、回転検出のためのCPUの演算負荷を抑制することができるロータリーエンコーダーの回転検出方法に関する。 The present invention relates to a method for detecting rotation of a rotary encoder. In particular, the present invention relates to a rotary encoder rotation detection method capable of preventing erroneous detection of the rotation direction of the rotary encoder due to chattering or the like and suppressing the calculation load of the CPU for rotation detection.

従来、ダイヤルやモーターなどの回転検出を行うことを目的としてロータリーエンコーダーが採用されている。 Conventionally, a rotary encoder has been adopted for the purpose of detecting the rotation of a dial or a motor.

ロータリーエンコーダーの回転検出の方式には光学式や磁気・電気誘導式などがあり、ロータリーエンコーダを搭載する機器の用途や使用環境により適切なものが採用されている。 There are optical and magnetic / electric induction methods for the rotation detection method of the rotary encoder, and the method suitable for the application and usage environment of the device equipped with the rotary encoder is adopted.

例えば光学式ロータリーエンコーダは、LEDなどの発光素子、フォトダイオードなどの受光素子、円周方向に等ピッチでスリットが設けられた回転スリット円板から構成される。 For example, an optical rotary encoder is composed of a light emitting element such as an LED, a light receiving element such as a photodiode, and a rotating slit disk provided with slits at equal pitches in the circumferential direction.

光学式ロータリーエンコーダにおいて、発光素子と受光素子は対面して配置されており、発光素子からの光は受光素子で受光されるように配置されている。回転スリット円板は発光素子と受光素子との間に挟まれるように配置され、回転する機械要素の回転に応じて回転する。 In the optical rotary encoder, the light emitting element and the light receiving element are arranged to face each other, and the light from the light emitting element is arranged so as to be received by the light receiving element. The rotary slit disk is arranged so as to be sandwiched between the light emitting element and the light receiving element, and rotates according to the rotation of the rotating mechanical element.

発光素子からの光は、回転する回転スリット円板の回転位置により、回転スリット円板に設けられたスリットを透過したり遮断されたりする。これにより受光素子は発光素子からの光を受光し、受光素子から出力される信号レベルはスリットの位置により変化する。受光素子から出力された信号レベルは周辺回路により処理されて矩形波として出力される。 The light from the light emitting element passes through or is blocked from the slit provided in the rotary slit disk depending on the rotational position of the rotating rotary slit disk. As a result, the light receiving element receives the light from the light emitting element, and the signal level output from the light receiving element changes depending on the position of the slit. The signal level output from the light receiving element is processed by a peripheral circuit and output as a square wave.

光学式ロータリーエンコーダからは回転方向を識別するための2つの相(A相・B相)の矩形波が出力される。A相・B相の矩形波は互いに所定の位相(例えば1/4周期)だけずらして出力される。互いに所定の位相だけずれたA相・B相の矩形波を出力するには、例えばA相・B相の受光素子をそれぞれ設け、これらを互いにずらして配置するように構成すればよい。 Two phases (A phase and B phase) rectangular waves for identifying the rotation direction are output from the optical rotary encoder. The A-phase and B-phase square waves are output with a predetermined phase (for example, 1/4 period) shifted from each other. In order to output a square wave of A phase and B phase which are shifted by a predetermined phase from each other, for example, light receiving elements of A phase and B phase may be provided respectively, and these may be arranged so as to be offset from each other.

図1は、光学式ロータリーエンコーダから出力される互いに1/4周期だけずれたA相・B相の矩形波の例を示す。ロータリーエンコーダの回転方向の識別は、識別を行う時点におけるA相・B相の矩形波の関係性に基づいて行われる。 FIG. 1 shows an example of A-phase and B-phase square waves output from an optical rotary encoder that are offset by a quarter period from each other. The rotation direction of the rotary encoder is identified based on the relationship between the A-phase and B-phase square waves at the time of identification.

例えば、図1のA相・B相の矩形波の関係性に基づく回転方向の識別方法では、B相の信号レベルがH(ハイレベル)からL(ローレベル)に立ち下がった時点においてA相の信号レベルがHである場合には時計回りに1段回転したと識別し、反対に、A相の信号レベルがHからLに立ち下がった時点においてB相の信号レベルがHである場合には反時計回りに1段回転したと識別する。 For example, in the method for identifying the rotation direction based on the relationship between the A-phase and B-phase square waves in FIG. 1, the A-phase is when the signal level of the B-phase drops from H (high level) to L (low level). When the signal level of is H, it is identified as having rotated one step clockwise, and conversely, when the signal level of the A phase drops from H to L, the signal level of the B phase is H. Is identified as having rotated one step counterclockwise.

ところで、光学式ロータリーエンコーダの回転方向を識別する時点を判断するA相・B相の信号レベルの変化(立ち下がり又は立ち上がり)は、光学式ロータリーエンコーダから出力される信号レベルに伝わるノイズによっても発生するおそれがある。ノイズが複数の電気的パルスである場合には、A相・B相の信号レベルが短時間に激しく振動するチャタリングという現象が発生する。これらのノイズは光学式ロータリーエンコーダの回転方向の識別の誤作動につながるおそれがある。 By the way, the change (falling or rising) of the A-phase and B-phase signal levels that determine the time point for identifying the rotation direction of the optical rotary encoder is also generated by the noise transmitted to the signal level output from the optical rotary encoder. There is a risk of When the noise is a plurality of electrical pulses, a phenomenon called chattering occurs in which the signal levels of the A phase and the B phase vibrate violently in a short time. These noises may lead to malfunction of the rotational direction identification of the optical rotary encoder.

特許文献1(特開平6-137892号公報)には、A相・B相の信号レベルにチャタリングが発生したとしても、回転方向の読取りの誤動作を防止することができるロータリエンコーダの読取り方法が開示されている。 Patent Document 1 (Japanese Unexamined Patent Publication No. 6-137892) discloses a method for reading a rotary encoder that can prevent a malfunction of reading in the rotation direction even if chattering occurs at the signal level of the A phase and the B phase. Has been done.

特許文献1のロータリエンコーダの読取り方法では、所定のサンプリング周期で読み取ったA相・B相の信号のレベル状態を、1サンプリング周期前に読み取ったA相・B相の信号のレベル状態と比較してカウント値を増減するサブカウンタを設け、A相・B相の信号のレベル状態の遷移が正常なロータリーエンコーダの回転によるものである場合には回転方向に応じてサブカウンタのカウント値を増減させ、A相・B相の信号のレベル状態が所定の状態にある時点においてサブカウンタのカウント値に基づいてロータリーエンコーダの回転方向を識別している。 In the method of reading the rotary encoder of Patent Document 1, the level state of the A-phase / B-phase signal read in a predetermined sampling cycle is compared with the level state of the A-phase / B-phase signal read before one sampling cycle. A sub-counter that increases / decreases the count value is provided, and if the transition of the level state of the A-phase / B-phase signal is due to the normal rotation of the rotary encoder, the count value of the sub-counter is increased / decreased according to the rotation direction. , The rotation direction of the rotary encoder is identified based on the count value of the sub-counter at the time when the level state of the A-phase / B-phase signal is in a predetermined state.

特開平6-137892号公報Japanese Unexamined Patent Publication No. 6-137892

しかしながら、特許文献1に開示されたロータリエンコーダの読取り方法は、チャタリングによる回転方向の読取りの誤動作を防止することはできるものの次の課題がある。 However, the method for reading a rotary encoder disclosed in Patent Document 1 has the following problem, although it can prevent a malfunction of reading in the rotation direction due to chattering.

特許文献1において、高速回転するロータリーエンコーダの回転検出をチャタリングの影響を受けることなく行うためには、サブカウンタを監視する所定のサンプリング周期をより短くしなければならない。また、実際にロータリーエンコーダが回転していない時間であっても、高速回転するロータリーエンコーダの回転検出に対応するために、より短いサンプリング周期で常にサブカウンタを監視しなければならない。したがって、特許文献1に開示されたロータリエンコーダの読取り方法では、CPUなどの制御装置に大きな演算負荷がかかってしまう。 In Patent Document 1, in order to detect the rotation of a rotary encoder rotating at high speed without being affected by chattering, a predetermined sampling cycle for monitoring a sub-counter must be shortened. Further, even when the rotary encoder is not actually rotating, the sub-counter must be constantly monitored with a shorter sampling cycle in order to cope with the rotation detection of the rotary encoder rotating at high speed. Therefore, the reading method of the rotary encoder disclosed in Patent Document 1 imposes a large computational load on a control device such as a CPU.

さらに、ロータリーエンコーダが所定のサンプリング周期以上で高速回転した場合には、サブカウンタによる所定のサンプリング周期での監視がA相・B相の信号のレベルの変化のスピードに追いつかず、サブカウンタがカウント値の増減を正しく行うことができなくなることによりロータリーエンコーダの回転方向の識別を誤ってしまうおそれがある。 Furthermore, when the rotary encoder rotates at high speed in a predetermined sampling cycle or longer, the monitoring in the predetermined sampling cycle by the sub counter cannot keep up with the speed of change in the signal level of the A phase and B phase, and the sub counter counts. Since the value cannot be increased or decreased correctly, the rotation direction of the rotary encoder may be erroneously identified.

上記課題を解決するために、本発明に係る第1の発明のロータリーエンコーダーの回転検出方法は、互いに位相がずれたA相・B相の二つの信号レベルに基づいて回転検出を行うロータリーエンコーダーの回転検出方法において、A相又はB相の信号レベルの変化により割り込みを検知し、前記割り込みを検知した一方の相についての割り込み処理を開始し、前記一方の相について開始した前記割り込み処理は、前記一方の相とは異なる他方の相の信号レベルを取得する信号レベル取得ステップと、前記他方の相の割り込み検知フラグの有無を取得する割り込み検知フラグ取得ステップと、A相の信号レベルとB相の信号レベルが同一であり、かつ、前記他方の相の前記割り込み検知フラグが有りである場合に、ロータリーエンコーダーの回転検出を行う回転検出ステップとを有することを特徴とする。 In order to solve the above problems, the rotation detection method of the rotary encoder of the first invention according to the present invention is a rotary encoder that detects rotation based on two signal levels of A phase and B phase which are out of phase with each other. In the rotation detection method, an interrupt is detected by a change in the signal level of the A phase or the B phase, interrupt processing is started for one phase that has detected the interrupt, and the interrupt processing started for the one phase is described above. A signal level acquisition step for acquiring the signal level of the other phase different from one phase, an interrupt detection flag acquisition step for acquiring the presence / absence of the interrupt detection flag of the other phase, and a signal level of the A phase and the B phase. It is characterized by having a rotation detection step for detecting the rotation of the rotary encoder when the signal levels are the same and the interrupt detection flag of the other phase is present.

本発明に係る第2の発明のロータリーエンコーダーの回転検出方法は、A相又はB相の信号レベルの変化により割り込みを検知し、開始された前記割り込みを検知した一方の相についての割り込み処理において、前記割り込み検知フラグ取得ステップで取得した前記一方の相とは異なる他方の相の割り込み検知フラグが有りである場合には、前記他方の相の前記割り込み検知フラグをクリアする割り込み検知フラグクリアステップをさらに有することを特徴とする。 The rotation detection method of the rotary encoder of the second invention according to the present invention detects an interrupt by a change in the signal level of the A phase or the B phase, and in the interrupt processing for one of the detected interrupts. If there is an interrupt detection flag for the other phase that is different from the one acquired in the interrupt detection flag acquisition step, an interrupt detection flag clear step for clearing the interrupt detection flag for the other phase is further added. It is characterized by having.

本発明に係る第3の発明のロータリーエンコーダーの回転検出方法は、A相又はB相の信号レベルの変化により割り込みを検知し、開始された前記割り込みを検知した一方の相についての割り込み処理において、前記割り込みを検知した前記一方の相の信号レベルと前記信号レベル取得ステップにおいて取得した前記一方の相とは異なる他方の相の信号レベルとが異なる場合には、前記一方の相の割り込み検知フラグを有りとする割り込み検知フラグセットステップをさらに有することを特徴とする。 The rotation detection method of the rotary encoder of the third invention according to the present invention detects an interrupt by a change in the signal level of the A phase or the B phase, and in the interrupt processing for one of the detected interrupts, the interrupt is started. When the signal level of the one phase in which the interrupt is detected and the signal level of the other phase different from the one acquired in the signal level acquisition step are different, the interrupt detection flag of the one phase is set. It is characterized by further having an interrupt detection flag set step to be present.

本発明に係る第4の発明のロータリーエンコーダーの回転検出方法は、A相又はB相の信号レベルの変化により割り込みを検知し、開始された前記割り込みを検知した一方の相についての割り込み処理において、前記回転検出ステップで回転検出される回転方向は前記一方の相とは異なる他方の相の割り込み処理の回転検出ステップで回転検出される回転方向と互いに反対向きであることを特徴とする。 The rotation detection method of the rotary encoder according to the fourth aspect of the present invention detects an interrupt due to a change in the signal level of the A phase or the B phase, and in interrupt processing for one of the detected interrupts. The rotation direction detected by the rotation detection step is opposite to the rotation direction detected by the rotation detection step of the interrupt processing of the other phase, which is different from the one phase.

本発明に係るロータリーエンコーダーの回転検出方法は、チャタリングなどにより回転検出の誤動作が発生することを防止した上で、高速回転時においてもCPUなどの制御装置の演算負荷を抑え、回転検出の誤動作を防止することができる。 The rotation detection method of the rotary encoder according to the present invention prevents the rotation detection from malfunctioning due to chattering or the like, suppresses the calculation load of the control device such as the CPU even during high-speed rotation, and suppresses the rotation detection malfunction. Can be prevented.

ロータリーエンコーダから出力されるA相・B相の矩形波を示す図である。It is a figure which shows the rectangular wave of A phase and B phase output from a rotary encoder. 本実施例のデジタルカメラにおけるロータリーエンコーダを示す構成図である。It is a block diagram which shows the rotary encoder in the digital camera of this Example. ロータリーエンコーダから出力されるA相・B相の矩形波を示す図である。It is a figure which shows the rectangular wave of A phase and B phase output from a rotary encoder. 本実施例のロータリーエンコーダの回転検出方法の原則を説明する図である。It is a figure explaining the principle of the rotation detection method of the rotary encoder of this Example. ロータリーエンコーダの回転検出方法を示すフローチャートである。It is a flowchart which shows the rotation detection method of a rotary encoder. A相割り込み処理を示すフローチャートである。It is a flowchart which shows A phase interrupt processing. B相割り込み処理を示すフローチャートである。It is a flowchart which shows the B phase interrupt processing. A相の信号レベルにノイズが発生した場合を示す図である。It is a figure which shows the case where noise occurs in the signal level of A phase.

以下、本発明に係るロータリーエンコーダの回転検出方法を採用するデジタルカメラの実施例について説明する。 Hereinafter, examples of a digital camera that employs the rotation detection method of the rotary encoder according to the present invention will be described.

従来、デジタルカメラには、撮影条件やメニュー項目などを設定するための操作ダイヤルが搭載されている。ユーザは操作ダイヤルを操作することにより、例えば、オート・絞り優先・シャッター速度優先などの撮影モードや、絞り値・シャッター速度・露出補正などの設定値を設定することができ、また、メニューや再生画像を操作することができる。 Conventionally, a digital camera is equipped with an operation dial for setting shooting conditions, menu items, and the like. By operating the operation dial, the user can set shooting modes such as auto, aperture priority, and shutter speed priority, and set values such as aperture value, shutter speed, and exposure compensation, as well as menus and playback. You can manipulate the image.

操作ダイヤルがユーザにより操作された場合には、デジタルカメラは正確に操作ダイヤルの回転検出を行い、ユーザの意図通りに動作しなければならない。また、操作ダイヤルがユーザにより操作されない場合にも、いつでも回転検出を行えるようにスタンバイしておかなければならない。操作ダイヤルの回転検出にはロータリーエンコーダが用いられる。 When the operation dial is operated by the user, the digital camera must accurately detect the rotation of the operation dial and operate as the user intends. In addition, even if the operation dial is not operated by the user, it must be on standby so that rotation detection can be performed at any time. A rotary encoder is used to detect the rotation of the operation dial.

図2は本実施例のデジタルカメラにおけるロータリーエンコーダを示す構成図である。図2において、10は操作ダイヤル、20はロータリーエンコーダ、30は周辺回路、40は制御装置、41は割り込み検知部、42はA相割り込み処理部、43はB相割り込み処理部、44は記憶部を示す。 FIG. 2 is a configuration diagram showing a rotary encoder in the digital camera of this embodiment. In FIG. 2, 10 is an operation dial, 20 is a rotary encoder, 30 is a peripheral circuit, 40 is a control device, 41 is an interrupt detection unit, 42 is an A-phase interrupt processing unit, 43 is a B-phase interrupt processing unit, and 44 is a storage unit. Is shown.

操作ダイヤル10は、撮影条件の設定値やメニューの操作などを設定を意図するユーザにより回転操作される。 The operation dial 10 is rotated by a user who intends to set setting values of shooting conditions, menu operations, and the like.

ロータリーエンコーダ20は、回転軸と、回転スリット円板と、LEDなどの発光素子と、フォトダイオードなどの受光素子から構成される。 The rotary encoder 20 is composed of a rotating shaft, a rotating slit disk, a light emitting element such as an LED, and a light receiving element such as a photodiode.

回転軸は、操作ダイヤルに連結されており、操作ダイヤルの回転に従って回転する。回転スリット円板は、回転軸に固定されており、回転軸の回転に従って回転する。回転スリット円板には円周方向に等ピッチのスリットが設けられている。発光素子と受光素子は回転スリット円板を挟むように配置されて、回転スリット円板のスリットを透過した発光素子からの光は受光素子により受光される。発光素子からの光は回転スリット円板の回転に応じてスリットを透過したり遮られたりする。受光素子は受光した発光素子からの光を回転スリット円板のスリットの有無に応じて出力信号を出力する。受光素子は、互いに1/4周期だけ位相がずれたA相・B相の出力信号を取得できるように2つ設けられている。 The rotation shaft is connected to the operation dial and rotates according to the rotation of the operation dial. The rotary slit disk is fixed to the rotary shaft and rotates according to the rotation of the rotary shaft. The rotary slit disk is provided with slits at equal pitches in the circumferential direction. The light emitting element and the light receiving element are arranged so as to sandwich the rotating slit disk, and the light from the light emitting element transmitted through the slit of the rotating slit disk is received by the light receiving element. The light from the light emitting element passes through the slit or is blocked according to the rotation of the rotating slit disk. The light receiving element outputs an output signal of the light received from the light emitting element according to the presence or absence of a slit in the rotating slit disk. Two light receiving elements are provided so as to be able to acquire output signals of A phase and B phase which are out of phase by 1/4 period from each other.

周辺回路30は、ロータリーエンコーダ20から出力されたA相・B相の出力信号を増幅したり、ハイレベル(H)・ローレベル(L)に2値化された信号レベルからなる矩形波に変換したりする。 The peripheral circuit 30 amplifies the A-phase and B-phase output signals output from the rotary encoder 20 and converts them into a square wave composed of signal levels binarized to high level (H) and low level (L). Or

周辺回路30から出力された出力信号は、図3に示すように互いに1/4周期だけ位相がずれたA相・B相の矩形波となる。ロータリーエンコーダ20の回転により正常に出力された矩形波にはH・Lの信号レベルが交互に現れる。 As shown in FIG. 3, the output signal output from the peripheral circuit 30 is a square wave of A phase and B phase which are out of phase by 1/4 period from each other. H and L signal levels appear alternately in the rectangular wave normally output by the rotation of the rotary encoder 20.

周辺回路30から出力されたA相・B相の矩形波に基づいてロータリーエンコーダ20の回転方向を識別することができる。例えば、A相・B相の矩形波を常に監視しておき、A相の信号レベルの立ち下がりがあった時点で、B相の信号レベルがHである場合には正転(CW)方向の回転方向であると識別し、B相の信号レベルがLである場合には反転(CCW)方向の回転方向であると識別することができる。 The rotation direction of the rotary encoder 20 can be identified based on the A-phase and B-phase square waves output from the peripheral circuit 30. For example, if the A-phase and B-phase square waves are constantly monitored and the B-phase signal level is H at the time when the A-phase signal level falls, the normal rotation (CW) direction is obtained. It can be identified as the rotation direction, and when the signal level of the B phase is L, it can be identified as the rotation direction in the inversion (CCW) direction.

制御装置40は、周辺回路30から出力されたA相・B相の出力信号からロータリーエンコーダ20の回転検出を行う。制御装置40は、例えばCPUやその一部の制御ブロックである。 The control device 40 detects the rotation of the rotary encoder 20 from the A-phase and B-phase output signals output from the peripheral circuit 30. The control device 40 is, for example, a CPU or a control block thereof.

制御装置40は、割り込み検知部41、A相割り込み処理部42、B相割り込み処理部43、記憶部44から構成される。 The control device 40 includes an interrupt detection unit 41, an A-phase interrupt processing unit 42, a B-phase interrupt processing unit 43, and a storage unit 44.

割り込み検知部41は、周辺回路30から出力されたA相・B相の矩形波のいずれかに信号レベルの変化があったことを検知して、A相又はB相の割り込みを検知する。本実施例では、A相・B相の出力信号のいずれかに立ち下がりがあったことを検知することにより割り込みを検知する。 The interrupt detection unit 41 detects that there is a change in the signal level in either the A-phase or B-phase square wave output from the peripheral circuit 30, and detects the A-phase or B-phase interrupt. In this embodiment, an interrupt is detected by detecting that one of the output signals of the A phase and the B phase has a fall.

A相割り込み処理部42及びB相割り込み処理部43は、割り込み検知部41により割り込みが検知されたA相又はB相についての割り込み処理を行いロータリーエンコーダ20の回転検出を行う。A相又はB相についての割り込み処理の内容については後述する。 The A-phase interrupt processing unit 42 and the B-phase interrupt processing unit 43 perform interrupt processing for the A-phase or B-phase in which an interrupt is detected by the interrupt detection unit 41, and detect the rotation of the rotary encoder 20. The contents of the interrupt processing for the A phase or the B phase will be described later.

記憶部44は、割り込み検知部41により検知されたA相・B相の割り込みの有無を示す割り込み検知フラグなどを制御装置40の内部で一時的に保持する。割り込み検知フラグの割り込み処理における役割については後述する。 The storage unit 44 temporarily holds an interrupt detection flag or the like indicating the presence / absence of an A-phase / B-phase interrupt detected by the interrupt detection unit 41 inside the control device 40. The role of the interrupt detection flag in interrupt processing will be described later.

次に、本実施例のデジタルカメラにおけるロータリーエンコーダの回転検出方法の流れについて説明する。図4に示すように、本実施例のロータリーエンコーダの回転検出方法では、A相・B相の割り込みを検知して割り込みを検知した一方の相について割り込み処理を行い、A相・B相の両方に割り込みが発生し、かつ、他方の相の信号レベルが一方の相の信号レベルと同一である場合に回転検出を行う。これにより、ロータリーエンコーダの回転検出の際に、A相・B相の両方について割り込みの発生を確認することとで、チャタリングなどによるノイズの影響を受けることのないより確実な回転検出を行うことができる。 Next, the flow of the rotation detection method of the rotary encoder in the digital camera of this embodiment will be described. As shown in FIG. 4, in the rotation detection method of the rotary encoder of the present embodiment, interrupt processing is performed for one of the phases that have detected the interrupt by detecting the interrupt of the A phase and the B phase, and both the A phase and the B phase are performed. Rotation detection is performed when an interrupt is generated in and the signal level of the other phase is the same as the signal level of the one phase. As a result, when detecting the rotation of the rotary encoder, it is possible to confirm the occurrence of interrupts for both the A phase and the B phase, so that more reliable rotation detection that is not affected by noise due to chattering or the like can be performed. can.

図5は本実施例のデジタルカメラにおけるロータリーエンコーダの回転検出方法を示すフローチャートである。図5のフローチャートの各ステップについて説明する。 FIG. 5 is a flowchart showing a rotation detection method of the rotary encoder in the digital camera of this embodiment. Each step of the flowchart of FIG. 5 will be described.

まず、制御装置40の割り込み検知部41がA相・B相のいずれかについて割り込みを検知した場合には、割り込み処理開始ステップS101において、A相・B相のうち割り込みのあった一方について割り込み処理を開始する。割り込みは、周辺回路30から出力された出力信号においてA相・B相の信号レベルのいずれかに立ち下がりがあったことににより検知される。信号レベルの立ち下がりは、矩形波として出力された出力信号における信号レベルのHからLへの変化とする。 First, when the interrupt detection unit 41 of the control device 40 detects an interrupt for either the A phase or the B phase, interrupt processing is performed for one of the A phase and the B phase in the interrupt processing start step S101. To start. The interrupt is detected because there is a drop in either the A-phase or B-phase signal level in the output signal output from the peripheral circuit 30. The falling edge of the signal level is the change of the signal level from H to L in the output signal output as a square wave.

そして、割り込み処理開始ステップS101において開始されたA相割り込み処理S102又はB相割り込み処理S103のいずれかを行う。A相割り込み処理S102又はB相割り込み処理S103が終了した場合には図5のフローチャートを終了する。 Then, either the A-phase interrupt process S102 or the B-phase interrupt process S103 started in the interrupt process start step S101 is performed. When the A-phase interrupt process S102 or the B-phase interrupt process S103 is completed, the flowchart of FIG. 5 is terminated.

次に、A相割り込み処理S102について、図6のフローチャートを用いて説明する。 Next, the A-phase interrupt process S102 will be described with reference to the flowchart of FIG.

まず、B相信号レベル取得ステップS201において、A相の他方の相であるB相の信号レベルを取得する。本実施例では、A相の信号レベルに立ち下がりがあった割り込み直後の時点におけるB相の信号レベルを取得する。これにより、A相割り込み処理S102の間にB相にノイズが発生して回転検出を誤ってしまうことを回避することができる。 First, in the B phase signal level acquisition step S201, the signal level of the B phase, which is the other phase of the A phase, is acquired. In this embodiment, the signal level of the B phase at the time immediately after the interrupt where the signal level of the A phase has a fall is acquired. As a result, it is possible to prevent noise from being generated in the B phase during the A phase interrupt processing S102 and erroneous rotation detection.

次に、B相割り込み検知フラグ取得ステップS202において、制御装置40の記憶部44に一時保持されているB相割り込み検知フラグを取得し、B相の割り込みの有無を判別する。B相割り込み検知フラグは、A相割り込み処理の前のB相の割り込みの有無を示すためのフラグである。 Next, in the B-phase interrupt detection flag acquisition step S202, the B-phase interrupt detection flag temporarily held in the storage unit 44 of the control device 40 is acquired, and the presence or absence of the B-phase interrupt is determined. The B-phase interrupt detection flag is a flag for indicating the presence / absence of a B-phase interrupt before the A-phase interrupt processing.

B相割り込み検知フラグ取得ステップS202においてB相の割り込みが有りと判別された場合には、B相検知フラグクリアステップS203においてB相検知フラグをクリアする。すなわち、B相検知フラグをクリアしてB相の割り込みを無しとする。これにより、A相割り込み処理S102の後にこれより前のB相の割り込みの履歴を持ち越さないようにすることができる。 When it is determined in the B-phase interrupt detection flag acquisition step S202 that there is a B-phase interrupt, the B-phase detection flag is cleared in the B-phase detection flag clear step S203. That is, the B-phase detection flag is cleared and the B-phase interrupt is eliminated. As a result, it is possible to prevent the history of B-phase interrupts before this after the A-phase interrupt processing S102 from being carried over.

A相割り込み処理S102の後にこれより前のB相の割り込みの履歴を持ち越してしまうと、チャタリングなどによりA相の信号レベルに連続して立ち下がりが発生した場合に、すべての立ち下がりについてA相割り込み処理S102における回転検出を行ってしまうおそれがある。B相割り込み検知フラグが有りの場合にこれをクリアすることで、A相割り込み処理S102の後に連続してA相の信号レベルに立ち下がりが発生したとしても、A相の割り込み処理S102における回転検出を1回のみとすることができる。 If the history of B-phase interrupts before this is carried over after the A-phase interrupt process S102, if a continuous fall occurs at the signal level of the A phase due to chattering or the like, the A-phase is all dropped. There is a possibility that rotation detection will be performed in the interrupt process S102. By clearing the B-phase interrupt detection flag when it is present, rotation detection in the A-phase interrupt process S102 occurs even if the signal level of the A-phase continuously drops after the A-phase interrupt process S102. Can be done only once.

次に、B相信号レベル判別ステップS204において、B相信号レベル取得ステップS201で取得したB相の信号レベルがHであるか否かを判別する。ここで、A相割り込み処理S102はA相の信号レベルの立ち下がりをA相の割り込みとして検知して開始されているので、A相割り込み処理S102におけるA相の信号レベルはLである。すなわち、B相信号レベル判別ステップS204において、B相の信号レベルがHであると判別された場合はA相とB相の信号レベルは異なるということと同等であり、B相の信号レベルがLであると判別された場合はA相とB相の信号レベルは同じであるということと同等である。 Next, in the B phase signal level determination step S204, it is determined whether or not the signal level of the B phase acquired in the B phase signal level acquisition step S201 is H. Here, since the A-phase interrupt process S102 is started by detecting the falling edge of the A-phase signal level as an A-phase interrupt, the A-phase signal level in the A-phase interrupt process S102 is L. That is, when it is determined in the B phase signal level determination step S204 that the signal level of the B phase is H, it is equivalent to the fact that the signal levels of the A phase and the B phase are different, and the signal level of the B phase is L. When it is determined that the signal level is the same, it is equivalent to that the signal levels of the A phase and the B phase are the same.

B相信号レベル判別ステップS204においてB相の信号レベルがLであると判別された場合には、CW回転検出ステップS205において正転(CW)方向に1段回転されたとして回転検出を行う。1段あたりの操作ダイヤル10の回転量(回転角度)はあらかじめ制御装置40に設定されており、これに回転検出された段数をかけ合わせることにより実際の操作ダイヤル10の回転量(回転角度)を求めることができる。 When it is determined in the B phase signal level determination step S204 that the signal level of the B phase is L, rotation detection is performed assuming that the signal level is rotated one step in the normal rotation (CW) direction in the CW rotation detection step S205. The rotation amount (rotation angle) of the operation dial 10 per step is set in the control device 40 in advance, and the actual rotation amount (rotation angle) of the operation dial 10 is obtained by multiplying this by the number of steps detected for rotation. You can ask.

A相割り込み処理S102では、これより前にB相の割り込みがあった場合にのみ回転検出を行うこととしているため、ロータリーエンコーダ20の回転検出は正転(CW)方向についてのみとしている。 In the A-phase interrupt process S102, rotation detection is performed only when a B-phase interrupt occurs before this, so rotation detection of the rotary encoder 20 is performed only in the forward rotation (CW) direction.

A相割り込み処理S102において回転検出を行わない場合には、A相割り込み検知フラグセットステップS206及びS208においてA相割り込み検知フラグをセットする。すなわち、A相検知フラグをセットしてA相の割り込みを有りとする。A相割り込み検知フラグは制御装置40の記憶部44に一時保持される。 When rotation detection is not performed in the A-phase interrupt process S102, the A-phase interrupt detection flag is set in the A-phase interrupt detection flag setting steps S206 and S208. That is, the A-phase detection flag is set to enable the A-phase interrupt. The A-phase interrupt detection flag is temporarily held in the storage unit 44 of the control device 40.

B相割り込み検知フラグ取得ステップS202でB相割り込み検知フラグが有りと判定され、B相信号レベル判別ステップS204でB相の信号レベルがHであると判定された場合には、A相割り込み検知フラグセットステップS206においてA相割り込み検知フラグをセットする。これは主に、ロータリーエンコーダ20の正転(CW)方向の回転時にB相割り込み処理S103においてB相割り込み検知フラグがセットされ、その後に反転(CCW)方向に回転した場合において、即座に反転(CCW)方向の回転検出を行うことができるようにするためである。 When it is determined that the B-phase interrupt detection flag is present in the B-phase interrupt detection flag acquisition step S202 and the B-phase signal level is determined to be H in the B-phase signal level determination step S204, the A-phase interrupt detection flag is determined. In the set step S206, the A-phase interrupt detection flag is set. This is mainly because the B-phase interrupt detection flag is set in the B-phase interrupt process S103 when the rotary encoder 20 rotates in the forward rotation (CW) direction, and then immediately inverted (when it rotates in the inversion (CCW) direction (CCW). This is to enable rotation detection in the CCW) direction.

B相割り込み検知フラグ取得ステップS202でB相割り込み検知フラグが無しと判定され、B相信号レベル判別ステップS207でB相の信号レベルがHであると判定された場合には、A相割り込み検知フラグセットステップS208において、A相割り込み検知フラグをセットする。これは主に、ロータリーエンコーダ20の反転(CCW)方向の回転時にA相割り込み検知フラグをセットしてA相の割り込みの履歴を残して反転(CCW)方向の回転検出を行うことができるようにするためである。 When it is determined in the B-phase interrupt detection flag acquisition step S202 that the B-phase interrupt detection flag is absent, and in the B-phase signal level determination step S207 it is determined that the B-phase signal level is H, the A-phase interrupt detection flag is determined. In the set step S208, the A-phase interrupt detection flag is set. This is mainly so that the rotation detection in the inversion (CCW) direction can be performed by setting the A-phase interrupt detection flag when the rotary encoder 20 rotates in the inversion (CCW) direction and leaving the history of the A-phase interrupt. To do.

また、B相割り込み検知フラグ取得ステップS202でB相割り込み検知フラグが無しと判定され、B相信号レベル判別ステップS207でB相の信号レベルがLであると判定された場合には、A相割り込み処理S102が開始されたきっかけとなったA相の信号レベルの立ち下がりは例えばノイズによるものであると判断してA相割り込み検知フラグをセットしない。B相割り込み検知フラグは無しと判定されているので、当然、ロータリーエンコーダ20の正転(CW)方向の回転検出も行わない。 If it is determined in the B-phase interrupt detection flag acquisition step S202 that the B-phase interrupt detection flag is absent, and if it is determined in the B-phase signal level determination step S207 that the B-phase signal level is L, the A-phase interrupt is interrupted. It is determined that the drop in the signal level of the A phase that triggered the start of the process S102 is due to noise, for example, and the A phase interrupt detection flag is not set. Since it is determined that there is no B-phase interrupt detection flag, naturally, the rotation detection of the rotary encoder 20 in the forward rotation (CW) direction is not performed.

A相割り込み処理S102が終了した後は、制御装置40の割り込み検知部41はA相・B相いずれかについて割り込みを検知するまで待機する。 After the A-phase interrupt process S102 is completed, the interrupt detection unit 41 of the control device 40 waits until an interrupt is detected for either the A-phase or the B-phase.

次に、B相割り込み処理S103について、図7のフローチャートを用いて説明する。 Next, the B-phase interrupt process S103 will be described with reference to the flowchart of FIG.

まず、A相信号レベル取得ステップS301において、B相の他方の相であるA相の信号レベルを取得する。本実施例では、B相の信号レベルに立ち下がりがあった割り込み直後の時点におけるA相の信号レベルを取得する。これにより、B相割り込み処理S103の間にA相にノイズが発生して回転検出を誤ってしまうことを回避することができる。 First, in the A phase signal level acquisition step S301, the signal level of the A phase, which is the other phase of the B phase, is acquired. In this embodiment, the signal level of the A phase at the time immediately after the interrupt where the signal level of the B phase has a fall is acquired. As a result, it is possible to prevent noise from being generated in the A phase during the B phase interrupt processing S103 and erroneous rotation detection.

次に、A相割り込み検知フラグ取得ステップS302において、制御装置40の記憶部44に一時保持されているA相割り込み検知フラグを取得し、A相の割り込みの有無を判別する。A相割り込み検知フラグは、B相割り込み処理の前のA相の割り込みの有無を示すためのフラグである。 Next, in the A-phase interrupt detection flag acquisition step S302, the A-phase interrupt detection flag temporarily held in the storage unit 44 of the control device 40 is acquired, and the presence or absence of the A-phase interrupt is determined. The A-phase interrupt detection flag is a flag for indicating the presence / absence of an A-phase interrupt before the B-phase interrupt processing.

A相割り込み検知フラグ取得ステップS302においてA相の割り込みが有りと判別された場合には、A相検知フラグクリアステップS303においてA相検知フラグをクリアする。すなわち、A相検知フラグをクリアしてA相の割り込みを無しとする。これにより、B相割り込み処理S103の後にこれより前のA相の割り込みの履歴を持ち越さないようにすることができる。 When it is determined in the A phase interrupt detection flag acquisition step S302 that there is an A phase interrupt, the A phase detection flag is cleared in the A phase detection flag clear step S303. That is, the A-phase detection flag is cleared and there is no A-phase interrupt. As a result, it is possible not to carry over the history of the A-phase interrupt before the B-phase interrupt process S103.

B相割り込み処理S103の後にこれより前のA相の割り込みの履歴を持ち越してしまうと、チャタリングなどによりB相の信号レベルに連続して立ち下がりが発生した場合に、すべての立ち下がりについてB相割り込み処理S103における回転検出を行ってしまうおそれがある。A相割り込み検知フラグが有りの場合にこれをクリアすることで、B相割り込み処理S103の後に連続してB相の信号レベルに立ち下がりが発生したとしても、B相の割り込み処理S103における回転検出を1回のみとすることができる。 If the history of the interrupts of the A phase before this is carried over after the B phase interrupt process S103, when the signal level of the B phase continuously falls due to chattering or the like, the B phase for all the falls. There is a possibility that rotation detection will be performed in the interrupt process S103. By clearing the A-phase interrupt detection flag when it is present, even if the B-phase signal level drops continuously after the B-phase interrupt process S103, rotation detection in the B-phase interrupt process S103 occurs. Can be done only once.

次に、A相信号レベル判別ステップS304において、A相信号レベル取得ステップS301で取得したA相の信号レベルがHであるか否かを判別する。ここで、B相割り込み処理S103はB相の信号レベルの立ち下がりをB相の割り込みとして検知して開始されているので、B相割り込み処理S103におけるB相の信号レベルはLである。すなわち、A相信号レベル判別ステップS304において、A相の信号レベルがHであると判別された場合はB相とA相の信号レベルは異なるということと同等であり、A相の信号レベルがLであると判別された場合はB相とA相の信号レベルは同じであるということと同等である。 Next, in the A phase signal level determination step S304, it is determined whether or not the signal level of the A phase acquired in the A phase signal level acquisition step S301 is H. Here, since the B-phase interrupt process S103 is started by detecting the falling edge of the B-phase signal level as a B-phase interrupt, the B-phase signal level in the B-phase interrupt process S103 is L. That is, when it is determined in the A phase signal level determination step S304 that the signal level of the A phase is H, it is equivalent to the fact that the signal levels of the B phase and the A phase are different, and the signal level of the A phase is L. When it is determined that the signal level is the same, it is equivalent to that the signal levels of the B phase and the A phase are the same.

A相信号レベル判別ステップS304においてA相の信号レベルがLであると判別された場合には、CCW回転検出ステップS305において反転(CCW)方向に1段回転されたとして回転検出を行う。1段あたりの操作ダイヤル10の回転量(回転角度)はあらかじめ制御装置40に設定されており、これに回転検出された段数をかけ合わせることにより実際の操作ダイヤル10の回転量(回転角度)を求めることができる。 When it is determined in the A phase signal level determination step S304 that the signal level of the A phase is L, rotation detection is performed assuming that the signal level is rotated by one step in the inversion (CCW) direction in the CCW rotation detection step S305. The rotation amount (rotation angle) of the operation dial 10 per step is set in the control device 40 in advance, and the actual rotation amount (rotation angle) of the operation dial 10 is obtained by multiplying this by the number of steps detected for rotation. You can ask.

B相割り込み処理S103では、これより前にA相の割り込みがあった場合にのみ回転検出を行うこととしているため、ロータリーエンコーダ20の回転検出は反転(CCW)方向についてのみとしている。 In the B-phase interrupt process S103, rotation detection is performed only when there is an A-phase interrupt before this, so rotation detection of the rotary encoder 20 is performed only in the inversion (CCW) direction.

B相割り込み処理S103において回転検出を行わない場合には、B相割り込み検知フラグセットステップS306及びS308においてB相割り込み検知フラグをセットする。すなわち、B相検知フラグをセットしてB相の割り込みを有りとする。B相割り込み検知フラグは制御装置40の記憶部44に一時保持される。 When rotation detection is not performed in the B-phase interrupt process S103, the B-phase interrupt detection flag is set in the B-phase interrupt detection flag setting steps S306 and S308. That is, the B-phase detection flag is set to enable the B-phase interrupt. The B-phase interrupt detection flag is temporarily held in the storage unit 44 of the control device 40.

A相割り込み検知フラグ取得ステップS302でA相割り込み検知フラグが有りと判定され、A相信号レベル判別ステップS304でA相の信号レベルがHであると判定された場合には、B相割り込み検知フラグセットステップS306においてB相割り込み検知フラグをセットする。これは主に、ロータリーエンコーダ20の反転(CCW)方向の回転時にA相割り込み処理S103においてA相割り込み検知フラグがセットされ、その後に正転(CW)方向に回転した場合において、即座に正転(CW)方向の回転検出を行うことができるようにするためである。 When it is determined in the A-phase interrupt detection flag acquisition step S302 that the A-phase interrupt detection flag is present and the A-phase signal level is determined to be H in the A-phase signal level determination step S304, the B-phase interrupt detection flag is determined. In the set step S306, the B-phase interrupt detection flag is set. This is mainly because the A-phase interrupt detection flag is set in the A-phase interrupt process S103 when the rotary encoder 20 is rotated in the reverse (CCW) direction, and then the rotary encoder 20 is immediately rotated in the forward rotation (CW) direction. This is to enable rotation detection in the (CW) direction.

A相割り込み検知フラグ取得ステップS302でA相割り込み検知フラグが無しと判定され、A相信号レベル判別ステップS307でA相の信号レベルがHであると判定された場合には、B相割り込み検知フラグセットステップS308において、B相割り込み検知フラグをセットする。これは主に、ロータリーエンコーダ20の正転(CW)方向の回転時にB相割り込み検知フラグをセットしてB相の割り込みの履歴を残して正転(CW)方向の回転検出を行うことができるようにするためである。 When it is determined in the A-phase interrupt detection flag acquisition step S302 that the A-phase interrupt detection flag is absent, and in the A-phase signal level determination step S307, it is determined that the A-phase signal level is H, the B-phase interrupt detection flag is determined. In the set step S308, the B-phase interrupt detection flag is set. This can mainly detect rotation in the forward rotation (CW) direction by setting a B-phase interrupt detection flag when the rotary encoder 20 rotates in the forward rotation (CW) direction and leaving a history of B-phase interrupts. To do so.

また、A相割り込み検知フラグ取得ステップS302でA相割り込み検知フラグが無しと判定され、A相信号レベル判別ステップS307でA相の信号レベルがLであると判定された場合には、B相割り込み処理S103が開始されたきっかけとなったB相の信号レベルの立ち下がりは例えばノイズによるものであると判断してB相割り込み検知フラグをセットしない。A相割り込み検知フラグは無しと判定されているので、当然、ロータリーエンコーダ20の反転(CCW)方向の回転検出も行わない。 If it is determined in the A-phase interrupt detection flag acquisition step S302 that the A-phase interrupt detection flag is absent, and if it is determined in the A-phase signal level determination step S307 that the A-phase signal level is L, the B-phase interrupt is interrupted. It is determined that the drop in the signal level of the B phase that triggered the start of the process S103 is due to noise, for example, and the B phase interrupt detection flag is not set. Since it is determined that there is no A-phase interrupt detection flag, naturally, the rotation of the rotary encoder 20 in the inversion (CCW) direction is not detected.

B相割り込み処理S103が終了した後は、制御装置40の割り込み検知部41はB相・A相いずれかについて割り込みを検知するまで待機する。 After the B-phase interrupt process S103 is completed, the interrupt detection unit 41 of the control device 40 waits until an interrupt is detected for either the B-phase or the A-phase.

次に、本実施例のロータリーエンコーダの回転検出方法において、チャタリングなどによる回転検出の誤検出を防止する様子について説明する。 Next, in the rotation detection method of the rotary encoder of this embodiment, a state of preventing erroneous detection of rotation detection due to chattering or the like will be described.

図8は、操作ダイヤル10の正転(CW)方向の回転時に、A相の信号レベルにチャタリングなどによるノイズが発生した例を示す。本実施例のデジタルカメラにおけるロータリーエンコーダの回転検出方法の流れで説明したとおり、A相の信号レベルの立ち下がりは正転(CW)方向の回転検出を行うためのA相割り込み処理S102を開始するきっかけとなる。 FIG. 8 shows an example in which noise due to chattering or the like is generated at the signal level of the A phase when the operation dial 10 is rotated in the forward rotation (CW) direction. As described in the flow of the rotation detection method of the rotary encoder in the digital camera of this embodiment, the falling edge of the signal level of the A phase starts the A phase interrupt process S102 for detecting the rotation in the forward rotation (CW) direction. It will be a trigger.

図8において、B相の信号レベルの立ち下がりD1の後にA相の信号レベルの立ち下がりD2が発生して正転(CW)方向の回転検出が行われた後に、ノイズN1がA相の信号レベルに発生した場合、B相割り込み検知フラグはクリアされており、B相の信号レベルはLであるので、ノイズN1はノイズとして判断されてA相割り込み検知フラグのセットも回転検出も行われない。 In FIG. 8, after the falling D1 of the signal level of the B phase is followed by the falling D2 of the signal level of the A phase and the rotation detection in the normal rotation (CW) direction is performed, the noise N1 is the signal of the A phase. When it occurs at the level, the B-phase interrupt detection flag is cleared and the B-phase signal level is L. Therefore, the noise N1 is judged as noise, and neither the A-phase interrupt detection flag is set nor the rotation detection is performed. ..

また、図8において、ノイズN2又はノイズN3がA相の信号レベルに発生した場合、B相割り込み検知フラグはクリアされており、B相の信号レベルはHであるので、A相割り込み検知フラグがセットされるが、正転(CW)方向の回転検出は行われない。A相割り込み検知フラグは、反転(CCW)方向の回転検出に用いられるものなので、正転(CW)方向の回転検出に影響を与えない。 Further, in FIG. 8, when noise N2 or noise N3 is generated at the signal level of the A phase, the B phase interrupt detection flag is cleared and the B phase signal level is H, so that the A phase interrupt detection flag is set. Although it is set, rotation detection in the forward rotation (CW) direction is not performed. Since the A-phase interrupt detection flag is used for rotation detection in the inversion (CCW) direction, it does not affect rotation detection in the forward rotation (CW) direction.

また、図8において、ノイズN4がA相の信号レベルに発生した場合、ノイズN4はA相の信号レベルの立ち下がりD2の前に発生するため、ノイズN4によるA相の信号レベルの立ち下がりを割り込みとして正転(CW)方向の回転検出が行われてしまう。しかしながら、その際にB相割り込み検知フラグはクリアされるため、ノイズN4の後に立ち下がりD2が発生しても、回転検出は1回のみ行われるので、正転(CW)方向の回転検出に影響を与えない。さらに、ノイズN4が連続して複数回発生した場合も、最初のノイズN4が発生した際にB相割り込み検知フラグはクリアされるため、正転(CW)方向の回転検出に影響を与えない。 Further, in FIG. 8, when the noise N4 is generated at the signal level of the A phase, the noise N4 is generated before the falling D2 of the signal level of the A phase, so that the falling of the signal level of the A phase due to the noise N4 is caused. Rotation detection in the forward rotation (CW) direction is performed as an interrupt. However, since the B-phase interrupt detection flag is cleared at that time, even if a falling D2 occurs after the noise N4, the rotation detection is performed only once, which affects the rotation detection in the normal rotation (CW) direction. Do not give. Further, even when the noise N4 is generated a plurality of times in succession, the B-phase interrupt detection flag is cleared when the first noise N4 is generated, so that the rotation detection in the forward rotation (CW) direction is not affected.

なお、本実施例では、A相・B相の信号レベルの立ち下がりをそれぞれの割り込みとしてA相・B相の割り込み処理を開始するきっかけとしていたが、これをA相・B相の信号レベルの立ち上がりとしても本発明と同じ効果を得ることができる。 In this embodiment, the fall of the signal level of the A phase and the B phase is used as an interrupt to start the interrupt processing of the A phase and the B phase, but this is the trigger for starting the interrupt processing of the A phase and the B phase. The same effect as that of the present invention can be obtained as a rising edge.

以上説明したように、本発明のロータリーエンコーダの回転検出方法によれば、高速回転するロータリーエンコーダの回転検出に対応するためにCPUなどの制御装置のサンプリング周波数を上げる必要がない。また、ロータリーエンコーダの非回転時においてもCPUなどの制御装置により常に所定の周期でA相・B相の信号レベルを監視する必要がない。これによりCPUなどの制御装置の演算負荷を抑えることができる。 As described above, according to the rotation detection method of the rotary encoder of the present invention, it is not necessary to increase the sampling frequency of the control device such as the CPU in order to support the rotation detection of the rotary encoder rotating at high speed. Further, even when the rotary encoder is not rotating, it is not necessary to constantly monitor the signal levels of the A phase and the B phase by a control device such as a CPU at a predetermined cycle. As a result, the calculation load of a control device such as a CPU can be suppressed.

また、チャタリングなどによりA相・B相の信号レベルにノイズが発生したとしても、A相・B相の両方に割り込みが有り、かつ、A相・B相の信号レベルが同一の場合にのみ回転検出を行うため、ロータリーエンコーダの回転検出に誤作動が発生するおそれがない。 Even if noise occurs at the signal levels of A phase and B phase due to chattering, etc., it rotates only when there is an interrupt in both A phase and B phase and the signal levels of A phase and B phase are the same. Since the detection is performed, there is no possibility that a malfunction will occur in the rotation detection of the rotary encoder.

10 操作ダイヤル
20 ロータリーエンコーダ
30 周辺回路
40 制御装置
41 割り込み検知部
42 A相割り込み処理部
43 B相割り込み処理部
44 記憶部
10 Operation dial 20 Rotary encoder 30 Peripheral circuit 40 Control device 41 Interrupt detection unit 42 A-phase interrupt processing unit 43 B-phase interrupt processing unit 44 Storage unit

Claims (4)

互いに位相がずれたA相・B相の二つの信号レベルに基づいて回転検出を行うロータリーエンコーダーの回転検出方法において、
A相又はB相の信号レベルの変化により割り込みを検知し、前記割り込みを検知した一方の相についての割り込み処理を開始し、
前記一方の相について開始した前記割り込み処理は、
前記一方の相とは異なる他方の相の信号レベルを取得する信号レベル取得ステップと、
前記他方の相の割り込み検知フラグの有無を取得する割り込み検知フラグ取得ステップと、
A相の信号レベルとB相の信号レベルが同一であり、かつ、前記他方の相の前記割り込み検知フラグが有りである場合に、ロータリーエンコーダーの回転検出を行う回転検出ステップとを有することを特徴とするロータリーエンコーダーの回転検出方法。
In the rotation detection method of a rotary encoder that detects rotation based on two signal levels, A phase and B phase, which are out of phase with each other.
An interrupt is detected by a change in the signal level of the A phase or the B phase, and interrupt processing for one of the detected phases is started.
The interrupt processing started for one of the phases
A signal level acquisition step for acquiring the signal level of the other phase different from the one phase,
The interrupt detection flag acquisition step for acquiring the presence / absence of the interrupt detection flag in the other phase, and
It is characterized by having a rotation detection step for detecting the rotation of the rotary encoder when the signal level of the A phase and the signal level of the B phase are the same and the interrupt detection flag of the other phase is present. How to detect the rotation of the rotary encoder.
A相又はB相の信号レベルの変化により割り込みを検知し、開始された前記割り込みを検知した一方の相についての割り込み処理において、
前記割り込み検知フラグ取得ステップで取得した前記一方の相とは異なる他方の相の割り込み検知フラグが有りである場合には、前記他方の相の前記割り込み検知フラグをクリアする割り込み検知フラグクリアステップをさらに有することを特徴とする請求項1に記載のロータリーエンコーダーの回転検出方法。
In the interrupt processing for one phase in which an interrupt is detected by a change in the signal level of the A phase or the B phase and the started interrupt is detected.
If there is an interrupt detection flag of the other phase different from the one phase acquired in the interrupt detection flag acquisition step, an interrupt detection flag clear step for clearing the interrupt detection flag of the other phase is further added. The rotation detection method for a rotary encoder according to claim 1, wherein the rotary encoder has.
A相又はB相の信号レベルの変化により割り込みを検知し、開始された前記割り込みを検知した一方の相についての割り込み処理において、
前記割り込みを検知した前記一方の相の信号レベルと前記信号レベル取得ステップにおいて取得した前記一方の相とは異なる他方の相の信号レベルとが異なる場合には、前記一方の相の割り込み検知フラグを有りとする割り込み検知フラグセットステップをさらに有することを特徴とする請求項1又は請求項2に記載のロータリーエンコーダーの回転検出方法。
In the interrupt processing for one phase in which an interrupt is detected by a change in the signal level of the A phase or the B phase and the started interrupt is detected.
If the signal level of the one phase that detected the interrupt is different from the signal level of the other phase that is different from the one phase acquired in the signal level acquisition step, the interrupt detection flag of the one phase is set. The rotation detection method for a rotary encoder according to claim 1 or 2, further comprising an interrupt detection flag set step to be present.
A相又はB相の信号レベルの変化により割り込みを検知し、開始された前記割り込みを検知した一方の相についての割り込み処理において、
前記回転検出ステップで回転検出される回転方向は前記一方の相とは異なる他方の相の割り込み処理の回転検出ステップで回転検出される回転方向と互いに反対向きであることを特徴とする請求項1乃至請求項3のいずれかに記載のロータリーエンコーダーの回転検出方法。
In the interrupt processing for one phase in which an interrupt is detected by a change in the signal level of the A phase or the B phase and the started interrupt is detected.
Claim 1 is characterized in that the rotation direction detected in the rotation detection step is opposite to the rotation direction detected in the rotation detection step of the interrupt processing of the other phase different from the one phase. The method for detecting rotation of a rotary encoder according to any one of claims 3.
JP2020173490A 2020-10-14 2020-10-14 How to detect rotation of a rotary encoder Active JP7468901B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2020173490A JP7468901B2 (en) 2020-10-14 2020-10-14 How to detect rotation of a rotary encoder

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2020173490A JP7468901B2 (en) 2020-10-14 2020-10-14 How to detect rotation of a rotary encoder

Publications (2)

Publication Number Publication Date
JP2022064701A true JP2022064701A (en) 2022-04-26
JP7468901B2 JP7468901B2 (en) 2024-04-16

Family

ID=81385722

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2020173490A Active JP7468901B2 (en) 2020-10-14 2020-10-14 How to detect rotation of a rotary encoder

Country Status (1)

Country Link
JP (1) JP7468901B2 (en)

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP5580185B2 (en) 2010-12-20 2014-08-27 スタンレー電気株式会社 Rotary encoder signal processing method

Also Published As

Publication number Publication date
JP7468901B2 (en) 2024-04-16

Similar Documents

Publication Publication Date Title
JP5111200B2 (en) Multi-turn type absolute encoder
EP3255385B1 (en) A controller to reduce integral non-linearity errors of a magnetic rotary encoder
WO1991000499A1 (en) Encoder
JP7468901B2 (en) How to detect rotation of a rotary encoder
US9083272B2 (en) Motor control circuit, motor control system and motor control method
JP2011089935A (en) Resolver abnormality detector
JP5870977B2 (en) Rotation angle detection system
JP2011027628A (en) Rotation angle detection device of stepping motor
JP2001249154A (en) Disconnection detecting device for encoder and method for disconnection detection
JP4882955B2 (en) Rotation detector
JP3315780B2 (en) Noise removal device and period measurement device
JP2009153335A (en) Brushless servo motor
JP2004037246A (en) Bit error detection of encoder sensing position data and presuming method
JP5195739B2 (en) Rotation detection device signal processing device
US7459876B2 (en) Motors and control methods thereof
CN112290847B (en) Rotation angle estimation device
JP2006177733A (en) Failure detecting apparatus of rotation speed detector
JPH04285815A (en) Position counter circuit of rotary encoder
JP3090069B2 (en) Control device
JP2005017000A (en) Encoder
JP5939851B2 (en) Photoelectric sensor and photoelectric sensor failure detection method
JP2010014578A (en) Signal processing circuit of encoder
JP2016080547A (en) Position controller
KR940022059A (en) Encoder Output Error Compensation Method
JPH11308887A (en) Disk drive system

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20230517

A977 Report on retrieval

Free format text: JAPANESE INTERMEDIATE CODE: A971007

Effective date: 20231115

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20231212

A521 Request for written amendment filed

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20240205

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: 20240326

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20240328