Summary of the invention
The invention provides a kind of magnetic card coding/decoding method, can improve the accuracy of reading data on magnetic card effectively.
A kind of magnetic card coding/decoding method,
A1, the pwm value of the level signal of magnetic signal pulse correspondence is stored successively;
A2, with the pwm value of precedence bits 0 correspondence of magnetic card as the initial baseline pulsewidth, with the benchmark of current benchmark pulsewidth as the subluxation of the pwm value corresponding bit 0 of differentiating storage or bit 1;
A3, successively the pwm value of storage is differentiated with current benchmark pulsewidth, if be judged to other current pwm value corresponding bit 0, then current benchmark pulsewidth is updated to the weighting of previous benchmark pulsewidth and current pwm value, and next pwm value is differentiated;
Wherein, bit 1 is made of two consecutive pulses, and bit 0 is made of a pulse.
Adopt dynamic current benchmark pulsewidth as the benchmark of differentiating bit 0 and bit 1, reduced the probability of the reading of data mistake that causes owing to the magnetic card translational speed is inhomogeneous effectively, the pulsewidth that adopts bit 0 correspondence is about the twice of pulsewidth of bit 1 correspondence, can make current benchmark pulsewidth more accurate as the wherein claim of current benchmark pulsewidth the pulsewidth of bit 0 correspondence.
Preferably, in steps A 2, the pwm value of at least two precedence bits 0 correspondence is averaged the back as described initial baseline pulsewidth.
Employing averages the back as the initial baseline pulsewidth to precedence bits 0, has reduced owing to certain bit 0 corresponding pulsewidth occurs making the discriminating data probability of errors unusually, makes that the initial baseline pulsewidth is more accurate.
Preferably, in steps A 3, if current pwm value is greater than the doubly current benchmark pulsewidth of k1, less than the doubly current benchmark pulsewidth of k2, wherein, and 0<k1<k2<1, then carry out following steps:
B1, if previous pwm value and back pwm value corresponding bit 0 all, then current pwm value is differentiated and is corresponding bit 0;
B2, if a back pwm value corresponding bit 0, and preceding two pwm values corresponding bit 1 is altogether then differentiated current pwm value and is corresponding bit 0;
B3, if previous pwm value corresponding bit 0, and latter two pwm value corresponding bit 1 is then differentiated current pwm value and is corresponding bit 0;
B4, if the subluxation of previous pwm value corresponding bit 1, an and back pwm value corresponding bit 0 is then differentiated current pwm value and previous pwm value altogether and is corresponding bit 1;
B5, if previous pwm value corresponding bit 0, and the subluxation of a back pwm value corresponding bit 1 is then differentiated current pwm value and a back pwm value altogether and is corresponding bit 1.
When the situation that data bit that magnetic bias causes is lost occurring, adopt technique scheme, can effectively the data bit of losing be recovered, and then improve the accuracy rate of magnetic card identification.
Preferably, if current pwm value does not belong to the arbitrary situation of step B1 to the step B5, judge then whether the number of bits that has determined constitutes a byte, if then the bit value of each data bit of described byte is carried out XOR and the result and the exclusive or check position of described byte compare, and then differentiate the bit value of current pwm value correspondence.
Preferably, in steps A 3, current benchmark pulsewidth is updated to 1/2nd of previous benchmark pulsewidth and adds 1/2nd of current pwm value.
Preferably, if current pwm value〉80% * current benchmark pulsewidth, then current pwm value being differentiated is corresponding bit 0, if 20% * current benchmark pulsewidth<current pwm value<60% * current benchmark pulsewidth then is the subluxation of corresponding bit 1 with current pwm value differentiation.
The present invention also provides a kind of magnetic card reading device, comprises decoder module,
Described decoder module carries out the magnetic-pulse signal decoding according to the arbitrary described magnetic card coding/decoding method of claim 1-6 to be handled.
Preferably, also comprise induction amplifying circuit, bandwidth-limited circuit and threshold value shaping circuit;
Described induction amplifying circuit is used for magnetic signal being converted to electric signal and amplifying;
Described bandwidth-limited circuit carries out bandpass filtering to the electric signal of induction amplifying circuit output;
Described threshold value shaping circuit carries out offering described decoder module after the shaping to the electric signal of bandpass filtering filtering circuit output.
Preferably, described induction amplifying circuit comprises coil, first resistance, second resistance, the 3rd resistance, first electric capacity, second electric capacity, first amplifier, one end of described coil is connected with the negative input end of described first amplifier by first resistance, the other end is connected with the positive input terminal of first amplifier by described second resistance, described first electric capacity, one end is connected with the positive input terminal of described first amplifier, the other end is connected with the common port of described first resistance and coil, described coil is connected with reference voltage with the common port of second resistance, is connected across the negative input end and the output terminal of described first amplifier after described the 3rd resistance and the second electric capacity parallel connection.
Preferably, described bandwidth-limited circuit comprises the 3rd electric capacity, the 4th electric capacity, the 4th resistance, the 5th resistance, the 6th resistance, the 7th resistance, second amplifier, first diode and second diode; The negative input end of described second amplifier is connected with the output terminal of the 3rd electric capacity with described first amplifier by the 4th resistance respectively, the positive input terminal of described amplifier is connected with reference voltage by the 5th resistance, described the 4th electric capacity and the negative input end and the output terminal that are connected across second amplifier after the 6th resistance is in parallel, the negative electrode of first diode is connected with the negative input end of described second amplifier by the 7th resistance, anode is connected with the output terminal of described second amplifier, and the anode of described second diode is connected with anode with the negative electrode of described first diode respectively with negative electrode.
Preferably, described shaping circuit comprises the 8th resistance, the 9th resistance, the tenth resistance and the 3rd amplifier, the negative input end of described the 3rd amplifier is connected with the output terminal of described second amplifier by the 8th resistance, the positive input terminal of described the 3rd amplifier is connected with the output terminal of reference voltage with described the 3rd amplifier with the tenth resistance by the 9th resistance respectively, and the output terminal of described the 3rd amplifier is connected with described decoder module.
The present invention adopts the algorithm of dynamic current benchmark pulsewidth and fuzzy error correction, has improved the accuracy rate that reads data on magnetic card greatly.
Embodiment
Below with reference to accompanying drawing, preferred embodiment of the present invention is described in further detail.
To shown in Figure 5, a kind of magnetic card reading device comprises induction amplifying circuit, bandwidth-limited circuit, threshold value shaping circuit and decoder module as Fig. 2;
Described induction amplifying circuit is used for magnetic signal being converted to electric signal and amplifying;
Described bandwidth-limited circuit carries out bandpass filtering to the electric signal of induction amplifying circuit output;
Described threshold value shaping circuit carries out shaping to the electric signal of bandpass filtering filtering circuit output;
Described decoder module is connected with described threshold value shaping circuit, is used to implement following magnetic card coding/decoding method, as shown in Figure 2:
S001, the pwm value of the level signal of magnetic signal pulse correspondence is stored successively;
S002, with the pwm value of precedence bits 0 correspondence of magnetic card as the initial baseline pulsewidth, with the benchmark of current benchmark pulsewidth as the subluxation of the pwm value corresponding bit 0 of differentiating storage or bit 1;
S003, successively the pwm value of storage is differentiated with current benchmark pulsewidth, if be judged to other current pwm value corresponding bit 0, then current benchmark pulsewidth is updated to the weighting of previous benchmark pulsewidth and current pwm value, and next pwm value is differentiated;
Wherein, bit 1 is made of two consecutive pulses, and bit 0 is made of a pulse.
Preferably, as shown in Figure 4, described induction amplifying circuit comprises coil L, first resistance R 1, second resistance R 2, the 3rd resistance R 3, first capacitor C 1, second capacitor C 2, the first amplifier U1, the end of described coil L is connected with the negative input end of the described first amplifier U1 by first resistance R 1, the other end is connected with the positive input terminal of the first amplifier U1 by described second resistance R 2, described first capacitor C, 1 one ends are connected with the positive input terminal of the described first amplifier U1, the other end is connected with the common port of described first resistance R 1 and coil L, described coil L is connected with reference voltage V REF with the common port of second resistance R 2, is connected across negative input end and the output terminal of the described first amplifier U1 after described the 3rd resistance R 3 and 2 parallel connections of second capacitor C.
The magnetic head of magnetic card reading device can convert the magnetic signal of magnetic card record to electric signal, when magnetic card passes through magnetic head with certain speed, in magnetic head coil, can induce corresponding electric signal, under the situation of impedance matching, the signal that magnetic head induces, voltage is usually below 10mV, and the card that has even be lower than 1mV, this induction amplifying circuit also have low pass (20dB), rectify and equate function.
Preferably, as shown in Figure 5, described bandwidth-limited circuit comprises the 3rd capacitor C 3, the 4th capacitor C 4, the 4th resistance R 4, the 5th resistance R 5, the 6th resistance R 6, the 7th resistance R 7, the second amplifier U2, the first diode D1 and the second diode D2; Described the 3rd capacitor C 3 is connected with the negative input end of the second amplifier U2 by the 4th resistance R 4, and described the 3rd capacitor C 3 is connected with the output terminal of the first amplifier U1 by interface TP2; The positive input terminal of the described second amplifier U2 is connected with reference voltage V REF by the 5th resistance R 5, described the 4th capacitor C 4 and the negative input end and the output terminal that are connected across the second amplifier U2 after the 6th resistance R 6 is in parallel, the negative electrode of the first diode D1 is connected with the negative input end of the described second amplifier U2 by the 7th resistance R 7, anode is connected with the output terminal of the described second amplifier U2, and the anode of the described second diode D2 is connected with anode with the negative electrode of the described first diode D1 respectively with negative electrode.T5, T8 are the signal testing port.
Preferably, described shaping circuit comprises the 8th resistance R 8, the 9th resistance R 9, the tenth resistance R 10 and the 3rd amplifier U3, the negative input end of described the 3rd amplifier U3 is connected with the output terminal of the described second amplifier U2 by the 8th resistance R 8, the positive input terminal of described the 3rd amplifier U3 is connected with the output terminal of reference voltage with described the 3rd amplifier U3 with the tenth resistance R 10 by the 9th resistance R 9 respectively, the output terminal of described the 3rd amplifier U3 be connected by the described decoder module of interface MIG2.
The magnetic head of magnetic card reading device is a sensitive element, has various undesired signals at work, thereby needs interference such as noise are suppressed, and this bandwidth-limited circuit has the function of signal being carried out linear amplification, shaping, and can filtering interfering and clutter.
Adjustable during the threshold value of this threshold value shaping circuit, after signal was restored to state easy to identify, the signal of MIG2 interface entered timing microprocessor device counter controls mouth, carries out software decode by microprocessor (single-chip microcomputer).
Below be another embodiment more specifically of magnetic card coding/decoding method:
The counting of the timer by single-chip microcomputer is measured the pwm value of the level signal of magnetic signal pulse correspondence, each pwm value directly is stored in the timer counter register in the counting process, reads the pwm value in the timer counter register then and is stored in magnetic signal pulse width count buffer district TK1TimeBuf[1024 successively] (being called for short the pulsewidth buffer zone).In preferred embodiment,, timer timing pulse frequency F is set because the magnetic signal bandwidth is 5K
CShould that is to say a minimum counting of signal period 20 times greater than 100K, the size of pulsewidth buffer zone is 1Kbyte, each bytes store pulse width, i.e. a pwm value.For example: the clock frequency of single-chip microcomputer is 11.0592M, does 64 frequency divisions and can get F
CThe count frequency of=172.8K, timer counter register TCNT are 16 counter register.
As shown in Figure 6, in the pulsewidth buffer zone, read the magnetic card magnetic track and begin one section uniform magnetic recording signal precedence bits 0(initial baseline position just) corresponding one group of pulsewidth of beginning, carrying out arithmetic mean must the pulsewidth of falling the initial baseline, give current benchmark pulsewidth TK1CLK with initial baseline pulsewidth assignment, as the standard scale of initial differentiation pulsewidth corresponding bit 0 or 1.Preferably, the pwm value of choosing 20 precedence bits 0 correspondences carries out arithmetic mean and obtains the initial baseline pulsewidth; Then receive start byte, reception data and end byte, reception check byte; In above-mentioned steps, need to judge whether corresponding complete byte of the pulsewidth TK1Time that reads continuously, if not, then continue from pulsewidth buffer zone TK1TimeBuf[1024] read pulsewidth.Judge whether the complete byte of obtaining is data byte opening flag (start byte), if, then carry out byte count, complete byte of later every reception then adds 1 with the byte number that receives; And judge whether this byte is data byte end mark (end byte), if, then obtain a check byte again, then all data bytes that get access to (are comprised start byte, data byte and end byte.Do not comprise check byte) carry out LRC verification calculating, if result of calculation and check byte are inconsistent, then the data that receive are carried out error flag, otherwise, data storage is arrived buffer zone ByteBuff[] in.
Current benchmark pulsewidth TK1CLK is a dynamic benchmark pulsewidth, current benchmark pulsewidth TK1CLK=TK1CLK*50%+TK1Time*50%, promptly, if current pwm value TK1Time correspondence is bit 0, current benchmark pulsewidth TK1CLK then is updated to: 50% of previous current benchmark pulsewidth add current bit 0 correspondence current pwm value 50%, as shown in Figure 7.
The pwm value of magnetic signal correspondence changes with the magnetic card gait of march, and the inhomogeneous meeting of the speed that magnetic card moves is fluctuateed the magnetic signal frequency within the specific limits, if adopt the fixed reference pulsewidth to come distinguishing signal, can cause the magnetic card reading device to differentiate error in data.Because the magnetic card translational speed can not suddenly change, velocity variations has continuity, i.e. the velocity correlation of current movement speed and previous moment, current benchmark pulsewidth (dynamic benchmark pulsewidth) promptly are associated with pulsewidth at data-signal.Thereby the velocity variations that the size of current benchmark pulsewidth is advanced along with magnetic card and changing is dynamic, as to change data, can reduce the inhomogeneous discriminating data probability of errors that causes because of the magnetic card translational speed effectively.
Preferably, to from pulsewidth buffer zone TK1TimeBuf[1024] the pulsewidth TK1Time that reads out, carry out following operation:
Calculate peak pulse duration RB=TK1Time/TK1CLK*100%;
Peak pulse duration RB is considered as bit " 0 " greater than the data bit of 80% pulsewidth correspondence.Peak pulse duration RB is considered as " half " or " subluxation " of bit " 1 " between 20% to 60% data bit, and continuous two " half " constitute a complete bit " 1 ".Peak pulse duration RB is considered as uncertain position between 60% to 80% data bit.
In another specific embodiment, for uncertain position, adopt fuzzy error correction algorithm to carry out further determining, as shown in Figure 8:
B1, if previous pwm value and back pwm value corresponding bit 0 all, then current pwm value is differentiated and is corresponding bit 0;
B2, if a back pwm value corresponding bit 0, and preceding two pwm values corresponding bit 1 is altogether then differentiated current pwm value and is corresponding bit 0;
B3, if previous pwm value corresponding bit 0, and latter two pwm value corresponding bit 1 is then differentiated current pwm value and is corresponding bit 0;
B4, if the subluxation of previous pwm value corresponding bit 1, an and back pwm value corresponding bit 0 is then differentiated current pwm value and previous pwm value altogether and is corresponding bit 1;
B5, if previous pwm value corresponding bit 0, and the subluxation of a back pwm value corresponding bit 1 is then differentiated current pwm value and a back pwm value altogether and is corresponding bit 1.
If current pwm value does not belong to the arbitrary situation of step B1 to the step B5, judge then whether the number of bits that has determined constitutes a byte, if, then the bit value of each data bit of described byte is carried out XOR and the result and the exclusive or check position of described byte compare, and then differentiate the bit value of current pwm value correspondence.
Because magnetic bias causes losing of data bit, the data that can recover to lose by fuzzy algorithm improve the magnetic card signal identification rate.
Since the start bit of the start byte after the precedence bits 0 promptly first be bit 1, so need to detect first bit 1 after the precedence bits 0, to judge the beginning of start byte.The method of discrimination of start bit 1 is as shown in Figure 9:
1, reads pulse-width data TK1Time from the pulsewidth buffer zone;
2, calculate the peak pulse duration RB of this pulse-width data TK1Time correspondence;
3, judge that this pulse-width data TK1Time is corresponding bit 0, bit 1 or uncertain position;
If 4 uncertain positions are then differentiated the bit of this pulse-width data TK1Time correspondence by fuzzy error correction algorithm, whether if not uncertain position then differentiates this pulse-width data TK1Time correspondence is the preceding subluxation of bit 1, if not the preceding subluxation of bit 1 then carries out from 1 step again since 1, if the preceding subluxation of bit 1 then continues execution in step 5;
5, continue to read next pulse-width data TK1Time;
6 and calculate corresponding peak pulse duration RB;
7, definite correspondence is the subluxation or the uncertain position of bit 0 or bit 1, if uncertain position is then differentiated the bit of correspondence once more by fuzzy error correction algorithm;
If the subluxation of 8 bits 1, receiving of promptly whole start bit 1 then re-executes from step 1 if not.
Shown in Figure 10,11 and 12, it is respectively the reception process flow diagram of start byte, ED byte, check byte, wherein need the pulse-width data TK1Time of each bit correspondence of constituting byte is differentiated, its discriminant approach front is described in detail, those skilled in the art do not repeat them here being expressly understood corresponding process in conjunction with Figure 10,11 and 12.