aster94:
i' m trying to implement a tachometer in a project, my need is to measure the rpm of a brushless motor with not more than 4000rpm at max speed, usually.
4000rpm = 66 2/3 rps = 15 millis/rev = 41 2/3 micros per degree to put it on Arduino-speed-scales.
If you can put a magnet on the shaft and use 2 hall switches, the time from one to the next gives you inverse speed and you also get direction of turn.
Make instead a ring of 6 sensors (on Uno, 8 on Nano, Mega, some others) around the shaft all wired to the pins on one port. Then direct port read the sensors (1 cycle) and operate on all of the sensors as bits in 1 byte, use logic operations to work them all at once and not in some baroque loop. The only non-zero will be a single bit, progress should be easy to track. The Mega is full-port rich and has 8K RAM and 4 serial ports.
6 sensors, 60 degrees apart, 2500 micros, 2.5 millis apart at 4000 rpm.
Set a Pin Change Interrupt on all of the pins and capture the port in the IRQ or poll at 50KHz?
With an Uno you can handle 3 sets of 6 switches max, Uno has no port with more than 6 pins free.