Gbulmer, I thought about using a Hall or a reed switch, but the problem then becomes that I have to infer the stroke based on another factor, the easiest being an valve sensor. A Hall or reed will be triggered EACH time the engine makes a revolution. The intake opens once every TWO revolutions. I could use both in conjunction to provide verification, but that would make the code more complicated. Just off the top of my head it would be something like:
void hall() {
if (digitalRead(valveSensor) == HIGH); {
//interrupt stuff//
}
}
This then raises the issue of timing, because it has to poll the pin for the valve's position. By that time, the valve could have closed again. Even if I place the Hall a few degrees in advance of the time when the valve opens and closes, I would still run into issues because I have a large speed range (400-4000 rpm).
Poslathian, I will do so as soon as I can. I just found out that the lab I work at has a pulse generator (I'd just have to stick a pot on it to get to 3.3V from 5V) and a scope so I can look at both my PWMs and other stuff as necessary. I'll probably just hold the switch and shake it around like it's on the engine. Otherwise, I've been looking into other solutions like a laser "tripwire" or sonar. Both have their problems, but would be MUCH more accurate if it works. The other thing I might try is mounting the switch in the crankcase, provided it is adequately shielded from the oil. There should be fewer vibrations there.