Power Supply Problem with L298N Motor Driver

I have a L298N Motor Driver, connected to a two dc geared motor and I am using an Arduino Nano as a microcontroller for it.

I'm also using a HW688 buck converter, it has two terminals, a terminal for output (and this is what I use to power the 5V Arduino) and another terminal for input (it has a 12V male power jack and a terminal screw, this is where I connected the L298N)

But the problem is, as I observed the LED of the buck converter turns off (indicating that the power suppy suddenly turns off) whenever I intend to stop the motor in the code. Upon troubleshooting, I started using different L298N motor driver, thinking that the one I use is faulty but the problem still persists. I started looking around in the code, and noticed that when I set the speed below 255 (for example 200) it fixes the problem and the power supply does not turn off when the motor stops.

the connections are as similar to this

and I use the L298NX2.h library for the code

#include <L298NX2.h>

const unsigned int EN_A = 10;
const unsigned int IN1_A = 9;
const unsigned int IN2_A = 8;
const unsigned int IN1_B = 7;
const unsigned int IN2_B = 6;
const unsigned int EN_B = 5;

L298NX2 motors(EN_A, IN1_A, IN2_A, EN_B, IN1_B, IN2_B);

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  motors.setSpeedA(200);
  motors.setSpeedB(200);

  Serial.println("Forward");
  motors.forwardA();
  motors.forwardB();
  delay(2000);

  Serial.println("Stop");
  motors.stopA();
  motors.stopB();
  delay(1000);

  Serial.println("Backward");
  motors.backwardA();
  motors.backwardB();
  delay(2000);

  Serial.println("Stop");
  motors.stopA();
  motors.stopB();
  delay(1000);
}

I have also tried to use a different code without any library and solely relying on digitalWrite() but notices that it is still having the same problem and convinced that it is a hardware problem

What is the reason for this problem? and how to fix it?

Why is that a problem?

What's your 12V supply?

Its design lacks the 5 V power supply from the L298 module.
Is the +5V enable jumper connected?
If in the real project you did not power the module with 5V or jumper is connected ,it will not work.

Check if you really have 12V on the connector pins on the module.

Because it wasn't supposed to do that. The buck converter/power supply must not turn off even though the motor stopped. And since the arduino is also connected to that power supply, whenever the power supply turns off the arduino also turns off causing it to reset and to not properly run the whole code.

the 12V power supply that I use is from a 12V power adapter that I directly connected to an outlet

Yes the jumper of the regulator is still connected. I am confuse, as I read it is suppose to be connected? is my assessment correct and if not can you further elaborate on this?

And yes, I have check the voltage of the L298N terminals using a multimeter, the buck converter is giving the L298N consistent 12V and both motor is receiving approximately 8V-10V.

When that library stops the motor(s), does the motor coast or brake to a stop? What is the 12V power supply's current rating? What are the motor(s) current rating? You might try removing the power jumper on the L298 (behind the 3 terminal block) and supply the 5V logic power from the Arduino's 5V pin.

Which current rating?

It may fail under special circumstances (back EMF?) and make the buck converter turn off. I'd try a diode towards the motor driver to prevent spikes entering from the stopping motors.

Read the section on Power. It will solve all your problems.

That's not shown in your picture.

Yes, the jumper must be connected.

It brakes to a stop then the power supply turns off.

I'm using a 12V power adapter 2A and according to the site where I bought the motor it's Stall Current is 2.8A

I have tried this, removing the jumper and connecting another wire from Arduino 5V to VSS/5V of L298N. The problem still persists.

I actually think this is the problem, when the motor stop it probably gives back an EMF that makes the buck converter turns off, what diode would you recommend for this? and can you elaborate how should I connect it to the motor?

It must support the maximum motor current. Insert it from the 12V supply to the L298 board.