hello guys im working on a small bike ecu project
what im trying to do at the moment is trigger the ignition coil on at a desired angle based on some sensor parameters
now the thing that i got stuck for some days is to decode the engine crankshaft wheel correctly.
lets take this example
my bike use a similar wheel its called 12-1 wheel becouse there is one teeth missing out of 12 so in reality there are 11 teeths . bike also use a sensor to count the teeths so it can adjust the mixture and ignition with some calculations.The sensor report 1 if a tooth is on the sensor or 0 if its not so we got something like this pulse
now as we now eatch tooth is 30 deg since 360/12 = 30
and lets say i want to trigger the ignition 45 deg before TDC(when the piston is on top) or 360 - 45 = 315deg.Now to trigger the ignition coil you need to wait 4.3ms(4300uS) to charge the coil before it fires the spark.
Lets take some numbers to work with. I know for example that for one wheel rotation aka 360degs i need 12345uS that means if we do
60000000 / 12345 = 4860 thats our rpm. Now if 12345uS its for 360
then ( ( 360 - 45 ) / 360 ) * ( 12345 - 4300 ) =6501uS is the time to wait before triggering the ignition coil so the spark will be at 315degs as we want it.I need first to find a way to improve it if its possible and second i want to add a "trigger" offset. Trigger offset is for example when the tooth 9 is on sensor and piston is at TDC that means the piston is on top at 270 deg of the wheel