KrisKasprzak
Well-known member
All,
I have a data logger that is being used to measure wheel RPM (0 to about 500 RPM) in and electric go cart. I'm using an infrared sensor and for the most part it works very well. When the throttle "on/off button" is on, everything is fine--sensor works well and RPM is very accurate, upon release of the throttle, I sometimes get very wrong results (RPM is reported as say 100000). My calculations are every second (so the driver has a good view of current speed).
My approach is NOT to measure pulses per second and compute rpm based on that, but get The delta in micros() between first and last pulse (within the 1 second update time) the compute RPM based on number of pulses and elapsed micros() between the start and end pulse. I'm adopted this approach to give more accurate RPM's--especially at low speeds
Anything look error prone in my ISR? All variables are assigned as volatile? Any bad practices here?
My code is 2500 lines long but I can probably strip it down if that would help.
Snippet of the errors
Point ,RPM ,Speed ,Total Rev.
4105 ,1042 ,11.3 ,20687
4106 ,990 ,10.74 ,20690
4107 ,933 ,10.12 ,20693
4108 ,896 ,9.72 ,20696
4109 ,834 ,9.04 ,20700
4110 ,782 ,8.48 ,20702
4111 ,724 ,7.86 ,20704
4112 ,14954 ,162.11 ,20708
4113 ,12566 ,136.22 ,20712
4114 ,9349 ,101.35 ,20714
4115 ,1100 ,11.93 ,20716
4116 ,260 ,2.83 ,20717
4117 ,969 ,10.51 ,20719
4118 ,0 ,0 ,20719
I have a data logger that is being used to measure wheel RPM (0 to about 500 RPM) in and electric go cart. I'm using an infrared sensor and for the most part it works very well. When the throttle "on/off button" is on, everything is fine--sensor works well and RPM is very accurate, upon release of the throttle, I sometimes get very wrong results (RPM is reported as say 100000). My calculations are every second (so the driver has a good view of current speed).
My approach is NOT to measure pulses per second and compute rpm based on that, but get The delta in micros() between first and last pulse (within the 1 second update time) the compute RPM based on number of pulses and elapsed micros() between the start and end pulse. I'm adopted this approach to give more accurate RPM's--especially at low speeds
Anything look error prone in my ISR? All variables are assigned as volatile? Any bad practices here?
My code is 2500 lines long but I can probably strip it down if that would help.
Code:
void inc_rpm() {
PulseStartTime = micros();
if ((PulseStartTime - PulseDebounce) > RPMDebounceTime) {
PulseDelta = PulseStartTime - PulseOldTime;
PulseOldTime = PulseStartTime;
PulseDebounce = PulseStartTime;
wRPM = 60000000L / PulseDelta;
PulseCount++;
TotalRevolutions++;
LapPulses++;
}
}
Snippet of the errors
Point ,RPM ,Speed ,Total Rev.
4105 ,1042 ,11.3 ,20687
4106 ,990 ,10.74 ,20690
4107 ,933 ,10.12 ,20693
4108 ,896 ,9.72 ,20696
4109 ,834 ,9.04 ,20700
4110 ,782 ,8.48 ,20702
4111 ,724 ,7.86 ,20704
4112 ,14954 ,162.11 ,20708
4113 ,12566 ,136.22 ,20712
4114 ,9349 ,101.35 ,20714
4115 ,1100 ,11.93 ,20716
4116 ,260 ,2.83 ,20717
4117 ,969 ,10.51 ,20719
4118 ,0 ,0 ,20719