SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By wordyallen
#172617
I'm controlling a small 12V motor (start and stop, no reverse). I remember hearing about inrush current so I wrote the code to gradually ramp up using PWM. I just don't wanna fry anything. However doing that has made the code a lot more complicated. I think its a mess right now. Can anyone help me simplify it? Or should I simply start it at full speed?

The breaking out of the ramping up loop and the steady state loop is really awkward.... here's what i have:
Code: Select all
char PLANT1; 


const int PUMP1=3;


void setup()
{
   Serial.begin(9600); 
   pinMode(PUMP1, OUTPUT);
}

void loop()
{
   if (Serial.available() > 0) //Input
   {
      PLANT1 = Serial.read(); //Read state of PLANT1

      if (PLANT1 == '1')   //Plant 1 is thirsty
      {
      Serial.println("Plant 1 is Thirsty.");
      for (int i=0; i<256; i++) //ramp to protect from high inrush
         {
            analogWrite(PUMP1, i);
	    delay(10);
	    
	    PLANT1 = Serial.read();
	    if (PLANT1 == '2')  //break out of ramp
	       {
		  Serial.println("Plant 1 is quenched.");
		  analogWrite(PUMP1, 0);
		  break;
	       }
	       if (i == 256 && PLANT1 == '1') //hold at steady state
	       {
		  i = 255;
		  	    }
	 }
       else if (PLANT1 == '2') //check for quench
       {
	 Serial.println("Plant 1 is quenched");
         analogWrite(PUMP1, 0);
	 delay(10);
       }
      delay(1000);
   }
}
   
Thanks!
By jremington
#172618
A DC motor briefly draws the stall current every time it starts up, and it can draw nearly twice the stall current if it is suddenly reversed. There is nothing programmatically that you can do about that, but you can use a current-limiting motor driver to perform a soft start. PWM does not limit the instantaneous motor current, only the long term average.

What method are you using to drive the motor, and why are you worried about "inrush current"?
By wordyallen
#172619
So are you saying that even if my PWM duty cycle starts at 1%, it will still draw the stall current?

I gave up on the gradual start. I'm starting the motor at 50% duty cycle. I'm using an NPN and flyback diode to drive.
By jremington
#172625
even if my PWM duty cycle starts at 1%, it will still draw the stall current
Yes. PWM applies the full voltage to the motor (for a short period of time) and by Ohm's law, the stall current flows until the armature starts rotating and generating back EMF.