Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 22 of 22

Thread: Could you help me?

  1. #1

    Could you help me?

    Hello professor, I use Arduino Micro hardware and the freqCount library to measure the frequency, and the maximum frequency can only reach 8MHz, may I ask why? Can we get higher frequencies? If so, how? thank you

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,362
    The processor is clocked at 16MHz so can only sense one transition every 62.5ns, 8MHz has one transition every 62.5ns.

    Use a faster processor. A Teensy springs to mind given which forum this is

    Or use a pre-scaler chip (such as divide-by-10 or divide-by-16).

    Professor??

  3. #3
    sorry, my friend.why 8MHz has one transition every 62.5ns? and It has to do with the clock rate of the processor, right? Does it have anything to do with timer T1?

  4. #4
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,407
    No it's a fundamental law.
    https://en.wikipedia.org/wiki/Nyquist_rate

  5. #5
    What is mean that?

  6. #6
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,407
    Quote Originally Posted by zgd674319083 View Post
    What is mean that?
    That it is not possible to reach more than 8 MHz.

  7. #7
    You mean that just measaure the 8MHz frequency?

  8. #8
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,407
    See Post#2

  9. #9
    I want to know why 8MHz has one transition every 62.5ns?

  10. #10
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,407
    ?? School Math :-)
    1 / 2 / 8000000Hz = 62.5ns

  11. #11
    why 1/2/8000000 rather than 1/8000000?

  12. #12
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,362
    Draw a square wave and count the transitions per complete cycle. You'll see there are two transitions for each complete
    cycle. Hz is just cycles per second. So 8MHz has 16000000 transistions per second.

    The microcontroller samples the input upto 16M times a second, so can only count transitions upto that rate.
    Clocked logic samples inputs on a clock edge and is blind to anything happening faster than the clock period.

    In the analog world this is know as the Shannon sampling theorem, ie you have to sample faster than 2f to
    correctly represent a waveform of frequency f.

    In practice you won't get reliable reading of frequency as the input starts to approach 8MHz due to jitter in the
    signal and clocks, I'd suggest treating the limit as somewhat less than 8MHz for reliable counting with a 16MHz
    clock

  13. #13
    What does it mean to have two transformations per cycle?

  14. #14
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,215
    The AVR chip you are using simply can not count an external signal faster than half its clock frequency. Its clock is 16 MHz. It does not support a faster clock and still give USB communication. The only clock speeds for that chip are 8 or 16 MHz.

    To count higher, you should use a faster board. Teensy 3.2 or 4.0 would be a better choice.

  15. #15
    Shouldn't this have something to do with the timer frequency? Do you know the T1 frequency of Arduino Micro

  16. #16
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,215
    Why can you not hear the answer? The hardware you are using simply can not use an external signal to its timer which is higher than half its clock frequency (16 MHz). No matter how many times you ask, the answer will always be the same. It is a hardware limit of the chip.

  17. #17
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,362
    Quote Originally Posted by zgd674319083 View Post
    What does it mean to have two transformations per cycle?
    I don't know, I never mentioned transformations.

    Transitions is what I was talking about. Logic signals transition between HIGH and LOW and back again. These
    are also known informally as edges (rising edge, falling edge). Each cycle has to have both a rising and falling edge - so
    two edges per cycle.

    Microcontrollers (and other synchronous clocked logic chips) sample incoming signals synchronous to their internal clock
    rising edge typically using a string of synchronization flip-flops.

  18. #18
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    1,084
    > Can we get higher frequencies? If so, how? thank you

    You could add a flip-flop clock divider circuit. But I second the recommendation to just use a teensy 4.0.

  19. #19
    I just want to know the reason, thank you

  20. #20
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,734
    See Answer in post #2...

    As has been answered several times in this thread: This is the limits of your hardware.

    You can not expect that your hardware which runs at 16mhz is going to be able to detect an IO pin changing more than 16M states of the IO pin, And A cycle has two changes: High to Low to High
    or Low to high to low... depending on which way you wish to measure. So 16/2 = Max frequency of 8 Megahertz...

    How to go faster with just that hardware. You can not... Except maybe with one caveat, which is trying to overclock the Pro Micro, such as mentioned in:
    https://github.com/Phasip/SparkfunPr...ster/README.md

    If you really want to better understand why, you should probably download an Atmega32u4 reference and read through it.

    Sounds like a lot of work and makes it far less reliable and sounds like maybe 20mhz... So you could maybe get 10mhz sample...

    But as the others have suggested, you are far better off getting faster hardware.

    If you are still wishing to pursue this, I would suggest that you ask this up on a forum that is more applicable to the Arduino Micro, such as the Arduino forum.

    Good luck

  21. #21
    Junior Member
    Join Date
    Sep 2021
    Posts
    16
    Let me try to explain with an Analogy:
    Say you spin a coin 10 times per second and take photos of it.
    -If you take 20 photos per second you will see half the time being heads, the other half Tails. From this you can figure out it is spinning around 10x per second!
    -But If you take 10 photos per second you will see it always being heads. You see no difference between the photos and have no clue if its even spinning at all!

    So to be able to spot from photos that the coin is spinning you need to be making them at least twice as often as it is spinning.


    The same applies here. A single "clock-cycle" is like a single full spin of the coin, except instead of heads and tails it goes ON and OFF.
    If the controller is to successfully count the cycles it needs to be twice as fast to spot it going ON and OFF. Simply no getting past that.


    If you want to get past this limit you'd either need something that count more often (e.g. a way faster Teensy) OR you need to slow down the signal so it can be counted (e.g. a Flip-Flop Frequency Divider)

  22. #22
    Senior Member
    Join Date
    Aug 2019
    Location
    southwest USA
    Posts
    130
    this is a wonderfully clear and concise analogy of nyquist sampling restrictions

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •