Dario Greggio wrote: > Basically I need to be sure that VAC is not lower > than 200V (say) or higher than 240 before activating > the pumps, the valves, or else. So precision is not > *that* important, but still somehow. ... > Basically - pseudocode: > > Take 20 samples/sine > for each sample > =A0 =A0 =A0 =A0take previous sum > =A0 =A0 =A0 =A0divide by 20 > =A0 =A0 =A0 =A0subtract this (sum/20) from previous sum > =A0 =A0 =A0 =A0add new sample to sum > > At the end of 20 samples... then what? Why not some simple scheme with Zener diode and an optocoupler to send a signal to the PIC when the peak voltage is higher than some certain level? Two voltage dividers and the optocouple between them. One divider would have a Zener instead of the bottom resistor. Select the resistor values the way that the shortest signal would correspond to the bottom value of the desired voltage range. Measuring length of the signal you could figure out the peak voltage. Also a PIC could adjust the divider ratio using relays if you need to change the measured range dynamically. -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist