Connect with us

Microcontroller Help!!

Discussion in 'Microcontrollers, Programming and IoT' started by DevilMoo, Mar 24, 2015.

Scroll to continue with content
  1. DevilMoo

    DevilMoo

    6
    0
    Mar 24, 2015
    Hi,

    I want to give some frequency to ATMEL microcontroller. And it outputs the frequency which times 10.
    How do I use mcu to measure frequency?
     
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    10,585
    2,360
    Nov 17, 2011
    Welcome to electronicspoint.

    There are (at least) two methods to measure frequency:
    • If the frequency is high (e.g. >1 kHz), use a timer to create a "window" (a span of time) during which you count impulses on an input pin. Setthe window to e.g. 100ms, count pulses during this time. The frequency of the input signal is then 10*no_of_pulse/second.
    • If the frequency is low (e.g. <1kHz), you will receive not many pulses within a small window. For good accuracy you will have to make the window longer which is impractical because it leads to a long measurement time. Instead, use the input signal to define the window and measure impulses from a fast internal counter. This in efffect measures the period "T" of the input signal with good resolution. You get the input frequency from f=1/T
    Regards,
    Harald
     
  3. DevilMoo

    DevilMoo

    6
    0
    Mar 24, 2015
    I am too new about microcontroller.
    If I use the first method, what kind of mcu can I use?
    I do not know how I should choose it because it has too many brand for me to use.
    Does the first method is related to the programming on the mcu?
     
  4. Harald Kapp

    Harald Kapp Moderator Moderator

    10,585
    2,360
    Nov 17, 2011
    Any that is fast enough. As you say there are so many types that it is impossible to give a general recommendation. It will depend on what other things the MCU has to do besides counting pulses.

    Both methods require programmin the µC, that's what µC are all about.
     
  5. DevilMoo

    DevilMoo

    6
    0
    Mar 24, 2015
    If I buy ATMEL, is there any recommendation about the programming?
    WinAvr or AVR studio
    Are they both available on ATMEL mcu?
     
  6. Harald Kapp

    Harald Kapp Moderator Moderator

    10,585
    2,360
    Nov 17, 2011
    AVR studio can use WINAVR as a plugin to easliy program Atmel µCs in C language.
    You need to download AVR studio from the Atmel website and WinAvr from their website. Follow the instructions there.
    Alternatively you can use WinAvr alone without the studio. Which method you chose is your choice.
     
  7. DevilMoo

    DevilMoo

    6
    0
    Mar 24, 2015
    I have watched information for writing a program but how do I write the program to mcu?
    Do I need SPI and USB?
    Is there any other ways?
    In WINAVR, I cannot find my brand of mcu in the MakeFile.
     
  8. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
    There is often a tutorial or 'getting started' section that can be read that will get you setup and running with a simple 'hello world' application/program.
    If you run into problems already, I would strongly encourage you to find this tutorial / guide. The information that needs to be presented to get someone programming an AVR (or other microcontroller) can involve quite a few steps depending on your current understanding.
    Additionally, I'd like to urge you to try programming an Arduino instead. They come with a built in programmer, and all you need is a USB cable and the Arduino IDE.
    The downside here is that they cost a little more than other microcontrollers, but the ease to get setup and working is hard to compete against.


    AVR Resources:
    http://www.atmel.com/Video/default.aspx
    Look for any and all 'getting started' videos.
     
    Harald Kapp likes this.
  9. Colin Mitchell

    Colin Mitchell

    1,417
    312
    Aug 31, 2014
    It sounds like you want to deliver a 1kHz signal and the micro outputs a 10kHz signal.
     
  10. Harald Kapp

    Harald Kapp Moderator Moderator

    10,585
    2,360
    Nov 17, 2011
    How does this help? The absolute frequency is nowhere mentioned by DevilMoo. It could be 1Hz -> 10Hz or 100kHz -> MHz, too.
     
  11. Harald Kapp

    Harald Kapp Moderator Moderator

    10,585
    2,360
    Nov 17, 2011
    You will need a programmer (Google AVR programmer).

    You write your own Makefile for your project, there you insert the CPU type you use.
     
  12. Colin Mitchell

    Colin Mitchell

    1,417
    312
    Aug 31, 2014
    The OP has not replied with any sort of coherent understanding that I tried to simplify the situation so I could get some sort of intelligent reply.
     
  13. Harald Kapp

    Harald Kapp Moderator Moderator

    10,585
    2,360
    Nov 17, 2011
    Understood - you might have expressed that intent a bit clearer.
     
  14. DevilMoo

    DevilMoo

    6
    0
    Mar 24, 2015
    Actually, I would like to input frequency to mcu.
    After measuring, it will make LCD to display the result.
    The frequency will be generated by sensor.
    If I have a 8-bit mcu, can I make a register or memory to store a 16-bit value.
    According to the 16-bit value, mcu will change the display of LCD.
    Does it work?
    Or 8-bit mcu only have 8-bit memory or register size?
     
  15. Harald Kapp

    Harald Kapp Moderator Moderator

    10,585
    2,360
    Nov 17, 2011
    Just to clarify matters: You don't "input frequency" to anything. You input a signal (e.g. a voltage) that changes periodically in time, this change in time is a property of the voltage called frequency.

    What range is the frequency in (see discussion above)? a fe Hz, a few 10 Hz, 100z, kHz or ...?

    You use 2 8 bit registers (or memory locations) to store one 16 bit value.

    If done properly: yes.

    This is why it is called an 8 bit mcu. larger words (16 bit, 2 bit 64 bit etc.) can be handled as a set og 2*8bit, 4*8bit, 8*8bit etc. A compiler can handle this for you.

    You seem to have no idea how an mcu operates and how you are going to program it. I suggest you follow Gryd's advice in post #8 and get a feeling for the mcu of your choice.
     
  16. DevilMoo

    DevilMoo

    6
    0
    Mar 24, 2015
  17. BobK

    BobK

    7,682
    1,686
    Jan 5, 2010
    To measure low frequencies you want to start a timer at one pulse, the capture it at the next pulse. Or, let it run freely, and capture at each pulse and subtract the previous from the current value, adjusting for overflow if necessary.

    Bob
     
  18. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
    It's not measuring 'up to' ... it's more like measuring 'down to', as 0.01 Hz is a much slower frequency than even 1Hz.

    What 'range' do you want to be able to measure? Higher frequencies can be measured by counting the number of pulses in a small window, or calculating (with high accuracy) the time between pulses. Lower frequencies should be measured by the time between pulses... and frequencies as low as you want MUST be measured by time between pulses.

    Just to clarify, 0.01Hz is one pulse every 100 seconds. Your microcontroller will start a timer, and will take over a minute and a half to show you this frequency.
     
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

-