H-Bridge L298N Outputs voltage too high (PWM)

Hey everyone,

I'm trying to use L298N to control my 12v battery output.
I am using Arduino Uno. (and 11.1V LiPo battery)
The wiring is fine, however the output voltage is always a bit too high, and PWM value of 128 isn't actually half of the voltage I get with 255.

These are some PWM values I tried, and the output voltage:
PWM - Voltage
255 - 10.25
128 - 7.90
64 - 6.25
50 - 5.84 - 5.86

And here is the wiring: (first time I'm using Fritzing, I hope it looks okay)


(I couldn't find a better battery schematic, so it is not 100% accurate - the battery I am using is 11.1V)

Any ideas why it behaves like that?
I'm using Arduino for years, but didn't use L298N often, so.. Am I missing something?
Thanks in advance! :smiley:

What load do you use? The output voltage depends on the kind of the load, okay for resistive or inductive loads.

Please provide a circuit diagram including the load and where you measure the voltage. The Fritzing cable spaghetti "Breadboard" tab does not help much, choose the proper "Schematic" tab or do a hand drawn circuit diagram.

An H-bridge just outputs the supply voltage, minus some internal voltage drop.

The internal voltage drop depends on the output current, and for the ancient, inefficient L298, the internal voltage drop can be as high as 4V (with loads up to about 1 Ampere, above that the L298 overheats and shuts down).

Sorry I forgot to mention the load, no idea how I missed that :sweat_smile:
I'm using a 12v led as the output, and I measure the voltage.
But the load would explain voltage-drop, not why the voltage is too high.. Or am I wrong?

The voltage is too high, not too low.
If the voltage was too low, then the internal resistance of the H bridge, or the load itself, might explain it.
But the voltage is too high, not too low, so the h bridge's resistance isn't the problem

If the voltage is what it is. Reread reply #3. PWM reduces the time average voltage (average of peak voltage alternated with zero), not the peak voltage.

If the peak voltage is too high for you, your only option is to lower the battery voltage.

That's a non-linear load, not usable for your tests. A filament bulb may do, or a resistor.

Or measure the output current instead of the voltage.

Your load is not shown in the fritzing.
Besides, the PWM command has nothing to do with the output voltage.
It simply controls the duty cycle.
As stated, you can't use a non-linear load. The load must be inductive, or at least resistive.

So I will ask the question differently:
Why do I get "false" PWM output when I use analogWrite, and get "correct" output when I manually create pulses? Instead of using the enable pin, I manually trigger the two other pins to create PWM pulses.
For example:

    digitalWrite(MotorA, LOW);
    digitalWrite(MotorB, HIGH);
    delayMicroseconds(900);
    digitalWrite(MotorA, LOW);
    digitalWrite(MotorB, LOW);
    delayMicroseconds(100);

This code works perfectly fine, just as expected.
But I cannot achieve the same result using analogWrite.

This way I get good result both with and without load. With analogWrite, I never manage to get good results

You hide essential details.

Like what? which details do you want to know?

  1. Microcontroller: Arduino UNO original
    1.1 Powered via USB / 9v battery
  2. H-Bridge L298N, module as shown in the Fritzing
  3. Battery: LiPo 11.1V 5000mAh
  4. Load:
    4.1. LED, unknown watt. (cheap led from ebay).
    4.2. I get the same result doesn't matter what the load is. (More or less the same, it obviously depends on the load, but the result is almost identical)
  5. Cables: 12awg wires for the H-bridge input output, jumper wires for the logic data from the Arduino.

What else do you want to know?

You have not demonstrated that you get a "false" PWM output.

PWM cannot be used to control the voltage applied to an LED.

PWM can be used to control brightness of a current limited LED.

Alright, I get it, the led wasn't a good example, I'm sorry, you were right, my bad. (silly of me.. it is obviously the current that controls the led, not the voltage.. unlike in motors, where the voltage controls the speed, and the current controls "just" the torque)

Anyways, I get the same results also with several motors I tried, or with no load at all (and just multimeter measurements)
When I wire a motor, and give it analogWrite(100) , it is still almost as fast as 255, almost no difference.

The detail(s) that make your different results using PWM in hard or software. If such a difference really exists then you obviously missed to find the reason in your project. Perhaps it's in your original code which you did not show yet.

What's the power source for the motor?

The response of a brushed DC motor to PWM percentage is highly nonlinear, especially when it is unloaded. Here is a typical plot.

See DC motor speed vs PWM duty cycle - Electrical Engineering Stack Exchange

Wrong.
The current does control the instantaneous brightness but that it not something the
human eye can detect. The brightness the eye can detect is determined by the duty cycle
of the pwm , due to POV (persistance of vision) phenomenon. The instantaneous led
current is set by the led current limiting resistor.

Due to inductance, motors have an inrush current and due to mass, they cannot
accelerate instantaneously so they ramp up over some period of time during the
inrush current and average out after the inrush current, at which time the speed
is a function of the duty cycle and the motor current. Speed under load vs no load
is a function of the V/impedance of the motor. If a motor has enough current
there is no noticeable reduction in speed as you increase the load until the load
approaches the current rating of the motor.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.