Peak Detection Using ADC of ATMEGA16

Thread Starter

Usama_ali143

Joined Jul 17, 2017
27
Hi guys ! I want to detect peak of sine wave using built_in ADC of Atmega16. How can i achieve this? please cooperate..i m new in embedded world.
 

MrChips

Joined Oct 2, 2009
34,807
Hi guys ! I want to detect peak of sine wave using built_in ADC of Atmega16. How can i achieve this? please cooperate..i m new in embedded world.
One of two ways:

1) Digitize the sine wave at a sampling rate to get as many points per cycle as possible and search for the maximum value.

2) Use a hardware peak detect circuit and sample the output of the circuit.
 

DickCappels

Joined Aug 21, 2008
10,661
To do it in firmware:

1. Feed the signal into an A-to-D channel

2. Set some variable (or register or memory location) to zero. Call this variable "peak" for now.

3. Sample the value frequently and if the sampled value is greater than the value in "peak" replace the value in "peak" with the new sampled value.

4. Repeat

To be very useful you will need to also have a routine that is called regularly that decrements the value in "peak" by some number of counts or some fraction of the total so that if the peak input value gets lower with time the value in "peak" will track it.
 

MrChips

Joined Oct 2, 2009
34,807
To do it in firmware:

1. Feed the signal into an A-to-D channel

2. Set some variable (or register or memory location) to zero. Call this variable "peak" for now.

3. Sample the value frequently and if the sampled value is greater than the value in "peak" replace the value in "peak" with the new sampled value.

4. Repeat

To be very useful you will need to also have a routine that is called regularly that decrements the value in "peak" by some number of counts or some fraction of the total so that if the peak input value gets lower with time the value in "peak" will track it.
You can sample at a slower rate if you make sure that your sampling rate is not some exact multiple or inverse multiple of the sine wave frequency, i.e. you want samples taken randomly at different phase points in the cycle.
 

Andrei Suditu

Joined Jul 27, 2016
52
As the others pointed out you can analyze the ADC samples ....but I wonder if you could just detected the zero cross and calculate your peaks( or the time when the peaks come).
Something like 2 optocouplers (2 for detection of both + side of the sin and - side) and fire an interrupt when both inputs from optocouplers are off.
See the interval of time between two "zeros" and calculate the frequency.From there the wines are at pi/2-3pi/2
 
Top