View previous topic :: View next topic |
Author |
Message |
ratheeshbr
Joined: 26 Jan 2011 Posts: 31
|
Voltage Measurement using PIC16f877a |
Posted: Tue Mar 06, 2012 5:19 pm |
|
|
I am trying to measure AC voltage using micro controller. I am using a 3-0-3 transformer and after converting to DC using diode, I am reading it using ADC. But the output voltage shows around 105-115 volts. I think there is mistake in the multiplication factor. I am using (230v/1023). Is there any mistake? Please reply. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Mar 06, 2012 7:13 pm |
|
|
a mistake ?? Could well be ...
but without a schematic and your code??
who can tell? |
|
|
ratheeshbr
Joined: 26 Jan 2011 Posts: 31
|
Details |
Posted: Tue Mar 06, 2012 7:54 pm |
|
|
Sorry. I forget to give the details. The circuit is nothing but a 3-0-3 centre tapped transformer- a rectifier to make it and a 10uF capacitor for smoothening and reading using ADC of PIC16f877a.
Code: | #include<16f877a.h>
# use delay(clock=20000000)
#USE RS232(BAUD=9600,errors,PARITY=N,XMIT=PIN_C6,RCV=PIN_C7,BITS=8)
void main()
{
int x,volt;
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(ALL_ANALOG);
while(1)
{
set_adc_channel(2);
delay_us(20);
x=read_adc();
volt=x*230/1023;
printf("%d",volt);
}
}
|
O/p is around 170v |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Tue Mar 06, 2012 8:11 pm |
|
|
Recognize that when you half wave rectify your signal and feed it to a filter cap, you have just introduced a couple of significant errors - the first is you are going to be reading peak voltage while the line voltage spec you are talking about (either 115 or 230 is RMS (.707 * peak for a sine wave). Also, at that low a voltage (3 volts, if you are using a silicon diode, the typical drop across it is 0.7 volts which also is going to screw up your reading. Both of those factors need to be taken into consideration in your calculations. The diode drop will probably be the harder one to deal with because the forward drop across the diode is a non-linear function of the current through the diode (see the spec sheets for your diode of choice).
There are a couple of ways around the diode issue - use a "precision rectifier" usually built with an op-amp and a diode in the feedback. Another way would be to not use a diode. Use a zero-crossing detector then measure the voltage 90 degrees later (granted, this requires you to be working with a known frequency - in this case the line mains for example). Another way to minimize the diode drop issues is to step the voltage down to 100VAC for example (using a transformer for isolation) rectify that then use a resistive voltage divider to drop it down to the level of the ADC in the PIC - at 100v, a 0.7 drop is not very significant - at 3 volts it is.
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Mar 06, 2012 8:22 pm |
|
|
default for ADC is 8 bits....... |
|
|
ratheeshbr
Joined: 26 Jan 2011 Posts: 31
|
|
Posted: Tue Mar 06, 2012 8:26 pm |
|
|
ya I changed it to 10. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Wed Mar 07, 2012 1:03 am |
|
|
gpsmikey wrote: |
There are a couple of ways around the diode issue - use a "precision rectifier" usually built with an op-amp and a diode in the feedback.
|
I think with a single diode you want it in series with the output and then feeding back.
for the orignal poster (if they want):
http://en.wikipedia.org/wiki/Precision_rectifier _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Wed Mar 07, 2012 2:42 am |
|
|
Key line:
int x,volt;
How big can an 'int' be?.
What will happen when you multiply an incoming value like '200', by '230'?.....
Best Wishes |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed Mar 07, 2012 9:38 am |
|
|
also...
x=read_adc();
what does 'x' contain after the read_adc() function ?
hint, it ain't 10 bits of adc data ! |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
Measuring ac |
Posted: Wed Mar 07, 2012 2:55 pm |
|
|
If you want to measure ac, you don't HAVE to rectify.
Feed your stepped down voltage into your ADC, with the ADC input biased to Vref/2.
By taking ADC values at regular intervals you can then calculate any parameter of your input voltage.
NB. I am not contradicting anything that has been said by other contributers to this post, simply adding to it.
Mike |
|
|
|