Hi everyone.
I really need help wiyh a AC voltmeter. How can i measure AC voltage?
does anybody know any link ? any code sample !
thx
Hi everyone.
I really need help wiyh a AC voltmeter. How can i measure AC voltage?
does anybody know any link ? any code sample !
thx
Hi Uludere,
If you're intending to use a PIC with ADC such as e.g. the 16F87* and you want to measure directly then it's only a question of the frequency you are dealing with and the speed of the PIC oscillator. If you are prepared to do a little circuit work and you don't need to read the frequency you can rectify the AC line and simply measure the DC component, which is easier and requires much less code.
It's no problem, though. Let me know what range of voltage and frequency you're interested in and I'll send you info.
Greetings,
Rob
Hi Rob:
I have a similar application and I need to read from 0 to 3v ac with a
16F876 at 4 mhz.
Any hints.?
Thanks in advance...
Ruben de la Pena V.
Hi,
The simplest way to measure a sinewave ac is to rectify the input and do an ADC. Simply multiply the result with 0.707 to get the RMS value. If your input range is too low then some amplification and active rectification through OP-AMPS maybe needed. In fact the gain of the op-amp stage can be calibrated to give you an average dc reading (no need for maths in the PIC side). That is what is done in low cost multimeters. To get best results (depending on the speed needed) do an averaging of the samples collected. Please let me know your exact requirement
1. Range of Input Voltage
2. Maximum Frequency
3. Input waveform
I will try to help.
Regards
Sougata
Mr.Sougata:
I am trying to read a Current transformer. It gives 1000 to 5 amps transformation. With a proper load resistor it will give you a AC voltage proportional to the current.
The range will be between 0 and 3 volts. The ac is plain 60 hertz, but the
rectification reduces the range to .7 to 3 Volts more or less.
If those voltages correspond to 0 to 1000 amps,I can only read from 233 amps to 1000.
Any simple way to overcom the rectification loss.?
Thanks in advance..
Ruben de la Pena
You can't. This is not away to measure AC current in full scale.Originally Posted by Ruben Pena
In one of my project I had exactly the same problem : measuring AC current using current transformer. First idea was to do ADC sampling from time to time and search for max. value in recent period (to find amplitude for ac signal) and then calculate RMS (0.707*peak). This gave poor results so I used different approach: As mains frequency should be 50Hz+/-1Hz, I used interrupt routine synchronized with zero crossing of current, then trigger another interrupt that waits that you come near the expected peak of current and then start to do ADC searching for max value.
In my case, timings were 19.6ms for start and 20.6 for finishing ADC's (50 Hz mains). Since you got approx 40us resolution, this would capture a peak value with sufficient accuracy. This actually worked pretty good, I was able to calculate RMS and from there power. Problem was that in real application, AC mains were distorted (not pure sinus wave). I tried to introduce correction factor, but couldn't (you should calculate trig function in interrupt, that was impossible task for me and poor 18F).
Solution? Well, I finally used specialized (signal->True rms converter) IC. Not a great solution, but it worked and saved me a great time.
Also, put some bigger resistor so you expand your range from 0-3V to 0-5V or you would get poor resolution.
Last edited by lab310; - 20th January 2006 at 09:11.
Originally Posted by boboco
I want to measure upto 300 V AC/ 50 Hz. I have 16f877 20 MHz ..
but any other appliction maybe helpfull !!
Last edited by uludere72; - 20th January 2006 at 11:07.
Hi All,
most has been already said, but a few points to the remarks of other posters, thanks by the way.
One safety point to start: by any sort of voltage (current) measurement please be sure that the complete supply to the PIC etc. is either floating or that grounds of both circuits (Voltmeter and Circuit to be tested) are connected to the same level.
To measure low AC voltages (< ca. 10V) accurately by rectification it is necessary to use ideal diodes. Normal diodes will have a forward drop voltage of ca. 0.6V (silicon) or ca. 0.3V (germanium). Best here is to use two OPs with diodes in the feedback, trimmed to 0V. For those who wish, I will be happy to supply circuits etc.
OP use has the additional advantage of common mode rejection and quasi-floating inputs. It also allows good frequency compensation and, of course, fine adjustment.
To avoid such circuitry it can (with a bit of fiddling) be done by setting the PIC power supply ground to have an offset to the half of the AC peak to be measured. Set a resistor divider chain so as to arrange for an AC signal of not more than +/2.5V at an ADC input.
Read this input as fast as possible at a consistant frequency. While the e.g. PIC16F877 has a 10 bit ADC, you will have an accuracy of not more than 9 bit, so if you measure 300 V you will have a maximal possible accuracy of ca. 0.6V.
With a 4 meg oscillator and a sample time from say 50 uS you could have a theorectical sample rate of 20 K/S, at 50 Hz a read of 400 per cycle. By adding all values from lowest to highest each cycle, a value can be calculated that will represent the AC voltage.
By measuring how many reads are possible in the one sweep, a rudimentery frequency value can be detected. By adding new volt and frequency values to the old and dividing by two, each value is averaged and will become more accurate with time. This accuracy will be maintained up to Nyquist, which put very simply says that if you can't have more than one sample per half-wave, you can't measure it. (Not completely right, I know, but good enough for now.)
If any are interested, let me know with details of max. V, max. F and accuracy and I will be happy to help.
Greetings,
Rob
Thanks Rob:
I will try with a RMS to DC converter.
Regards..
Ruben de la Pena V
thx rob
i understood like this..
i am going to Read this input ,which is reduced to 2.5 V ac, every 50 uS.
then i am going to add all values at each cyle !!
thx
Hi Uludere,
Have you converted to DC (RMS method) or are you reading AC?
If you have converted to DC, you can read each 50 uS and average the readings, but only if you are reading lower frequencies. Taking as example 50 Hz, you have a cycle period of 20 mS. Reading at 50uS you have 400 reads per 20 mS cycle. Add each input and divide by two each time to average.
Example:
readinput:
ADCIN 0, Readvolts 'Get value
volts = volts + readvolts 'Add value to volts variable
volts = volts / 2 'Average volts variable
GOTO readinput 'Start again
With this you'll get fairly good results up to about 100 Hz, then it will start getting increasingly erratic.
If you are measuring AC directly it's a little more complicated. It also depends on if you are measuring floating AC (not swinging symmetrically around ground) or grounded (swinging symmetrically about ground).
If you have arranged so that the AC is swinging around 2.5V at the PIC ADC input you read inputs and find out the highest and lowest values, which you use to calculate the difference.
Example
Readinput:
ADCIN 0, readvolts ‘Read input
IF readvolts > highvalue THEN highvalue = readvolts ‘Find maximal value
IF readvolts < lowvalue THEN lowvalue = readvolts ‘Find minimal value
Voltsvalue = highvalue – lowvalue ‘Calculate difference to find AC value
GOTO Readinput
To be honest, neither method is especially good or accurate, but with the addition of a few components you could create a stable, accurate and precise AC voltmeter, which I think would be of more interest to you than the above two mwthods. If you would prefer that, please let me know and I’ll send you the circuit and details.
GHreetings,
Rob
thx you very much rob !!
I wrote this code. for AC measurment . But i didn't check on real device!
does it work ? It worked with DC :-)
If you can send any cirtuit and detail , it will be help to us !
best regards
Define LOADER_USED 1
;Define OSC 20
'Test Kart LCD
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
adval var word ' Create adval to store result
AcVolt var word
Acvolt2 var word
volt1 var word
volt2 var word
Cnt var byte
Cnt =1
ADCON1 = 7 ' Set PORTA and PORTE to digital
Low PORTE.2 ' LCD R/W line low (W)
Pause 100 ' Wait for LCD to start up
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify result
loop:
For cnt = 1 to 400
ADCIN 0, adval ' Read channel 0 to adval
adval= (adval*10)/204 ' 0 -5 V
volt1 = adval/10
Volt2= (adval - volt1*10)
'LCDout$fe, 1 ,"Value: ",dec(volt1) ,".",dec (volt2), " Say:" ,dec say
ACVolt = Acvolt + (volt1)*(volt1)
AcVolt2= AcVolt2+ volt2*volt2
'LCDout$fe, $c0 ,"Value: ",DEC (acvolt )
'pause 250
pauseus 50
next cnt
acvolt = sqr(acvolt/400)
AcVolt2= sqr(Acvolt2/400)
LCDout$fe, 1 ,"RMS AC V: ",DEC (acvolt),".", dec acvolt2' Display value
' Pause 1000 ' Wait .1 second
adval=0
Goto loop ' Do it forever
End
Last edited by uludere72; - 26th January 2006 at 13:09.
Bookmarks