This is part of a program I wrote a couple of years ago that looks for a noise of a certain length in a quiet room. Wondered why micro-sampling seemed to ring a distant bell. The PIC has 2*3-way DIP switches on it to set the sampling length and the time-out before the next round of sampling. Basically the PIC looks at the comparator under WDT timing and does a rough majority test for the number of samples that are "1", just to eliminate sounds that are too short. The signal level that will cause a "1" at the output is set by a preset on the LP311's input, ie no s/w filtering, it just has to be loud enough to flip the comparator. The h/w is very similar to the pic I posted tsmp = # of samples that are "1" trp = sampling period in WDT wake-ups ipt = input from comparator gps1 = general purpose scratch gps2 = general purpose scratch ;------ WAIT FOR TRIGGER zzzz sleep ;low-power mode. Wait for WDT wake-up btfss ipt ;process if comparator active goto zzzz ;else back to sleep movf trp,w ;get trigger timing period reference btfsc zero ;if <> 0 then WDT required, start counting goto out ;else straight to output / timeout ;------ PROCESS TRIGGER AND COMPARATOR SIGNAL movwf gps1 ;number of samples taken counter movf tsmp,w movwf gps2 ;results counter sample sleep ;stay in this loop as long as needed ;sampling every 192mS bcf led ;LED off by default btfsc ipt ;test comparator for LED bsf led ;LED on if comparator high tcomp btfsc ipt ;test comparator for compiling results decfsz gps2,f ;decrease result ref value if sample = '1' goto dtime ;decrement timer goto out ;exit sampling loop if ref down to 0 dtime decfsz gps1,f ;decrement sample timer count goto sample ;continue if time left goto entry ;else start again ;------ OUTPUT out bcf psu ;front end power off bsf opto ;output on bsf led ;indicator on etc -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu