0

Synchronise stacked motor shield v2s?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Synchronise stacked motor shield v2s?

by AnArduinoFan on Wed Aug 28, 2019 10:55 pm

Hi. I have a theoretical problem to solve - at least I expect to run into it shortly do seeking advice in advance.

I have a pair of shields that I'm intending to use to power 8 sections of a model railway (12v DC using PWM for speed control). As trains move from one section to another the PWM waveforms must be temporarily synchronised between the 2 respective H-bridges to ensure the duty ratio is the same during the transition. I believe I've been able to do this successfully in software between 2 bridges on the same shield as they share the same PWM driver chip.

However I expect to run into problems when the 2 sections involved are being driven by drivers on different shields. Even if I configure the same base frequency on both there is no guarantee the PWM waveforms will align and hence I may get an increase in duty ratio during transition.

Any thoughts as to whether there is a software solution to this?

Has anyone successfully synchronised multiple shields in order to increase the current drive capability of a single board (a different use case but I would think with the same problem)?

Many thanks in advance.

AnArduinoFan
 
Posts: 3
Joined: Wed Aug 28, 2019 10:32 pm

Re: Synchronise stacked motor shield v2s?

by adafruit_support_bill on Thu Aug 29, 2019 6:10 am

The PCA9685 PWM chips on the shield are running from their own internal clocks. There is no way to synchronize the internal clocks. In theory, you might be able to get two of them to run off the same external clock signal. But that would involve a board re-design as well as some library hacking.

Has anyone successfully synchronised multiple shields in order to increase the current drive capability of a single board (a different use case but I would think with the same problem)?

You could assign the same i2c address to 2 boards so that they respond to the same i2c commands. That would avoid any shoot-through issues with the bridges. But you would have the same issue with the PWM clocks being out-of-synch.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Synchronise stacked motor shield v2s?

by AnArduinoFan on Thu Aug 29, 2019 8:04 am

Thanks for your reply. I thought as much re. not able to syncronise the internal clocks. No problem!

As I need each shield to still operate independently I still have to assign unique addresses - so I'm going to try the following as a SW only solution...

* Use arduino interrupts to call Adafruit_MotorShield.setPin on the relevant pin(s) to manually generate my PWM wave forms...
* I think the change gets applied at the completion of the PCA9685s PWM cycle so as long as I set their freq to be much higher than my desired motor PWM freq. the change should get applied as soon as possible despite any clock mismatches.

I think that as long as there isn't too much delay between the I2C commands arriving at each board, and the command taking effect on the Waveform - it probably should be good enough. I think the PWM freq of my motors is going to be limited by the data rate of the commands pushed though the IC2 bus... any prior experience of this would be useful info.

I need to get hold of an oscilloscope and do some testing to confirm.

Any other ideas / suggestions welcome!


Additional - I haven't entirely lost sight of the fact that I could build an 8 channel version using a 16-channel PWM driver shield and 4 discrete Dual H Bridge boards... as that would guarantee alignment... but thought I'd try to exhaust the SW solutions first.

AnArduinoFan
 
Posts: 3
Joined: Wed Aug 28, 2019 10:32 pm

Re: Synchronise stacked motor shield v2s?

by adafruit_support_bill on Thu Aug 29, 2019 8:48 am

* Use arduino interrupts to call Adafruit_MotorShield.setPin on the relevant pin(s) to manually generate my PWM wave forms...

That's a lot of communication overhead.

I think that as long as there isn't too much delay between the I2C commands arriving at each board, and the command taking effect on the Waveform - it probably should be good enough.

With 2 H-bridges connected in parallel, you need to watch out for shoot-through. If the two bridges are set for opposite polarity, you will have a direct short from 12v to GND which will most likely fry an output FET on one or both bridges. If you are switching them serially between forward and reverse, you will need to first switch them both to high impedance mode so that you don't have shoot-through in the transition. See page 4 of the TB6612 datasheet:
https://cdn-shop.adafruit.com/datasheet ... 121101.pdf

At this point, it is probably worth taking a step back and re-evaluate the hardware choices. If I understand correctly, the two main limitations of the motor shield you are trying to work around here are:
1) Synchronizing the PWM between boards.
2) Increasing the output capacity of the boards.

Taking the second issue first, you could start with a higher capacity motor driver such as the DRV8871: https://www.adafruit.com/product/3190
That would give you up to 3.6A per channel and eliminate the possible shoot-through issue. And although you would be giving up the integrated package of the shield, you are also freeing yourself from the constraints of that design.

For the PWM, you could use the PWM/Servo shield: https://www.adafruit.com/product/1411
That has the same PCA9685 chip used on the motor shield. But you could dedicate one chip to provide synchronized PWM signals for up to 16 motor driver channels.

Direction control could be handled by one or more other PCA9685 shields. (You could also use MCP23017 chils for lower overhead https://www.adafruit.com/product/732)

The only remaining synchronization issue to consider is the potential for shorts when two adjacent track blocks are energized in reverse polarity as a locomotive is bridging between them.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Synchronise stacked motor shield v2s?

by AnArduinoFan on Thu Aug 29, 2019 9:19 am

That's a lot of communication overhead.


Indeed - I'd also begun to reach that conclusion after some googling...

(2) was really just another scenario where I thought people might have had to solve the sync issue - I gratefully note your points on shoot through - thanks.

At this point, it is probably worth taking a step back and re-evaluate the hardware choices


A professional lifetime of developing SW solutions on HW not quite designed for the job has probably coloured my judgement... that and I hadn't realised just how cheap the discete Dual H-Bridge boards are until now - 5 just purchased from the well known online auction site. I already have one of your 16 channel PWM shields which will do nicely.

The only remaining synchronization issue to consider is the potential for shorts when two adjacent track blocks are energized in reverse polarity as a locomotive is bridging between them.


Quite right - Considered, coded for and simulated extensively to ensure the above is avoided.

Many thanks for your help and advice. Am already looking forward to playing with the new HW when it arrives.

AnArduinoFan
 
Posts: 3
Joined: Wed Aug 28, 2019 10:32 pm

Please be positive and constructive with your questions and comments.