Capture of Peak voltage with ADC

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Capture of Peak voltage with ADC

Post by fotios »

Hi everyone

I have the following problem:
A PWM signal with modulated duty cycle from 5 to 95%, that is produced by the source in 4 different levels:
3.0Vp (byte value = 153)
2.72Vp (byte value = 139)
2.33Vp (byte value = 119)
1.94Vp (byte value = 99)
Which is the best way to catch only the peak level of the PWM signal, ignoring the duty cycle (or pulse width)?
The best way i found so far, is an ADC channel configured as usually, and a routine that rejects any ADC reading below 99 (1.94Vp) to remove the 0 reading of it. (Averaging should be excluded as the reading also depends on the duty cycle)
I can say that is working OK by 90%, but some times the unwanted 0 readings of ADC can pass in the rest program loop, causing wrong results.
Please see in attached fcf.
Is there any other way to measure JUST the peak value?

Thanks
evcPulse.fcf
(19.84 KiB) Downloaded 206 times
Best Regards FOTIS ANAGNOSTOU

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Capture of Peak voltage with ADC

Post by medelec35 »

Hi fotios,
If it was me I would use a decision branch like:

Code: Select all

If Peak_Variable > ADC then Peak_Variable = ADC : Peak_Variable = 0  : Do something 
You could of course use a timer interrupt to sample every few seconds.

Martin
Martin

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: Capture of Peak voltage with ADC

Post by fotios »

Hi Martin
Thank you for the advice. However it mostly seems to be a joy with delays, to obtain more stable readings of ADC. To the present, i use the function generator to produce the PWM signal by changing its pulse width and level. Maybe the actual project will produce more stable pulses at the the input of ADC, as it will jump exactly from 3.0Vp -> 2.72Vp -> 2.33Vp -> 1.94Vp and vice versa. Now, i use the output level pot of generator to obtain the desirable level and some flickering is inevitable i think?
You could of course use a timer interrupt to sample every few seconds.
That is correct. This code is experimental and just to explore the behaviour of ADC converter on the given issue.
However, i modified the code for your favor :)

Fotis
evcPulse.fcf
(23.01 KiB) Downloaded 210 times
Best Regards FOTIS ANAGNOSTOU

Post Reply