Let's Make Robots! | RobotShop

Arduino motor control problems!

 

Update 06/11/2016

Hey guys,

I sort of got the motor working. Adding a small resistance(about 2-3ohms) in series with the motor seemed to stop the Atmega reseting whenever Pin 3 was pulled HIGH (still don't know for sure what was causing this!). I'll still continue t troubleshoot this problem and completely figure out what exaclty was causing the Atmega to reset, since the resistor is not a permanent solution (wasteful energy loss). I'm really grateful for the huge amount of help from here guys!! Thanks alot! :)

Cheers!

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Hey guys,

I'm having trouble regarding motor control in a project I'm working on.

It uses an ATMega328 DIP package on a PCB. The motors I'm using are small coreless motors and I'm trying to control them using Si2302ds N-MOS FETs. For the power supply I'm using a 3.7V(4.2V on full charge) Lipo. I've tested this setup on a promini before and the motors turned on and off just fine.

This time I'm having problems with controlling 1 motor out of the 4. I've attached 0.1uF caps across each motor terminal (see schematic). Them control pins used for the motors are pins 3,5,6,9. The problem occurs at pin 3. I tried running the blink program on pin 3 to pulse the motor on and off through the FET but all I get is a bit of clicking from the motor.

Things I've already checked relating to the circuit :

  • FETs are soldered on correctly and made sure they aren't defective.
  • Motor works fine prior to connecting it to the circuit.
  • Disconnected the FET and motor from pin 3 and checked the output. It works fine on its own.

Is the problem occuring due to noise generated by the motor? What could be the problem? I've attached the schematic to this post. Thanks in advance :D

Schematic

Here is the code I'm testing. (Simple blink program)

#define motor1 5
#define motor2 3
#define motor3 6
#define motor4 9

void setup()

{
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
pinMode(motor3, OUTPUT);
pinMode(motor4, OUTPUT);

digitalWrite(motor1,LOW);
digitalWrite(motor2,LOW);
digitalWrite(motor3,LOW);
digitalWrite(motor4,LOW);

delay(1000);
}

void loop() {


 digitalWrite(motor1,HIGH);
 delay(10);
 digitalWrite(motor2,HIGH);
 delay(10);
 digitalWrite(motor3,HIGH);
 delay(10);
 digitalWrite(motor4,HIGH);
delay(10);
delay(1500);
 
 digitalWrite(motor1,LOW);
 digitalWrite(motor2,LOW);
 digitalWrite(motor3,LOW);
 digitalWrite(motor4,LOW);
 
 delay(1000);
}

AttachmentSize
ATMega_v1.5.sch428.37 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
  1. When you mention pins are you refering to the CPU chip pin?
  2. Have you set the associated DDR in the code? 

Hey ggallant,

1. The pins I mentioned are the digital ones (i.e Pin 3 would be the 5th pin on the physical package). Pin 3,5,6,9 are the pins with PWM.

2. I'm sorry but I don't understand what associated DDR meant. I googled it and found this "a computer bus operating with double data rate (DDR) transfers data on both the rising and falling edges of the clock signal." Did you mean this ?

I'm simply using the blink program for testing whether the chip can succrssfully turn the motors on and off using the DigitalWrite command. So far three of the motors are working fine but one motorat Pin 3 refuses to turn on and just makes a clicking sound.

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 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?

Hey ggallant,

1. The chips I mentioned are the digital ones (i.e Pin 3 would be the 5th pin on the physical package). Pin 3,5,6,9 are the pins with PWM.

2. I'm sorry but I don't understand what associated DDR meant. I googled it and found this "a computer bus operating with double data rate (DDR) transfers data on both the rising and falling edges of the clock signal." Did you mean this ?

I'm simply using the blink program for testing whether the chip can succrssfully turn the motors on and off using the DigitalWrite command. So far three of the motors are working fine but one motorat Pin 3 refuses to turn on and just makes a clicking sound.

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

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.

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 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 ?

  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.