|
|
【原文】
单片机系统中的软件抗干扰技术
【译文】
Single a machine software in the system anti- interference technique
【原文】
The Soft Anti-jamming Tech.
【译文】
The Soft Anti-jamming Tech.
【原文】
In SCM System
【译文】
In SCM System
【原文】
近年来单片机系统在工业测控领域的应用越来越广泛,而对于环境恶劣的工业现场,这种新型的微控制器的可靠性、安全性就成为了一个大问题。
【译文】
The single a machine system measures the application that control the realm in the industry in recent years more and more extensive, but for bad industry in environment the spot, the dependable, safety of this kind of new tiny controller became a big problem.
【原文】
在实验室运行正常的程序到了工业现场却不能运行,或者出现运行不稳定经常死机等。
【译文】
Circulate in the laboratory the normal procedure arrived the industry however the spot can’t circulate, or appear the movement the unsteady usually dying machine etc..
【原文】
在这里主要讨论一下如何通过软件技术来增强系统的稳定运行。
【译文】
Discuss primarily here once how to pass the software technique to the stability movement that strengthen the system.
【原文】
当系统的CPU部位受到干扰信号的作用时,将使系统失控。
【译文】
When the part of CPU of the system suffers the function of the interference signal, will make system lost control.
【原文】
最典型的故障是破坏程序计数器PC的状态值。
【译文】
The most typical breakdown is an appearance to break procedure count the machine PC value.
【原文】
导致程序在地址空间内乱飞,或者陷入死循环。
【译文】
Cause procedure is in address space the confusion flies, or sink into the dead circulation.
【原文】
对这种情况的处理主要有这么几种方法:
【译文】
Handles to this kind of circumstance to have so a few methods primarily:
【原文】
1、指令冗余技术;
【译文】
1, instruction redundancy technique;
【原文】
2、软件陷阱技术;
【译文】
2, software trap technique;
【原文】
3、看门狗技术。
【译文】
3, watchdog technique.
【原文】
下面 以MCS-51单片机来做说明。
【译文】
Underneath with MCS-51 single a machine to do the elucidation.
【原文】
指令冗余技术
【译文】
Instruction redundancy technique
【原文】
指令由操作码和操作数组成,操作码指明CPU要完成什么样的操作,而操作数是操作码的对象。
【译文】
Instruction from operation code with operation number constitute, operate the code indicate the CPU wants to complete the what kind of operation, but operation number is an object to operate the code.
【原文】
单字节指令只有操作码,隐含操作数;
【译文】
Word stanza instruction only contain operation code, implicit operation number;
【原文】
双字节指令,第一个字节是操作码,第二个字节是操作数;
【译文】
A word stanza instruction, the first word stanza is to operates the code, the second word stanza is an operation number;
【原文】
三字节指令第一个字节是操作码,后二个字节是操作数。
【译文】
Three word stanza instruction the first word stanzas are to operate the code, empress two words stanza is an operation number.
【原文】
CPU在取指令的时候是先取操作码再取操作数,如何判断是操作码还是操作数就是通过取指令的顺序。
【译文】
The CPU takes first to operate at the time of taking the instruction the code takes again the operation counts, howing to judge is a sequence to operate a code or an operation number is pass to take the instruction.
【原文】
而取指令的顺序完全由指令计数器PC来控制,因此,一旦PC受干扰出现错误程序便会脱离正常轨道,出现乱飞,这样就会出现把操作数当作操作码,或者把操作码当作操作数的情况。
【译文】
But takes the sequence of the instruction complete be counted by instruction machine PC to control, therefore, once the PC is appeared by interference the mistake procedure will escape from the normal orbit then, appearing the confusion flies, will appear to regard as the operation like this the number operates the code, or regard as the operation the code the circumstance of the operation number.
【原文】
但只要PC指针落在单字节指令上程序就可纳入正轨,所以为了快速将程序纳入正轨,应该多用单字节指令,并在关键的地方人为插入一些单字节指令NOP,或将有效的单字节指令重写,这就称之为指令冗余。
【译文】
But as long as the PC points the needle fall on the word stanza instruction procedure can bring onto proper course, so bring onto proper course the procedure for the sake of the fleetness, should use word stanza instruction more, and the local factitiousness in key inserts the some word stanza instruction NOP, or rewrite the valid word stanza instruction, this call it as the instruction redundancy.
【原文】
常用的方法就是在一些双字节、三字节指令后面插入两个单字节指令NOP,或在一些对程序的流向起决定作用的指令前面插入两条NOP指令。
【译文】
The in common use method is in the some a words stanza, three word stanza instructions insert two words stanza instruction NOP behind, or fly to the instruction that rises the decision function to the procedure to insert two NOPs instruction before at the some.
【原文】
还可对一些重要的指令进行重复放置。
【译文】
Can also proceed to the some important instruction the repetition place.
【原文】
【译文】
【原文】
但采用指令冗余技术将程序纳入正轨的条件是:
【译文】
But adoption instruction redundancy technique term that bring onto proper course procedure is:
【原文】
乱飞的PC必须指向程序运行区。
【译文】
The PC confusion fly and must point to the procedure circulates the area.
【原文】
软件陷阱技术
【译文】
Software trap technique
【原文】
当乱飞的程序进入非程序区的时候,就可设定软件陷阱对乱飞的程序进行拦截从而将程序引向一个固定的位置。
【译文】
When the procedure that confusion fly time that enter not procedure area, can set up the software trap procedure that fly to proceed to intercept to the confusion from but lead face a fixed position the procedure.
【原文】
这样就可将捕获的程序重新纳入正轨。
【译文】
The procedure that can will succeed in catching like this brings onto proper course afresh.
【原文】
软件陷阱主要就是把程序重新引入它的复位入口处,也就是说在适当的地方设置这样的指令:
【译文】
Software trap primarily is to leads the procedure to reply into it afresh an is entrance, also ising to say to establishes in the appropriate place such instruction:
【原文】
NOP
【译文】
NOP
【原文】
NOP
【译文】
NOP
【原文】
LJMP 0000H
【译文】
LJMP 0000H
【原文】
软件陷阱主要安排在这样一些区域:
【译文】
The software trap arranges primarily in the like this some district:
【原文】
未使用的中断区、未使用的EPROM空间及非EPROM空间、程序运行区及中断服务程序区。
【译文】
Not the interruption area that use, not the space of EPROM that use and not the space of EPROM, procedure circulates the area and breaks off the service procedure area.
【原文】
主要来看前三种:
【译文】
Main before coming to seeing three kinds of:
【原文】
1、未使用的中断区
【译文】
1, not the interruption area that use
【原文】
如果对于未使用的中断因干扰而开放的话, 可以这样写中断服务程序:
【译文】
If write not use of interruption liberal because of interference, can very much the interruption service procedure:
【原文】
NOP
【译文】
NOP
【原文】
NOP
【译文】
NOP
【原文】
POP D1 ;
【译文】
POP D1;
【原文】
将原来的错误断点弹出
【译文】
Break the original mistake to order to flick open
【原文】
POP D2 ;
【译文】
POP D2;
【原文】
将原来的错误断点弹出
【译文】
Break the original mistake to order to flick open
【原文】
PUSH 00H
【译文】
PUSH 00H
【原文】
PUSH 00H;
【译文】
The 00 Hs of PUSH;
【原文】
将断点地址重写为 0000H
【译文】
Will break to order the address rewrite to 0000 Hs
【原文】
RETI
【译文】
RETI
【原文】
2
【译文】
2
【原文】
.
【译文】
.
【原文】
未使用的EPROM区
【译文】
Not the area of EPROM that use
【原文】
假设用了一片2764,但并没有用完整个存储区。
【译文】
The assumption used the one 2764, but did not use up whole saving area.
【原文】
这时候就可在未用的区域里填充上020000数据,这样当程序飞入其中时就会很快的走入正轨。
【译文】
Can fill the 充 in not the district that use by this time last 020000 data, be like this the procedure fly into among them hour will walk into the correct path very quickly.
【原文】
这条指令其实是LJMP 0000H的机器码。
【译文】
This instruction is the machine code of the the 0000 Hs of LJMP in fact.
【原文】
3
【译文】
3
【原文】
.
【译文】
.
【原文】
非EPROM空间
【译文】
Not the space of EPROM
【原文】
单片机系统的程序空间是64K,正常情况下 所使用的EPROM不会占用所有的空间,假设 现在的EPROM占用16K的空间,那么剩下的48K空间就被闲置不用了。
【译文】
The procedure space of the single a machine system is a space that the EPROM that an EPROM for, normal circumstance descending use can’t take up all spaces, suppose now to take up a 16 Ks spaces, leave so drive idle need not.
【原文】
当乱飞的PC落入这些空间时,读入的数据将为FFH,这是 :
【译文】
When the PC confusion flies to fall into these spaceses, the data that read into will for FFH, this is:
【原文】
MOV R7,A 指令的机器码,将修改R7的内容。
【译文】
MOV R7, the instruction of A machine code, will modify the R7 contents.
【原文】
因此,当程序乱飞入非EPROM芯片区后,不仅无法导入正规,而且破坏了R7的内容。
【译文】
Therefore, be the procedure confusion fly into not EPROM 芯 slice District empress, can’t not only duct into regular, but also break the R7 contents.
【原文】
当CPU读程序存储器的时候,伴随着会产生一个PSEN信号, 就可利用这个信号,再加上一个非EPROM区的地址译码信号,构成一个选通信号来起动一个空闲的中断,再用软件陷井的方法从中断程序中把程序导入正规。
【译文】
When the CPU reads the procedure saves the machine of time, accompanying with will produce a PSEN signal, can make use of this signal, plus an address for not the area of EPROM translate the code signal, constituting a method for choosing corresponding by letter number to starting a leisure interruption, then with the software sinking well from break off the procedure inside duct into the procedure regular.
【原文】
看图1:
【译文】
See the figure 1:
【原文】
也可通过硬件的方法用一个缓冲器直接给数据线写一个值,其原理与上述方法相同。
【译文】
Also can pass the method of the hardware use a buffer to write the data line a value directly, itsing principle is same alike to above method.
【原文】
软件看门狗技术
【译文】
Software watchdog technique
【原文】
看门狗的作用就是防止程序发生死循环,或者说程序跑飞。
【译文】
The function of the watchdog is to keeps procedure from occurrence to die the circulation, or say that the procedure run to fly.
【原文】
硬件看门狗是利用了一个定时器,来监控主程序的运行,也就是说在主程序的运行过程中, 要在定时时间到之前对定时器进行复位,如果出现死循环,或者说PC指针不能回来。
【译文】
The hardware watchdog is a movement to made use of a settle machine, supervise and control the main procedure, and also is to say in the movement process of the main procedure, want to be while settling before timing is up to settle the machine proceeds to reply, if appear the dead circulating, or say that the PC points the needle can’t come back.
【原文】
那么定时时间到后就会使单片机复位。
【译文】
While settling so will make the single a machine reply after timing is up.
【原文】
软件看门狗技术的原理和这差不多,只不过是用软件的方法实现, 还是以51系列来讲,在51单片机中有两个定时器, 可以用这两个定时器来对主程序的运行进行监控。
【译文】
The technical principle in watchdog in software is about with this, ising a movement to use the method of the software realizes, still with 51 serieses speak, at 51 single have in a machine two settle machine, can use these two settle machine to main procedure to proceed to supervise and control only.
【原文】
对T0设定一定的定时时间,当产生定时中断的时候对一个变量进行赋值,而这个变量在主程序运行的开始已经有了一个初值,要设定的定时值要小于主程序的运行时间,这样在主程序的尾部对变量的值进行判断,如果值发生了预期的变化,就说明T0中断正常,如果没有发生变化则使程序复位。
【译文】
Set up to the T0 to settle certainly always a time for, being creation settling interruption thered has been a beginning value to a beginning for changing deal proceeding 赋 value, but this changing measuring at main procedure circulating, toing set up of settle at a time when movement time of wanting the smaller and main procedure, like this the tail in main procedure a worth proceeding for to changing deal judges, if the value took place the anticipant variety, explain the T0 break off normal, if has no occurrence the variety then make the procedure reply.
【原文】
T1 用来监控主程序的运行, 给T1设定一定的定时时间,在主程序中对其进行复位,如果不能在一定的时间里对其进行复位,T1 的定时中断就会使单片机复位。
【译文】
The T1 be used movement that supervise and control the main procedure, set up the T1 to settle certainly always, in main procedure as to it’s proceed to reply a, if can’t in certain time as to it’s proceed to reply a, the T1 settles break off and then will make the single a machine reply.
【原文】
在这里T1的定时时间要设的大于主程序的运行时间,给主程序留有一定的裕量。
【译文】
Settle in here T1 always movement time of an over and above main procedure for wanting establishing, stay the main procedure the certain amount of 裕 .
【原文】
而T1的中断正常与否 再由T0定时中断子程序来监视。
【译文】
But whether T1 interruption is normal or not be settled by T0 again break off the sub- procedure to keep watch on.
【原文】
这样就够成了一个循环,T0监视T1,T1监视主程序,主程序又来监视T0,从而保证系统的稳定运行。
【译文】
Like this enough a circulating, T0 surveillance T1, the T1 keeps watch on the main procedure, the main procedure comes to keeps watch on the T0 again, from but guarantee the stability movement of the system.
【原文】
【译文】
【原文】
注:
【译文】
Note:
【原文】
本文仅代表个人观点,与『光电资讯网』无关,转载或引用『光电论坛』内容请注明出处!
【译文】
This text represents the personal standpoint only, having nothing to do with light electricity information net, turning to carry or quote from light electricity forum the contents pleases note the source!
【原文】
【译文】
|
|