Best method of controlling DC motor speed based tachometer input to Arduino Uno

I posted about the feasibility of this project a while back and have been reading up and testing my 2 cycle oil pump delivery at different speeds to determine just what oil pump RPMs match the lubrication ratio requirements at a given engine RPM . ( I know I could just premix but I don't want the heavy smoke in marinas and 5 mph zones )

I mapped an analog input to a PWM output controlled with a pot to control the DC pump motor speed . The oil pump is package made brushed 12vdc motor coupled to a Mikuni oil pump .

I am planning on using an Optical IR sensor to read engine RPM's from a single strip of reflective tape on the flywheel which will be operating at 10 Hz at idle to 100 Hz at WOT .

I am going to use 10 different points along the engine operating range with ever increasing oil delivery ratios from idle to wot . From what I have read so far it looks like "Switch Case " or "Multi-Map" might be the way to go for the coding ?

It is not critical but I would also like to incorporate a PID scheme for the pump speed control if memory allows.

What have I got wrong ?

Just use a lookup table. Map your input (engine RPM) quantized into 10 bins and the values in the array are the PWM values for the pump

// psudo code
// PWM values
const int PWMvalue[11] = { 0, 23, 55, 77, //...}
int rpm = readRPM(); // returns value from 10-100
int bin = (rpm+5)/10; // bin is 0-10
analogWrite(motorPin, PWMvalue[bin]);
//...

I'd skip the PID at least until you get this working.

kls2020:
It is not critical but I would also like to incorporate a PID scheme for the pump speed control if memory allows.

That will require some means (equivalent to the reflective tape on the flywheel) to measure the speed of the DC motor.

What happens if your DC motor fails? Do you have a system to stop the main motor automatically to prevent it running without lubrication?

...R

Yes there is a portion of the motor shaft exposed on the opposite end of the motor away from the pump coupling . I have already been using an optical sensor on that end for plotting pump rpms and oil delivery in CC's . I am planning on comparing engine rpms and oil pump speed to force a digital output if there is a mismatch between the expected speeds of each but that will be further along in the project .

blh64:
Just use a lookup table. Map your input (engine RPM) quantized into 10 bins and the values in the array are the PWM values for the pump

// psudo code

// PWM values
const int PWMvalue[11] = { 0, 23, 55, 77, //...}
int rpm = readRPM(); // returns value from 10-100
int bin = (rpm+5)/10; // bin is 0-10
analogWrite(motorPin, PWMvalue[bin]);
//...



I'd skip the PID at least until you get this working.

I have experience with programming PLCs with ladder logic , FBD , and other graphical logic editing but this Arduino IDE coding in text is a totally Greek to me so I am taking things slow one step at a time . I don't believe the PID is really needed but was thinking it would be a nice feature to add only after the basic operation is proven .
Thank you so much for your assistance .

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.