Current sensing and overcurrent - short circuit handling by arduino

Hello and happy new year.
I would to discuss a thought.
The situation is referred to the model trains and especially to the DCC (digital command control). DCC is a bidirectional pwm signal carrying power and data along the rails. Its frequency is about 8-10kHz and the peak to peak voltage for H0 scale is 28V.

I have two isolated sections of track, separated by small gaps. Each section is powered from an IBT-2(2xBTS7960) motor driver. The signal to the motor drives comes from the same command station. In one of these sections, the HI/LOW signal in rails can be reversed. When that is happening and a part of the rolling stock bridges the gap a short circuit is happening. On this event I want to reverse the HI/LOW signal in the one section before the current goes too high in any of the IBT-2s and shutdown the motor drives. If the reversing does not resolve the short circuit it will means that there is a short circuit on the track and the motor drive has to be shutdown.

In my approach I use a current transformer for current sensing (an acs712 sensor would do the same job) . I know that the IBT-2 has current sensing, but the low quality of some builds (inconsistent resistors, improper installed heatsinks) makes the current sensing unusable. An Arduino is used, for each IBT-2, to handle an interrupt event when a short circuit happens.
The Arduino also reads the current (analogread) and communicate with a pc through a RS485 bus. The communication through RS485 is used to collect the status of each booster and to control the boosters from the pc.

I define :slight_smile: as a short circuit any current above 7A, because I don’t know another way to catch it and the 7A current is too high for the certain application. The output from the CT is rectified and scaled to 7A->5V. The output is suppressed to that value to protect the Arduino. The same output goes to a comparator. When the voltage is over 4.9V the comparator’s output goes high and triggers the interrupt handler (on rising event). The rectified CT’s output has the peak value, so it is necessary, after each analog read and after the interrupt event, discharge the capacitor by a pulse from the Arduino.
The interrupt handler:
If the motor drive (IBT-2) acts as a reverser, the interrupt handler reverses the signal to the IBT-2 (by the use of 2x XOR gates) and sets a flag to 1.
If the flag is 1, (the signal was reversed once from the rising event), the handler shutdown the IBT-2.
If the motor drive does not act as a reverser, the handler shutdown the IBT-2.

The reverser’s detection level has to be lower than the non-reverser’s. So the reverser has (?) enough time to reverse or shutdown before the non-reverser, if the shortcut persists after the reversing.

I understand that the IBT-2 can supply more current than the sensor can handle, but I hope this would be an exceptional situation :D. I understand that the current measurement accuracy is not good, but imho is enough to have a picture of what is going.

Has this approach any chance?
If I build the IBT-2 (I could do that with through-hole components) and use the native sensing, can this be done? Have I to catch, with an interrupt, the fault condition (Vis>=4V for Ris=1K) or check and the duration (datasheet BTS7960_Datasheet.pdf, page 21, 4.4.7)?

I will appreciate any comment, even if it is about a partial issue i.e. the arduino’s protection or anything else. I attached the circuit in LTspice and the output. I can upload the model too or any other info is needed.

PS: excuse my English and my ignorance

LTspice current sense IBT-2.PNG

LTspice current sense IBT-2 output.PNG

Do all train circuits using DCC have this short circuit issue?
If so, how do they solve the problem, and what is the advantage of your proposed alternative?

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.

If you are using DCC why have you got two isolated sections?

Can I suggest you have a section of transition track, between the two sections, this is isolated from both sections, and you change the connection of the transition section from one to the other when the loco passes through the transition section.

Thanks.. Tom... :slight_smile:

Your mix of analog and digital electronics is not mastered easily, and actually is not optimal. Why have a capacitor to hold a peak value, if this can be done in a digital way as well, using a comparator and time flag?

The take-over between both transistors is fixed in hardware, for each half bridge. If you want to reduce eventual overlap you can switch the circuits off (INH) for a short time. This shut off also can be forced immediately by the current sensor.

Answers to your questions depend on the actual circuit, because the timing depends on wire length, resistors and (stray) capacitors, as well as on digital delays in signal processing and generation of the inverse IN signals. I'd think that a scope is inevitable in tuning such circuits.

There exist more specific railroad forums, where your ideas may have been evaluated already. Tom already mentioned a practical solution (rail gap).

Off-the-shelf devices to solve this problem are common in the model railway world. However I don't know how they work. It would be strange if Google does not know.

I avoid this problem by using battery powered radio control - so no need for track power.

...R

mikb55:
Do all train circuits using DCC have this short circuit issue?
If so, how do they solve the problem, and what is the advantage of your proposed alternative?

TomGeorge:
If you are using DCC why have you got two isolated sections?

Can I suggest you have a section of transition track, between the two sections, this is isolated from both sections, and you change the connection of the transition section from one to the other when the loco passes through the transition section.

TomGeorge:
If you are using DCC why have you got two isolated sections?

Can I suggest you have a section of transition track, between the two sections, this is isolated from both sections, and you change the connection of the transition section from one to the other when the loco passes through the transition section.

Yes, this situation is common. If a train enters to a loop and exits from the same point. The left rail meets the right and the right the left. It isn't so important, why it happens. The solution is to have the track out of the loop and the loop's track isolated and individually powered. Then the track polarity, inside the loop, has to match the polarity of the outside track. This can be done manually or automatically on a short circuit event. This is what people do, reversing the loop's polarity to match the polarity of the external track at the border gap.
The commercial autoreversers are analog with a pic(?) and maybe can be centrally managed from the commercial command stations, i don't know details. I'm not inventing something.There are diy boosters with the arduino, but I haven't see an autoreverser. Motor drives like IBT-2 are low cost and if they can act as autoreversers too, is good I think. The feature to have the boosters monitored and managed from a pc, as they are placed allong the layout, it's good too. The commercial solutions are expensive. There is an open source dcc command station the DCCpp, based on an an arduino and an arduino m. shield. Not everyone can pay the commercial solutions.

Tom, I read the "how to use this forum" before. I tried to give the most info about the issue.
I'm sorry if I missed something. If my post violates the rules or enything else, you can delete it.
No problem, but I would to know.

DrDiettrich:
Your mix of analog and digital electronics is not mastered easily, and actually is not optimal. Why have a capacitor to hold a peak value, if this can be done in a digital way as well, using a comparator and time flag?

The take-over between both transistors is fixed in hardware, for each half bridge. If you want to reduce eventual overlap you can switch the circuits off (INH) for a short time. This shut off also can be forced immediately by the current sensor.

Answers to your questions depend on the actual circuit, because the timing depends on wire length, resistors and (stray) capacitors, as well as on digital delays in signal processing and generation of the inverse IN signals. I'd think that a scope is inevitable in tuning such circuits.

There exist more specific railroad forums, where your ideas may have been evaluated already. Tom already mentioned a practical solution (rail gap).

Ok. I used the cap as buffer to give the time to the arduino read it. I will connect the comparator's output to the digital pin. The protection circuit arround the arduino analog pin is ok? Have you any suggestion about the components?
I realised, that had to ommit everything and maybe ask like this:
"The IBT-2, according to the data sheet, on overcurrent, closes the one switch for tCLS (70 115 210 µs) and then returns to the normal.
This, I assume, happens until the temperature limit is reached and the IBT-2 shutdown. Is this time enough to handle an overcurent event by the arduino and reverse the polarity of the input signal, before the temperature limit is reached?"
Can you please answer to this? This is a question to all.
Thank you.

Robin2:
Off-the-shelf devices to solve this problem are common in the model railway world. However I don't know how they work. It would be strange if Google does not know.

I avoid this problem by using battery powered radio control - so no need for track power.

...R

I have bad days too.
If this forum is a link to the google or to the shops, you have to write it with big letters. I read in the "how to", that the conversation has to be polite.
Buy battery trains and have a nice day.

Vggrek:
I have bad days too.
If this forum is a link to the google or to the shops, you have to write it with big letters. I read in the "how to", that the conversation has to be polite.

I don't believe I was in any way impolite.

If you are enquiring about where to buy these devices then I reckon all the sellers of DCC equipment will stock them.

As I mentioned, if you want to build your own, I can't help. but it sounds like an interesting project.

Buy battery trains

I get more fun out of making them. I have an award from the N Gauge Society for converting a Graham Farish N-Gauge large Prairie tank locomotive to battery powered radio control. I am currently using N Gauge Kato tram chassis to make 009 locos with the bodywork made from card.

...R

Vggrek:
I realised, that had to ommit everything and maybe ask like this:
“The IBT-2, according to the data sheet, on overcurrent, closes the one switch for tCLS (70 115 210 µs) and then returns to the normal.
This, I assume, happens until the temperature limit is reached and the IBT-2 shutdown. Is this time enough to handle an overcurent event by the arduino and reverse the polarity of the input signal, before the temperature limit is reached?”

Of course an overcurrent can be detected only while the bridge output is enabled. Then the device is shut off, for some time, then turned on again and, as you said, this game can continue until an overheat. Do you have an idea how long such a short will take , while the train is rolling? Does a short occur with every axle of every wagon, or only with the loco?

I’d think that a 1-2mm isolated rail at the breaks will prevent that problem, but if you want to roll your own solution you should explore a bit more yourself, in a life circuit.

Thinking some more about this...

I have been using Infineon TLE5206 h-bridge chips for powering a DC model railway. They could also be used with a DCC system. Those chips produce an error signal that can trigger an Arduino interrupt when they detect a short circuit or overload. That happens on every PWM pulse separately so it should be possible for an Arduino to react to a short within the time of a single PWM (or DCC) cycle.

(I'm assuming the two track sections would be fed through two separate TLE5206 chips)

...R

Of course you can detect a short at the begin of every PWM cycle, and then truncate such cycles.

Did you consider that a train with such reduced power may stop and cause a persistent shortcut?

DrDiettrich:
Of course you can detect a short at the begin of every PWM cycle, and then truncate such cycles.

Did you consider that a train with such reduced power may stop and cause a persistent shortcut?

To whom is that question addressed?

If it is meant for me, why would one wish to truncate the cycles? AFAIK the OP just needs to sync the cycles for two sections of track.

...R

Robin2:
I don't believe I was in any way impolite.

If you are enquiring about where to buy these devices then I reckon all the sellers of DCC equipment will stock them.

As I mentioned, if you want to build your own, I can't help. but it sounds like an interesting project.

I get more fun out of making them. I have an award from the N Gauge Society for converting a Graham Farish N-Gauge large Prairie tank locomotive to battery powered radio control. I am currently using N Gauge Kato tram chassis to make 009 locos with the bodywork made from card.

...R

Robin, I wanted to talk about a DCC problem and you said me about google, shops and battery trains. I don't doubt you are a good and capable person. I've been reading this forum for years and I have the impression that you are a positive person. It was a short circuit, a mismatch of polarity :). Please, let's we forget it.

I will try to answer to you and to DrDiettrich in the next post. I think we are too close to a solution or at least to a conclusion.

I just came across this Youtube video about an Arduino controlled reversing loop that may help - I have only watched the first few minutes.

...R

DrDiettrich:
Do you have an idea how long such a short will take , while the train is rolling? Does a short occur with every axle of every wagon, or only with the loco?

I’d think that a 1-2mm isolated rail at the breaks will prevent that problem, but if you want to roll your own solution you should explore a bit more yourself, in a life circuit.

The locos and some cars have 2 and 3 axle bogies. The locos have electrical pickups from one or every axle of each bogie. The passenger cars, sometimes, have pickups for lights. The dcc from rails goes through pickups to the decoder. The miniature decoder decodes -extracts the digital commands from the dcc signal and has a rectifier and a motor drive to drive the motor with the PWM. The pickups of each side are connected and represent a duct from the first wheel to the last wheel. The short circuit, usually, is not happenig, but it can be happen, because the wheels of the first axle fall simultaneously in the gap and bridge the two sections. The gaps on rails are not so perfectly alligned. The short circuit happens when both wheels from the first axle are touching or are on the other section. So we have to faceout the short circuit. There is no workaround except to reverse the polarity.

The short circuit will last till the magic smoke will get out or till you reverse the polarity.

Robin2:
Thinking some more about this…

I have been using Infineon TLE5206 h-bridge chips for powering a DC model railway. They could also be used with a DCC system. Those chips produce an error signal that can trigger an Arduino interrupt when they detect a short circuit or overload. That happens on every PWM pulse separately so it should be possible for an Arduino to react to a short within the time of a single PWM (or DCC) cycle.

(I’m assuming the two track sections would be fed through two separate TLE5206 chips)

…R

I did a quick google about this h-bridge and it seems to be ok for dcc trains but gives 5A (top 6A). This is very low compared to the 43A of the IBT-2. The IBT-2 is durable, “forgives”. The IBT-2 has overcurrent control and fault state too, like that you described it. I agree that is the key to solution.

DrDiettrich:
Of course you can detect a short at the begin of every PWM cycle, and then truncate such cycles.

Did you consider that a train with such reduced power may stop and cause a persistent shortcut?

The “PWM truncate” is the same to what the h-bridge does on overcurrent by switching off one switch. If by “truncate” you mean to low the duty cycle, that will not work. The short circut “eats” the voltage across the rails and sucks all the available energy with too high current.
BTW in your “begin of every PWM cycle” is hidding a verry good idea about the measurement. It will be clear at the end.
What if the train stop? The same as when it moves. If the short circuit will not handled immediatelly (by reversing the polarity) the IBT-2 will shutdown.
I think your second question has to be formed “how long a train can be unpowered, without be noticed?”
I can’t say how long, but given that some auto-reversers have relays, who have switching time measured in ms, i assume it isn’t a big problem.
The IBT-2 timeout during an overcurrent is between 70us and 420us. I think is enough time to reverse the polarity on the fault event mentioned before by Robin too. Interrupt call, exit 10us(?), digitalwrite 4us. XOR gates time in ns. I think it can fit to the 70us. A power off for 420us, it can’t be noticeable.

So, I agree that the short circuit handling has to be based on the IBT-2’s native current sense and fault on overcurrent. In the time the IBT-2’s switch is off the handler has to perform the reverse of the input signal. If the short circuit persists after the reversing the handler turns off the IBT-2. And I will do as DrDiettrich said “you should explore a bit more yourself, in a life circuit”.

I found this Video IBT-2 DCC BOOSTER. The man is very capable.
His method for measuring the current on pulses by an interrupt to the esp, is very clever. He is promising and the autoreverse function. I’m looking forward to see it.
From my point of view, the raising of the measuring interrupt at every pulse takes all the mcu time. Maybe will disable the interrupt for short periods to have the abillity execute and other functions in the loop.
Take a look, it is very well presented.
Thank you both.

Vggrek:
I did a quick google about this h-bridge and it seems to be ok for dcc trains but gives 5A (top 6A). This is very low compared to the 43A of the IBT-2.

Why would you need 43A? Why would you need more than 5A?

If you have a device that can sustain 42 amps without cutting out then unless you have very heavy cable there will be a serious fire risk.

...R

Robin2:
I just came across this Youtube video about an Arduino controlled reversing loop that may help - I have only watched the first few minutes.

...R

Yes it is another approach. I'm aware of this. There is a better alternative to the IR sensors.
This is based on pass sensing and this implementation is some kind "primitive" and limited to this type of the loop. The sensors are intrussive on the layout.
It is beter have phototransistors between the rails on each side of the gap. Then the reversing will be based on the trains "intention" to bridge the gap. Sensor covered! Train is near to this gap! Change the polarity to match the polarity of the adjacent section! Train may not pass the gap, but we are prepared.
It can be summarized in to this. Every border (gap) between a reversible section and a nonreversible section has a constant state of polarity CPS and a reversible state RPS. If a train is sensed near the gap (no matter on which side) then must RPS=CPS.
The reversing based on a short circuit is more versatile.

Robin2:
Why would you need 43A? Why would you need more than 5A?

If you have a device that can sustain 42 amps without cutting out then unless you have very heavy cable there will be a serious fire risk.

...R

You are right, I don't need so much and it is a little hazardous with no additional protection. An Arduino failure or native current sense failure or no shutdown on overtemperature can cause damages if the power source to the IBT-2 is capable to offer too much power.
I think an additional analog circuit for protection is a must, though I can't say how has to be.Maybe a fuse will do the job.
I see the major advantage of the powerfull IBT-2 in its abillity to sustain the stress.
It is like ride a super car in the city. If you push it to its limits you will be dead, but if you are logical you can enjoy the ride and the hidden power if will need. A super car can go very fast even if use a fraction of it's power.

Vggrek:
I think an additional analog circuit for protection is a must, though I can't say how has to be.Maybe a fuse will do the job.
I see the major advantage of the powerfull IBT-2 in its abillity to sustain the stress.

Seems to me that powerful device is just creating extra work for you. But each to his own - I'm planning to create extra work for myself but it is not related to Arduinos.

...R
PS ... Supercars just get their plugs fouled up in cities :slight_smile: