Thanks for the video. Indeed, the analog reading of the pins of the BTS7960 is catastrophic. In addition, the analog signals at the same period as the PWM. Since I fixe the frequency at 16Mhz, reading analog signals is not easy. And to close it all, the analog signal has a sinusoidal signal that resamble to a amplitude modulation. I added a 15µF /25V electrolytic capacitor in parallel with this 10k resistor for each of the analog pins IS_R and IS_L before routing the signal to the analog pins of the Arduino board. This gives me a clean analog DC values with 90-95% noise removed and that can be read very quickly. The disadvantage is that I have negative pulses of -540mV. Higher the PWM duty, the lower the négative pulse. I do not combine the analog outputs because I prefer to read them independently.
A capacitor is for sure a good idea. I am using 10uF and it works quite well. The resistor is chosen so that the output voltage is not exceeding 5V for the current range I want to use. For safety, I am also using a zener diode, but within the normal current limits it is not used. In an H Bridge application, only one sensor is active at any point in time, so even if you combine the outputs, you can always tell based on the control signals, where the current information is coming from. Combining safes one analog input.
Another great video Hans. I've been hoping someone would make an MRR DCC-specific Arduino Shield that took care of all the signal inversion and other passives to produce reliable operation and it looks like you're doing it which will be awesome. Looking forward to giving this a go some time. I think I have some of those IBT2 modules so need to wire it up sometime.
Thanks, Alex. Yes,, that's the idea: Arduino Uno, 2 x IBT-2 Motorshield, RedHat on top, makes a Loconet command station with two 5Amp tracks, one of which can alternatively be used as programming track. Plus WiThrottle, Loconet over TCP, MQTT built in by default as it is part of the IoTT Stick anyway. I probably will call it "The IoTT Cube" ;-)
@@IoTT Awesome roadmap Hans! I'm looking forward to seeing it all working and ordering some boards. The need for a simple and reliable >2A capability has been around for a long time and has undoubtedly proved the concept and made it easy to get started, but the original Arduino L298* boards are a bit limiting for anything more than small layouts. The capability for multiple 5A drivers will undoubtedly be another game-changer for DCC-EX.
Thank you very much for this video. I have been searching for more information on this current sensing feature of the rather cheap module for control of a size of motor of about 300 W for sewing machine. 1) You say, that the current from the "current source" is measured. Could you be a bit more specific here? Is it the current through the transistor to the + supply or the current to the transistor in the negative supply or somewhere else? 2) When you turn off the digital inputs, I guess that both transistors becomes off, and that the only way some current may be through free wheeling diodes. Is the free wheeling diodes part of the transistors and is it safe to rely on them? 3) I have read, that the transistors may not withstand a continuous current above 15 A. If the application only require the DC motor to run one way, you may be interested in running the two pairs of transistors in parallel. It could make problems, if shifting time delays are different. What do you think about that?
I think I found the answer to question 1 in the data from Infineon for the BTS 7960. It is the active positive current in the upper transistor, that is measured. So if you drive a motor having its inductance, the actual motor current should be corrected in accordance with the PWM value, because the current continues in the motor in the lower transistor or free wheeling diode, when the upper transistor is off.
1) The IS pin is the current source. It is fed to a resistor, which converts it into a voltage that is measured. There are current sensors on both, the hi and low side for protection reasons, but for current measuring only the hi side is used. 2) Yes, when the enable pins go low, the device goes in high impedance mode. Any inductive load will discharge via clamping diodes. If you want to use it for braking, you put both bridges to high, so one is conducting, the other conducts via clamping diode. Putting both to low has the same effect, essentially shorting the output for braking. 3) No idea, but I did a load test with 5 and 8 Amp (video 121) and the chips got pretty hot. Plus the pins in my opinion are not made for the 43 Amps the device is supposed to do. Maybe for a few secs, but not longer. That is probably the main reason why the successor of the chip has 2 pins for feeding instead of one.
@@IoTT Thank you. Am I right to assume, that one PWM input control the left side of the H bridge and the other PWM input controls the right side of the H-bridge? I read, that the IS pins are only affected by the positive current in the upper transistors. In order to measure the motor current you need the Arduino AD-converter sample hold circuit to sample the current signal the right time. With a switch frequency of 20 kHz it is not trivial. But I think it is possible to use Timer1 of the normal Arduino Uno to start the AD-converter at right time. Otherwise you need to low pass filter the analog signal significantly.
Yes, each PWM controls one chip. The need opposite signals to make it work. Yes, with 20kHz PWM frequency, the Arduino AD converter is too slow, and also, you would get garbage anyway because of the fact that you either read PWM ON or OFF, but you don't get the impact of the duty cycle. So, low pass is the correct answer. Or what you also can do is sampling at a constant rate and do an RMS calculation. That way you get ON/OFF samples with a probability proportional to your duty cycle, and the RMS calculation will make the result right. In a DCC application it is different as it is always 100% duty cycle, but the polarity changes with 11kHz average. At that rate it is possible to sync the ADC with the timer interrupt.
@@IoTTThanks. It is a bit difficult to explain everything here. And I am new to Arduino, so it is a part of the problem. I have tried to open a thread for comments in the Arduino Forum on motors. I am "Backflip". I do not know yet, but I guess it would be in order to sample and measure the current signal for every 0.5 ms or something like that and then calculate a mean value for a control loop, that might run for every 5 ms. With a 125 kHz ADC-clock, the signal can be read after 104 micro seconds. But sampling of signal takes much less time.
Scary indeed! Congratulations on such a thorough analysis of the IBT-2. Your plans will certainly make this a better option for higher current needs with DCC-EX. I like your idea for a small daughter board but, without a heat sink, would the setup run too hot? As most people limit their DCC current to 5amps, is this well below the threshold we should concern ourselves with? This latest video again makes me think that my NCE system just might be up for sale. Great stuff Hans! Keep them coming!
Thank you. Up to 5 Amps temperature is not a concern. The On resistance is 16mOhms, resulting in a power dissipation of about 200 mWatts per chip, which is not a problem for a device that size, it pretty much stays at room temperature.
@@IoTT Hans, thank you for your answer. I doubt that there is a need for more than 5amps for any N-scale layout and with a decent circuit breaker, I won’t have any worries. My Red Hat DCC-EX just moved up in priority.
Hans, Thank's for this info. I recently built a booster board that is Dave Bodnar design and IBT-2 ( w/cooler) for use with my DCC++ system. the system works good. After adding IBT-2 my Digitrax AR-1 auto reversers trips the "SHORTCIRCUIT" . Digitrax info says .25 to 5 amps trip current is adjustable with a POT. but clearly the current sense shuts down the system when it see's the condition. I was able to use the AR-1 with the Base Station prior to the booster. Is there a safe way to implement the AR-1? Thanks for any advice you could offer, Dave...
Most likely DCC EX sees a huge current spike when the locomotive bridges the track gap. - adjust the settings in the motordriver.h setup. I don't know who came up with the default values, but they are ways off. Use 8.3 for senseFactor and 7000 for tripMilliamps. - add a small capacitor, e.g. 100nF between Arduino GND and the analog input you are using. This slows down how fast the sensor voltage can raise, so the spike might be gone before the value gets critical.
@@IoTT Thank you very much, I am waiting on a makerfab wifi shield to complete my EX station and I will implement the changes when complete. thank you for all you do. I do not believe motordriver.h is in basic DCC++ base station I am currently using, just current monitor.h. The Booster Board has it's own little sketch with if statements, for current sense analog pin if : > greater than pin current booster board shuts down. It is so satisfying , exciting and rewarding when this stuff works as intended, Have a safe and happy holidays.
Hello! My IBT-2 module, when no current, has 1.8V on L_IS and 2.2V on R_IS. When I put 10Ohm resistor - it increase to 2.3 and 2.7V. So command station shows 2-3Amp. I put capasitor 10nF but it doesn't change situation. Maybe it's bad module?
I have seen some BTN chips that give an output current on IS as soon as voltage is applied. Is the 10 Ohm resistor your output load? The BTN chips I had with that problem at least had a linear error, so it is easily possible to compensate in the software by just deducting a constant value to the measured input. Are you using an external IBT-2 module with the 10k resistors to convert sensor current to voltage? I would try a different IBT-2 module and compare the results.
@@IoTT Of'course I have seen your video with maximum attantion. And ofcourse my module has 10kOhm resistor to convert sensor current to voltage. I check it many times. And i put capasitor 10n (and try 0.1mk and 1mk). I even order ASC724 current sensor 50A - but it has the same 50% voltage with 0A current. What is the way to deducting a constant value? And Yes a order another one IBT-2 to compare.
If you get the same results with the ASC724 I would check if there maybe is a problem with the GND potential that would lift the sensor voltage. To compensate for the offset, you would deduct a constant value from the value you read from the analog input and then use the result for the TrueRMS calculation.
Maybe more of a follow on to Rob's comment. Are the two types cooler vs non-cooler pin compatible? I use the cooler version and under normal usage use 8 to 10 Amps. Could I just run jump wires from the daughter board to the pins on the cooler version?
8-10 Amps? sounds like Lionel ;-) But yes, both use the same pins. The layout is different, though. 4x2 on the Standard, 1x8 arrangement on the No Cooler. Not a problem if you use Jumper wires.
Thank you for such thorough coverage. Much needed digest of the current measurement essentials for the active project.
Glad it was helpful!
Thank you for your efforts on this matter -- provides insight into just how software needs to understand the different hardware "personalities"
Thanks, yes, that sort of details is a lot of fun. But there is no way around it if you want things to work reliably.
Very useful discussion. Thank you.
Glad it was helpful!
thanks for share fruitful knowledge
Thanks for the video. Indeed, the analog reading of the pins of the BTS7960 is catastrophic. In addition, the analog signals at the same period as the PWM. Since I fixe the frequency at 16Mhz, reading analog signals is not easy. And to close it all, the analog signal has a sinusoidal signal that resamble to a amplitude modulation.
I added a 15µF /25V electrolytic capacitor in parallel with this 10k resistor for each of the analog pins IS_R and IS_L before routing the signal to the analog pins of the Arduino board. This gives me a clean analog DC values with 90-95% noise removed and that can be read very quickly. The disadvantage is that I have negative pulses of -540mV. Higher the PWM duty, the lower the négative pulse.
I do not combine the analog outputs because I prefer to read them independently.
A capacitor is for sure a good idea. I am using 10uF and it works quite well. The resistor is chosen so that the output voltage is not exceeding 5V for the current range I want to use. For safety, I am also using a zener diode, but within the normal current limits it is not used.
In an H Bridge application, only one sensor is active at any point in time, so even if you combine the outputs, you can always tell based on the control signals, where the current information is coming from. Combining safes one analog input.
Another great video Hans. I've been hoping someone would make an MRR DCC-specific Arduino Shield that took care of all the signal inversion and other passives to produce reliable operation and it looks like you're doing it which will be awesome. Looking forward to giving this a go some time. I think I have some of those IBT2 modules so need to wire it up sometime.
Thanks, Alex. Yes,, that's the idea: Arduino Uno, 2 x IBT-2 Motorshield, RedHat on top, makes a Loconet command station with two 5Amp tracks, one of which can alternatively be used as programming track. Plus WiThrottle, Loconet over TCP, MQTT built in by default as it is part of the IoTT Stick anyway. I probably will call it "The IoTT Cube" ;-)
@@IoTT Awesome roadmap Hans!
I'm looking forward to seeing it all working and ordering some boards. The need for a simple and reliable >2A capability has been around for a long time and has undoubtedly proved the concept and made it easy to get started, but the original Arduino L298* boards are a bit limiting for anything more than small layouts.
The capability for multiple 5A drivers will undoubtedly be another game-changer for DCC-EX.
Thank you very much for this video. I have been searching for more information on this current sensing feature of the rather cheap module for control of a size of motor of about 300 W for sewing machine.
1) You say, that the current from the "current source" is measured. Could you be a bit more specific here? Is it the current through the transistor to the + supply or the current to the transistor in the negative supply or somewhere else?
2) When you turn off the digital inputs, I guess that both transistors becomes off, and that the only way some current may be through free wheeling diodes. Is the free wheeling diodes part of the transistors and is it safe to rely on them?
3) I have read, that the transistors may not withstand a continuous current above 15 A. If the application only require the DC motor to run one way, you may be interested in running the two pairs of transistors in parallel. It could make problems, if shifting time delays are different. What do you think about that?
I think I found the answer to question 1 in the data from Infineon for the BTS 7960. It is the active positive current in the upper transistor, that is measured. So if you drive a motor having its inductance, the actual motor current should be corrected in accordance with the PWM value, because the current continues in the motor in the lower transistor or free wheeling diode, when the upper transistor is off.
1) The IS pin is the current source. It is fed to a resistor, which converts it into a voltage that is measured. There are current sensors on both, the hi and low side for protection reasons, but for current measuring only the hi side is used.
2) Yes, when the enable pins go low, the device goes in high impedance mode. Any inductive load will discharge via clamping diodes. If you want to use it for braking, you put both bridges to high, so one is conducting, the other conducts via clamping diode. Putting both to low has the same effect, essentially shorting the output for braking.
3) No idea, but I did a load test with 5 and 8 Amp (video 121) and the chips got pretty hot. Plus the pins in my opinion are not made for the 43 Amps the device is supposed to do. Maybe for a few secs, but not longer. That is probably the main reason why the successor of the chip has 2 pins for feeding instead of one.
@@IoTT Thank you. Am I right to assume, that one PWM input control the left side of the H bridge and the other PWM input controls the right side of the H-bridge?
I read, that the IS pins are only affected by the positive current in the upper transistors. In order to measure the motor current you need the Arduino AD-converter sample hold circuit to sample the current signal the right time. With a switch frequency of 20 kHz it is not trivial. But I think it is possible to use Timer1 of the normal Arduino Uno to start the AD-converter at right time. Otherwise you need to low pass filter the analog signal significantly.
Yes, each PWM controls one chip. The need opposite signals to make it work.
Yes, with 20kHz PWM frequency, the Arduino AD converter is too slow, and also, you would get garbage anyway because of the fact that you either read PWM ON or OFF, but you don't get the impact of the duty cycle. So, low pass is the correct answer.
Or what you also can do is sampling at a constant rate and do an RMS calculation. That way you get ON/OFF samples with a probability proportional to your duty cycle, and the RMS calculation will make the result right.
In a DCC application it is different as it is always 100% duty cycle, but the polarity changes with 11kHz average. At that rate it is possible to sync the ADC with the timer interrupt.
@@IoTTThanks. It is a bit difficult to explain everything here. And I am new to Arduino, so it is a part of the problem. I have tried to open a thread for comments in the Arduino Forum on motors. I am "Backflip". I do not know yet, but I guess it would be in order to sample and measure the current signal for every 0.5 ms or something like that and then calculate a mean value for a control loop, that might run for every 5 ms. With a 125 kHz ADC-clock, the signal can be read after 104 micro seconds. But sampling of signal takes much less time.
Scary indeed! Congratulations on such a thorough analysis of the IBT-2. Your plans will certainly make this a better option for higher current needs with DCC-EX. I like your idea for a small daughter board but, without a heat sink, would the setup run too hot? As most people limit their DCC current to 5amps, is this well below the threshold we should concern ourselves with? This latest video again makes me think that my NCE system just might be up for sale. Great stuff Hans! Keep them coming!
Thank you. Up to 5 Amps temperature is not a concern. The On resistance is 16mOhms, resulting in a power dissipation of about 200 mWatts per chip, which is not a problem for a device that size, it pretty much stays at room temperature.
@@IoTT Hans, thank you for your answer. I doubt that there is a need for more than 5amps for any N-scale layout and with a decent circuit breaker, I won’t have any worries. My Red Hat DCC-EX just moved up in priority.
Hans, Thank's for this info. I recently built a booster board that is Dave Bodnar design and IBT-2 ( w/cooler) for use with my DCC++ system. the system works good. After adding IBT-2 my Digitrax AR-1 auto reversers trips the "SHORTCIRCUIT" . Digitrax info says .25 to 5 amps trip current is adjustable with a POT. but clearly the current sense shuts down the system when it see's the condition. I was able to use the AR-1 with the Base Station prior to the booster. Is there a safe way to implement the AR-1? Thanks for any advice you could offer, Dave...
Most likely DCC EX sees a huge current spike when the locomotive bridges the track gap.
- adjust the settings in the motordriver.h setup. I don't know who came up with the default values, but they are ways off. Use 8.3 for senseFactor and 7000 for tripMilliamps.
- add a small capacitor, e.g. 100nF between Arduino GND and the analog input you are using. This slows down how fast the sensor voltage can raise, so the spike might be gone before the value gets critical.
@@IoTT Thank you very much, I am waiting on a makerfab wifi shield to complete my EX station and I will implement the changes when complete. thank you for all you do. I do not believe motordriver.h is in basic DCC++ base station I am currently using, just current monitor.h. The Booster Board has it's own little sketch with if statements, for current sense analog pin if : > greater than pin current booster board shuts down. It is so satisfying , exciting and rewarding when this stuff works as intended, Have a safe and happy holidays.
Hello! My IBT-2 module, when no current, has 1.8V on L_IS and 2.2V on R_IS. When I put 10Ohm resistor - it increase to 2.3 and 2.7V. So command station shows 2-3Amp. I put capasitor 10nF but it doesn't change situation. Maybe it's bad module?
I have seen some BTN chips that give an output current on IS as soon as voltage is applied. Is the 10 Ohm resistor your output load? The BTN chips I had with that problem at least had a linear error, so it is easily possible to compensate in the software by just deducting a constant value to the measured input.
Are you using an external IBT-2 module with the 10k resistors to convert sensor current to voltage? I would try a different IBT-2 module and compare the results.
@@IoTT Of'course I have seen your video with maximum attantion. And ofcourse my module has 10kOhm resistor to convert sensor current to voltage. I check it many times. And i put capasitor 10n (and try 0.1mk and 1mk).
I even order ASC724 current sensor 50A - but it has the same 50% voltage with 0A current.
What is the way to deducting a constant value?
And Yes a order another one IBT-2 to compare.
If you get the same results with the ASC724 I would check if there maybe is a problem with the GND potential that would lift the sensor voltage.
To compensate for the offset, you would deduct a constant value from the value you read from the analog input and then use the result for the TrueRMS calculation.
@@IoTT If you check ASC724-50A manual - you can find that it has 0V in -50A and 5V in 50A and 50% (2.5V) in 0A
Maybe more of a follow on to Rob's comment. Are the two types cooler vs non-cooler pin compatible? I use the cooler version and under normal usage use 8 to 10 Amps. Could I just run jump wires from the daughter board to the pins on the cooler version?
8-10 Amps? sounds like Lionel ;-) But yes, both use the same pins. The layout is different, though. 4x2 on the Standard, 1x8 arrangement on the No Cooler. Not a problem if you use Jumper wires.
Is their any way to have moment contact dowlpole down though contact switch to trigger points on dcc boar
Hmmm, I don't think I understand this question. Any more information?