Author Topic: Designing model train layout I/O and PWM speed control  (Read 40642 times)

0 Members and 1 Guest are viewing this topic.

Offline ilium007Topic starter

  • Frequent Contributor
  • **
  • Posts: 264
  • Country: au
Re: Designing model train layout I/O and PWM speed control
« Reply #175 on: November 29, 2017, 04:59:34 am »
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.
« Last Edit: November 29, 2017, 05:14:48 am by ilium007 »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12875
Re: Designing model train layout I/O and PWM speed control
« Reply #176 on: November 29, 2017, 05:23:05 am »
That's why you don't do the bridging relay control over CANbus.  :-DD

Opto-isolated control signals between adjacent track segment controller MCUs would be the way to go, with each MCU controlling one or a group of track segments, associated bridging relays and train position sensors.  Multi-segment controllers would run a task for each segment.

The CANbus interface would be to assign a power level and direction to a train number, specify the segment it is currently in and specify if it is to bridge to the next segment.  That segment would power the train as long as it continues to draw current. Inactive segments would be tristate.  If requested, the bridging relay in the direction of travel would be closed.  When a segment detects that all the current is being taken via the bridging relay, it signals the next segment to take over, which then handshakes back for the active segment to go tristate and release the relay, in that order , and then goes active itself, reporting back via CAN bus that it has the train.

You'll need to devise some interlocks such that attempting to close a bridging relay between two active segments, or over-current on any segment, or a train detected closely approaching an intersegment gap without a closed bridging relay, all E-stop the whole layout track power and hold internal state for the master controller to interrogate for a crash dump.
« Last Edit: November 29, 2017, 05:27:50 am by Ian.M »
 

Offline ilium007Topic starter

  • Frequent Contributor
  • **
  • Posts: 264
  • Country: au
Re: Designing model train layout I/O and PWM speed control
« Reply #177 on: November 29, 2017, 05:26:05 am »
So is my diagram correct re. the position of the bridging relay ? I'm driving the coil via the MCU ? I have seen some other diagrams where they were driving the coil when the track segment was connected to the previous track via the loco (if that makes sense). I'm still not sure how I am to do the current sensing.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12875
Re: Designing model train layout I/O and PWM speed control
« Reply #178 on: November 29, 2017, 05:31:37 am »
Bridging relay coil controlled by the loco would be a LOT harder to do.

Current sensing could be done a number of ways e.g. a coil on a gapped toroidial core in series with one pole of the relay contacts, and a hall sensor in the core gap, or a low-ohm resistor as a current shunt and amplify the voltage across it etc.

Although ideally you'd do the switchover in one PWM cycle, you could let the traiin coast with both controllers tristated for about a millisecond and I doubt anyone would notice the stutter.
« Last Edit: November 29, 2017, 05:34:25 am by Ian.M »
 

Offline ilium007Topic starter

  • Frequent Contributor
  • **
  • Posts: 264
  • Country: au
Re: Designing model train layout I/O and PWM speed control
« Reply #179 on: November 29, 2017, 05:50:30 am »
Ok. I like the toroidal core option. Aside from now researching toroidal coil wire size and number of turns I guess I also need to think about a fly back diode on this coil just as I would on a solenoid coil.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12875
Re: Designing model train layout I/O and PWM speed control
« Reply #180 on: November 29, 2017, 05:57:09 am »
You'll like the core option a lot less after you've fractured a bunch of them trying to gap them with a diamond cutting disk.
 

Offline C

  • Super Contributor
  • ***
  • Posts: 1346
  • Country: us
Re: Designing model train layout I/O and PWM speed control
« Reply #181 on: November 29, 2017, 06:01:56 am »
First remember the kid & smoke.
Control logic failures
Two active sections.

An insulated section a little longer then engine makes things much safer.
 

Offline ilium007Topic starter

  • Frequent Contributor
  • **
  • Posts: 264
  • Country: au
Designing model train layout I/O and PWM speed control
« Reply #182 on: November 29, 2017, 07:10:20 am »
I’m looking at this layout trying to work out how a DPST relay would work. Wouldn’t I require a complete segment of track isolated in both directions and then a DPDT to supply power to the middle segment from both directions ? I’m at a loss as to where the current sense would be done. If it was in series with the relay pole then it would still draw current from the outter segment whilst in the middle segment as per the quick diagram attached that I did whilst I was looking at the layout this afternoon.

« Last Edit: November 29, 2017, 07:13:35 am by ilium007 »
 

Offline ilium007Topic starter

  • Frequent Contributor
  • **
  • Posts: 264
  • Country: au
Re: Designing model train layout I/O and PWM speed control
« Reply #183 on: November 29, 2017, 07:12:18 am »
An insulated section a little longer then engine makes things much safer.
This is exactly what I’m proposing above. An insulated segment longer than the longest loco. I’ve checked the layout this afternoon and there is plenty of space for two segments in the ‘green’ section (original diagram).
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12875
Re: Designing model train layout I/O and PWM speed control
« Reply #184 on: November 29, 2017, 07:19:19 am »
Put ONE current sense in series with ONE relay pole common.  You'd also need a current sensor for one side of every other track power feed, so you can detect when the loco power pickup wheels have fully left the previous section.

However IMHO its all overkill - just use H-bridges that can be paralleled with fast acting low side current sensors that toggle a flipflop that tristates the H-bridge on over-current.   The filter inductors will prevent the current building up too fast for the over-current protection, and if you reset the flipflop at the start of every PWM cycle it will limit the current to a peak of the setpoint and an average of about half that till the fault is cleared (e.g. the loco has fully crossed into the section with a different PWM duty cycle.)   To handle idiocies like two adjacent sections set in opposite directions with a train running up to the joint, when the protection trips, if the fault doesn't clear in a couple of seconds, E-stop the layout as there must be a train stalled on the joint between the conflicting sections.

« Last Edit: November 29, 2017, 07:30:26 am by Ian.M »
 

Offline ilium007Topic starter

  • Frequent Contributor
  • **
  • Posts: 264
  • Country: au
Re: Designing model train layout I/O and PWM speed control
« Reply #185 on: November 29, 2017, 07:20:23 am »
Ok but I’d still require a DPDT relay wouldn’t I ?
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12875
Re: Designing model train layout I/O and PWM speed control
« Reply #186 on: November 29, 2017, 07:35:47 am »
Yes, if you are dumb enough to go for this over-complex relay switched short length of track between sections.  :scared:

Consider the cost of the relays, controllers, fitting extra power feeds and insulating fishplates (and the irreplaceable time to mod the layout - nobody's getting any younger here) and the potential for it to go badly wrong, v.s, the cost of doing it right with absolutely no relays, instead using parallelable H-bridges with good enough over-current protection to make them 'bomb proof', even if you torture them by directly shorting the track or shorting diagonally across two different track sections

Ultimate torture test - If you can clip one lead to the tang of a new coarse steel file and run a nail down it attached to the other lead without doing any damage, no matter what the H-bridge control inputs are doing, its sufficiently bomb-proof.

You deal with the possibility of a H-bridge or over-current protection circuit failure by fusing the supply to them.   Worst case - if one fails it may take out an adjacent section before the fuse blows.  Swap out the affected section drive boards and you are back in business.  Replace the damaged H-bridges and test (and maybe fix) the over-current protection, and you've got your spare drive boards back.
« Last Edit: November 29, 2017, 07:46:45 am by Ian.M »
 

Offline ilium007Topic starter

  • Frequent Contributor
  • **
  • Posts: 264
  • Country: au
Re: Designing model train layout I/O and PWM speed control
« Reply #187 on: November 29, 2017, 07:39:32 am »
Umm ok. I wasn’t trying for a ‘dumb’ solution. I just went back through the thread and started looking at your first solution.

I’ll go to the next option now of paralleled H-bridges. Pololu told me today that what I was trying to do wasn’t considered ‘paralleling’ and that what I was trying to do would never work but I’ll do some more research on running two L298 which should be less.... dumb
 

Offline ilium007Topic starter

  • Frequent Contributor
  • **
  • Posts: 264
  • Country: au
Re: Designing model train layout I/O and PWM speed control
« Reply #188 on: November 29, 2017, 07:42:04 am »
I found Allegro do a series of current detection IC’s that might be suitable.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12875
Re: Designing model train layout I/O and PWM speed control
« Reply #189 on: November 29, 2017, 07:54:06 am »
As I said, L298 or similar H-bridges with robust low side over-current detection and limiting added (they have provision for connecting the required sense resistors) can be bomb-proof even if their control is fully distributed.  Any conflicts can be handled by the fast over-current protection, even if they are on fully independent PWMs, though you'll get less jerking at handover points if you don't try to have local track power control  modules and instead you keep them all together and run them from one MCU, sync the PWMs, and distribute their track power outputs over heavy twisted pair.

As it will be the main power consumer, you can build it in the same box as the main PSU, with a big-ass heatsink on the back for all the H-Bridges,  each H-bridge chip and current sense circuit on its own little board for ease of maintenance.
Put the whole shebang under the layout somewhere in the middle to reduce the power wiring length, with remote CANbus control and diagnostics.  I'd advise using pluggable screw terminal strips for the track wiring - that way you can easily disconnect it and pull it out for maintenance.

IMHO you need to get a minimum radius loop of track on your bench with three sets of insulating fishplates, three power feeds and a loco and start experimenting.
« Last Edit: November 29, 2017, 08:00:59 am by Ian.M »
 

Offline ilium007Topic starter

  • Frequent Contributor
  • **
  • Posts: 264
  • Country: au
Designing model train layout I/O and PWM speed control
« Reply #190 on: November 29, 2017, 07:54:18 am »
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.

So this is the non-dumb solution that I’m now looking in to. Trying to find a H-Bridge that can be paralelled.
« Last Edit: November 29, 2017, 07:57:35 am by ilium007 »
 

Offline ilium007Topic starter

  • Frequent Contributor
  • **
  • Posts: 264
  • Country: au
Re: Designing model train layout I/O and PWM speed control
« Reply #191 on: November 29, 2017, 07:56:13 am »
As I said, L298 or similar H-bridges with robust low side over-current detection and limiting added (they have provision for connecting the required sense resistors) can be bomb-proof even if their control is fully distributed.  Any conflicts can be handled by the fast over-current protection, even if they are on fully independent PWMs, though you'll get less jerking at handover points if you don't try to have local track power control  modules and instead you keep them all together and run them from one MCU, sync the PWMs, and distribute their track power outputs over heavy twisted pair.
I’ll go through the L298 datasheet tonight and try and work something out. I have 8 timer outputs on the Teensy on two of the hardware timers so I have plenty of outputs to keep the h-bridges in perfect sync.
 

Offline C

  • Super Contributor
  • ***
  • Posts: 1346
  • Country: us
Re: Designing model train layout I/O and PWM speed control
« Reply #192 on: November 29, 2017, 08:01:06 am »
To be safe last drawing needs a ONOFF relay to middle section.

Only safe thing is to sense voltage change to un-powered section to detect a engine entering that area.
When one wheel touches un-powered area you have a voltage change.
You do not have a large current until engine is drawing power from section.

Now convert to rugged solid state.

Keep in mind that a in relay logic an H-Bridge is a DPDT relay and most have off to this relay.
Some can turn off one side of H=bridge
Some sense only common low side current
Some sense common high side and low side current.

A mosfet is a one direction switch with a diode in other direction.



 

Offline C

  • Super Contributor
  • ***
  • Posts: 1346
  • Country: us
Re: Designing model train layout I/O and PWM speed control
« Reply #193 on: November 29, 2017, 08:08:00 am »

lan.M
is adding fast current sense
Safe current short
Fast control
prevention of fast current change
and others.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12875
Re: Designing model train layout I/O and PWM speed control
« Reply #194 on: November 29, 2017, 08:12:01 am »
Yep.  Thanks for hiliting those key bullet points.
 

Offline ilium007Topic starter

  • Frequent Contributor
  • **
  • Posts: 264
  • Country: au
Re: Designing model train layout I/O and PWM speed control
« Reply #195 on: November 29, 2017, 08:32:48 am »
So if I can tri-state the MC33926 outputs then why can’t I just put a break between the two track segments, have one side tri-stated and when the active side senses zero current tri-state it’s output and enable the other side ?
 

Offline C

  • Super Contributor
  • ***
  • Posts: 1346
  • Country: us
Re: Designing model train layout I/O and PWM speed control
« Reply #196 on: November 29, 2017, 08:37:56 am »

For MC33926

You are controlling inputs.
MC33926 is controlling the outputs.

To protect it's self the MC33926 does different then what you put on inputs.
 

Offline ilium007Topic starter

  • Frequent Contributor
  • **
  • Posts: 264
  • Country: au
Re: Designing model train layout I/O and PWM speed control
« Reply #197 on: November 29, 2017, 08:40:19 am »
From the MC33926 datasheet:
Quote
Two independent disable inputs are provided to force the H-bridge outputs to tri-state (high-impedance off state).
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12875
Re: Designing model train layout I/O and PWM speed control
« Reply #198 on: November 29, 2017, 08:42:59 am »
For the MC33926, you've got to be certain the train has cleared the previous section (which means a delay), and tristate it before you can start the new section's PWM.  It will therefore jerk badly as if you'd slammed on the brakes when crossing a section gap.  Also consider the false zero current detection problems you will get if there is any dirt whatsoever on the track or wheels.

That's why all the mess with bridging relays was needed if you were going to use the MC33926 so you could pick the time to switch which section was active without needing to detect or know the exact loco wheel positions with respect to the insulating fishplate.
« Last Edit: November 29, 2017, 08:45:15 am by Ian.M »
 

Offline ilium007Topic starter

  • Frequent Contributor
  • **
  • Posts: 264
  • Country: au
Designing model train layout I/O and PWM speed control
« Reply #199 on: November 29, 2017, 08:44:55 am »
So how does changing PWM driver fix this ? If they can be “paralleled” are you saying they can both be “active” at the same time as long as they are timed exactly the same ?

I’m not tied to the MC33926 - I had only bought one of them for testing.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf