19v DC Motor Running All or Nothing

I'm using a XY-1600 motor controller (uses L298n logic), and a DrillMaster drill motor and battery. My code matches the example provided with the board, but for some reason my motor only runs when the PWM value is over half way. Is this a code problem or electrical? I'm setting the speed to an int between 0-255, but I'm only seeing a change after the 1/2 way threshold.

You ask if this is a code problem, they will beat you up for not posting the code in code tags. Just watch..

-jim lee

It takes a certain amount of current to get the motor to start. It is called the stall current. It may very well be that it takes that PWM value to supply the required current to the motor to start it. Post a data sheet for the motor.

The L298 is ancient and inefficient technology. I wastes a good deal of energy as heat because of the 2 to over 4 volts that it drops in the output stage. And the claims of the board vendors are often inflated in terms of current capacity.

I would suggest that you choose a modern motor driver suitable for that motor. Pololu has a good selection of motor drivers and their instructional pages for their products are very good. You should pick a driver that can handle the motor stall current.

I’m setting the speed to an int between 0-255, but I’m only seeing a change after the 1/2 way threshold.

Sounds like you are analog writing a non PWM pin;

analogWrite(2,127); // pin is LOW
analogWrite(2,128); // pin is HIGH

groundFungus:
It takes a certain amount of current to get the motor to start. It is called the stall current. It may very well be that it takes that PWM value to supply the required current to the motor to start it.

But then why does the motor slowly spin when using a drill, but is only one speed on the motor controller? I'm using the same motor and battery from the drill, so it should work the same. Right?

JCA34F:
Sounds like you are analog writing a non PWM pin;

analogWrite(2,127); // pin is LOW

analogWrite(2,128); // pin is HIGH

Oh! I think you may be on the right track! I checked my code and realized that the L298n Library must be using analog write to set the speed, but I'm giving it pin 14 (thinking in terms of digital pins). I'll change it to pin A0 and give it a try.

Since the ancient, weak, inefficient L298 driver can't possibly handle the start/stall current (rough guess 10 to 30 Amperes) required for a Drill Master drill motor, it is probably fried.

See Typical current draw on 18V cordless tools? - Endless Sphere

jremington:
Since the ancient, weak, inefficient L298 driver can’t possibly handle the start/stall current (rough guess 10 to 30 Amperes) required for a Drill Master drill motor, it is probably fried.

See Typical current draw on 18V cordless tools? - Endless Sphere

I doubt it’s fried, as it still runs, but my guess is it’s somehow digital writing, as it only runs once my PWM speed is over 123 (exactly half way for an integer)

Here’s the code:

#include <SPI.h>
#include <RF24.h>
#include <L298N.h>

#define ENA A0
#define IN1 15
#define IN2 16
#define ENB A3
#define IN3 18
#define IN4 19

L298N left_motor(ENA, IN1, IN2);
L298N right_motor(ENB, IN3, IN4);

RF24 radio(9, 10);
const uint64_t pipe = 0xE6E6E6E6E6E6; // Needs to be the same for communicating between 2 NRF24L01

float data[10];

float left_speed = 0;
float right_speed = 0;

void setup() {

  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  
  radio.begin(); // Start the NRF24L01
  Serial.begin(9600);

  radio.openReadingPipe(1,pipe);
  radio.startListening(); // Listen to see if information received
}

void loop() {

  if (radio.available()) {
    radio.read(&data, radio.getDynamicPayloadSize());
  }

  motorControl("left_motor");
  motorControl("right_motor");
  Serial.println(left_speed);
}

void motorControl(String motor) {
  if (motor == "left_motor") {
    //left motor control
        left_speed = abs(round(data[1] * 255));      
    if (left_speed > 255) {
      left_speed = 255;
    } else if (left_speed < -255) {
      left_speed = -255;
    }
  
    left_motor.setSpeed(abs(round(left_speed)));
    if (left_speed > 0) {
      left_motor.forward();
    } else {
      left_motor.backward();
    }
  } else if (motor == "right_motor") {
    //right motor control
        right_speed = abs(round(data[3] * 255));      
    if (right_speed > 255) {
      right_speed = 255;
    } else if (right_speed < -255) {
      right_speed = -255;
    }
  
    right_motor.setSpeed(abs(round(right_speed)));
    if (right_speed > 0) {
      right_motor.forward();
    } else {
      right_motor.backward();
    }
  }
}

But then why does the motor slowly spin when using a drill, but is only one speed on the motor controller? I'm using the same motor and battery from the drill, so it should work the same. Right?

I misunderstood what you meant. I thought that it took 1/2 of the PWM to start the motor and then it would speed up proportional to the PWM until it reached the ultimate speed at 255. I did not know that it was just off and on.

What board are you using? On a Mega board pins 2 - 13 and 44 - 46 are PWM capable. The analog inputs (A0-A15) are not PWM capable. On an Uno, Nano, Mini pins 3, 5, 6, 9, 10, 11 are PWM capable. See the analogWrite() function reference.

Really, you need to find out the stall current and choose a modern driver capable of supplying that current if you are to have a reliable and efficient motor control system.

my guess is it's somehow digital writing

Utterly hopeless. But good luck anyway!

groundFungus:
The analog inputs (A0-A15) are not PWM capable.

I'm using a Nano, but I didn't realize that analog ports weren't PWM. I'll switch it over and try them with the correct digital ports.