At 03:17 AM 3/8/2010, Dario Greggio wrote: >I am to use a 24FJxxGA106 to (along other things) measure 220V mains >voltage with some coarse accuracy, say 1-2% > >I have a small 220->6V transformer, whose inputs goes via a partitor >(still have to decide, but let's assume it 4K7 - 2K2) to AN2 of the PIC. >So, more or less 2Vrms or 3Vpp circa when mains is nominal 220V. > >I'm planning on sampling/reading the input voltage some ... 100? times / >second, and perform a ... FFT or something simpler upon it. I'm currently doing something similar with a 12f675 running directly from a 120Vac power-line input. In my case, I threw extra parts at the problem to make the software easier and to allow the PIC pin to work as both an input and an output. The 120Vac input is sampled with a 100K resistor, then to 2- 1n4148 diodes: one to clamp the negative half-cycle, the other feeds into a 1u0 63V capacitor. The capacitor also feeds into a 100K / 10K voltage divider which then feeds the PIC input. Note that the first 1n4148 diode wouldn't be needed if I used diodes with a higher PIV rating but 1n4148 is a standard part for us - easier to add the extra diode. All three resistors are 1%. Total of 6 extremely inexpensive parts. The software samples the input every 1.024ms and feeds a 16 times IIR filter. The output of that filter is then fed into a peak detector with a period of 20ms (20 ticks of 1.024ms each). This allows me to accurately measure the 120Vac line voltage and make decisions on whether to allow system operation or not. You could scale this for 220Vac input just by changing the input resistor. I'd be tempted to use 2 resistors in series for better protection against transient spikes, though. Hope this helps! dwayne -- Dwayne Reid Trinity Electronics Systems Ltd Edmonton, AB, CANADA (780) 489-3199 voice (780) 487-6397 fax www.trinity-electronics.com Custom Electronics Design and Manufacturing -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist