Hello

I would like to build a project who can change the avance ,degrees timing, in an single one piston engine without injector,only the avance i must change.

I programming in assembly all my projects,i try some times in c with not good results.

Now my thoughts about how to do this:

First I will calculate the rpm of flyweel with the crank sensor who allready the bike have,this is simple.

Lets say for now that the crank sensor is at 0 degrees

And the rpm is 8000/min

Each complete cycle of flyweel is 360 degrees.

That mean that in one min the sum of degrees is 360*8000=2880000

so if i want to give a spark at 20 degrees the calculation is 20*60sec/2880000 who is 0.0041sec =>4.1ms

So after the crank signal I have to wait 4.1ms and then give spark.

Is this thought ok?Or I missing something?

Now for all maths it is very helpful to use c language but only for maths do you suggest me to begin learn winavr or avr gcc or to try with assembly maybe with different way of mathematics?

I have never done mathematics with so large numbers in assembly.

## Motorcycle ignition avance module ,math in c?

I think you're out by a factorof 10. Here's how i calc it:

60/8000 *360 = 2.083^-5 per degree. Times 20 gives you 417us per 20 degrees.

It is easier to think in terms of timer ticks as this is how you will measure the period using the input capture. So, if we assume a timer tick of 2us, one revolution at 8000rpm will take 3750 timer ticks. To speed up the math, rather than working in degrees, we divide the revolution into a nice binary weight, say 256,512 or 1024 depending on the resolution you would like. So to convert timer ticks to an angle, twenty degrees is around 28 512s of a revolution. So the calc would be 3750*28 /512. Rather than divide by 512, you would left shift by 9 bits. But you want 20 degrees before zero angle ( or TDC top dead centre is the official term) so the actual timer ticks would be 3750 - 208.