Current sense circuit customisation - Page 1
Forum section: electronics / projects

author: danners430
author_rank: Regular Contributor
timestamp: November 05, 2018, 02:43:17 pm
content: 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, fromhttps://www.jlcenterprises.net/pages/chapter-3but 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?

author: t1d
author_rank: Super Contributor
timestamp: November 06, 2018, 05:37:36 am
content: Quote from: danners430 on November 05, 2018, 02:43:17 pmI 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.

author: danners430
author_rank: Regular Contributor
timestamp: November 06, 2018, 06:35:17 am
content: 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

author: rs20
author_rank: Super Contributor
timestamp: November 06, 2018, 06:46:38 am
content: 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.

author: danners430
author_rank: Regular Contributor
timestamp: November 06, 2018, 06:49:13 am
content: 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

author: rs20
author_rank: Super Contributor
timestamp: November 06, 2018, 07:05:51 am
content: 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?

author: danners430
author_rank: Regular Contributor
timestamp: November 06, 2018, 07:10:16 am
content: 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 5ASent from my ONEPLUS A3003 using Tapatalk

author: rs20
author_rank: Super Contributor
timestamp: November 06, 2018, 07:13:19 am
content: 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.

author: t1d
author_rank: Super Contributor
timestamp: November 06, 2018, 09:49:45 am
content: 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

author: danners430
author_rank: Regular Contributor
timestamp: November 06, 2018, 10:17:27 am
content: 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.

author: danners430
author_rank: Regular Contributor
timestamp: November 06, 2018, 10:33:54 am
content: 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!)

author: fourtytwo42
author_rank: Super Contributor
timestamp: November 06, 2018, 05:27:20 pm
content: 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 yourselfFinally 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.

author: t1d
author_rank: Super Contributor
timestamp: November 06, 2018, 08:04:26 pm
content: Quote from: fourtytwo42 on November 06, 2018, 05:27:20 pmYou 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...

author: rs20
author_rank: Super Contributor
timestamp: November 06, 2018, 10:24:57 pm
content: 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, soBy 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.

author: danners430
author_rank: Regular Contributor
timestamp: November 06, 2018, 11:01:15 pm
content: 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

author: rs20
author_rank: Super Contributor
timestamp: November 06, 2018, 11:32:14 pm
content: Quote from: danners430 on November 06, 2018, 11:01:15 pmKirchoff's current law dictates that all thecurrentsin a loop are equal, so there's no difference in thecurrentsin 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.

author: danners430
author_rank: Regular Contributor
timestamp: November 06, 2018, 11:35:55 pm
content: Quote from: rs20 on November 06, 2018, 11:32:14 pmAye, 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

author: rs20
author_rank: Super Contributor
timestamp: November 07, 2018, 12:15:32 am
content: Quote from: danners430 on November 06, 2018, 11:35:55 pmI 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.Quote from: danners430 on November 06, 2018, 11:35:55 pmThat 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?

author: danners430
author_rank: Regular Contributor
timestamp: November 07, 2018, 05:33:08 am
content: 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