Speed detecting apparatus
BACKGROUND OF THE INVENTION 
     1. FIELD OF THE INVENTION 
     This invention relates to a speed detecting apparatus suitable for use for controlling the speed of a rotating body or a moving body in a digital manner. 
     2. DESCRIPTION OF THE PRIOR ART 
     For the detection of the rotational speed of, for example, an electric motor as a digital signal, an encoder is generally used which generates a pulse signal whose frequency is proportional to the rotational speed of the motor. The encoder generates one pulse each time it rotates by an amount corresponding to 1/m (m: a large integer) of one complete revolution. A train of such pulses generated from the encoder is processed to detect the rotational speed of the motor. According to a known method as, for example, disclosed in JP-A-57-144465 (corresponding to U.S. Pat. No. 4,584,528), the rotational speed of a motor is detected with high accuracy by counting the number of pulses generated from an encoder mechanically coupled to the motor, and measuring the time in synchronous relation with the counting operation counting the number of the pulses. However, this method has the problem that speed detection is impossible in a low speed range where the output pulse frequency of the encoder is very low. A method to deal with such a problem is reported in the Society for the Research of Industrial Power Applications of the Institute of Electrical Engineers of Japan, IA-85-11 (1985). According to the reported method, an encoder generating a sine-wave signal is used, and the rotational speed of an associated motor is detected by detecting the rotational phase of the encoder from the analog output signal of the encoder and computing the rotational speed on the basis of a variation of the rotational phase. Although the latter method is advantageous in that the rotational speed can be detected with high resolution even in a low speed range, difficulty is encountered in high-accuracy speed detection due to, for example, distortion of the waveform of the sine-wave signal. Thus, the former method is defective from the aspect of the resolution in a low speed range, and the latter method is defective in the lack of consideration of the accuracy of speed detection. It has therefore been difficult to detect rotational speed with high resolution and high accuracy over a wide speed range, according to the prior art methods. 
     SUMMARY OF THE INVENTION 
     It is a primary object of the present invention to provide a speed detecting apparatus which can detect the speed of, for example, a rotating body with high resolution and high accuracy over a wide speed range. 
     The speed detecting apparatus according to the present invention is featured in that it uses an encoder which generates a sine-wave signal whose frequency is proportional to the rotational speed of a rotating body and that, in a high speed range, the rotating speed of the rotating body is detected on the basis of the number of occurrences of zero volts (zero-crossing) in the waveform of the sine-wave signal within substantially a predetermined period of time and the time interval between the first and last zero-crossing points, but, in a low speed range, the rotating speed of the rotating body is detected on the basis of the difference between the phase angle of the sine-wave signal detected at present time in relation to the zero-crossing point of the waveform of the sine-wave signal and the phase angle detected at a time earlier by a predetermined period of time than the present time. 
    
    
     BRIEF DESCRIPTION OF THE DRAWINGS 
     FIG. 1 is a block diagram showing the structure of an embodiment of the speed detecting apparatus of the present invention. 
     FIGS. 2 and 3 are time charts illustrating the operation of the apparatus shown in FIG. 1. 
     FIG. 4 is a flow chart showing the steps of processing by the microcomputer shown in FIG. 1. 
    
    
     DESCRIPTION OF THE PREFERRED EMBODIMENTS 
     FIG. 1 is a block diagram showing the structure of the embodiment of the speed detecting apparatus according to the present invention. 
     Referring to FIG. 1, an encoder 1 mechanically coupled to an electric motor (not shown) generates sine-wave signals A and B, having a phase difference of 90° therebetween, when it rotates by an amount corresponding to 1/m (m: a large integer) of one complete encoder revolution. The output signals A and B of the encoder 1 are applied to comparators 2 and 3 where the signals A and B are compared with zero volts and are converted into squarewave signals AS and BS respectively. It will be seen in FIGS. 2 and 3 that the positive half wave of the signals A and B corresponds to the &#34;1&#34; level of the signals AS and BS. The sine-wave signal A is applied also to an A/D converter 4. The square-wave signal AS is applied to a pulse forming circuit 5. In synchronism with the leading edge and trailing edge of the waveform of the square-wave signal AS, the pulse forming circuit 5 generates zero-crossing pulses AP. This zero-crossing pulse signal AP is applied to a reversible counter 7 through a normal-reverse change-over circuit 6. In response to a direction decision signal RD applied from a direction decision circuit 11, described later, the normal-reverse change-over circuit 6 changes over the polarity of the zero-crossing pulse signal AP. More precisely, the count of the reversible counter 7 is incremented when the encoder 1 rotates in the normal direction, but the count of the reversible counter 7 is decremented when the encoder 1 rotates in the reverse direction. The zero-crossing pulse signal AP is applied also to a set terminal SET of a register 8. As soon as a pulse of the zero-crossing pulse signal AP is applied to the set terminal SET of the register 8, the count of a clock counter 9 is transferred to and registered in the register 8. A clock pulse generator 10 generates clock pulses at a predetermined frequency, and the clock counter 9 counts these clock pulses. The frequency of the clock pulses generated from the clock pulse generator 10 is selected to be higher, by one decimal place or more, than the maximum operating frequency of the encoder 1. In the meantime, the square-wave signals AS and BS are applied to a direction decision circuit 11 and a quadrant decision circuit 12. The operation of the direction decision circuit 11, which discriminates the direction of rotation of the encoder 1, is such that it decides that the encoder 1 is rotating in the normal direction when the phase of the square-wave signal AS lags that of the square-wave signal BS, but it decides that the encoder 1 is rotating in the reverse direction when the phase of the square-wave signal AS leads that of the square-wave signal BS. The phase relationship between the square-wave signals AS and BS can be identified, for example, by reference to the level of the square-wave signal BS at the rise time of the square-wave signal AS. Depending on the relative levels of the square-wave signals AS and BS, the quadrant decision circuit 12 decides the quadrant (0-π/2, π/2-π, π-3π/2, 3π/2-2π) of the square-wave signal As and generates a 2-bit quadrant decision signal D. That is, the 2-bit quadrant decision output signal D of the quadrant decision circuit 12 represents 0 (the first quadrant) when both the square-wave signals AS and BS are in their &#34;1&#34; level; 1 (the second quadrant) when the square-wave signal AS only is in its &#34;1&#34; level; 2 (the third quadrant) when both the square-wave signals AS and BS are in their &#34;0&#34; level; and 3 (the fourth quadrant) when the square-wave signal BS only is in its &#34;1&#34; level. This 2-bit quadrant decision signal D is used to select a corresponding area of a memory 13 which stores a table of values of four kinds of inverse sine functions (sin -1 ). The combination of the A/D converter 4, the quadrant decision circuit 12 and the memory 13 constitutes a phase angle detecting circuit 15 detecting the phase angle θ of the sine-wave signal A. A microcomputer 14 fetches the contents of the reversible counter 7, register 8 and memory 13 and executes necessary computation for speed detection at an interval of a predetermined period of time. 
     The operation of the speed detecting apparatus of the quadrant invention will now be described in detail with reference to FIGS. 2 to 4. FIG. 2 is an operation time chart in a high speed range, and FIG. 3 is an operation time chart in a low speed range. 
     With the rotation of the encoder 1, the sine-wave signals A and B, having the phase difference of 90° therebetween as shown in FIGS. 2 and 3, are generated. These sine-wave signals A and B are applied to the comparators 2 and 3 where the signals A and B are converted into the square-wave signals AS and BS having their &#34;1&#34; level corresponding to the positive half wave of the signals A and B respectively. In synchronism with the leading edge and trailing edge of the squarewave signal AS, the pulse forming circuit 5 generates the zero-crossing pulses AP. This zero-cross pulse signal AP is applied to the reversible counter 7 to increment the count of the reversible counter 7 when the encoder 1 is rotating in the normal direction, but to decrement the count of the reversible counter 7 when the encoder 1 is rotating in the reverse direction. Thus, the count output C of the reversible counter 7 is indicative of the angular position of rotation of the encoder 1. Suppose, for example, that the sine-wave signals A and B are generated from the encoder 1 each time the encoder 1 rotates by an amount corresponding to 1/m of one complete encoder revolution. In such a case, the amount of rotation of the encoder 1 is C(n)/2m, when the count output C of the reversible counter 7 is C(n). 
     In the meantime, the zero-crossing pulse signal AP is applied to the register 8 as a set signal. The register 8 stores the count of the clock counter 9 at the moment of application of a pulse of the zero-cross pulse signal AP to the register 8. Since the clock counter 9 counts the clock pulses having the predetermined frequency, the count output of the clock counter 9 is indicative of time. Thus, the output T of the register 8 changes stepwise with time as shown in FIGS. 2 and 3, and the amount of change, corresponding to one step, of the output T of the register 8 indicates the period of time required for the encoder 1 to rotate by the amount corresponding to 1/2m of one complete encoder revolution. 
     On the other hand, the direction decision circuit 11 discriminates the direction of rotation of the encoder 1 on the basis of the relative levels of the square-wave signals AS and BS. In the case shown in FIGS. 2 and 3, the phase of the square-wave signal BA leads that of the square-wave signal AS. Therefore, the direction decision circuit 11 decides that the encoder 1 is rotating in the normal direction, and the direction decision signal RD of &#34;1&#34; level appears from the direction decision circuit 11. The phase angle detecting circuit 15, constituted by the combination of the quadrant decision circuit 12, the A/D converter 4 and the memory 13, detects the phase angle θ of the sine-wave signal A. The A/D converter 4 converts the analog sine-wave signal A into a corresponding digital signal. The digital output signal from the A/D converter 4 is converted into a corresponding phase angle θ in the memory 13 which stores the table of the values of the four kinds of inverse sine functions. Consider now that the phase angle θ of the sine-wave signal A is in the range of o to π radians. In this case, there are two different phases θ and (π-θ) of the same value. The output signal (the quadrant decision signal) D of the quadrant decision circuit 12 is utilized for discriminating between these two different phase so as to find out the correct phase from the table of inverse sine functions. As described already, the memory 13 stores a table of the values of the four kinds of inverse sine functions. In the memory 13, the table portion, corresponding to two kinds of inverse sine functions among the four, stores the phase range of 0 to π radians divided into N bits. When the quadrant decision signal D is indicative of 0, the function table portion corresponding to the phase range of 0 to π/2 radians in the memory 13 is retrieved. Similarly, when the quadrant decision signal D is indicative of 1, the function table portion corresponding to the phase range of π/2 to π radians in the memory 13 is retrieved. Therefore, a phase angle signal indicative of a phase angle θ as, for example, shown in FIG. 3 appears from the memory 13. 
     The microcomputer 14 fetches the outputs of the reversible counter 7, register 8, direction decision circuit 11 and memory 13 and executes a processing sequence as shown in the flow chart of FIG. 4 at an interval of a predetermined period Tc. The length of time of this predetermined period Tc is about 5 to 10 ms. 
     In step 20 in FIG. 4, the microcomputer 14 fetches the output C(n) of the reversible counter 7, the output T(n) of the register 8, the output θ(n) of the memory 13 and the output RD of the direction decision circuit 11. The symbol n in the outputs C(n), T(n) and θ(n) indicates an n-th time of data detection. In step 22, the difference ΔC between the present count C(n) and the previous count C(n-1) of the reversible counter 7 is computed. As shown in FIG. 2, this difference ΔC indicates the amount of change of the angular position of rotation of the encoder 1 during a period Ta of from time (i-1) to time i. The amount of change of the angular position of rotation of the encoder 1 during the period Ta is substantially equal to that during the period Tc. Therefore, the difference ΔC is generally indicative of the speed change of the encoder 1. When the absolute value of the difference ΔC is larger than a predetermined setting C 0 , it indicates that the encoder 1 is rotating at a high speed. In step 24, judgment is made as to whether or not the absolute value of the difference ΔC is larger than the setting C 0 , and, when the result of judgment is YES, the step 24 is followed by step 30. In this step 30, the different Ta between the present output T(n) and the previous output T(n-1) of the register 8 is computed. As seen in FIG. 2, the data T registered in the register 8 is held at the same level until the next zero-crossing pulse AP is applied to the register 8. Therefore, the data output of the register 8 fetched at the n-th time of data detection indicates the data of the register 8 detected at time i in FIG. 2. That is, the register 8 stores the data of the time at the moment of appearance of the zero-crossing point of the waveform of the sine-wave signal A generated from the encoder 1. Therefore, in step 32, the rotation speed N D  of the encoder 1 can be accurately computed according to the equation N D  =k 2  |ΔC|/T a , where |ΔC| is the absolute value of the distance of angular rotation of the encoder 1 during the period Ta, and k 2  is a constant. 
     On the other hand, when the result of judgment in the step 24 is NO, the rotation speed N D  of the encoder 1 is low, and the sine-wave signal A has a waveform as shown in FIG. 3. In this case, the phase angle θ(n) detected in the step 20 and the previously detected phase angle θ(n-1) are used to compute, in step 26, the value Δθ of the phase angle θ, which has changed within the predetermined period of measurement Tc, according to the equation Δθ=θ(n)-θ(n-1)+2 N . In the equation shown in the step 26, 180° of the sine-wave signal A generated from the encoder 1 is represented by a digital value designated by 2 N . On the other hand, when the distance ΔC of angular rotation of the encoder 1 exceeds the value corresponding to 180°, its absolute value |ΔC| is multiplied by the weight 2 N , and the resultant value is added to the phase difference Δθ. Since the period Tc is constant, the detected rotation speed N D  of the encoder 1 is proportional to (|ΔC|·2 N  +Δθ). In step 28, the rotational speed N D  of the encoder 1 is computed according to the equation N D  =k 1  (|ΔC|·2 N  +Δθ), where k 1  is a constant. 
     The constant Co used in the step 24 is preferably determined as described now. In the application of the present invention to an electric motor, it is required to ensure the accuracy of control at speeds higher than a certain value, but it is merely required to retain the rotation of the motor at speeds lower than that value. Therefore, according to a first method, the constant Co is selected to determine the lowest rotational speed at which the accuracy of control is ensured. According to a second method, the result of judgment made in the step 24 is always YES so that the processing in the steps 30 and 32 can be necessarily executed. For this purpose, the constant Co is preferably selected to be Co=0. When the constant Co is so selected, the processing in the steps 30 and 32 is necessarily executed to detect the rotational speed N D  of the encoder 1 when the zero-crossing point of the waveform of the sine-wave A appears at least once within the detection period Tc. 
     It will be seen from the above manner of speed detection according to the present invention that, when the rotational speed of the encoder 1 is high, the accurate angular position of rotation of the encoder 1 is measured on the basis of zero-crossing points of the waveform of the sine-wave signal A, and the period of time within which the above angular rotation of the encoder 1 has occurred is measured in synchronism with the zero-crossing points of the waveform of the sine-wave signal A, thereby computing the rotational speed of the encoder 1. Therefore, the rotational speed of the encoder 1 can be detected with high accuracy. It will be also seen that, when the rotational speed of the encoder 1 is low, the phase angle θ detected within one cycle of the sine-wave signal A is used for the computation of the rotational speed of the encoder 1. Therefore, even at a very low speed where no zero-crossing pulse AP may appear within the measuring period Tc, the rotation speed of the encoder 1 can be detected with improved resolution. 
     In an encoder commonly used for the purpose of speed detection of a motor, a zero-cross point of a sine-wave signal generated from the encoder coincides with a corresponding angular position of rotation of the encoder with an accuracy of about ±5%. Also, any error attributable to non-coincidence therebetween is rendered null when the encoder makes one complete revolution. Therefore, when the zero-crossing point is counted a plurality of times (ΔC times), an error of the angular position of rotation of the encoder attributable to the aforementioned non-coincidence is decreased to about ±5/ΔC%. Thus, the rotational speed in a high speed range can be detected with high accuracy by accurately measuring the number of times ΔC of appearance of the zero-crossing points, accurately measuring the period Ta of measurement of ΔC in synchronism with the zero-crossing points, and then computing the value of ΔC/Ta. On the other hand, in a low speed range where high accuracy of speed detection is not so required, the rotational speed can be detected with high resolution by measuring the number of times ΔC of appearance of the zero-cross points within a predetermined period Tc, measuring a corresponding variation Δθ (rad) of the rotational phase angle within that period Tc, and computing (k 1  ·ΔC+Δθ). 
     It will be understood from the foregoing detailed description of the present invention that, when a motor is rotating at a high speed, the zero-crossing point of a sine-wave signal generated from an associated encoder is noted for the detection of the rotational speed of the motor, while when the motor is rotating at a low speed, the phase angle of the sine-wave signal generated from the encoder is noted for the detection of rotational speed of the motor. Therefore, the rotational speed of the motor can be detected with high accuracy and high resolution over a wide speed range.