Connect with us

Calculate frequency using MCU

Discussion in 'Microcontrollers, Programming and IoT' started by Cruzer, Mar 20, 2012.

Scroll to continue with content
  1. Cruzer

    Cruzer

    2
    0
    Mar 20, 2012
    Hi, im a beginner with microcontrollers. Im using a function generator to generate sinusoidal signals with 0-5V amp and any desired frequency. ill provide these signals as input to an ADC(successive approximation, 8-bit) and its out to a microcontroller. I want the microcontroller to calculate the frequency and amplitude of the sampled signal. How do i do that? Also how do i set the sampling rate to the desired samples/sec?
     
  2. GreenGiant

    GreenGiant

    842
    6
    Feb 9, 2012
    Which microcontroller are you using?

    You can count the pulses from the ADC and use that to determine frequency.

    Amplitude you will have to measure before the ADC or else you will just get the amplitude of the output.

    before knowing the board that you are using it will be very difficult to recommend a way to code that
     
  3. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,500
    2,840
    Jan 21, 2010
    0 - 5 amp?

    What do you mean? Is this a current source with current varying as a function of time?

    Or do you want an AC voltage source that can supply up to 5A?
     
  4. Cruzer

    Cruzer

    2
    0
    Mar 20, 2012
    @Greengiant
    thank you for your reply. i have 8051 and atmel 8515L. Since im learning i want to do it with both of them.
    So how can i measure the amplitude before a2d and have it read by the mcu?

    @Steve:
    by 0-5V amp i meant the amplitude level since ill give this as the input to the a2d.
     
  5. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,500
    2,840
    Jan 21, 2010
    Sorry, then by "0-5V amp" you simply mean "0-5V"? Oh and you used "amp" as a rather unfortunate abbreviation for amplitude? OK.

    To measure amplitude you could use a pair of peak and hold circuits to detect the largest excursion in either direction, or you could simply sample very quickly and look at the range of values obtained.

    As for measuring frequency, you count pulses over a time (or the time between pulses and invert). The trick is defining what a "pulse" is. Some sort of Schmitt trigger to clean up the signal (remove any noise) will assist greatly in this. You can do it in hardware or software.
     
  6. BobK

    BobK

    7,682
    1,688
    Jan 5, 2010
    If you are sampling at at least 10X the frequency you can get the frequency and amplitude from the samples, no need to determine the amplitude separately.

    Bob
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-