Author Topic: Current sense circuit customisation  (Read 3606 times)

0 Members and 3 Guests are viewing this topic.

Offline danners430Topic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Current sense circuit customisation
« on: November 05, 2018, 02:43:17 pm »
Afternoon all,

I'm working out a current sense circuit for a model railway - it's DCC, so 14-18V AC square wave at 5-8.62KHz.
I found the below circuit online, from https://www.jlcenterprises.net/pages/chapter-3 but would like to simplify it a little. I would be connecting the output to an MCU in every case.

The following is all based on my interpretation of the circuit - if I'm wrong, please do tell me!!

Firstly, I would replace the 12V supply with a 5V supply, which I think should work just the same as the higher voltage.

Secondly, I would do one of the following:

1. Remove "stage 3", the last op-amp and associated circuitry, which only serves to introduce a time delay, and the transistor. From my interpretation of the circuit, this should simply provide an output to the MCU - whether it would be a digital or analogue output I'm afraid I'm not sure - anyone know? I could use an ADC input on the MCU anyway, so it wouldn't be a problem.
2. Remove all but the first op-amp and associated circuitry, and use an analogue signal into the MCU.

The idea behind this is twofold: firstly to save on unnecessary additional circuitry (the original circuit doesn't take any MCUs into account), and secondly to allow me to use two, perhaps four, current sense transformers with the one LM324N op-amp, again saving on space. Reason for this is that I'm going to have a large number of these in a small area, so it's simply convenient to save some space.

Do my interpretation and alterations make sense?
 

Offline t1d

  • Super Contributor
  • ***
  • Posts: 1285
  • Country: us
Re: Current sense circuit customisation
« Reply #1 on: November 06, 2018, 05:37:36 am »
Afternoon all,

I'm working out a current sense circuit for a model railway - it's DCC, so 14-18V AC square wave at 5-8.62KHz.
I found the below circuit online, from https://www.jlcenterprises.net/pages/chapter-3 but would like to simplify it a little. I would be connecting the output to an MCU in every case.

The following is all based on my interpretation of the circuit - if I'm wrong, please do tell me!!

Firstly, I would replace the 12V supply with a 5V supply, which I think should work just the same as the higher voltage.

Secondly, I would do one of the following:

1. Remove "stage 3", the last op-amp and associated circuitry, which only serves to introduce a time delay, and the transistor. From my interpretation of the circuit, this should simply provide an output to the MCU - whether it would be a digital or analogue output I'm afraid I'm not sure - anyone know? I could use an ADC input on the MCU anyway, so it wouldn't be a problem.
2. Remove all but the first op-amp and associated circuitry, and use an analogue signal into the MCU.

The idea behind this is twofold: firstly to save on unnecessary additional circuitry (the original circuit doesn't take any MCUs into account), and secondly to allow me to use two, perhaps four, current sense transformers with the one LM324N op-amp, again saving on space. Reason for this is that I'm going to have a large number of these in a small area, so it's simply convenient to save some space.

Do my interpretation and alterations make sense?

I am n-o-o expert, but I think that you are on the right track...

5v - Should be no problem, but check the voltage needed to drive the gates of the op amps and transistor. You may need to change the value of various components, based on the new voltage. Resistor divider networks are likely to need attention. Newer MCUs are going to 3v3.

You might check on a better op amp, than the old-school 324, though it is a known workhorse. Op amps are prone to oscillate. Newer ones might be less susceptible?

You will also need to be careful with noise protection. I would think that you are in a very noisy environment.

Using an MCU, there may be a simpler means... Maybe just use a current sense resistor circuit, read across it and have the MCU do all the heavy (math) lifting... This is where we get beyond my skill level. Maybe google for current sensing circuits, for the MCU of your choice.

An interesting subject... I'll be following it. Do well.
« Last Edit: November 06, 2018, 05:40:51 am by t1d »
 

Offline danners430Topic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Current sense circuit customisation
« Reply #2 on: November 06, 2018, 06:35:17 am »
Unfortunately I can't use any form of invasive current monitoring, as the power supply to the model railway track also carries a modulated digital signal - it's the variance of the AC square wave between 5-8KHz that sends commands to the trains :-)

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2323
  • Country: au
Re: Current sense circuit customisation
« Reply #3 on: November 06, 2018, 06:46:38 am »
What's the goal of your project? To measure current consumption accurately, measure power consumption accurately, or just to detect for the presence of a locomotive?

BTW, a current sense resistor isn't any more "invasive" than a transformer.
 

Offline danners430Topic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Current sense circuit customisation
« Reply #4 on: November 06, 2018, 06:49:13 am »
It's simply to detect the presence of a locomotive in an electrical section.

My plan is to divide my layout into block sections, and fit a detector to each one.

I'm a little confused then... Ideally I don't want to have too much voltage drop to the track, and the modulated signal needs to be kept intact - how would the resistive circuit work?

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2323
  • Country: au
Re: Current sense circuit customisation
« Reply #5 on: November 06, 2018, 07:05:51 am »
As with any current sense resistor circuit, you choose a resistor value small enough so that its voltage drop is negligible as far as the locomotive is concerned but still easily detectable.

One disadvantage of the current sense resistor is that you don't get the galvanic isolation that a transformer provides, the negative swings will appear below ground to the circuit. But given that we're only detecting presence, that seems to be a non-issue. If it's important that your circuit ground be disconnected from the track ground common, then transformers are basically required.

If you want to reduce component count and maximise your utilisation of the MCU as much as possible, I don't see why having even 2 active devices for signal conditioning is required. Either an appropriately designed transformer+protection diodes, or an op-amp+resistor, can feed directly into the MCU which can then rapidly sample the signal. If like 0% of the readings come up high, there's no train. If like 50% of the readings are high, a train is there.

Would an empty track consume current for any reason? What are the ranges of currents consumed by a locomotive?
 

Offline danners430Topic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Current sense circuit customisation
« Reply #6 on: November 06, 2018, 07:10:16 am »
I do think the circuit ground needs to be separate - the way DCC works is that it consists of alternate pulses of (generally) 16V, first on one rail then on the other, so there isn't really a ground unless it's rectified. I'm willing to be corrected on this fact though!

I'm looking to detect not just locomotives, but any vehicle, the latter would be fitted with resistors across the wheels to enable detection. And no, there shouldn't be any current flowing when a train isn't present, but there would be a smart current, in the mA range, when it's stationary. The supply could go anywhere up to 5A

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2323
  • Country: au
Re: Current sense circuit customisation
« Reply #7 on: November 06, 2018, 07:13:19 am »
BTW, antiparallel diodes can be a better choice than resistors when all you care about is presence, as explained in the article you linked to. Resistors and antiparallel diodes are interchangeable as far as our discussion is concerned. I doubt that the drop caused by antiparallel schottky diodes would be all that significant in the whole scheme of things. But, transformers are fine to, albeit generally bulkier.

I just saw your most recent reply, let me find out more about this transformer.
 

Offline t1d

  • Super Contributor
  • ***
  • Posts: 1285
  • Country: us
Re: Current sense circuit customisation
« Reply #8 on: November 06, 2018, 09:49:45 am »
I know nothing about them, but what about a Hall Effect Current Sensor Circuit?

If you are just sensing presence, there a ton of ready-made breakout sensors, for Arduinos and the like. Photo/Light, Infrared light, regular Hall Effect Magnetic, Sonic... Even micro-radar is being developed... It is, even now, being used in the new generation of LED security lights.

Infrared would be easy... IR LED bulb, on one side of the track. Photo transistor, on the other. When the train blocks the beam, a train is present. You might need to shield ambient light sources, by placing covers around the bulbs, but it would be very doable, I think. Small and easy to hide with decorations. Just throwing out ideas...
https://www.rakeshmondal.info/IR-Infrared-Sensor-Interface-lcd-Arduino-uno
 

Offline danners430Topic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Current sense circuit customisation
« Reply #9 on: November 06, 2018, 10:17:27 am »
I've already got "point sensors", as I like to call them, but they're not the same as what I'm trying to achieve here.

On the "big railway", track circuits literally detect the completion of a circuit between the rails formed by the presence of a set of train wheels. On a model railway, where the opposing rails form the positive and return paths for the train, this obviously isn't possible. Hence the plan here.

This is a replacement for a track circuit, detecting the presence of a train within a defined section of track - for example to lock signals and points to prevent a train being inadvertedly driven into another train. it's also perfect for displaying where the train is on a panel.

"point sensors" I'm still going to use, probably infra-red gates, but I'd only use them for indicating when to stop a train on approach to a siding, for example, and at some point in the future to assist with full automatic control.
 

Offline danners430Topic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Current sense circuit customisation
« Reply #10 on: November 06, 2018, 10:33:54 am »
Doing a little more research, I had an idea (dangerous, I know. The fire brigade have been informed  ;) )

If I were to use a cheap and cheerful 1:50 toiroidal transformer (for example RS Components 173-0041), and fitted a 50k potentiometer across the secondary winding, then I'd get 1V out at 1mA, which I believe is a common "idle" current draw for a stationary locomotive with no functions activated. Coupling this to a MOSFET with a suitable threshold voltage, I'd have a simple logic output for my microcontroller. Adjusting the pot would adjust the sensitivity.

Obviously, I'd still keep the clamping diodes to prevent the voltage falling below -0.3V or above 5V to protect the FET.

In theory, and in my mind (which almost in itself invalidates the theory...  ;) ), this should work equally well, but use a minimum of components. Would you agree that this would work, or have I made a flaw somewhere? (not uncommon for me!)
« Last Edit: November 06, 2018, 10:35:56 am by danners430 »
 

Offline fourtytwo42

  • Super Contributor
  • ***
  • Posts: 1248
  • Country: gb
  • Interested in all things green/ECO NOT political
Re: Current sense circuit customisation
« Reply #11 on: November 06, 2018, 05:27:20 pm »
Your maths work fine BUT you must consider what will happen when the track is short circuited! I believe some DCC equipment will deliver 2 amps or more making the secondary current >=80mA and that must be dealt with by the overvoltage device protecting the FET gate (e.g. Zener). IMOP you don't really need the fet, just connect the PROTECTED output of the CT directly to the microcontroller!

The second problem comes from your very high sensitivity of just 1mA to operate the detector, it is likely at that sensitivity just the track and wiring capacitance will cause a phantom signal especially at the edges of the square wave so some filtering may be required. It might be an idea to try measuring the idle loco current yourself :)

Finally due to the switching nature of the DCC current the signal to the microcontroller will not be continuous, as the detector is unipolar but DCC is bipolar the signal will be a 50% duty cycle square wave. Again filtering could resolve this problem depending on the response time you require or you could rectify the output of the current transformer.
 

Offline t1d

  • Super Contributor
  • ***
  • Posts: 1285
  • Country: us
Re: Current sense circuit customisation
« Reply #12 on: November 06, 2018, 08:04:26 pm »
Finally due to the switching nature of the DCC current the signal to the microcontroller will not be continuous, as the detector is unipolar but DCC is bipolar the signal will be a 50% duty cycle square wave. Again filtering could resolve this problem depending on the response time you require or you could rectify the output of the current transformer.
You might be able to work-around this issue, by programming the MCU to test the signal, by taking samples over a period of time? I am new to programming...
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2323
  • Country: au
Re: Current sense circuit customisation
« Reply #13 on: November 06, 2018, 10:24:57 pm »
Yeah, that's a good idea danners, definitely worth breadboarding. I also agree with fourtytwo42 that the MOSFET isn't contributing much; I'd start by feeding the protected signal directly into the MCU. If you're scared of hurting your MCU and want a visual or oscilloscope output, or don't want to code yet, just use some similar logic-level input (buffer, inverter, NAND gate) as a subsitute.

So referring to the circuit diagram, I'd have R1, R2, D1, D3 and R11 in place. Then, the MCU's digital (or analog) input can go directly where U1A is. To add adjustability, I'd add P1 in series with R2, or add it in parallel to D1. Just make sure that D1 and D2 can handle the worst case current (as pointed out by fourtytwo42), build it up on a breadboard, and try it out!

Be wary of this though: D3 will allow a certain amount of charge to flow up to the +5V rail every cycle of the DCC, in other words, it will be pumping a certain current up into the +5V rail. This means that C3 is essential for a start, but it also means that if the other circuitry running off that 5V rail isn't consuming a large amount of current, and if the 5V PSU doesn't support sinking the excess current away, the 5V rail could start rising out of control. This might be a non-issue, or might be something that deserve further protection circuitry (which could be a simple as a big ol' resistor from 5V to ground); only time and/or details calculations will tell. To be fair, this might be an issue with the original circuit, so  :-//

By the way, what I'm suggesting is basically exactly the same as what you're suggesting, just to be clear. Your 50k pot would be R2, and R1 + R11 are both just current limiting resistors that can be 10 - 100kiloohms each. You can also try adding a tiny capacitor where C1 is, which would keep noise under control.
 

Offline danners430Topic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Current sense circuit customisation
« Reply #14 on: November 06, 2018, 11:01:15 pm »
That seems like a sensible idea - I suppose to get around the bipolar nature of the signal, I could run both feed wires to the track through the transformer?

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2323
  • Country: au
Re: Current sense circuit customisation
« Reply #15 on: November 06, 2018, 11:32:14 pm »
That seems like a sensible idea - I suppose to get around the bipolar nature of the signal, I could run both feed wires to the track through the transformer?

Kirchoff's current law dictates that all the currents in a loop are equal, so there's no difference in the currents in the two feed wires, and so no point in running both wires through the transformer. Unless I've misunderstood and the system isn't a simple loop.
 

Offline danners430Topic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Current sense circuit customisation
« Reply #16 on: November 06, 2018, 11:35:55 pm »
That seems like a sensible idea - I suppose to get around the bipolar nature of the signal, I could run both feed wires to the track through the transformer?

Kirchoff's current law dictates that all the currents in a loop are equal, so there's no difference in the currents in the two feed wires, and so no point in running both wires through the transformer. Unless I've misunderstood and the system isn't a simple loop.
Aye, that's a fair point...

Not sure what you mean by loop - basically the two rails on the model railway act as the positive and negative (if it were DC) feeds to the trains. With DCC, they are alternately powered, first a pulse on one rail then on the other rail.

Speaking to another friend off the thread, he suggested keeping everything up to U1B to "rectify" the voltage for ease of programming...

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2323
  • Country: au
Re: Current sense circuit customisation
« Reply #17 on: November 07, 2018, 12:15:32 am »
Not sure what you mean by loop - basically the two rails on the model railway act as the positive and negative (if it were DC) feeds to the trains. With DCC, they are alternately powered, first a pulse on one rail then on the other rail.

I mean there's a wire, then a train, then another wires. Kirchoff's current law says that if there's no other paths for current to flow, then the currents are equal through all three of those components and there's no point feeding both wires through the CT.

Speaking to another friend off the thread, he suggested keeping everything up to U1B to "rectify" the voltage for ease of programming...

That makes absolutely no sense. We're only testing for presence; the negative swings are unnecessary and are discarded by D1. If you're going to add a dozen extra components to your design, you should probably have a clear reason why?
 

Offline danners430Topic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Current sense circuit customisation
« Reply #18 on: November 07, 2018, 05:33:08 am »
To be honest, he completely lost me with his explanation... J reckon I'm going to quite simply go out and buy some components and do some testing :-)

Sent from my ONEPLUS A3003 using Tapatalk

 
The following users thanked this post: rs20


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->