I'm currently working with an inductive sensor, the kind you find on camshafts of motorcycles and automotive. I am running a disk on a electromotor, this disk has a "notch" on it, which the inductive sensor should sense. The problem is, that the "timing" my inductive sensor picks up the notch is different when I alter the speed of the disk.
My code:
I am switching a mosfet on and off, to make a spark with my ignition coil. My question is, how can I make sure my pickup detects the notch at exactly the same position on the disk at a changing RPM range ?
If I understand this correctly, you are using a sensor to detect when a notch in a disk passes a set point but you are finding that the position you detect depends upon the speed of the rotation.
If that's correct then it suggests there is a certain "lag" time between the notch passing and the signal reaching your arduino. Even if this was a constant lag time it would still result in the effect that you see. However, we don't know immediately whether the lag is constant.
On the assumption that you are working on a few thousand RPM at most, you have a detection frequency of up to around 100 Hz. That gives you masses of processing time and suggests that the delay will not be in your code. It also suggests that you have time to compensate in the firmware.
It sounds to me as if you need to offset your detector position ahead of the time you need the spark and then calculate a delay to put into your code so that it will know when the "spark point" is from the combination of the trigger time and the current speed. You could do that either with a calculation, if you can devise a suitable first or higher order curve-fit, or you could work out a lookup table experimentally.
You can't get fast enough "processing time" using analog input. The only way to do it with low latency is via digital input (2 or 3) and hardware interrupt feature. For 100 Hz, there is only 10 millisec per 360 degree, so to have an accuracy at least 1 degree processing should be accomplished in
10 / 360 = 27.7 usec.
You don't need to process in the time it takes for 1 degree of revolution. At least in theory you only need to take less than 10ms and take a length of time that is known to within 25 us.
Well, after messing about with some filtering settings on the signal, I decided to ditch this sensor. I connected a different sensor:
I made a rotor on the lathe for it, and it seems I can now switch using interrupts. I have pushed it up to about 10k RPM without any problem, the timing stays exactly the same. Another point in favour of the Hall sensor is the fact that I don't need to reach a "pickup" speed, it switches even at 1 RPM.