Peak Detection Using ADC of ATMEGA16

Discussion in 'Embedded Systems and Microcontrollers' started by Usama_ali143, Aug 3, 2017.

  1. Usama_ali143

    Thread Starter New Member

    Jul 17, 2017
    27
    0
    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.
     
  2. MrChips

    Moderator

    Oct 2, 2009
    17,119
    5,294
    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.
     
  3. DickCappels

    Moderator

    Aug 21, 2008
    4,962
    1,511
    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.
     
    Usama_ali143 likes this.
  4. MrChips

    Moderator

    Oct 2, 2009
    17,119
    5,294
    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.
     
    DickCappels likes this.
  5. Andrei Suditu

    New Member

    Jul 27, 2016
    22
    1
    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
     
Loading...