Rising edge detector with AVR32 UCA0512

Discussion in 'Embedded Systems and Microcontrollers' started by donaldm444, Aug 8, 2011.

  1. donaldm444

    Thread Starter New Member

    Jul 16, 2010
    I am new to programming micros, but I am using the EVK1100 (Atmel UC3A0512 32-bit processor) and I want to sample two sinusoidal voltage signals (using A/D) and detect when their rising edges occur. The time between rising edge detections between the two signals needs to be recorded, so that we can estimate power factor (of a grid demo unit we are creating).

    My approach is to: start a timer, start detecting rising edges in signal 1 and signal 2. When a rising edge is found, an interrupt records the time of detection and raises a flag. The algorithm runs until the rising edge in the other signal is found, at which point its time of detection is recorded. The difference in time of detections is calculated, and an estimate of the power factor is returned.

    If anyone has any suggestions on where to start it would be greatly appreciated. I have been looking at the A/D examples in the AVR32 software framework. Also, I am using AVR32 studio with GNU toolchain.
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    Doing this with the A2D will probably produce some innaccurate results as the A2D will take some time to do a conversion so you will be doing a lot of coding to back figure out at what time the wave was what voltage. Messy. Yuck. Simon sez don't do that.

    Better way is to do this digitally by converting the sine wave to a square wave that can drive a digital I/O pin directly. Depending on the amplitude of your sine wave this can be as simple as a largish value resistor between the sine source and the micro. That technique depends on using the internal ESD diodes to clamp the voltage to little below ground and a little above Vss. If that worries you, add in redundant schottky diodes for the clamps. I've done that when synching a PIC to the AC line (but I can't tell you any more without violating the TOS here).

    This way you jump right into your ISR just as the wave is changing from 0- to 0+ and you get the best resolution of zero you can get. Any delay error should cancel when you take the difference of the two waves.

    If your sine waves are on the small side you may need a comparator to help square them up.
    donaldm444 likes this.