The most common frequency counter for Arduino was published by Nick Gammon in 2012, and it can measure up to 5 MHz. Why is there no equivalent for the UNO R4? Well, the answer is, the chip itself contains input-capture pins similar to T0 (pin-4) and T1 (pin-5) of the ATmega328P, but those pins inside the RA4M1 are not accessible at the headers. So, the only way to proceed is by installing a pin-change interrupt procedure. Obviously, the entry- and exit-code for that procedure consumes precious time, which will reduce the performance. Although the R4 is clocked by 48 MHz, the maximum frequency that can be measured is less that 400 kHz. As the algorithm used is a reciprocal frequency counter it can show frequencies with a resolution of a fraction of 1 Hertz.
In this project I installed a square-wave generator of 40 kHz using the "pwn.h"-library to transmit ultrasonic sound, and connected a ultrasonic receiver to pin A1, whose received frequency was to measure. It is a well-known fact, that the received frequency will differ if sender and receiver are moving relatively to each other. These values can be displayed on the Serial plotter. It had been a nice feature if it also could be shown on the LED matrix, but the "pwm.h"-library and the "matrix.h"-library do not go together well.
(Other problems with conflicting libraries were described by Aaron Dahlen.)
Comments
Please log in or sign up to comment.