Arduino Counting 17MHz Clock Edges?

I have an Arduino Mega and wondering if it’s possible to use it to count 17Mhz clock edges. I have a 17MHz clock and I’d like to send the clock through a passthrough board I made and out the other side using a signal generator.

I want to measure the clock edges from the signal generator before they enter the passthrough board and also at the output. Comparing them will tell me if I lost any. Is it possible to measure the input, the output, or ideally both with a Mega?

Not likely.
Provide a more scientific description than words, like timing diagrams or so.

Possibly but not sure. The processor clock is 16 Mhz so measuring 17Mhz would have to be done by a hardware timer. I do not know the speed limit on the 16 bit timer counter. You would have to look. If it does you can count the rollovers and essentially reduce the time the processor has to measure by 2^16. However you still may not get enough resolution to meet your requirements.

1 Like

the maximum frequency you can count with an ATmega328 Arduino is 16/2.5 = 6.4 MHz.

That's using the timer/counter peripheral on the chip.

The counter input is sampled, the sampling goes by the microprocessor clock and makes a hard limit.

You could use an external divider to scale the frequency to something. Enough scaling and you could do the measurement without anything too exotic.

a7

What if I wanted to count all the clock edges of a 2MHz clock instead of 17MHz...I assume there is some type of interrupt on change pin that I can use to increment a counter?

The ESP32's I/O clock is set to 80Mhz, a 12.5 nanosecond pulse. The ESP32 has the PCNT, Pulse CouNTer module which can be programed under the Arduino IDE.

Pulse Counter (PCNT) - ESP32 - — ESP-IDF Programming Guide latest documentation for more information.

On the Arduino Mega, use Timer1 (or 3, 4 or 5) in externally clocked mode. This excellent tutorial will guide you:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.