Pages: [1]   Go Down
Author Topic: Arduino Micro with SN754410NE DIP-16 H Bridge  (Read 1476 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
 
I'm using an Arduino Micro with an SN754410NE H Bridge and an IR Receiver connected to 1 motor, all powered by a single 2 AMP AC/DC adapter.
The purpose of the IR Receiver is to run the motor either forwards, backwards or stop depending on the button code received.

If I use 5V as the AC/DC input power(see diagram),then everything works great (except that the motor runs slow since it only gets 5v)
(Arduino: Vin=5V / H Bridge: Pin1=5v/Pin8=5v/Pin9=5v/Pin16=5v)

If I use 7v as the AC/DC input power (see diagram), then the motor starts to work erratically.
When the power comes on, or the Arduino is reset then sometimes the motor immediately starts on full speed in one direction and will not go in reverse.
(Arduino: Vin=7v / H Bridge: Pin1=5v/Pin8=7v/Pin9=5v/Pin16=5v)

Could you please take a look at my diagram and see what i'm doing wrong?  (The chip supports up to 36v)

In the code, the only thing i'm doing is setting the pinmode to 'OUTPUT'  and telling the motor to not move:

int motor_1_pins[] = {2, 3};

void setup()
{
   Serial.begin(9600);
   pinMode(motor_1_pins[0], OUTPUT);
   pinMode(motor_1_pins[1], OUTPUT);
   digitalWrite(motor_1_pins[0], LOW);
   digitalWrite(motor_1_pins[1], LOW);
}

Any help would be really appreciated!

Thanks in advance,
Paul


* Micro_SN754410NE.jpg (433.11 KB, 1323x1095 - viewed 80 times.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Paul,

What drawing program do you use to create your attached drawing?  I normally use Visio; I've seen your program used and I really like the battery packs, breadboard and motor objects.

Any help would be appreciated.

Gary
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Paul,

Don't bother responding, I found it, Fritzing!.

Gary
Logged

Offline Offline
Edison Member
*
Karma: 64
Posts: 2488
The last thing you did is where you should start looking.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have always made it a policy to always use a separate power supply for the controller and the motor!

Quote
If I use 7v as the AC/DC input power (see diagram), then the motor starts to work erratically.
I would first confirm the 7 volt power supply is not being pulled down too low.

Quote
SN754410NE H Bridge
This is rated at 1.2 amps 2 amps peak. How much current is drawn by the motor if you connect it directly to 7volts?

Is this all the code you have?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
Thanks for your help, regarding the motor it has the following stats:

Operating range: 4.5 - 15v
No Load Current 0.15 A
At Maximum Efficiency: 0.84 A

The power adapter puts out 7 volts at 2000ma, I have also tried a second one with 7,5v 2100ma with the same results.
I tried to measure the amps when the motor is connected directly to the power adapter but it seemed almost too low to measure (0.05).  Perhaps I did this wrong.
 
I have also tried two different h bridges but they do the same.

For the code, I removed most of it to try and identify the cause of the problem and can see that the issue happens the when I call the "pinMode(motor_1_pins[0], OUTPUT);" commands
Here is the code I am left with:

int motor_1_pins[] = {2, 3};
 
void setup()
{
  Serial.begin(9600);
  pinMode(motor_1_pins[0], OUTPUT);
  pinMode(motor_1_pins[1], OUTPUT);
  // Problem happens already here
  delay(100);
  motor_stop(motor_1_pins[0],motor_1_pins[1]);
}

//-------------------------------------------
//Stop motor
int motor_stop(int pina, int pinb)
{
  digitalWrite(pina, LOW);
  digitalWrite(pinb, LOW);
}
//-------------------------------------------

//Main Program
void loop()
{
}

Thanks!
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

1. Please use code tags (the # button in the editor) when posting your code.

2. The problem is that the SN754410 has inputs that float high. So before you make the pinMode calls, both the 1A and 2A inputs are effectively high. Therefore, when you make the first pinMode call, you bring one input low while the other is high, which applies full power to the motor. This sudden load on your power supply is causing its voltage to droop, which in turn is causing the Arduino to malfunction.

Here are some possible solutions, any one of which may fix the problem:

(a) Use a power supply with higher current rating

(b) Use a separate power supply for the Arduino

(c) Connect a large capacitor (2200uF or more) across the power supply to better provide the surge current that is drawn between the two pinMode calls

(d) Before making the pinMode calls, digitalWrite HIGH to both pins, so that the input state doesn't change wheh you make the pinMode calls. Also change the motorStop code to write HIGH to both pins instead of low.

(e) Connect the 754410 EN (enable input, pin 1) to an Arduino output, preferably a PWM pin (then the 1A and 2A pins can be connected to any digital outputs, not necessarily PWM pins). Before you set pinMode for the pins driving 1A and 2A, set the pinMode for the pin driving EN. This will force EN low, disabling the whole driver. Then set 1A and 2A to select the direction you want, and use the EN pin to do on/off and PWM.

(f) Add 1K pulldown resistors on the pins driving 1A and 2A.
« Last Edit: February 09, 2013, 05:01:48 am by dc42 » Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks very much!, I've been trying testing your solutions and implementing what I can.
For point e), I tried to implement some changes in my code but i'm not sure if I understood fully.  Could you please check my code below? (it still sometimes causes a malfunction with my version).
Can you also please tell me if there is a way to implement a safety to stop the motor if the Arduino malfunctions or if the motor gets stuck running? (I was planning to leave it on all day).
I tried using the watchdog timer but it seems to malfunction with the 'Arduino Micro' and then won't let you upload anything to it again without a fix. (I put
Code:
wdt_enable(WDTO_8S)
in the setup and
Code:
wdt_reset
in the loop (every few ms).

Thanks again for your help!
Paul

Code:
int motor_1_pins[] = {5, 6};
int speedpin = 4;

void setup()
{
  Serial.begin(9600);
  pinMode(speedpin, OUTPUT);
  analogWrite(speedpin, 0); 
  pinMode(motor_1_pins[0], OUTPUT);
  pinMode(motor_1_pins[1], OUTPUT);
}

//-------------------------------------------
//Motor Control
int motor_control(int directionz,int motorpin1, int motorpin2,int controlpin)
{
  //Stop
  analogWrite(controlpin, 0);
  digitalWrite(motorpin1, HIGH);
  digitalWrite(motorpin2, HIGH);
 
  if(directionz==1) //Reverse
  {
    digitalWrite(motorpin1, HIGH);
    digitalWrite(motorpin2, LOW);
    analogWrite(controlpin, 255);
    Serial.println("Motor forwards");
  }
  if(directionz==3) //Forward
  {
    digitalWrite(motorpin1, LOW);
    digitalWrite(motorpin2, HIGH);
    analogWrite(controlpin, 255);   
    Serial.println("Motor backwards");
  }

}
//-------------------------------------------
//Main Program
void loop()
{
  motor_control(1,motor_1_pins[0],motor_1_pins[1],speedpin);
  delay(2000);
  motor_control(0,motor_1_pins[0],motor_1_pins[1],speedpin);
  delay(2000);
  motor_control(3,motor_1_pins[0],motor_1_pins[1],speedpin);
  delay(2000);
  motor_control(0,motor_1_pins[0],motor_1_pins[1],speedpin);
  delay(2000);
}
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In your code you've declared speedPin as 4 (which I presume is the pin you have connected to EN1,2 of the chip), but that is not a PWM pin on the Micro. So you need to use a different pin. On the other hand, the two direction control pins are currently 5 and 6, which do support PWM on the Micro, but you don't need PWM on those pins when you use the modified code.

The original cause of the problem was that you were getting a burst of high current between the two pinMode calls, and the power supply voltage was drooping as a result. With the modified code, you will still get a burst of high current if you switch your motors from off directly to full speed. So you will either need to use a better power supply, or a large capacitor across the power supply, or else you need to change your code so that you gradually increase the PWM from 0 to 255. For example, you could increase it by 25 every 100ms.

For the watchdog, you need to use wdt_reset(), not wdt_reset.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Great!
That helped me a lot so thanks.
I put the fixes in now and also testing ramping the speed up/down.
So far so good but the motor whines/hums quite bad at low speed (may be something to do with the frequency but i'm now sure).
For the watchdog, i double checked and do already include the brackets in my code (guess I made a copy/paste error) but the issue has always been a problem for me with the Micro (working fine on my Uno).
Thanks!
Paul
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

To stop the motor humming, you'll need to use a much higher PWM frequency.

Regarding the watchdog, it's good practice to disable the watchdog at the start of setup() and only enable it again at the end. However, the real problem may be that the bootloader for the Micro isn't compatible with using the watchdog. It may be that there is an alternative bootloader that is. If/when you migrate the system to a standalone board, you can avoid using a bootloader.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Pages: [1]   Go Up
Jump to: