I was playing with stepper motors and I noticed something odd in the library code (This is the Stepper library included in Arduino IDE).
case 2: //0101
digitalWrite(motor_pin_1, LOW);
digitalWrite(motor_pin_2, HIGH);
digitalWrite(motor_pin_3, LOW);
digitalWrite(motor_pin_4, HIGH);
break;
case 3: //1001
digitalWrite(motor_pin_1, HIGH); // At this point pin_1 and pin_2 are both HIGH
digitalWrite(motor_pin_2, LOW);
digitalWrite(motor_pin_3, LOW);
digitalWrite(motor_pin_4, HIGH);
break;
Take a look at the first line in "case 3": motor_pin_2 is HIGH from previous step ( for clockwise rotation ) and now we are setting motor_pin_1 to HIGH too. Wouldn't it short the H-bridge for a split second? But everything seems to work fine. Is there some "magic" in digitalWrite I am not aware of? Or is it shorting it?
ok, now i understand. both outputs are momentary (time to execute digitalWrite) the same
but there's still no issue setting both h-bridge outputs to the same value. As I said, doing so creates a short between the motor terminals if both outputs are enabled (0 < PWM), allowing a current generated by the BEMF of the motor to flow thru.
the result of this momentary short is braking, which is harmless if trying to reverse the motor.
Ok I am programmer by hearth and just electronics hobbyist. But I was thinking that 1101 is "illegal" in a dual H-bridge circuit ("H H"), because you open all four transistors in the first H and create two direct paths from VCC to GND ( those vertical lines in the first H).
in an H-bridge there are 4 transistors (see below). each pin in your library is controlling the transistors connected to one motor terminal whether the motor is connected to Vcc or ground. they both can't be on at the same time.
with 2 pins, you either connect both motor terminal to Vcc or ground or one to Vcc and the other to ground.
a dual h-bridge is two separate circuits, 8 transistors controlling 2 motors
Oh I see the problem now ... The H-bridge I was thinking about uses just two inputs, so dual H-bridge are those four bits. Your dual H-bridge would need 8inputs right?
if you have an h-bridge like the schematic I posted with mosfets and diodes, setting both sides of the h-bridge to either low or high creates a short across the motor which creates a load on the motor creating a braking force.
i don't see a problems setting both sides of the h-bridge you showed should have a problem, although, without the diodes I don't see how it creates a short across the motor to do braking.
the TI SN754410 i've used has Darlingtons and diodes.
those diode protect the transistors when the motor voltage is cut off abruptly, BEMF can generate high voltage spikes without a current path.
I am sorry man. I should have specified the schematic in the first place. But from this quote:
aren't pins 1& 2 for one motor and pins 3&4 for a 2nd motor?
I was thinking that we are on the same page. But somehow you started speaking about four pins per motor and braking. And I didn't catch that for few posts
did you look at braking?
My H-bridge can't do any braking. And it's fine because it's controlling a stepper motor anyway.
PetrChudoba's schematic is a variant called a half-controlled H-Bridge.
Thanks. I didn't know that.
It's the standard library included with the Arduino IDE. And I have seen tons of people using it (in youtube videos mostly) with this half-controlled H-Bridge without any issues. And mine is working flawlessly too.
Most power supplies have current limiting. It's likely that shorting the bridge for a few milliseconds will actually kill the voltage on the power supply for that period of time - not long enough to cause serious damage or even be noticeable. In that case, the power dissipation in the transistors would be very low. Not that it's a good thing! But the problem can be easily fixed by changing the order of digitalWrite()'s.
not sure that a scope is needed. electronics are damaged by heat and i'm not sure how much damage occurs if there a short for the period that digitalWrite() executes. but certainly should be avoided.
it seems clear that the stepper library may not be best for this type of h-bridge. why not write you own code? what features of the library do you need? (i could provide some code).