tachometer cycle double counting errors

I have been trying to get my improvised tachometer to work and count my cycles properly. i've been working on a DIY pickup winder and i've made my own cycle counter with a small coil and a disk with a magnet on the axis.
i'm quite new to this but i'll give as much information as i can.

the coil generates pulses up to 250mV and the axis can spin up to 8000 RPM.
i have written some code that can kind of count the cycles but i ran into some issues i can't find answers to on the forum or elsewhere :confused:

my "sensor" is connected parallel with a 10k resistor between A0 and the ground to make sure i don't shoot unlimited current into the analog inputs.

my 'if' structure seems to run multiple times in less than a millisecond even though i used a delay of 5ms in the loop. this causes the count to be off.
when I use the serial monitor to view the winding counter I can see that the timestamp on 2 different winding numbers is sometimes the same and i can't figure out why.

is this solely a problem in the coding? or is it my entire setup?

murp.ino (505 Bytes)

You cannot totally trust the timestamp because at 9600 bps the serial interface takes about 1ms to print a single character. With an int you would be printing up to 5 characters which takes about 5ms.

I have used a hall effect sensor for RPM on numerous occasions but I don't know what the maximum RPM is.

I feel like an analog-to-digital converter is not suitable for this purpose (too slow) and that you should consider running the output of the coil through a shaper circuit to create a digital pulse train that you can then feed to an input capture pin of a timer.

The circuit might include a rectifier diode to clamp negative-going transitions from the coil, a comparator and perhaps a Schmitt trigger buffer to clean up the waveform.

Or am I missing something?

thank you both for the input,
i dont know alot about the timing of the programming and converting so this was really helpful.

if i switch to a digital pin and use an external comparator circuit to boost the incoming signal to either a logic HIGH or LOW so i can use booleans, can the arduino process it faster?

also i thought the 9600 was just the baudrate, not the bitrate or am i getting my things confused