Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

AC Voltage Sampling program using PIC MCU

Not open for further replies.

Prince Vegeta

Member level 5
May 29, 2012
Reaction score
Trophy points
Activity points
Hi everyone.

I'm measuring 2 AC sources - 50Hz 230v RMS.

I read this subject about offsetting AC voltage to make it 0-5v DC one to get it in the ADC pin of PIC MCU for measuring it.

I have some questions after that:

1- How can I calculate RMS value of the signal?

I need code example of this question if you can. now 0v will be -380v peak AC voltage in real and 2.5v will be 0v and so on... now, do I need to worry about negative voltage (- signal in code?) or just calculate it then converting ADC value to actual voltage value?

2- I'm not good with op-amps so I did my offset circuit without them... like this:


is this applicable with 230v RMS means?

3- if there is harmonics, will it affect the readings made by THIS method?

4- I'm using PIC16F877A MCU, with 16MHz crystal (or should I use another?)... will it be enough to sample and measure 2-4 AC voltages (50Hz each) and display them at LCD with other small functions? gimme your recommendations.

5- I read a blog-post here that suggested adding a voltage follower to the voltage divider, then a filter... after them a 5.1v Zener diode THEN to ADC pin... is that applicable with this sinewave signal?


I read that thread but it didn't answer my main question which is how to calulate RMS in code? because there is -ve cycle and so...

also, why I need a transformer if voltage divider does the job?

Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to