Page 1 of 1

Measure peak voltage

Posted: Mon Feb 13, 2012 4:50 pm
by Will643
Hi

I would like to know how i would proceed to measure the peak voltage of the sine waveform. I am new to programming and flowcode. What i have thought so far is to use:
20MHz crystal/4 = 5MHz and then a prescale value of 8 brings the timer to 625kHz
FCV_COUNT = 625000/(256*tmr1h + tmr1l);
FCV_POS_PK_TM = (1/(FCV_COUNT/4)); //1/F=POS_PK_TM=Positive peak time
Which will give me the time until the peak of the waveform and then use the digital to analog converter to measure the voltage at this time. I have the analog to digital converter operating but cannot think of how to get the analog to digital converter to measure the peak voltage at the time calculated (POS_PK_TM=Positive peak time).

Any assistance would be appreciated.

Regards
Will

Re: Measure peak voltage

Posted: Mon Feb 13, 2012 6:26 pm
by Benj
Hello Will,

Could you simply sample as fast as possible for a period of time, after each sample check to see if the sample is greater then the last greatest sample. If it is then replace with the current sample value. If your time period covers at least a couple of cycles then you should get fairly good accuracy.

Or do you need to be able to sample the unique peak every cycle?

Re: Measure peak voltage

Posted: Tue Feb 14, 2012 1:33 am
by Will643
Hi Ben

I would like to sample each peak, both positive and negative. What i have is a scaled mains voltage between 0 and 5V centered at approximately 2.5V. So i need to measure the positive peak and negative peak, add the two peaks and divide by 2 to get the real peak as it may not be centered on 2.5V. I have the frequency measured so a can get the positive peak time and negative peak time. I would like to measure the peaks and update the lcd possibly once a second. Is it possible to measure at a certain point on the wave as i want to at the peak.

Regards
Will

Re: Measure peak voltage

Posted: Tue Feb 14, 2012 10:31 am
by Benj
Hi Will,

One way would be to perform multiple samples for an entire cycle. eg 1/50Hz = 0.02s or 20ms. You then do as I suggested above to get the maximum reading. At the same time you perform a similar method to give you the lowest reading. You then have the readings for the upper most sample and the lowest sample for that cycle. You could then print out the results to the display or you could repeat the process 50 times before updating the display to give you a more accurate reading and a display update once per second.

Re: Measure peak voltage

Posted: Wed Feb 15, 2012 6:47 pm
by STibor
Hi!
Rectifier, the program simpler and more accurate measurement.
http://ww1.microchip.com/downloads/en/A ... 01353A.pdf
http://ytdp.ee.wits.ac.za/cct.html
The simulation is slow due to the timer interrupt.