Hi,
I have 4 LMD 18200 motor driver boards that I am using to control 3 pumps and a stir motor. The inputs are PWM, Direction and Brake. As only one pump is running at any given time all of the pumps share a PWM signal. Individually I am controlling the direction and then releasing the brake. Then the PWM signal will ramp up the speed of the pump to max then the timer counts up to a set point and then the PWM signal ramps down the speed and the moves on to the next state. I have the basic ramp up and down working but I am having trouble integrating it into the existing program. Can you look at this and give me some guidance?
//////////////////////////////////////////
void HandleFILLING1State()
{
TSread(); // Check Touch screen for abort request
counter = counter + 1; //Display print counter
if (counter <2) // print screen once
{
///
tft.fillRect(10, 10, 320, 90, BLACK);
tft.drawRect(15, 20, 282, 90, GREEN);
tft.fillRect(15, 112, 282, 95, BLACK);
tft.setCursor(0, 35);
tft.setTextColor(GREEN);
tft.setTextSize(4);
tft.println(" Press to");
tft.println(" Abort Cycle");
tft.setTextColor(RED);
tft.setTextSize(4);
tft.setCursor(70, 140);
tft.println("Filling");
tft.setCursor(71, 170);
tft.println("Cleaner");
}
///////////////////////
digitalWrite(stir_brake, HIGH);
digitalWrite(pump1_direction,HIGH); //Fill so leave direction pin high
digitalWrite(pump1_brake, LOW); //Release brake on pump
digitalWrite(pump2_direction,HIGH);
digitalWrite(pump2_brake, HIGH);
digitalWrite(pump3_direction,HIGH);
digitalWrite(pump3_brake, HIGH);
for (int motorspeed = 0; motorspeed < pump_speed; motorspeed++) {
analogWrite(44, motorspeed); // ramp up motor speed PWM pin
Serial.println("ramping up ");
delay(pump_ramp); //
} //motor now running max speed
static unsigned long lastTick = 0; // set up a local variable to hold the last time we moved forward one second
// (static variables are initialized once and keep their values between function calls)
if (millis() - lastTick >= 1000) {
lastTick = millis();
second++; // add second
Serial.print("Second = ");
Serial.println(second);
if (second > FILLING1_TIME){ //time out
for (int motorspeed = pump_speed; motorspeed >= 0; motorspeed--) {
analogWrite(44, motorspeed);
Serial.println("ramping down ");
delay(pump_ramp);
} //motor is now stopped
clearcenter();
counter = 0 ;
second = 0 ;
state=STIRRING1;
}
}
if (counter > 5){
counter = 3 ;
}
}