Motor slows down, low voltage from MD01b?

Hey guys I am using an MD01b to control this motor link powered by a 1.5A wall wart.

I have run this motor no load via the driver for a minute or two at a time with no issues, however sometimes when using an arduino to control it it will run sluggishly, almost as if it is being pwm’d at a low rate. The next trip through it will run fine, then sporadically it will slow down again. Below is the simple function I am calling to run the motor, called via a buttonpress. Im not sure where to start debugging this? Any help would be appreciated.

*edit: I know this is lacking info, Ill be happy to provide any additional info anyone needs.
*edit 2: Some additional info, A voltmeter across the motor terminals shows 12v when it is running normally, but only 3-3.5v when it is running slowly.

while (!tripCount) {
    if (targetSteps - hallInterCount < 10){
    analogWrite(pwmPin, 60);
    }
    if (targetSteps - hallInterCount > 10){
    analogWrite(pwmPin, 255);
    }
      digitalWrite(CWpin, HIGH);
    }

    if (tripCount) {
    digitalWrite(CWpin, LOW);
    tripCount = false;
  }
}

Hello.

I really don’t understand what you’re doing, and I can’t give you feedback on your program segment without some insight into what your undefined variables are. However, your formatting makes it look like you might not be doing what you think you’re doing. If I reformat the spacing to match your braces, does it look like you intend?

while (!tripCount)
{
  if (targetSteps - hallInterCount < 10)
  {
    analogWrite(pwmPin, 60);
  }
  if (targetSteps - hallInterCount > 10)
  {
    analogWrite(pwmPin, 255);
  }
  digitalWrite(CWpin, HIGH);
}

if (tripCount)
{
  digitalWrite(CWpin, LOW);
  tripCount = false;
}
}  // there is no opening brace that corresponds to this

Note that there is nothing inside your while loop that can change the value of tripCount, so if you ever enter that loop, you will never exit. Generally speaking, if your motor is sometimes moving slowly, the condition that sets the PWM to 60 is probably evaluating as true, so you should be trying to figure out why that might be.

- Ben

Sorry about that, the missing brace corresponds to the top of the void function that I forgot to copy. “tripcount” is set by an ISR. That while loop exits just fine and both of the if statements inside evaluate to true when the values they are checking get changed by the ISR. May as well paste the code, but Im sure this is an electronics issue rather than a code issue.

ISR:

void hallCount() {
  hallInterCount = hallInterCount + 1;
  tempHallCount = hallInterCount;
  tripped = true;
  if (hallInterCount >= targetSteps) {
    tripCount = true;
    hallInterCount = 0;
  }
}

and the function above.

void stepOne() {

while (!tripCount) {
    if (targetSteps - hallInterCount < 10){
    analogWrite(pwmPin, 60);
    }
    if (targetSteps - hallInterCount > 10){
    analogWrite(pwmPin, 255);
    }
      digitalWrite(CWpin, HIGH);
      digitalWrite(CCWpin, LOW);
    } 
    if (tripCount) {
    digitalWrite(CWpin, LOW);
    tripCount = false;
    }

 lcd.setCursor(8,4);
 lcd.print(digitalRead(CWpin));
}

I added an edit to my original post, if I measure the voltage across the terminals of the motor, when it is running correctly I see 12v, when it is running badly I see like 3 - 3.5 volts. This happens occasionally even if I just set one of the input pins to high with the MD01B PWM pin pulled high. Im going to assume for now that my power supply is undersized.

Thanks for clarifying. If you continue to have problems with a beefier power supply, please let me know. In general, I suggest trying to come up with the simplest code (e.g something without interrupts) that demonstrates the problem. In doing so, you will probably figure out the source of the problem on your own, or at least you will make it much more likely that someone else can identify what the problem might be.

- Ben