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