Understnading of Rpm measurements

Hi there!

Working on a project using a hall effect sensor to measure rpm's.

I've got the code working but I can't wrap my head around some of the code. I've checked different projects and it seems to be the same.

The code below is not from my project but it doesn't matter.

SO, as far as I can grasp the code below starts a counter and when the counter counts to two (rotations of the magnet) calculations are made.

so far so good, but it's the calculations I'm having difficulties with.

When I read the formulae below i read:

(1000/timetaken1) = time in seconds for two rotations
(1000/timetaken1)*60; = time in minutes for two rotations

Let's assume that it takes 10 seconds to complete two rotations, the second line above will then give a result of 600.

Had it been if(engrotation>=1) I would have understood it.

one rotation would then be timed in millisec and converted to minutes.

ex: 10 sec for 1 rotation would give a rpm of 600

I feel like an idiot, can someone please sheed some light over this???

The complete code is found Arduino RPM and Speedometer for Fast Bikes (or Cars) :: Student Project - Programming Electronics Academy of the example juist in case that I'm missing something (thet's probably the case!)

void magnet1_detect() //Called whenever a magnet is detected
{
  engrotation++;
  engdtime=millis();
  if(engrotation>=2)
  {
    timetaken1 = millis()-engpevtime; //time in millisec for two rotations
    engrpm = engon = shiftrpm =(1000/timetaken1)*60;    //formulae to calculate rpm
    engrps =(1000/timetaken1);
    engpevtime = millis();

if(engrotation>=2) means it doesn't calculate rpm on the first rotation. I'm not sure why but that's what it does.

timetaken1 is the time in milliseconds it takes for one rotation.

(1000/timetaken1) is the revolutions per second
(1000/timetaken1)*60 is the revolutions per minute

Vetsoltech:
I feel like an idiot, can someone please sheed some light over this???

If I rewrite the code with more meaningful variable names it may make sense

void magnet1_detect() //Called whenever a magnet is detected
{
	pulseCount ++;
	thisPulseTime = millis();
	if(pulseCount >= 2) 
	{
		millisForOneRev = millis()- previousRevTime;
		engineRPS  = (1000 / millisForOneRev);
		engineRPM = engineRPS * 60;    //formulae to calculate rpm

		previousRevTime = millis();
	}
}

I am assuming there are two pulses per revolution because otherwise the maths does not work

And this approach would be better as all the calculations use the same value of millis()

void magnet1_detect() //Called whenever a magnet is detected
{
	pulseCount ++;
	thisPulseTime = millis();
	if(pulseCount >= 2) 
	{
		millisForOneRev = thisPulseTime- previousRevTime; 
		engineRPS  = (1000 / millisForOneRev);
		engineRPM = engineRPS * 60;    //formulae to calculate rpm

		previousRevTime = thisPulseTime;
	}
}

...R

Robin2:
If I rewrite the code with more meaningful variable names it may make sense

void magnet1_detect() //Called whenever a magnet is detected

{
pulseCount ++;
thisPulseTime = millis();
if(pulseCount >= 2)
{
millisForOneRev = millis()- previousRevTime;
engineRPS  = (1000 / millisForOneRev);
engineRPM = engineRPS * 60;    //formulae to calculate rpm

	previousRevTime = millis();
}

}




I am assuming there are two pulses per revolution because otherwise the maths does not work

And this approach would be better as all the calculations use the same value of millis()


void magnet1_detect() //Called whenever a magnet is detected
{
pulseCount ++;
thisPulseTime = millis();
if(pulseCount >= 2)
{
millisForOneRev = thisPulseTime- previousRevTime;
engineRPS  = (1000 / millisForOneRev);
engineRPM = engineRPS * 60;    //formulae to calculate rpm

	previousRevTime = thisPulseTime;
}

}




...R

Usually the two pulses per rotation is because the reed switch and the bar magnet are oriented in parallel. Then magnet rotates N-S for one closure and then S-N for the second closure. One revolution of the magnet.

Paul

Paul_KD7HB:
Usually the two pulses per rotation is because the reed switch and the bar magnet are oriented in parallel. Then magnet rotates N-S for one closure and then S-N for the second closure. One revolution of the magnet.

Paul

Hi Paul

So, if I'm understand you correctly, two pulses equals one passing of the magnet bar.
I'm guessing that even if I were to use a donut shaped magnet (which I am) the result would be the same? The magnetic field would be slightly different but the polarisation shift remains, right?

/Anders

GypsumFantastic:
if(engrotation>=2) means it doesn't calculate rpm on the first rotation. I'm not sure why but that's what it does.

timetaken1 is the time in milliseconds it takes for one rotation.

(1000/timetaken1) is the revolutions per second
(1000/timetaken1)*60 is the revolutions per minute

Ok, that makes sense. Could it be that at startup the rotations isn't reliable when calculating the rpm? If that's the case, maybe it would be appropriate to start count even later?!

Robin2:
If I rewrite the code with more meaningful variable names it may make sense

void magnet1_detect() //Called whenever a magnet is detected

{
pulseCount ++;
thisPulseTime = millis();
if(pulseCount >= 2)
{
millisForOneRev = millis()- previousRevTime;
engineRPS  = (1000 / millisForOneRev);
engineRPM = engineRPS * 60;    //formulae to calculate rpm

previousRevTime = millis();
}
}




I am assuming there are two pulses per revolution because otherwise the maths does not work

And this approach would be better as all the calculations use the same value of millis()


void magnet1_detect() //Called whenever a magnet is detected
{
pulseCount ++;
thisPulseTime = millis();
if(pulseCount >= 2)
{
millisForOneRev = thisPulseTime- previousRevTime;
engineRPS  = (1000 / millisForOneRev);
engineRPM = engineRPS * 60;    //formulae to calculate rpm

previousRevTime = thisPulseTime;
}
}




...R

Ok, I see. That also makes sense, using the same value, I mean.

Thanks!