Hello,
I am trying to get RPM from my diesel injection pump that has a 58 tooth wheel with 3 teeth missing in 4 locations. I am running the VR sensor through a op-amp Schmitt trigger and getting pulses but cannot seem to get the math right so to match the actual RPMs. I am just comparing time between pulses at the moment but the missing teeth throw it off, obviously. And I am not sure how to implement the math for missing the teeth and make it all work.
I have included the info I have on it below.
Any help would be greatly appreciated.
From the Manual:
Speed Sensor
The speed sensor is mounted so as to face the teeth of the pulsar (gear), which is pressed onto thepump drive shaft. The sensor contains a magnet and a coil, and when the pulsar rotates, the mag-netic flux that passes the coil increases and decreases, causing an alternate current voltage to begenerated in the coil. The computer counts the number of pulses to detect the engine speed. Thepulsar has 52 teeth, with 3 teeth missing at 4 locations. Thus, the pulsar rotation angle is detectedevery 11.25°CA.
#define ClockPin 2 // Must be pin 2 or 3
// My Encoder has 400 Clock pulses per revolution
// note that 150000.0 = (60 seonds * 1000000 microseconds)microseconds in a minute / 400 pulses in 1 revolution)
// change the math to get the proper multiplier for RPM for your encoder
// yours would have 70 pulses in 1 revolution if the missing pins were present
// note that 150000.0 = (60 seonds * 1000000 microseconds)microseconds in a minute / 70 potential pulses in 1 revolution)
#define Multiplier 857142.857142 // don't forget a decimal place to make this number a floating point number
volatile long count = 0;
volatile long EncoderCounter = 0;
volatile float SpeedInRPM = 0;
void onPin2CHANGECallBackFunction(){
static uint32_t lTime; // Saved Last Time of Last Pulse
uint32_t cTime; // Current Time
cTime = micros(); // Store the time for RPM Calculations
int32_t dTime; // Delt in time
// calculate the DeltaT between pulses
dTime = cTime - lTime;
lTime = cTime;
// SpeedInRPM = Multiplier / ((DataPinVal) ? dTime: (-1 * dTime)); // Calculate the RPM Switch DeltaT to either positive or negative to represent Forward or reverse RPM
SpeedInRPM = Multiplier / dTime; // Calculate the RPM Switch DeltaT to either positive or negative to represent Forward or reverse RPM
}
void setup() {
Serial.begin(115200); //115200
// put your setup code here, to run once:
pinMode(ClockPin, INPUT);
attachInterrupt(digitalPinToInterrupt(ClockPin),onPin2CHANGECallBackFunction,RISING);
}
void loop() {
// long Counter;
float Speed;
noInterrupts ();
// Because when the interrupt occurs the EncoderCounter and SpeedInRPM could be interrupted while they
// are being used we need to say hold for a split second while we copy these values down. This doesn't keep the
// interrupt from occurring it just slightly delays it while we maneuver values.
// if we don't do this we could be interrupted in the middle of copying a value and the result get a corrupted value.
Speed = SpeedInRPM;
interrupts ();
// use the speed and counter values for whatever you need to do.
static unsigned long SpamTimer;
if ( (unsigned long)(millis() - SpamTimer) >= (100)) {
SpamTimer = millis();
Serial.print(Speed , 3);
Serial.print(" RPM");
Serial.println();
SpeedInRPM = 0; // if no pulses occure in the next 100 miliseconds then we must assume that the motor has stopped
}
}
you will need to do something to ignore the longer pulse
From the drawing it look like there are 13 short pulses and then the long one. 4x13=52 which is the number of actual teeth. The gaps are missing 3 teeth 4x3=12. So if the wheel had all of the teeth it would be a 64 tooth wheel. So the correct terminology would be 64-3-3-3-3. Someone correct me if I am wrong.
I don't know where the OP got 58-3-3-3-3 because it clearly states in the drawing that it has 52 teeth. I guess the OEM was counting the actual teeth, not what it would be if it had all the teeth.
Count multiples of 13 teeth. The time taken for 13 teeth to go past the sensor is 1/4 of a revolution. If you are just counting then it doesn't matter if there are big and small gaps and it doesn't matter where the big gap is when you start counting.
Personally, I would count to at least 52 to get one full revolution and maybe even several revolutions.
MorganS:
Count multiples of 13 teeth. The time taken for 13 teeth to go past the sensor is 1/4 of a revolution. If you are just counting then it doesn't matter if there are big and small gaps and it doesn't matter where the big gap is when you start counting.
Personally, I would count to at least 52 to get one full revolution and maybe even several revolutions.
The code I shared earlier uses delta T between pulses the longer pulses are a multiple of 3 and could be ignored or decided by 3 to get an accurate rpm. Counting while it works requires much more processing time.
Z
void onPin2CHANGECallBackFunction(){
static uint32_t lTime; // Saved Last Time of Last Pulse
static count=0; /count teeth
if(count++<teethToCount) return;
count=0;
uint32_t cTime; // Current Time
cTime = micros(); // Store the time for RPM Calculations
int32_t dTime; // Delt in time
// calculate the DeltaT between pulses
dTime = cTime - lTime;
lTime = cTime;
// SpeedInRPM = Multiplier / ((DataPinVal) ? dTime: (-1 * dTime)); // Calculate the RPM Switch DeltaT to either positive or negative to represent Forward or reverse RPM
SpeedInRPM = Multiplier / dTime; // Calculate the RPM Switch DeltaT to either positive or negative to represent Forward or reverse RPM
}