Software filtering
Input errors can be controlled by software filtering (debouncing) of inputs. There are
many tried and true debouncing methods. The key is to choose one that
best balances the required responsiveness to the input versus the need
to tolerate glitches on the input.
For instance, if the system requirements state that you must
recognize a button press within 50ms, a good filtering method might be
to sample the input in a 10ms ISR and require the input to be seen at
the opposite state for at least 40ms (4 consecutive samples) for the
debounced state to logically change.
Also, some DSPs, such as TI's TMS320F28XX family, allow you to
configure filtering of inputs. The GPIO can have a sampling rate and a
qualification count configured. The two together form the sampling
window.
For the input qualifier to detect a change in the input, the level
of the signal must be stable for the duration of the sampling window
width or longer. This is filtering that consumes no instruction cycles
after it has been configured, so be sure to use it when you can!
Software can also be used to digitally filter an analog input
signal. This is most efficiently accomplished on a digital signal
processor, but it can also be implemented on a standard microcontroller
too. A FIR (finite impulse response) or IIR (infinite impulse response)
filter can be implemented to clean up an input signal that is dirtied
by EMI.
Digital filters can provide remarkable performance compared to their
analog counterparts. For implementation on a standard microcontroller,
there are many 'C' source implementations of these filters freely
available on the internet. For implementation on a DSP, almost all DSP
vendors provide optimized assembly implementations of these filters
that make use of the hardware features of the DSP.
 |
| Figure
1. ECG with 60Hz Power Line Interference |
For example, consider the case of a medical device that monitors ECG
through an A/D converter to detect the R-Wave in a QRS complex. The QRS
complex energy is typically in the band from 10Hz to 40Hz. An FIR band
pass filter in this band can be extremely effective at
eliminating 50/60Hz power line noise as well as other higher frequency
noise sources.
The attenuation below 10Hz is more to eliminate
uninteresting ECG components, but also eliminates baseline wander and
low frequency noise sources.
Figure 1
above shows a representative ECG signal with power line
interference.
Figure 2 below
shows the same signal after being filtered by a 100 tap FIR filter with
a 0 - 40Hz pass band.
If a transient EMI event corrupts the value of an output port, it is
possible that the effect may be minimized by a periodic refresh of the
output port values. Of course, in many cases having the output
corrupted for any amount of time is unacceptable, but in the cases
where it is manageable (an LED output for example), this could be an
acceptable solution.
 |
| Figure
2. ECG through 100 Tap FIR Filter |
This solution can also be applied to configuration registers of
on-chip peripherals. A periodic refresh of the configuration of those
peripherals might make the temporary corruption of one of those
registers tolerable. However, sometimes writing to a peripheral
configuration register can cause a reset or other disruption in the
operation of the peripheral, so use care when employing this method.
In many cases, the designer has a choice between using a
level-triggered or an edge-triggered interrupt. If it is feasible, the
level-triggered interrupt should be chosen. Whereas an edge-triggered
interrupt typically does not impose any minimum requirement on the
interrupt event pulse width, a level-triggered interrupt will.
Typically, an interrupt controller samples the interrupt inputs at
some defined frequency (once per instruction cycle, for instance). A
level-triggered interrupt will require the event to be present two
samples in a row before an interrupt is generated. The minimum width is
the sample period. An edge triggered interrupt will look for two
consecutive samples that indicate the intended transition.
Since the transition can occur almost immediately before the next
sample, there really is no minimum width imposed on the interrupt
event. The net effect is that noise is more likely to trigger an edge
triggered interrupt than a level triggered interrupt. Microcontrollers
sample interrupts using different methods. Understanding how your
microcontroller samples interrupts is the key to determining which type
of interrupt is less sensitive to noise than the other.