CANbus is certainly looking like the communication method I need to use. I have spent a fews days reading about it and now I need to prototype it. I have plenty more questions on the topic.
Back the the PWM speed control. I have received a response from Pololu and the VNH5019 based driver module I was looking at can't be run in parallel evidently.
To recap - the scenario I am facing. The train is running from right to left in the diagram. Orange track is powered by one PWM driver, in this example 70% duty cycle and the green track is powered by a seperate PWM driver at 30% duty cycle - both using the same 20kHz hardware timer. The trains have front and rear motors connected to the tracks via their wheels and both motors connected in parallel (going to clarify this 100%). When the front train wheels touch the green track they essentially bridge the two PWM drivers together and this can lead to 'shoot-through'.
So I need a way to stop the orange PWM driver and start the green PWM driver.
Ian.M made a suggestion previously that I that I need to re-visit - that is using a bridging relay:
It may be worth biting the bullet and investing in one controller per track segment and getting rid of the controller to track segment switching relays.
There is however one MAJOR fly in the ointment. Because of their internal current limit PWM and deadtime control, you cannot parallel active MC33926 H-bridges. There is a high risk of shoot-through resulting in a repetitive brief uncontrolled short between the power rail and ground, leading to overheating and possible destruction of the H-bridges.
You can however parallel an active MC33926 with an inactive one that has its outputs tristated. This means that to get a smooth handoff between adjacent track segments, you need a DPST bridging relay at each inter-segment gap, equipped with a current sensor so your MCU can detect when the loco crosses the gap*. Once the loco has crossed the gap, the MCU can, between PWM pulses, tristate the previous segment's H-bridge, and enable the new segments one, without missing a beat, then open the bridging relay. It should then immediately prepare the next segment by tristating its H-bridge, and closing the bridging relay at the next gap.
If you switch to another H-bridge controller chip that does permit paralleling, you can do away with the bridging relays. Simply drive adjacent segments H-bridges with *EXACTLY* the same signal until you are certain the loco has fully crossed the gap. If the MCU yu are using has sufficient PWMs that can run off exactly the same timebase, this can be done purely in software, otherwise you may need switching logic. Probably the easiest option there would be an analog switch matrix to switch N PWMs to M track segments. You can get the Microsemi MT8816 8:16 crosspoint switch array for as little as $10. It isn't SPI compatible, unless you add an external shift register and a little glue logic, but that isn't a show-stopper. That would let you switch eight control PWMs to 16 track segments. Each switch in the matrix is individually addressable so to switch PWMs to a singe output without conflicts requires two operations - one to turn the previous PWM off, and one to turn the new one on. Expanding to 8:32 would be as simple as adding another MT8816. It will switch 5V logic signals while running from 5V so no exotic supply voltages are required.
(a) did I get the diagram correct based on Ian.M's suggestion ?
(b) If I understand correctly as the train moves right to left the right hand PWM driver is supplying the PWM signal, if the user commanded the train to cross from the orange segment to the green segment the relay would be closed (not as shown in picture) and the orange PWM driver would be supplying current to the green segment. Once the current in the orange track has dropped to 0 I would know the train is off that segment so then I could tristate the orange PWM driver outputs, activate the green PWM driver outputs and open the bridging relay. Obviously doing the same thing on the other end of the segment.
The part that has me thinking is the timing - this is a 20kHz PWM signal (run from the same hardware timer) therefore I have 50uS to do the current sense, send that by CANbus, have another board receive the CANbus event, tristate the outputs on each PWM driver and close a relay.
50uS is a really short amount of time !
How do I do current sensing ? The MC33926 provides a 140uV/A analogue output that I could use, I am not sure if its output will be fast enough to provide the 0 current sense to use for switching. If I don't use the MC33926 for current sense, how else can I instantaneously measure current ? I looked at current transformers (used in DCC) will only work on an AC signal. I have seen guys solder tiny SMD resistors across the axles of trains to provide a current draw but not sure how they are then sensing this and how fast it is - I have to do the switchover in 50uS.
I am not tied to the MC33926 - I'm happy to look at the LM298 the Ian.M suggested as well. Obviously I wont get any fancy current sense output from them so the current sense part of the design is probably the most critical at this point.