L298N + Eagle Schematic Problem

Hello All,
We are working on a robot and everything was going great we etched our pcb and all our sensors worked then we got to our motors and they just freak out. We had originally bread boarded everything out and it worked fine. I am not sure what the problem is, I have tried re making the board on a perf board and its doing the exact same thing the motors just won't work or they will work if the FTDI chip is plugged in but they will still freak out. If the FTDI chip is not plugged in (not to the computer just on the pins) the motors won't even turn on and spin at all. I have checked double checked all the pins seem to be correct. I posted some pictures of the eagle schematic and some snippets of code. I am not 100% the code is written correctly usually the pre made H bridges I have used in the past worked a little different then when with wiring up my own 298. My understanding is that the h bridge takes the difference between the two pwm signals and that is what is passed to the motor in terms of voltage. So High would be 255 and then 110 = 145 to the motor. I wanted to add that I have 5v running to the logic of the H bridge and 7-8 V running to the VS pin for power to the motor. Thanks for the help!!!

void forward(){
  digitalWrite(PIN_R_MOTOR_DIR, HIGH);
  analogWrite(PIN_R_MOTOR_SPD, 110);
  
  digitalWrite(PIN_L_MOTOR_DIR, HIGH);
  analogWrite(PIN_L_MOTOR_SPD, 90);
}

Welcome back. I can't really read your schematic on this browser, it won't open very wie for me, have to wait until I get home. Can you post the rest of your code?

Here ya go, the code is quite large so I tried to just include the motor stuff. Basically I can't figure out if I am using the 298 wrong, first time using just a chip and not a pre made board. Or if its some wiring issue but my guess is on the 298 being wrong. If I wire this up regular to an arduino board and 298 pre made board it works fine but soon as I used my own atmega 328P and 298N chip no dice. Thanks!

PS. I have been investigating the possibility of the chip is resetting on its own? I have a pull up resistor to 5v and a capacitor that is in series with the FTDI DTR line when its connected for the auto reset, so I don't see why it would be. But I am at a loss at the moment.

#define PIN_R_MOTOR_SPD 3
#define PIN_R_MOTOR_DIR 5
#define PIN_L_MOTOR_SPD 6
#define PIN_L_MOTOR_DIR 4




void setup(){
  Serial.begin(9600);
  pinMode(PIN_R_MOTOR_SPD, OUTPUT); 
  pinMode(PIN_L_MOTOR_SPD, OUTPUT); 
  
  pinMode(PIN_R_MOTOR_DIR, OUTPUT); 
  pinMode(PIN_L_MOTOR_DIR, OUTPUT); 

void loop(){

  delay(3000);
  while(1){
  forward();
  }

void forward(){
  digitalWrite(PIN_R_MOTOR_DIR, HIGH);
  analogWrite(PIN_R_MOTOR_SPD, 110);
  
  digitalWrite(PIN_L_MOTOR_DIR, HIGH);
  analogWrite(PIN_L_MOTOR_SPD, 90);
}

 
}

Okay, I saved it & opened it locally.
You NEED to have 0.1uF caps on '328P pins 7 & 20.

L298: Normally the Enable lines are used to control speed, with the In1/In2 or In3/In4 used to set the direction (Hi/Lo, or Lo/Hi).
See the chart on Page 6 of the datasheet.

You are not connecting pins 1 & 15 back to the '328 for monitoring; remove R3 & R4 and just connect the pins to Gnd.

L298N.pdf (599 KB)

Yes, So I wasn't sure about the ENA ENB pins because I have seen schematics that just force them to 5v. I will try sending the PWM to them instead and setting IN pins HI LO. Thanks! Ya I figured the burden resistors were useless unless monitoring but I put them there for posterity lol. I will add the cap also but I have never seen any schematics with that cap what is the reason for having them between the power pins of the chip, just to isolate them?

I have never seen any schematics with that cap

Any good design will have them. They are called decoupling caps, and serve as a fast local source of current as the uC turns transistors on & off internally.

Thank you for the tips, So I am still having the Issue that if the FTDI chip is not on the pins the motors do not turn on for some reason....I have ENA ENB set to HIGH for full speed and IN1 IN2 HI LO same for IN 3 IN 4. It doesn't make any sense.....am I missing something about the FTDI chip having to always be part of the circuit? I am using this one from sparkfun https://www.sparkfun.com/products/9716

Same sketch?
For testing, Forward only needs to be called once.
Move it into setup(), then check the levels on the various control pins, see if everythiing is Hi or Lo as expected.

All pins are correct. The FTDI was plugged in motors were running correctly. As soon as I unplug the FTDI chip from the headers the system stops......I tested out the FTDI the motors run fine when the 5v and gnd of the FTDI are plugged into the header......

correction when I unplug the FTDI the atmega does not work for some reason all the pins are low that should be high going to the 298. When I have the FTDI 5v and GND plugged in everything works fine.

We have definitely pin pointed the FTDI chip is doing something to our 5v rail that is powering the chip when its plugged in allowing it to work. But we have not a clue as to what it is doing. Were going to see if its our regulator causing an issue with the 5v its sending to the chip.

Where does 5V come from when FTDI is not plugged in?

It seems to be our Regulator the NTE931 it puts out 5V just fine on the meter but we just ran our power supply directly to the chip and it works without the FTDI. So we are thinking that the 5V signal coming out of the regulator is shitty and making the chip not work unless the FTDI is plugged in because its pulling current like a resistor when its not plugged into the computer but still plugged into the header.

We had originally had some smoothing caps on the output of the NTE931 but we had one blow up on us and the datasheet said it was not completely necessary but maybe the atmega is very sensitive and this regulator just puts out a gritty 5v?

but we just ran our power supply directly to the chip and it works without the FTDI.

What voltage level is that?

What is NTE931? Is not a valid part # at digikey.com.

We found the problem it seems we never replaced the smoothing capacitor on the output after it blew up. Everything seems to be working now for the most part. The motor h bridge we still need to fix the pins so that we are sending PWM to ENA ENB and setting IN pins HI LO for direction. Thank you for your help it was a great adventure debugging to find out it was a capacitor haha.

had one last question. So everything is working pretty good but one of the outputs is getting like .5 volt more then the other one. Could this be a function of just the motors not being equal? I would assume the voltages should be constant if there getting the same signal though.

Thanks,

#define PIN_R_MOTOR_SPD 3 // ENA 
#define PIN_R_MOTOR_DIR 4 // IN1
#define PIN_R_MOTOR_DIR1 6 //IN2


#define PIN_L_MOTOR_SPD 5 //ENB
#define PIN_L_MOTOR_DIR 2 // IN3
#define PIN_L_MOTOR_DIR1 13 //IN4
void setup() {
 
}

// the loop routine runs over and over again forever:
void loop() {
  forward();
}


void forward(){
  analogWrite(PIN_R_MOTOR_SPD, 80);
  digitalWrite(PIN_R_MOTOR_DIR ,LOW);
  digitalWrite(PIN_R_MOTOR_DIR1, HIGH);
  
  analogWrite(PIN_L_MOTOR_SPD, 80);
  digitalWrite(PIN_L_MOTOR_DIR, LOW);
  digitalWrite(PIN_L_MOTOR_DIR1, HIGH);
  
}

One of the Arduino outputs, or one of the L298 outputs?
Arduino - is going into digital input on L298, would not be concerned.

L298 - if you swap the motors, does the lower voltage stay with the motor? If so, is likely the motor as you surmise. If not, maybe wiring for the output is going thru some higher resistance, is not making as good a connection. (protoboard contacts?)

A lot of the load from a motor at low power is its own friction (especially for brushed
motors) and this friction is, like all friction, rather random and "ill-characterized" - ie
messy. Expect differences between motors if they are cheap. Expensive well-engineered
motors use superior materials and undergo more quality control, cheap hobby motors
just fall into a bin at the factory, job done.

Also a fact that few people realise is that DC motors can be asymmetric, designed to
spin mainly in one direction, and the brushes are placed offset to advance the timing for one
direction of rotation (compensates for the inductive delay in current switching).

Thus in a two-wheel robot with mirror-symmetric drivetrains one motor is running opposite
to the other, so any difference will be noticable (should show up more at speed).

Thank you I will check, having a new issue now haha. There is a short or something in the board somewhere and I am unable to program the chip. So back to debugging !

Previously you had mentioned the decoupling caps, Do I just have

GND ----Capcitor ----- 5V/pin 7

GND ----Capcitor ----- 5V/pin 20

or

Regulator 5V -----Capacitor ---- pin 7

Regulator 5V -----Capacitor ---- pin 20

The only time I see decoupling caps mentioned are the smoothing caps right after a 5V regulator.

Note: I think I am used to decoupling caps being called smoothing caps from school which seem to be the same thing just industry seems to call them decoupling caps?

Thanks

Smoothing caps help regulators smooth out the AC they are regulating, left from when AC went a transformer and full wave bridge rectifier and a linear regulator - nowadays DC wallwart are so inexpensive, that method is, or should be, dead.
Decoupling caps are 0.1uF caps that mount right next to a chip and provide very localized current to support a chip internally internal transisitors are rapidly switched. GrumpyMike has very good web page on them.
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html
Short version: put a 0.1uF cap close to every Vcc pin of every device.
So a '328P DIP will have 2, a surface mount part 3, a 2560 4 or 5.
The websites and instructionals that leave them out are doing everyone a misjustice.