On Wed, 2005-06-29 at 11:56 +0800, Chen Xiao Fan wrote: > Looking forward to see your post on the FilterPulse(). Thanks really > a lot for your detailed explanation. Well, I was hoping that others would've chimed in by now in the other thread you started on how to filter your pulses. But the reason they probably haven't is because without more information about your system, there's no way to design a filter. So stating the obvious, a filter must separate the noise from the signal. This means you have to know the characteristics of each. You've briefly alluded to a few noise sources: fluorescent lights, 50/60 Hz stuff, and neighboring sensors. You really haven't described the signal other than to say that it consist of pulses and that you'd like to detect them fast as possible. I can infer from your earlier posts that a 1 mS signal detection time is acceptable, but that you really want something like 400 or 500 uS. I have no idea what your detectors are attempting to detect. I mean, I know they're proximity detectors, but are you wanting to detect bullets coming from the muzzle of a rifle or count Furbies on a conveyor belt? These two 'signals' have distinctly different characteristics, and I'm sure your marketing department wants you to be able to detect both! :) Before pretending that I can propose a filter, I think you'll find that the two techniques of pulse rejection mention so far (varying the pulse timing and measuring the pulse width) can go a long way in rejecting noise. While you agree in principle that these are good ideas, you've suggested that amplifier-introduced distortions limit their usefulness. I'd suggest fixing the amplifier! For example, have you ever investigated a cascading logarithmic amplifier? I think you could construct a 3 stage transistor amplifier following a simple preamp. The output of each stage can be monitored with PIC I/O pins. This essential becomes a 3-bit logarithmic ADC with a dynamic range of something like G^3 where G is the gain of each stage: signal --> preamp --> LinAmp --+--> LinAmp --+--> LinAmp --+--> ... | | | I/O 0 I/O 1 I/O 2 The 'LinAmp' is a transistor-based linear amplifier that is *designed* to saturate. I won't elaborate much more because a) I'm not expert in this area and b) I'm sure there are other physical constraints in your system. I can say that a single BJT, 4 resistors, and 2 capacitors can make a decent single stage. Also, another subtle feature is that the I/O pins can also be controlled outputs from the PIC. This could be used to create some form of active noise cancellation (e.g. 50/60 Hz noise could be rejected by adding an active source that's out of phase). But sticking with the amplifier you have already, the filter you proposed before seems reasonable enough. Here's a variation that is fast: MOVLW 1 BTFSS PULSE_PORT,PULSE_PIN MOVLW -1 ADDWF FilteredPulse,W BTFSC FilteredPulse,3 COMF FilteredPulse,W ANDLW 0b00000111 MOVWF FilteredPulse Here's the C-version that may be easier to follow: if (bPulse) { // Pulse is high if (++FilteredPulse > 8) FilteredPulse = 7; } else { // Pulse is low if (--FilteredPulse < 0) FilteredPulse = 0; } The filtered signal can be bit 2 of the filtered pulse: BCF Signal,0 BTFSC FilteredPulse,2 BSF Signal,0 Scott -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist