hello guys im trying to read a wheel spinning up to 13000 rpm. the wheel got 11 teeth with one missing teeth 12-1 witch i count em with an variable reluctance sensor
my idea for this is
if we do 1/360 = 0.0027777777777778
lets say time for a full rotation is 12345 micros
so if we do 12345 * 0.0027777777777778 = 34.29166666666694 micros for 1 deggre
and then lets say that 15555 micros passed that means
15555 / 34.29166666666694 = 453.6087484811628 deggrees after 15555 micros passed
but when i code this into arduino i always missing 3-4 deggrees example :171,175,179,183,186 etc
also when rpms start to rise arduio take so much time to slove that division 15555 / 34.29166666666694
and its startig to missing things
also im using a led to check if im at desired angle
is there any better method for this ? i just want 1 deggre acuracy plus to be able to work at 13k rpm
So by Robin's updated calculation there's about 200 instruction cycles in one degree. Your getCrankAngle() function is about that long, probably longer. So when you ask it to tell you the crank angle, do you want to know what the angle was when you called it or what it's going to be when it returns the number to you?
Just arbitrarily asking for the crank angle "now" doesn't seem very useful. Isn't it more useful to know when it is at a specific position, like degrees BTDC? Maybe there is another way to do what you want.
Is this system supposed to work under acceleration? In one revolution, the crank may accelerate significantly. Your code will think that it's at 320 degrees when the missing tooth comes past to say that you are actually at 360 degrees. To improve the situation, I would have getCrankAngle() work its calculations from the last tooth that was observed. Even if you only update the speed once per revolution, that will keep you closer to the actual position.
hey yes this is going to work under acceleration/decceleration.I want to see if the wheel is for example 32 deggres before TDC and by doing 360 - 32 we got 328 deg so i want to check if im at that potision.
another methond i tried was
for example we are at the 10 tooth so that gives us 300deg
if ( 328 > 300(current_teeth * 30){
if(328 - 300 < 30){
//do the calculations here }
}
this saved me some time i have to say but i dont like this method verry much
crankAngle = ((teethCounter)* triggerToothAngle);
if (teethPassedCounter < actualWheelTeeth) {
if (crankAngle <= targetAngle && (teethPassedCounter + 1) * 30 > targetAngle) {
int var = targetAngle - crankAngle;
int modulus = var % triggerToothAngle; //here we get the rest of the teeth lets say if wee need teeth 11.5 we get the .5 here
if (modulus > 0) {
offset = (((modulus * 100) / 30) * toothDuration) / 100;
}else { //if its the angle just on a teeth
offset = (microsNow - timeNow) * 2; //fire now
}
}
}
motoGuyDIY:
we got 328 deg so i want to check if im at that potision.
I still don't see the point. By the time you've answered the question, the crank has moved a significant (to you) distance past the point it was at when you asked the question. Even if you ask "am I at 327 yet?" to allow for a one-degree lag, that lag changes depending on the speed that you're doing so maybe you are still at 327 when the answer comes back or maybe you have reached the target 328.
It sounds like you're making an Arduino ECU. That can work for small (eg. single cylinder) engines at low speeds (not 13,000rpm.) For serious ECU work, it's better to start from a chip that's purpose-built for the task.
A better way to trigger a spark at a specific position BTDC is to calculate in advance which tooth it comes after and then, when you see that tooth, delayMicroseconds() for the correct number of microseconds to get the exact degrees after the tooth.
hey you are correct im trying to make an ecu for a single cylinder bike but for now im just doing tests with leds.i think it can work for example speeduino is working on 2560 mega and its more complicated that my simple for now project and it controls much more things so it needs more time to control things read a ton of sensors and calculate the angles.but anyway an arduino due could be a better option ? but its only 3.3v on the pins and i need 5v max from sensors
Not really true , a simple two resistor potential divider could allow 5v signals to be dropped to 3v3 for use with a due.
For analog a opamp would be a better option still