A kind of rotary encoder speed-measuring method and system thereof
Technical field
The present invention relates to speed detection method and system thereof, particularly a kind of rotary encoder side of testing the speed
Method and system thereof.
Background technology
In the operation and use of industrial inkjet printing device, printer needs to connect a kind of increment type
Rotary encoder, obtain the movement velocity of print media (such as paper, hereinafter referred to as medium).
Encoder has two ways to be connected with medium motion mechanism, a kind of driving being and drive medium motion
Axle axially connects together;Another kind is to make this driven pulley direct encoder one driven pulley of installation
Belt contacts with conveying medium.By the output number of pulses of statistical coding device, calculate and print Jie
The movement velocity of matter.Due to high-quality, high resolution printed needs, the accurate survey to encoder
Speed proposes the highest requirement.
In the working environment of printing device, it is desirable to the movement velocity in print procedure medium is even
Speed, without vibration or external force, the impact etc. of encoder rotary shaft is disturbed, then encoder
By the square-wave pulse signal of output fixed cycle, tachometer circuit is by the pulse in statistics certain time
Takeoff medium motion speed, its result will be also at the uniform velocity.
Owing to, in actual print job environment, the encoder at the uniform velocity rotated is easily subject to its place
The vibration of mechanical platform or directly act on the external impact force of rotary shaft of encoder.Above
Either way it is likely to result in the shake of code-disc, and gives the normal work of code-disc and photoelectric detective circuit
Bring interference.When encoder is interfered, the pulse signal of its output arises that shake, this
Time encoder output pulse signal be no longer the square wave of fixed cycle.By the volume containing Vibrating pulse
Code device signal is input in tachometer circuit, and tachometer circuit, it is possible that erroneous judgement and mistake in computation, makes
High-quality, high resolution printed can not complete.
Summary of the invention
The technical problem that present invention mainly solves be to provide a kind of rotary encoder speed-measuring method and
System, by the pulse signal numeral of the rotary encoder of collection being represented, and believes this numeral
Number representing with the standard digital of pre-stored and to compare, sieve removes not mate digital signal, eliminate due to
The erroneous judgement that mechanical shaking causes.
For solving above-mentioned technical problem, the technical scheme that the present invention uses is: provide one rotation
Turn encoder speed-measuring method, comprise the steps:
Receive the pulse signal of rotary encoder under current state, and this pulse signal is converted into works as
Front numeral represents;
Described Contemporary Digital representing, the standard digital with pre-stored represents compare, according to comparing
Result decides whether to calculate the velocity of rotation of rotary encoder under current state;
If described Contemporary Digital represents that the standard digital with storage represents when the match is successful, calculate current
The velocity of rotation of rotary encoder under state;If described Contemporary Digital represents and the standard digital of storage
When representing that it fails to match, the most do not calculate the velocity of rotation of rotary encoder under current state.
Further, two pulse signals of described rotary encoder output, in order to confirm described rotation
Turn the rotation direction of encoder.
Further, described confirmation rotary encoder rotation direction is particularly as follows: utilize said two
The phase relation (advanced or delayed) of pulse signal represents the rotation different with confirming rotary encoder
Direction;
Further, described rotary encoder rotation direction is confirmed by phase discriminator.
Further, two standards of rotary encoder output pulse signal under definition steady statue
Numeral represents, said two standard digital represents two pulse signals corresponding to rotary encoder.
Further, record described Contemporary Digital and represent that the standard digital with storage represents and mates into
The number of times of merit, when the described number of times that the match is successful reaches pre-set threshold number of times, calculates described rotation
Turn encoder velocity of rotation.
Further, described Contemporary Digital represents that the standard digital with storage represents that the match is successful
Time, the record matching successful persistent period;
Described Contemporary Digital represents that the standard digital with storage represents when it fails to match, and record matching loses
The persistent period lost.
Further, by two timers record respectively the described persistent period that the match is successful and
The persistent period that it fails to match.
Further, reading the described persistent period that the match is successful, by this, described the match is successful
Persistent period is as the parameter calculating rotary encoder velocity of rotation.
Further, the described number of times that it fails to match of record;
By recording, in comparing different time, the number of times that it fails to match, it is determined that residing for rotary encoder
The good and bad degree of working environment.
For solving above-mentioned technical problem, the present invention also provides for a kind of rotary encoder velocity-measuring system, bag
Include:
Rotary encoder, being used for mechanical rotation condition conversion is pulse signal;
Memorizer, the first depositor is rotary encoder output pulse signal under stable storage state
Standard digital represent.Second depositor is used for storing rotary encoder run duration current number word table
Show and represent, with standard digital, the total degree that it fails to match;
Doubler, for receiving the pulse signal of rotary encoder under current state, and by this pulse
Signal is converted into Contemporary Digital and represents;
The first enumerator in impulse scaler, is used for recording rotary encoder output signal through four times
Signal after frequency process comprises the number of pulses that the match is successful;
The second enumerator in impulse scaler, is used for recording each continuous mode it fails to match period
The number of times that it fails to match;
Comparator, compares for described Contemporary Digital representing, the standard digital with storage represents
Relatively, and according to comparative result decide whether to calculate the velocity of rotation of rotary encoder under current state;
Computing unit, for calculating the velocity of rotation of rotary encoder;
If described Contemporary Digital represents that the standard digital with storage represents when the match is successful, computing unit
Calculate the velocity of rotation of rotary encoder under current state;If described Contemporary Digital represents and storage
Standard digital represents when it fails to match, and computing unit does not calculate turning of rotary encoder under current state
Dynamic speed.
Further, record described Contemporary Digital and represent that the standard digital with storage represents and mates into
The number of times of merit, when the described number of times that the match is successful reaches pre-set threshold number of times, calculates described rotation
Turn encoder velocity of rotation.
Further, described Contemporary Digital represents that the standard digital with storage represents that the match is successful
Time, the record matching successful persistent period;
Described Contemporary Digital represents that the standard digital with storage represents when it fails to match, and record matching loses
The persistent period lost.
The invention has the beneficial effects as follows: the pulse signal numeral of the rotary encoder by gathering
Represent, and the standard digital of this digital signal with pre-stored is represented compare, sieve and go not mate
Digital signal, can eliminate the erroneous judgement caused due to mechanical shaking.
Accompanying drawing explanation
Fig. 1 is overall flow figure of the present invention;
Fig. 2 is rotary encoder of the present invention output pulse signal schematic diagram when rotating forward;
Output pulse signal schematic diagram when Fig. 3 is rotary encoder of the present invention reverse rotation;
Fig. 4 is that present system connects block diagram.
Detailed description of the invention
For the ease of understanding the present invention, below in conjunction with the accompanying drawings and specific embodiment, the present invention is carried out
More detailed description.It should be noted that when element is expressed " being fixed on " another element,
It can be directly on another element or can there is one or more unit placed in the middle therebetween
Part.When an element is expressed " connection " another element, and it can be directly to another
Individual element or one or more element placed in the middle can be there is therebetween.This specification is used
Term " vertical ", " level ", "left", "right" and similar statement simply to illustrate that
Purpose.
Unless otherwise defined, this specification is used all of technology and scientific terminology with belong to this
The implication that the those skilled in the art of invention are generally understood that is identical.In the present invention in this specification
Term used in the description be intended merely to describe specific embodiment purpose, be not intended to
Limit the present invention.The term "and/or" that this specification is used includes one or more relevant
Arbitrary and all of combination of Listed Items.
The present invention is described in detail with embodiment below in conjunction with the accompanying drawings.
Embodiment 1
Refer to Fig. 1, a kind of rotary encoder speed-measuring method, comprise the steps:
Under S1, definition steady statue, the standard digital of rotary encoder output pulse signal represents, and
Store this standard digital to represent.When medium rotation followed by rotary encoder, two pulses can be exported
Signal, respectively A phase pulse signal and B phase pulse signal.In stable state, rotate and compile
Code device A phase pulse signal advanced B phase pulse signal 1/4 cycle in the case of rotating forward, such as Fig. 2
Shown in.FPGA (field programmable gate array) circuit is by the rising of sequence detection A phase pulse signal
Edge, the rising edge of B phase pulse signal, the trailing edge of A phase pulse signal and B phase pulse signal
Trailing edge.Undisturbed ideally at rotary encoder, in continuous 4 1/4 cycles
In, the logic level values that FPGA circuitry is successively read from the two of rotary encoder input pins
It is respectively " 10 ", " 11 ", " 01 ", " 00 ", by shifting function, by the number of these 4 2bit
Value is placed in first depositor of a 8bit, then the numerical value of this byte is
" 10110100 ", are converted into hexadecimal equal to 0xB4.In the case of encoder inverts, B
Phase pulse signal advanced A phase pulse signal 1/4 cycle, as it is shown on figure 3, FPGA circuitry will order
The detection rising edge of B phase pulse signal, the rising edge of A phase pulse signal, B phase pulse signal
Trailing edge and the trailing edge of A phase pulse signal.Under the undisturbed stable case of encoder,
Within continuous 4 1/4 cycles, the numerical value that FPGA reads from two input pins is respectively
" 01 ", " 11 ", " 10 ", " 00 ", by shifting function, place the numerical value of these 4 2bit
In first depositor of a 8bit, the numerical value forming a byte is " 01111000 ", changes
It is counted as hexadecimal equal to 0x78.
The pulse signal of rotary encoder under S2, reception current state, and this pulse signal is converted
Represent for Contemporary Digital.When medium rotation followed by rotary encoder, two pulse signals can be exported,
It is respectively A phase pulse signal and B phase pulse signal.Stable and easily obtain in order to obtain one
Pulse signal, needs A phase pulse signal and B phase pulse signal are carried out process of frequency multiplication, uses four
A phase pulse signal is processed by times doubler with B phase pulse signal, the A phase arteries and veins after processing
Rush signal to be displaced in comparator with B phase pulse signal, comparator above-mentioned pulse signal is carried out
Process.During four times of doubler work, rotate forward the situation of reversion according to encoder, by each 1/4 week
The A phase pulse signal level value read in phase and B phase pulse signal level value one 2bit of composition
Numerical value, compare with the preferable 2bit value in the 1/4 corresponding cycle, if equal,
Then the first enumerator is added one by four times of doubler, when this first enumerator reaches maximum
(0xffffffff), time, it is zeroed out then restarting counting.
S3, described Contemporary Digital is represented, and the standard digital with storage represents and compares, according to than
Relatively result decides whether to calculate the velocity of rotation of rotary encoder under current state.To record first
The numeral expression of the pulse signal in continuous 4 1/4 cycles in stable state in depositor, with
By under the current state of the first impulse scaler record rotary encoder output continuous 4 1/4 week
In phase, the Contemporary Digital of pulse signal represents and compares, and decides whether to use according to comparative result
Current measurement parameter calculates the speed of rotary encoder axis of rotation.Concrete comparative result and follow-up
Processing scheme is: if Contemporary Digital represents that the standard digital with storage represents when the match is successful, calculate
The velocity of rotation of rotary encoder under current state;If Contemporary Digital represents and the standard digital of storage
When representing that it fails to match, the most do not calculate the velocity of rotation of rotary encoder under current state.
Owing to rotary encoder output has two pulse signals, respectively A phase pulse signal and B phase
Pulse signal.The effect that A phase pulse signal is believed with B phase pulse is: be easy to confirm that described rotation is compiled
The rotation direction of code device.Therefore before step S2, need to confirm the direction of rotation of rotary encoder.
Confirm rotary encoder rotation direction particularly as follows: definition said two pulse signal represents rotation respectively
The direction of rotation that encoder is different;According to the difference of the said two pulse signal time of advent, confirm
The rotation direction of rotary encoder.Illustrate, set A phase pulse signal and represent rotary encoder
In situation about rotating forward, set B phase pulse signal and represent the rotary encoder situation in reversion, rotate
Encoder is A phase pulse signal advanced B phase pulse signal 1/4 cycle in the case of rotating forward, such as figure
Shown in 2.By the phase contrast between phase discriminator detection A phase pulse signal and B phase pulse signal,
If A phase pulse signal arrives in phase discriminator in advance, then assert that the rotating shaft of rotary encoder rotates forward.
In the case of encoder inverts, B phase pulse signal advanced A phase pulse signal 1/4 cycle, as
Shown in Fig. 3, by the phase contrast between phase discriminator detection A phase pulse signal and B phase pulse signal,
If B phase pulse signal arrives in phase discriminator in advance, then assert that the rotating shaft of rotary encoder reversely rotates.
In some embodiments, in step S3, result of the comparison can be recorded, and record result is used
Interference and local environment excellent whether is there is in host computer assessment rotary encoder working environment
Bad degree.Represent and the standard of storage particularly as follows: arrange the second impulse scaler record Contemporary Digital
Numeral represents the number of times that it fails to match, and the second impulse scaler is also connected with the second depositor.Work as mould
Formula time the match is successful, first judges whether the value of the second impulse scaler is zero, if be not zero, then
The second depositor is entered, immediately after by the second step-by-step counting by cumulative for the value of the second impulse scaler
Device resets.When pattern match failure, the second impulse scaler is added 1, simultaneously immediately by first
Counter O reset.
The host computer being connected with rotary encoder is by reading the value in the second depositor termly, just
The good and bad degree of working environment residing for current encoder can be analyzed.Basic skills model and step
It is:
(1) the ta moment, host computer reads and records the value of the second depositor;
(2) the tb moment, host computer again reads off and records the value of the second depositor;
(3) calculate the difference of twice, if difference is less than or equal to Integer N 1, think environmental aspect
For well, if difference is more than N1 and less than or equal to N2, then it is assumed that environmental aspect is poor, if
More than N2, difference then thinks that environmental aspect is severe.(according to N1, N2, concrete application scenarios sets
Threshold value N1 < N2, tb-ta are approximately equal to a fixed time interval such as 5 minutes)
By this method, host computer or ARM and the whole print system of FPGA circuitry composition,
Just possessed the function of encoder environmental monitoring, and sound can be passed through, the means of the form such as optical, electrical are led to
Know user.
In some embodiments, the medium motion speed that rotary encoder is contacted by computing unit is used
Degree calculates.In computing unit, it is provided with two timer the first timers, the second timers,
First timer, the operation rules of the second timer be:
(1) when pattern match failure being detected, timer the first timer resets, enumerator
Second timer starts timing.
(2) when pattern match success being detected, timer the second timer resets, timer
First timer starts timing.
Therefore, timer the first timer correspond to continuous mode the match is successful duration,
Timer the second timer correspond to continuous mode it fails to match duration.
When the first enumerator is more than certain threshold value, start calculation medium movement velocity V (rice in real time
/ minute), computing formula is:
Wherein, C1 is the value of the first enumerator in impulse scaler, and D is that encoder rotary shaft drives
The diameter of wheel, is rice (m) by its unit conversion during calculating, T1 be in the first timer record time
Between, during calculating by its unit conversion it is minute.
Medium motion speed calculation is complete, and refreshing FPGA deposits with the speed of host computer interface immediately
Device, host computer this depositor of poll termly, it is possible to learn the real time kinematics speed of print media
Degree.
From algorithm above and various enumerator, timer operation rules, be not difficult to find out, this
The technical scheme of invention be substantially by by the byte of actual for encoder output with two kinds normally or
Co-rotating mode (0xB4) or reversing mode (0x78) ideally compare and pattern
Join, if it find that pattern match failure, abandon this section of unmatched waveform pulse the most immediately, stop
Test the speed, until FPGA circuitry monitors pattern match success, just start to test the speed.
Medium described in present embodiment is to can be used in the flaky material that printer prints: such as paper
, plastic foil or other lamellar print carriers.
Embodiment 2
Refer to Fig. 2, a kind of rotary encoder velocity-measuring system, including: FPGA (field programmable gate
Array) circuit and rotary encoder.FPGA circuitry 2 includes: memorizer 16, impulse scaler
13, comparator 14 and computing unit 15.Wherein, rotary encoder 1 is for by mechanical rotation shape
State is converted into pulse signal;Memorizer rotary encoder 1 under stable storage state exports pulse
The standard digital of signal represents;Doubler is for receiving the pulse of rotary encoder 1 under current state
Signal, and this pulse signal is converted into Contemporary Digital represents;The first counting in impulse scaler
Device is for recording the coupling comprised in rotary encoder output signal signal after quadruple processes
Successfully number of pulses;The second enumerator in impulse scaler, is used for recording each continuous mode
The number of times that during it fails to match, it fails to match;Comparator is for representing Contemporary Digital and the mark of storage
Quasi-numeral expression compares;Computing unit is for deciding whether to calculate current shape according to comparative result
The velocity of rotation of rotary encoder 1 under state, comparative result is: if described Contemporary Digital represents and deposits
The standard digital of storage represents when the match is successful, and computing unit calculates rotary encoder 1 under current state
Velocity of rotation;If described Contemporary Digital represents that the standard digital with storage represents when it fails to match,
Computing unit does not calculate the velocity of rotation of rotary encoder 1 under current state.Present embodiment is revolved
Turn encoder 1 velocity-measuring system also to include: phase discriminator 11 and doubler 12, phase discriminator 11 is used for examining
Survey the phase-shift value of the pulse signal of rotary encoder 1 output, in order to confirm described rotary encoder
The rotation direction of 1, doubler 12 carries out four times for the pulse signal exported by rotary encoder 1
Frequency processes.Annexation between this encoder velocity-measuring system each period is: rotary encoder 1
Two outfans are connected with phase discriminator 11, and the output signal of phase discriminator is directly connected with doubler 12,
The outfan of doubler 12 is connected with impulse scaler with comparator respectively, comparator and pulsimeter
The outfan of number device is connected with computing unit respectively, and also setting up between impulse scaler and comparator has
Annexation.
As a kind of selectivity embodiment of doubler, doubler is specially 2 octave frequency device.When again
Frequently, when device is 2 octave frequency device, the standard digital of memorizer storage represents and changes, the most just
True Contemporary Digital represents that also synchronization changes.
Wherein, memorizer includes: the first depositor and the second depositor, the first depositor with compare
Device connects.First depositor is rotary encoder 1 output pulse signal under stable storage state
Standard digital represents, the second depositor represents and the criterion numeral word table of storage for storing Contemporary Digital
Show the total degree that it fails to match.
Impulse scaler includes: the first impulse scaler and the second impulse scaler, the first pulsimeter
Number device is for recording the pulse number of doubler 12 output, and the second impulse scaler is with comparator even
Connect and represent and the standard digital of storage for the Contemporary Digital recording continuous mode it fails to match period
Represent the number of times that it fails to match, and the frequency of failure recorded according to operation rules adds up into second
In depositor.
Computing unit includes: the first timer, the second timer, the first timer, the second timing
The operation rules of device is:
(1) when pattern match failure being detected, timer the first timer resets, enumerator
Second timer starts timing.
(2) when pattern match success being detected, timer the second timer resets, timer
First timer starts timing.
Therefore, timer the first timer correspond to continuous mode the match is successful duration,
Timer the second timer correspond to continuous mode it fails to match duration.
The present embodiment only illustrates rotary encoder 1 velocity-measuring system hardware annexation, its concrete work
Make mechanism and method, refer to rotary encoder 1 speed-measuring method in embodiment 1.
It should be noted that the description of the present invention and accompanying drawing thereof give the present invention preferably
Embodiment, but, the present invention can be realized by many different forms, however it is not limited to this theory
Embodiment described by bright book, these embodiments, not as the extra restriction to present invention, carry
Purpose for these embodiments is to make the understanding to the disclosure more thorough comprehensively.And
And, above-mentioned each technical characteristic continues to be mutually combined, and forms various embodiments the most enumerated above,
It is accordingly to be regarded as the scope that description of the invention is recorded;Further, those of ordinary skill in the art are come
Say, can be improved according to the above description or convert, and all these modifications and variations all should belong to
Protection domain in claims of the present invention.