Arduino motor control problems!

What I would check.

Is the ATMega328 in a socket?  If so you can pull it out and spoof its output at the socket to see if its the chip or the socket.  

You can also swap motors to see if motor 3 works in the motor 1 circuit and vice versa.

You can make a simple logic probe from a led and resistor and check all the other pins when you think motor 3 should be working to see if you misread the pin assignments.  (It happens to everybody.)

Can you move the connection to a different PWM pin?  You don’t say if its a prototyping board or a etched board.

Check the traces and vias on the pcb.  Especially if you had someone else fab the board it could have a flaw short or open via.

Good Luck

RG

DDR

Data Direction Register. Determines whether an I/O pin is an input or an output. Some hardware functions and libraries will do this for you. If you are bit banging then you need to do it yourself. Perhaps post the code and we can be of more assistance.

 

Hey RG,The ATMega is in a

Hey RG,

The ATMega is in a socket. I put the chip back in the Arduino board and gave the outputs to the PCB as you suggested and it worked perfectly.So could the problem be that the chip on the PCB s underpowered ? Why would only Pin 3 not work ?

I’ve made this circuit on an etched board using toner trasnfer at home. Here’s a clearer sschematic of the motor connections as the earlier one I posted was not clear. I’ve connected all 4 motors identically so its really puzzling why only pin 3 malfunctions.

Screenshot__359_.png

Hey ggallant,The code I’m

Hey ggallant,

The code I’m running is just a simple blink program to test whether the chip can turn the motors on or off. I tested the same code by removing the chip from the PCB, then putting it back on the Arduino board and porting the o/ps to the PCB and all worked fine!

I’m guessing that it’s some underpowering issue then?

Check the socket.

Get out your magnifying glass and check the socket.  I have seen missing or damaged contacts.  Also check your soldering and resolder any connections that are suspect.  And resolder the suspect pin just to be sure.

That should fix it if its a bad solder joint.  If its a bad socket it will need to be replaced.

RG

Hey RG,I checked the socket

Hey RG,

I checked the socket using my DMM continuity tester and it didn’t show any bad connection between the pin and resistor. I still soldered the pin again but there was no change in the circuit. I even checked it with another chip just to make sure the defect wasnt in the chip.

When I try to switch all 4 motors on they dont come on (even the working ones). When I cut the trace of the non functioning motor, the other 3 work properly. I then tried connecting the pin and resistor through a external wire but then it shows the same result (i.e. no working ).

Is there some loading effect at the pin that causes the other motors to switch off too ?

Motor problems

  1. You are using the same Vcc to power both the CPU and the motors.
  2. There is only 1 cap from Vcc to GND (C1) and it does not display a value. Probably needs to be about 470uf.
  3. Post your code and we can duplicate a portion of your environment.

 

Hey ggallant,1. The whole

Hey ggallant,

1. The whole circuit is powered by a 3.7V (4.2V peak) 25C 500mAh Lipo. It works fine for powering 3 motors but is failing when I try to power one at pin 3(Even when that alone is the pin being powered). This caused me to doubt it being a power issue. I also tried the spoof test RG mentioned and all 4 pins worked fine.

2. The cap I’ve put is a 220uF electrolytic one. (Sorry for the unclear schematic) It is between vcc and gnd as you mentioned and is soldered close to the atmega chip. Should I add another 470uF ?? Or should I replace this with 470uF? The 220uF worked on a breadboard.

3. I have edited the original post with the code. Thank you so much!

I will load and test code,

I will load and test code, no motors or driver. Your schematic does not specify the crystal frequency but the 328 is not guarenteed to run at 16MHz at 3V. Are your promini’s 3V?

Hey ggallant,The crystal

Hey ggallant,

The crystal connected is of 16MHz. The promini was 5v one. I had connected the battery directly to the vcc pin bypassing the 5V regulator on the board. On the PCB I made the atmega vcc is also directly connected to the batterry. All the tests I tried were with the batter at 4.2V. Safe zone for 16MHz would be 3.8V and above right?

Thanks!!!

Vcc

Do you have a 5V supply? Can you supply separate power for CPU and motors?

I would suggest you add some serial print statement in both the init() and loop() functions. That way you can tell if the CPU is resetting.

 

Hey ggallant,I tested the

Hey ggallant,

I tested the code with the serial statements that you suggested and it helped clear the problem up alot. The atmega is restarting only when Pin 3 is activated. Any other pin on the board being switched on and there is no problem, but when I pull pin 3 HIGH the chip restarts.

Is this problem power related?? When I powered the chip from the arduino 5V and motors from battery all the pins worked fine, even pin 3. Why would it only be caused at pin 3?? Would i be a PCB trace problem??

I also took videos of the problem in order to make it clearer.

Here is a video of the board working when the chip is powered separately.

Here is a video when the board is continuously restarting when powered by battery only and pin 3 set to HIGH.

Thanks alot for your help ggallant!!

Not only the big capacitors…

Try to add a 0.1 uF cap over the 328 chip power pins. as close at the chip as possible. Those small caps do really help by filtering those little short power dips.

Another thing to look at is that your power wires should be soldered as direct as possible to your power supply and not via other wires/components. For example battery wire -> soldered on pcb by fet -> then another wire soldered at pcb to arduino power pin.

CPU reset

Try putting resistors in place of the motors. Start with a high value (500ohm) and work down. Verify that the reset condition is only on motor 3. If it is, it is time to test/replace the components in that path.

Note: For low value resistors you probably need the higher wattage types. Simple calculation. P = I x V or any other derivation using I,V & R.

Hey ggallant,I did this test

Hey ggallant,

I did this test on the pin the motor wasn’t working on and it worked fine until I reached 10ohms (lowest value I had).

Then I connected the motor in series with the resistor and it started to work. I checked the reisistance across the motors and it was between 1-2ohms. Is this causing some problemsfor the Atmega pins ? How come 3 motors are driven fine but it struggles with only this particular one ?

Also is it possible to isolate the MCU vcc from the rest of the circuit using a resistor ?

Thanks!

Motor drive circuit

Sounds like the system is resetting at 0.4A. Is this the same for all motor drive circuits?

Hey ggallant,This is only

Hey ggallant,

This is only happening with the motor controlled at pin 3. I thought it was a faulty capacitor or diode on that part of the board that was causing the voltage to drop but even after replacing both the problem is still there.

The arduino stopped resetting only after I connected a resistor in series with the motor.

 

Hey Dannyv,I already drilled

Hey Dannyv,

I already drilled some extra holes near the chip and soldered the capacitor. There’s also one of those soldered across every motor terminal (on the pcb).

The Vcc line is a continuous trace going to the motors, 328 chip and the 3.3V regulator. The battery input is given through header pins to this. I’ve read that isolating the chip and motor supply is good practice and I read on another old forum that it can be done with a resistor separating the different lines (still using 1 battery). Is it possible?

Cheers!

What level is the brownout reset at?

I have been busy and might have lost the thread of this.  

Have you checked the settings of the brown out detection programing fuses?

When you are using a separate power supply is it 5v or 3.2v?

If you put a volt meter (or o-scope) across the vin what happens when it resets?

RG

 

Hey RG,Brownout detection is

Hey RG,

Brownout detection is set at 2.7V, I wsa thinking of burning the bootloader again with either disabled brownout or a 1.8V setting. My battery never goes below 3.8V.

When it is separte the chip is on the arduino main board so that was powered by USB 5V.

The reset hapens continuously and very fast, so the DMM shows that the pin is still pulled up (Around 4.2V). But I tried printing to the serial monitor like ggallant suggested and confirmed that the atmega is continously resetting.

For now the only way the motor works is when a resistance is connected in series with it ( I’ve gone down to 10ohm ).

Thanks !