Reputation: 5
I'm designing a machine that requires an automated ignition system. This project uses a motor control script that I wrote for Arduino.
I need to calculate the delay between ignition based on the percentage motor load.
These are the variables currently used
//Variables
int potentiometerIn; //RAW Potentiometer data variable
int potentiometerIn2; //Used in percent calculation, Will be == to potentiometerIn, just a different operation order
int potentiometerDivper; //Variable to hold percentage calculation (first step)
int potentiometerPer; // Holds the integer percent for motor speed IE: motor at 83% speed would have this value at 83
int potentiometerDiv;
int motorPin = (); //REPLACE () with PIN NUM
int motorRly = (); //Motor Positive pin () = pin num + Motor Pin
int motorNeg = (); //Motor Negative Pin () = pin num (Likely Not Needed)
int igniteRly = (); //Ignition Control Positive Pin
int igniteNeg = (); //Ignition Control Negative Pin (Likely Not Needed)
int ignitionTime = 0; // This will be used to set the time for an electric ignition.
int ignitionCalc = (); //This should be the time in seconds, that it takes for the machine to complete a full cycle with the motor set to 50%
// This enables/disables the ignition portion
int ignitionEnabled = true; // Default = True
if (ignitionEnabled == true)
{
ignitionCalc * 1000; //Converts the seconds to a format accepted by delay
50 / ignitionCalc = potentiometerPer / ignitionTime;
}
A quick summary for those who don't want to read all of my comments (I'm writing this code before the motor arrives so the values are all unset)
potentiometerPer > This is the percentage of power being supplied to the motor.
ignitionTime > This value will be used to set the delay between ignition firing
ignitionCalc > The amount of time in seconds for 1 cycle at 50% power.
I'm trying to figure out a way to calculate the delay for ignition with regards to what percentage the motor is currently set to. For example:
If motor percentage is 80 and the time per cycle is 5, then at 100% power the time per cycle is X (in this case 6.25)
I can't seem to figure out how to do proportions in C++, I'm rather new to the language and only started to learn it for this project.
Upvotes: 0
Views: 305
Reputation: 263
Well since when the motor power is at 80%, the time per cycle you get is 5. So ignore the percentage, lets just say that when power level is 80, you get time per cycle as 5. Ratios in simpler words are just divisions. When 80 is divided by 16, you get 5. So what we know is the value 16 is going to remain constant. Similarly if you take any value of motor power, and divide by 16, you are going to get what you want. If this ratio is going to remain constant then it will be for all cases no matter what the motor power is. Im assuming that the ratio is going to remain constant.
So what you can do is -
float timePerCycle = potentiometerPer/16;
Upvotes: 1