Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Ac voltage and current measuring with PIC.

Not open for further replies.


Junior Member level 3
Jan 11, 2010
Reaction score
Trophy points
Activity points
Hello,everybody.I want to measure Ac currents and voltages with the following specifications;

My circuit & program code specifications;

Applied AC voltage 100Vpeak via a 1/20 resistor network attenuator to AN0/pin2 of PIC18F452/XTAL;20MHZ.

I wrote a program to show 25000Vrms/35355Vpeak,so we have a factor of;250x20x0.707xVadc=3535Vadc.[The followings are all detailes; my software].

But it shows only 0 on the LCD.For diagnosis I added this instruction to my program;
adclong0 =25000;then it showed on the LCD correctly.I even test my prog with LTC1966 chip[DC to RMS converter] or bridge or super rectifire[op-amp rectifier] or op-amp for voltage signal input conditioning but it does not work and just shows 0000000V.

Would you please tell me what is wrong with my program?

**My program;
MCU: PIC18F452.

Oscillator: HS, 20.0000 MHz

GLCD: PG24064F [ T6963C driver/display 240x64 pixels ].

SW: mikroC PRO for PIC.
#include "__T6963C.h"

unsigned long int adclong0=0,adclong1=0;
unsigned int ti=0,tn=0,t0=0,t1=0;
unsigned int xp,xl,yp,yl,xpos=0,ypos=0;
unsigned char ch0=0,ch1=0;
char *message;

//Voltage input calculations

void Display_Adcz(unsigned char ch0) {

extern unsigned int ypos;//To use a Zener at input so we have half wave
//and two zero points possibilities for Ac wave input.

//Get Vpeak from input voltage wave.

LADCV1:ti=ADC_Read(0);//Get ADC value from channel0;read until ti=0.
if(ti==0)goto LADCV2
else goto LADCV1
LADCV2:ti=ADC_Read(0);//1st sample;initial[previous].
tn=ADC_Read(0);//2nd sample;next.
if(tn>ti)goto LADCV2
else t0=ti;

adclong0 = (long)t0 * 5000;//Convert adc reading to milivolts.
adclong0 = adclong0 / 1023;// 0..1023 -> 0-5000mV.

//20=resistor network of input attenutor.
//Vrms = 0.707 Vpeak,[1/1.4142=0.707.].
//Input Transformer conversion index;[250=25000/100.].
//Peak input voltage= 35355v [2500Vrms.] at the primary
//converted to 141.42Vpeak[100Vrms.] peak at the secondary.

adclong0 = adclong0 * 3535;//0.707x20x250=3535.

Thanks & Regards,

Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com