# peak to peak of voltage

Discussion in 'Embedded Systems and Microcontrollers' started by king40, Aug 2, 2013.

1. ### king40 Thread Starter Member

Jul 17, 2013
75
0
hi
how possible to measure peak to peak of voltage in bascom avr
i measure voltage with this code :
Code ( (Unknown Language)):
1.
3. Config Adc = Single , Prescaler = Auto
5. Enable Interrupts
7. Dim Volt As Single
10. Volt = Volt * 25
11. lcd volt
12.
13.
but i dont know to measure peak to peak of voltage
thanks of any help

2. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
How many samples can you take per cycle of the waveform you are measuring?

What ability to you have to put circuitry in front of the A2D?

king40 likes this.
3. ### king40 Thread Starter Member

Jul 17, 2013
75
0
i dont know about take samples of per cycle in waveform

4. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
Well, what you are expecting to do? Take a single voltage measurement at one moment in time and somehow get the peak-to-peak voltage of the waveform?

king40 likes this.
5. ### Papabravo Expert

Feb 24, 2006
10,340
1,850
Well....
If the waveform is a sine wave then it has an amplitude and a frequency. The reciprocal of the frequency is the period. In order to have some chance of measuring the peak value you need to determine the period. This can be done with some precision by locating the zero crossings. The peaks are one quarter of a cycle before and after the zero crossings.
Does that help?

king40 likes this.
6. ### joeyd999 AAC Fanatic!

Jun 6, 2011
2,757
2,936
This seems like a rather round-about way of peak detection. Why not just sample the signal *fast enough* to capture the peaks, and keep your low and high values?

king40 likes this.

Jul 17, 2013
75
0
yes exactly

8. ### king40 Thread Starter Member

Jul 17, 2013
75
0
i think most of the voltage have sine waveform.

i can measure period of frequency by create a timer
and then measuring peak by the period ?

9. ### king40 Thread Starter Member

Jul 17, 2013
75
0
thanks
how i can take sample of signal??

10. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
Okay, then I just measured a voltage and it was 1.435V. What is the peak-to-peak voltage?

If you can't do it based on one measured value, how can you possibly hope to write a computer program to do it?

But now let's say that I measure the voltage every, say, 5ms and I get the following results:

 Voltage (V) 31.257 31.746 5.216 -22.282 -23.748 2.258 30.200 32.642 7.185 -21.173 -24.587 0.295 29.041

What is your best estimate of the peak-to-peak voltage?

How might you do this programmatically?

There are a number of different ways, some simpler and some more accurate than others. Which is "best" depends on your needs. The real question isn't, "which is best?", but rather something more like, "which method is the simplest/cheapest while also being good enough?"

11. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
Knowing the period isn't going to give you the peak-to-peak voltage. In theory it would allow you take one measurement at one peak and then another measurement at the other peak. But it tricky to get it good enough and the time you spend trying to find the period and the proper time reference to you, you could have just brute forced the measurement of the min and max values and calculated the peak-to-peak votlage directly.

king40 likes this.
12. ### king40 Thread Starter Member

Jul 17, 2013
75
0
i'm new in avr bascom and want to learning
i use external 12MHZ crystal
and my micro is ATMEGA 32
my min voltage is 0
and my max voltage is 25
i can measure voltage but
i dont know how to measure peak to peak of voltage

13. ### king40 Thread Starter Member

Jul 17, 2013
75
0
i think this way very good
if i measure the one peak i have max values
and if i measure the other peak i have min values
but how i can measure amplitude in max values and min values

14. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
Are you trying to measure peak-to-peak voltage or are you trying to measure amplitude. These are NOT the same thing. Make up your mind!

Go back to the post where I gave a list of measured values and try to answer the question. What is the peak-to-peak voltage of that data set? Now plot the data on a time axis, knowing that the measurements were taken 5ms apart. What is your best estimate of the peak-to-peak voltage based on the drawing?

king40 likes this.
15. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
The min voltage that you can measure is 0V. The max voltage you can measure is (probably) 2.5V (unless you have a voltage divider or other attenuator).

But these are the min/max we are talking about, they are the capabilities of your system. The min/max we are talkiing about are the min and max values OF THE WAVEFORM being measured.

king40 likes this.
16. ### king40 Thread Starter Member

Jul 17, 2013
75
0
i wants in first post measure peak to peak of voltage
but when i see post#5 by @Papabravo
this post change my mind
this is possible to measure all detail about waveform of voltage
like amplitude ,wavelength ,.....??

17. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
Why don't you pick ONE thing and learn how to measure that ONE thing, before trying to measure "all detail" about the waveform?