How to connect Arduino Uno to h-bridge for locked antiphase

Hi!

I have bought a h-bridge on ebay to connect to Arduino. I want to use it in locked antiphase technique. I need help connecting Arduino Uno to it. It has an "enable" pin for each motor and two "in" pins. On Arduino I have two pwm pins in inverse mode. Do I just simply connect the two pwm pins to the two "in" pins or does pwm have to be applied to "enable" pin and "in" pins are just for direction?

Here's a pic

Thanks for help!

Supply a link to the board so we can get more information on it.

Weedpharma

weedpharma:
Supply a link to the board so we can get more information on it.

Weedpharma

It is this one. In the meantime I pushed my luck and tried connecting as I thought. Fortunately, it didn't smoke. I PWMed the two "in" pins one as inverse of the other and it worked. The motor and bridge got a bit warm but thats probably to be expected. However I forgot to connect enable pin to MCU and instead left that jumper on it, which probably meant it was braking all the time I left it alone (for hours). It was warm when I came back and realized my mistake.

You need to include deadtime or you'll get shoot-through (hence the board warming up)
You do this by having one of the PWM values a small offset from the other and you must
use phase-correct mode for this to work.

MarkT:
You need to include deadtime or you'll get shoot-through (hence the board warming up)
You do this by having one of the PWM values a small offset from the other and you must
use phase-correct mode for this to work.

Thank you, advices like this were exactly what I was looking for.

So if I understand correctly, I have to raise the channel B register for 1 to make its HIGH time narrower and with that add some space before channel A starts rising (add deadtime). Frequency is 20 kHz.

One quick question if you don't mind (I don't want to make a new thread just for this), how can I define the "neutral" position if TOP is for example 401? If its 400 neutral position is 200, but what to do if its 401?
Thanks!

Yes, I think you've got the idea.

You need to ensure you don't drive to 400 - limit at 399 perhaps?

You also need to find out how fast your H-bridge switches off to set the actual
dead-time value.

If you footle with the timer TCCRxA register (I think) you can invert one of the pins
it drives but not the other, and the code can be as simple as:

  analogWrite (pinA, x) ;    // or a direct register access like  OCRxA = x ; OCRxB = x+1
  analogWrite (pinB, x+1) ;

Careful reading of the relevant timer section of the datasheet is recommended.

Do I just simply connect the two pwm pins to the two "in" pins or does pwm have to be applied to "enable" pin and "in" pins are just for direction?

Have you looked at the datasheet for the L298N chip?

MarkT:
Yes, I think you've got the idea.

You need to ensure you don't drive to 400 - limit at 399 perhaps?

You also need to find out how fast your H-bridge switches off to set the actual
dead-time value.

If you footle with the timer TCCRxA register (I think) you can invert one of the pins
it drives but not the other, and the code can be as simple as:

  analogWrite (pinA, x) ;    // or a direct register access like  OCRxA = x ; OCRxB = x+1

analogWrite (pinB, x+1) ;




Careful reading of the relevant timer section of the datasheet is recommended.

I will probably need only from around 130 to around 270 (I'm driving CD player ejection motors).

If I understand correctly its a few microseconds? Thats a lot :\ If frequency of timer is 16MHz, one tick lasts 62.5ns and thus the enforced dead time by adding "1" distance. Im not sure how to calculate with these values there, do I have to subtract rise and fall or something else. With these values I might have to put difference of even 32 :\ Current still flows a bit after turning off, right, so if I make a big gap it wont be actually seen as a big gap by the motor, right? I dont want to defeat the purpose of locked antiphase drive by adding too much space between phases :\

You know, despite the heating I guess the h-bridge must have some sort of protection or it would get much more hot I reckon.

Yes, I did that, I was using exactly that when I was testing:

void connectPWM(int val)
{
 // Disable interrupts for this timer
 TIMSK1 = 0;
 // Set Phase-Correct PWM, use ICR1 as TOP
 // Set prescaler to 1
 TCCR1A = BIT(WGM11);
 TCCR1B = (BIT(WGM13) | BIT(CS10));
 // Set TOP to 400 + 1 for 20kHz PWM
 ICR1 = 401;
 // Reset Timer/Counter to 0
 TCNT1 = 0;
 // Set duty cycles
 int norm_val = val - 1; // Dead Time. Temp variable to be able to change registers at the same time (well as possible)
 int invr_val = val + 1;
 OCR1A = norm_val; // set pwm duty
 OCR1B = invr_val; // set pwm duty
 // connect pwm to pins on timer 1, channels A and B
 // Clear OC1A on Compare Match when upcounting. Set OC1A on Compare Match when downcounting.
 // Set OC1B on Compare Match when upcounting. Clear OC1B on Compare Match when downcounting.
 TCCR1A |= (BIT(COM1A1) | BIT(COM1B1) | BIT(COM1B0));
 digitalWrite(ENABLE_PIN, HIGH);
}

Edit:
Looking at the times, to me it seems that there is already built-in some delay to prevent shoot through?

To me it seems there is already built-in some dead time?

zoomkat:
Have you looked at the datasheet for the L298N chip?

Quite frankly I forgot that there was a L298N there and that I can look at its datasheet, and since Arduino Motor Shield R3 also uses the same chip but introduces a different way of control I would probably be a bit confused anyway.

Can you explain what "locked antiphase technique" is, as that might help with the chip control logic.

zoomkat:
Can you explain what "locked antiphase technique" is, as that might help with the chip control logic.

It's when you drive the motor in one direction, but you also drive it in the other at the same time (but weaker - with lower duty cycle). Well almost the same time. 50% 50% duty cycle pwm on both direction pins (from the same timer) will stop the motor. The two pwm signals must be inverse to each other.