How It Works L298 H-Bridge

One of the challenges of driving DC electric motors is that they sometimes need the capability to operate in reverse.
To do this, the current flow must be reversed. Arranging for this requires additional hardware.
The H-Bridge driver can be used to drive a reversible DC motor or a bipolar stepper motor. Unlike the unipolar motor, the field windings of a bipolar stepper motor require reversible current flow to operate.
An H-Bridge is an electronic circuit that enables a voltage to be applied across a load in either direction. These circuits are often used in robotics and other applications to allow DC motors to run forwards and backwards.
Most DC-to-AC converters (power inverters), most AC/AC converters, the DC-to-DC push–pull converter, most motor controllers, and many other kinds of power electronics use H-Bridges. In particular, a bipolar stepper motor is almost invariably driven by a motor controller containing two H-Bridges.

The L298 integrated circuit implements a convenient H-Bridge driver circuit. An H-Bridge can be built from discrete
components, but integrated circuits are more convenient for lower-current applications.
The motor in the figure is driven when Q 1 and Q 4 are turned on. Q 2 and Q 3 are kept off when the other transistors are on. If Q 1 and Q 2 were allowed to be on at the same time, a short circuit would exist from V SS to ground. The and logic gates driving these transistors prevent this.
With Q 1 and Q 4 on, the current flows through the motor from left to right. Turning all transistors off results in no current flow. Turning Q 3 and Q 2 on causes the current to flow from V SS to ground, passing this time through the motor from right to left. By controlling pairs of transistors, current can be made to flow in one direction or the other.
When used, the sensing resistor R S is a low-resistance resistor for sensing how much current flows through the motor. As current flow increases, the voltage V RS across the resistor increases. When the motor stalls, for example, V RS will exceed a certain threshold voltage, allowing protective circuitry to turn the drivers (and thus the motor) off.
The L298 is a dual-bridge driver, with units A and B. The enable inputs EnA and EnB enable or disable the drive to units A and B, respectively. Without a high signal on the enable input, no current will flow through the bridge, no matter what the other input signals are. The enable input can be used by the protective circuitry to disable the motor outputs, should the V RS voltage rise too high. Otherwise, the enable inputs can be tied to the logic high or controlled by the microcontroller.
Each half of the dual-bridge driver has a pair of logic inputs. They are In1 and In2 for bridge A, and In3 and In4 for
bridge B.
When the enable EnA pin is enabled, the In1 and In2 inputs have the following results for the motor drive.

A simple way to think about this is that one input must be high, while the other is low for the motor drive. The direction is selected by the input that is high.
No inductive driver circuit is complete without protective diodes. When the applied voltage is suddenly removed from the motor coil, the magnetic field collapses, producing an electric current, the reverse-biased diode was used to bleed off the inductive kick in the unipolar motor drive.