Background technology
When single-chip microcomputer is worked as a control system; Can produce extremely serious electromagnetic interference (EMI) when the direct current generator in the control system or other equipment works; As at the center that utilizes single-chip microcomputer for Test Switchboard amount control; The on off operating mode of tested switching value is encoded by scale-of-two, accomplish switching value signals collecting, button identification, time measurement and Presentation Function with single-chip microcomputer.The Single-chip Controlling direct current generator produces switching value, the LCD display unit as control system, LCD can occur and flower screen phenomenon occur, can't carry out proper testing.Extremely serious through looking into the electromagnetic interference (EMI) that produces when reason is direct current generator work; The frequency spectrum that can observe interference with spectrum analyzer is very wide, and this strong electromagnetic causes system's cisco unity malfunction from the 5V direct-current switch power supply that power ground seals in to the control system power supply.After single-chip microcomputer P1 mouth added π type filtering circuit, situation made moderate progress after circuit board carried out layout again, but flower screen phenomenon still often appears in LCD.Singlechip chip is taken off with the artificial head replacement, and with emulator emulation on computers, it is in proper working order to observe single-chip microcomputer.Therefore the reason that can judge LCD flower screen is that the strong electromagnetic radiation that the microprocessor in the display receives direct current generator disturbs and cisco unity malfunction.Through taking shielding measure also can't eliminate interference fully to LCD and data line, control line.Be head it off, changed the stronger LCD of other several kinds of antijamming capabilities and made an experiment that test effect is still very undesirable.Inquire into and demonstration through technology, change design proposal again, adopt charactron to realize the demonstration of measurement data.When the design circuit plate makes an experiment again according to this scheme, disturb still frequent the appearance, caused tester the phenomenon that numeral daps often to occur, and more and more serious trend is arranged.Adopted measures such as power filter, ground connection processing and system mask to handle to this phenomenon, the result is not still effectively improved.So, carry out emulation with emulator once more, through observing the numerical value of each timer of single-chip microcomputer; Finally find that when electromagnetic interference (EMI) occurs disorder has appearred in the timer count value of single-chip microcomputer, the function of the timing Interrupt Process subroutine of single-chip microcomputer is that count value adds up automatically; Count value does not add 1 automatically when timer receives strong electromagnetic; But having jumped to a random number, the phenomenon that reflects thus is exactly digital irregular saltus step, normally timing.
Summary of the invention
For solving the problems of the technologies described above, the invention provides the disorder that a kind of timer that utilizes single-chip microcomputer under the situation that two inner timers of single-chip microcomputer are corrected in electromagnetic interference (EMI) occurs.
A kind of SCM system anti-disturbance method is characterized in that: two timer T0 of single-chip microcomputer and timer T1 are worked simultaneously, T0 also will keep watch on T1 outside the adding up of count value count value; If the count value of T1 gets muddled; Disorderly standard is two adjacent count values of inspection, disorder occurred if the difference of the two greater than setting, is just thought; Just correct the count value of T1 with the count value of T0; T0 also wants negate to the state of own corresponding output pin at every turn, make and oneself can be detected by T1, negate square wave that to export a frequency simultaneously be 500Hz as the time base calibrating use; Equally, T1 also will keep watch on T0 outside the adding up of count value count value is if the count value of T0 gets muddled; Disorderly standard is two adjacent count values of inspection, disorder occurred if the difference of the two greater than 1, is just thought; Just correct the count value of T0 with the count value of T1; T1 also wants negate to the state of own corresponding output pin at every turn, make and oneself can be detected by T0, negate square wave that to export a frequency simultaneously be 500Hz as the time base calibrating use.
The concrete progress of work is following:
Be checked through the low level of T1 at T0 after, the count value of timer T1 put into variable s1_1 store; After being checked through the high level of T1 then, the count value of timer T1 being put into variable s1_2 store, if | s1_1-s1-2|>=setting; Think then to begin to have got muddled that the count value of T0 is corrected the count value of timer T1.Likewise, be checked through the low level of T0 at T1 after, the count value of timer T0 is put into variable s0_1 stores; After being checked through the high level of T0 then, the count value of timer T0 being put into variable s0_2 store, if | s0_1-s0-2|>=setting; Think then to begin to have got muddled that the count value of T1 is corrected the count value of T0.So, T0 and T1 keep watch on the other side mutually, and T0 and timer 1 are normally counted, if there is a timer to get muddled, just can be corrected by the other side at once, thereby fundamentally solve problem.
Possibly have viewpoint thinks: if two timers all disturb simultaneously got muddled; Is not problem still to exist so? Answer as follows: the timer like single-chip microcomputer is set in working method 1; Then counting maximal value is 65535; So the probability that timer gets muddled first is that the probability that 1/65535, two timer gets muddled simultaneously is 1/ (65535 * 65535)=2 * 10
-10, so little probability can be ignored basically.
The present invention is through to the ingenious use of two timers in the single-chip microcomputer, overcome single-chip microcomputer in use electromagnetic interference (EMI) the influence of SCM system has been improved the stability of SCM system.
Protection scope of the present invention is not limited only to two timers and keeps watch on each other and prevent to correct a mistake mutually, all falls into protection scope of the present invention thereby use our ratio juris to correct single-chip microcomputer because of electromagnetic interference (EMI) produces the wrong practice.