Code which reads the input constantly and updates the output voltage accordingly based on the above timing variables
0-10V output.
Now I know how to do the basics of reading the analogue in and outputting a PWM through a low pass filter and op-amp to give the 0-10V output. The piece I am struggling to figure out in my mind is how does an inverter typically calculate the ramp? I assume it isn't PID based as this would not give a slow smooth acceleration over 60 seconds and would be too erratic.
If you are trying to accomplish a particular acceleration, you need to measure the results of trying to do and adjust the increasing rate of the ramp.
PID would be useful here. What you do not have yet is the required input, which here would be the acceleration the motor is making at an instant.
Inputs: desired acceleration, current acceleration
Output: throttle
If the acceleration is too low, the throttle is increased. if the acceleration is too high, the throttle is reduced. With a fast enough loop, there is no need to expect that this would not be smooth.
Obvsly something else has to set the desired acceleration to zero when the speed is attained.
Many acceleration or fading or ramping things are done open loop. A LED just gets brighter, no need for feedback. A motor that is never asked to do more that it was found able to do in testing is just ramped up blindly, with the ramp slope determining the acceleration.
Change the brightness one step every 30 milliseconds.
The rest of the code handles switching directions when the min or max of the fade range is reached.
As such it is totally open loop. The value would go from, say, 0 minimum to 255 maximum over 30 * 255 milliseconds, 7.65 seconds.
So you can do the same, adjust the step size and time between steps. You will be writing a linearly increasing value to the motor speed input, who knows what the motor will or won't do? Not the open loop control algorithm this is.
a) the potentiometer/the user/the interfaces defines the target voltage
b) if the current voltage is below the target voltage increase the current voltage by one step
if the current voltage is above the target voltage decrease the current voltage by one step
the periode of how often you call for action b) defines the slope of the ramp, hence you can also give different periods for ramping up and ramping down.
you might consider this code i just posted for moving a servo more slowly. you can add a delay argument and replace the servo.write() with an analogWrite() to generate PWM
int pos;
void
move (
int target )
{
if ((target - pos) > 0)
servo.write (++pos);
else if ((target - pos) < 0)
servo.write (--pos);
delay (15);
}
Nice demo. Here's a place where the serial monitor graphical output can be fun.
Swap in this modified update method and turn on the serial plotter, in the woki that's a button in the lower right hand corner, in the IDE open the "Serial Plotter" from the Tools menu.
// the run method to be called in loop
void update(uint32_t currentMillis = millis()) {
if ((current < target) && (currentMillis - previousMillis > intervalUp)) { // increase PWM
previousMillis = currentMillis;
current++;
analogWrite(pin, current);
// Serial.print("up "); Serial.println(current); // just for debug/demo - comment it out if you see it works
}
else if ((current > target) && (currentMillis - previousMillis > intervalDown)) { // decrease PWM
previousMillis = currentMillis;
current--;
analogWrite(pin, current);
// Serial.print("down "); Serial.println(current); // just for debug/demo - comment it out if you see it works
}
Serial.print(target);
Serial.print(", ");
Serial.println(current);
}
I thought it was broken until I noticed separate manifest constants for the up and down timing.