Help with current limit for DC motor driver - Page 1
Forum section: electronics / projects

author: MarkF
author_rank: Super Contributor
timestamp: May 29, 2015, 02:43:42 am
content: I need some suggestions for providing current limit of DC motor drivers for a HO model railroad engines. Analog design is not one of my strong areas.Most HO engines require 1.0A to 1.5A current @ 12VDC at full speed. I generating PWM waveforms with pic16f876 microcontrollers and MCP4802 D/A converters. My thoughts are to use a voltage follower darlington pair configuration to power each engine. However I need to limit the current when a short ( accident) occurs on the track. I believe I can limit the current with a resistor (R1 in the circuit) in series with the base. Can anyone suggest a better way to do this.I would like to retain the 2N3055 and LM358 as I have a stock of these already. In addition, this circuit will be duplicated 30 times. So part count and cost must be considered.

author: rx8pilot
author_rank: Super Contributor
timestamp: May 29, 2015, 03:26:57 am
content: Consider the Linear LT1910 which will sense current and shut the circuit down after an over current fault. You can set a delay if needed to prevent false alarms. You can have it self reset, or latch off. It comes in a SOIC-8 and only needs a few external parts. Bomb proof and requires very little knowledge of analog power electronics except maybe doing a kelvin connection on the sense resistor. Has an enable pin so you can have a low current switch as well if you choose.

author: TerminalJack505
author_rank: Super Contributor
timestamp: May 29, 2015, 04:37:48 am
content: It's past my bedtime so I'll just post this without really going into details.The circuit shown is simulating driving a 10 ohm load for the first 2.5 ms and then experiencing a short at 2.5 ms and limiting the current to about 1.5 amps.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 29, 2015, 04:50:31 am
content: You want current limiting by adding a series emitter resistor after the follower, and sensing its voltage drop with another BJT. Like the stuff along the top right in here,Or the 2SD1273 here,which also shows what's called foldback current limiting (the 22k to +V and series 1k act to further reduce current draw when the output voltage is low).In either case, when the shunt resistor (330 or 0.22 ohms in these examples) carries enough current to develop a voltage drop around the base-emitter voltage Vbe, about 0.7V, this starts to turn on the current-limiting transistor. Which pulls down the pass transistor, thus holding current constant.By the way, each transistor you stack in series (forming a Darlington pair, or triple, or...) loses at least 0.7V. So even if your LM358 were capable of outputting the full +18V, you'll get more like 16V maximum.In reality, the LM358 itself has a Darlington design inside, so it will never pull that high, not with a load on it anyway. You've really got four transistors stacked, and you'll be lucky to get more than 14V at the output.How much of the +18 do you need, how much were you expecting?If you don't need a regulated output at all, you might simply replace the LM358 with a potentiometer (or rheostat..). This can swing all the way to +18V, and a small enough resistance (and big enough power dissipation rating..) can drive the power transistor directly, so you lose less voltage drop.I would suggest finding something other than 2N3055. It'sliterally not 1960 anymore,and far better transistors exist. The most egregious characteristics are the low hFE (needs more base current), the high Vce(sat) (which suggests that, even if you could bring the base voltage up near +18V, the transistor itself will just wheeze out of steam as it gets within a few volts, for loads of a few amperes), and the overall poorly controlled specs (which means you could get anything from Chinese factory floor sweepings, to a surprisingly top-notch transistor that didn't quite meet specs as something better, but is still way better performing than you're expecting, and plagues you as a better power oscillator than a linear amplifier!).That said, you still need an alternative. This looks cheap and useful:http://www.digikey.com/product-detail/en/KSD363YTU/KSD363YTU-ND/1057674You need a heatsink (you need one either way..), but TO-220 is easier to mount (and easier to find hardware for) than TO-3. (Well, unless your stock of 2N3055 is paired with an equal array of heatsinks, in which case I can't really complain, the hardware is worth more in the end.)As for controls:You want the op-amp feedback (if any) taken from the motor terminal, not the amp's output. That way, it can account for all the voltage drops: the series resistor, the Vbe's, everything.So you're PWMing this?... from a DAC?Why? The DAC is perfectly capable of producing an accurate proportional value, straightaway. Which this circuit will be capable of handling. Or if you want PWM control and all that (using the motor to perform filtering, and getting better efficiency that way), you should use a switching circuit instead (which could use either a BJT or a MOSFET).Tim

author: rx8pilot
author_rank: Super Contributor
timestamp: May 29, 2015, 06:01:39 am
content: That seems like a complicated solution, maybe good as a fun learning experience though.

author: Richard Head
author_rank: Frequent Contributor
timestamp: May 29, 2015, 06:02:56 am
content: Can you not install the freewheeling diode in the loco's rather than four feet away? It'll reduce the EMI.

author: Seekonk
author_rank: Super Contributor
timestamp: May 29, 2015, 01:34:35 pm
content: The loco has to go backwards. As alluded to before put a resistor in the +18V line that will generate .6V at the current you want to limit at. Put the EB, of a PNP transistor, across that resistor with a 1K resistor in series with the base to limit current. Collector goes to a voltage divider to common so voltage will never exceed 5V to the A/D. A RC filter to smooooooth out the current pulses for better reading. That will adjust the PWM, assuming you wrote the program. It could also go to a digital input.

author: MarkF
author_rank: Super Contributor
timestamp: May 29, 2015, 02:41:03 pm
content: PWM is used to overcome friction and provide smooth starting motion thus eliminating the engine jumping when first starting to move when using only DC voltage. However, the PWM voltage tends to heat up the motors. Therefore, the microcontroller will only generate PWM for slow speeds and transition into pure DC for higher speeds. I still haven't settled on the PWM amplitude nor the transition voltage to DC.In the future, I want to modify the engines with constant lighting. So the microcontroller will need to send out a low voltage DC level to turn on the headlight and inside cab lights while the engine is sitting still in the yard.The microcontroller and D/A can only output a maximum of 4V. So the op-amp is required to amplify the D/A output into the 14V range. Finally, I expect to have a maximum of 12V to the track.Also, the train direction is provided with a DPDT relay controlled by the microcontroller.Tim, is my updated circuit what you had in mind?Seekonk, I think I would need a picture to see the PNP configuration.Thanks everyone for your comments.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 29, 2015, 02:47:08 pm
content: Quote from: Richard Head on May 29, 2015, 06:02:56 amThe diode MUST be at the switch, not the load.TIm

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 29, 2015, 02:53:17 pm
content: Quote from: MarkF on May 29, 2015, 02:41:03 pmAh OK, 12V output will be fine. Yes, this captures the current limit. The resistor will have to be R2 = 0.7V / (current limit in amps), maybe 1-3A, depending on how you want to control it (while the motor might draw only 1.5A continuous, it may need 3A+ to accelerate?).Remember, limiting a motor to no more current (and therefore torque) than it draws at cruise, is the same as trying to drive around in a Geo Metro: you have to floor it to get moving at all, and you might be able to reach highway speed, but with no extra capacity, it takes forever to get there! (And even then, the car has a notable advantage over your train -- a transmission!)The right hand side of the 33k should be connected to the output node, so the op-amp can regulate actual output voltage, not its own output.Tim

author: MarkF
author_rank: Super Contributor
timestamp: May 29, 2015, 05:43:56 pm
content: Quote from: T3sl4co1l on May 29, 2015, 02:53:17 pmDo you mean the top or bottom of R2 (i.e. before or after the current sensing resistor)?

author: Seekonk
author_rank: Super Contributor
timestamp: May 29, 2015, 06:26:35 pm
content: Transitioning from PWM to analog is an interesting idea.My limiting would be under program control. You see many beginners here wanting constant current supplies to protect against shorts. That is not really a solution if protecting against "shorts." A preferable solution is to have some sort of foldback when a short is detected. If you are current limiting at 1.5A the output transistor will see that full 18V in a short and produce 30W in heat till the short is removed. Better have a big heat sink. Under software control a short would be detected and and the supply could shut down for 5 seconds and then try again. After so many tries it would shut down, maybe lighting a LED, until power is removed. Input could be analog or digital as the voltage sensed would fully transition in likely a 100ma. The filter capacitor would average the pulses a little and prevent false trips.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 29, 2015, 07:26:09 pm
content: Quote from: MarkF on May 29, 2015, 05:43:56 pmBottom, where it joins the diode, and just before the relay.

author: eneuro
author_rank: Super Contributor
timestamp: May 29, 2015, 10:16:15 pm
content: ACS712 hall effect current sensor, inductor, diode (better synchronized rectifier) and N-channel mosfet on battery (-) with gate driver and comparator to detect overcurrent from ACS712 outputIn MPU version I do not switch off PWM, but decrease duty cycle by 2, compare current with required and if still too high divide duty by another 2 till current is within limit-if it is below in similar fashion up to high curent limit, so eg. from 75%pwm, after first overcurrent, PWm droped to 37%, if stll too high 18%, so PWM can reach 0%PWM and turn off PWM, but tries to do it in not ON/OFF but a way described aboveWhen size is not concern I use even radiometric SS495A hall sensor with printed PCB coil, while it is cheaper than ACS712 and can decide how wide my PCB power track will be.Classic current limit for old school lead-acid 12V battery charger which works a few years with ATTiny85 MPU and TL431I voltage reference without any problems with two IRFZ44N in parallel.

author: MarkF
author_rank: Super Contributor
timestamp: May 29, 2015, 10:54:46 pm
content: You must have been reading my mind Seekonk. While re-examining this circuit, I was just considering sensing the current with the microcontroller and shutting the voltage down when a short is detected. It would also address a second issue that I haven't considered. And that is what to do when 2 or 3 engines are coupled together in one train consist.It looks like I need to build up this circuit again and take some measurements with a few different configurations.

author: jamesglanville
author_rank: Contributor
timestamp: May 29, 2015, 11:15:47 pm
content: How likely is a short? I'd be tempted to just use a standard fuse if replacement isn't too much of an issue. You can get fast/slow blow types, a slow blow type is probably ideal - it won't burn out if you have peaky current when revving up, but will for a sustained short. Cheap, too.

author: rickey1990
author_rank: Regular Contributor
timestamp: May 29, 2015, 11:54:37 pm
content: Adding some diodes to where the key components are might work.INCREASING OUTPUT CURRENTThe 555 will deliver 200mA to a load but the chip gets extremely hot (12v supply). The answer is to use a buffer transistor.For 200mA, use a BC547 or equivalent.For 500mA use a BC337 or equivalentFor 1A, use a TIP31 or equivalent.For 3A - 5A use a BD679 or equivalent with heatsinkFor 5A to 10A use TIP3055 with heatsinkCONSTANT CURRENTThe 555 will deliver 200mA to a load but this might be too much. You can add a dropper resistor (current limiting resistor) but the current will reduce as the supply voltage drops.To provide a constant output current to a device such as an IR LED, the following circuit can be used. The current will be constant for any supply voltage but the best range will be 7v to 12v.The current is determined according to the value of R. You can use this table:(would using no resistor work)R Current5R6 100mA10R 60mA22R 30mA47R 15mA100R 6mA

author: Seekonk
author_rank: Super Contributor
timestamp: May 30, 2015, 12:54:09 am
content: I highly recommend these for layouts that experience fumbly fingers. It is a PTC fuse that acts thermally. Once tripped it consumes 1/4 watt toll power is removed. A little bit of a delay and can handle three times the current for short periods and cheap.http://www.ebay.com/itm/RXEF135-LOT-OF-20-POLYSWITCH-RXE-SERIES-1-35A-HOLD/221252599018?_trksid=p2060778.c100276.m3476&_trkparms=ao%3D1%26asc%3D30986%26meid%3D7e10249636924cc6af58d496939ff264%26pid%3D100276%26Don't know what else you have running off that transformer, but you could sense current in the - side just before the power cap or - to the direction switch and A/D the real current. Also a big fan of the ACS712 which makes things easy and safe.One new idea is to measure the output voltage. As long as things don't get near zero volts when drawing a lot of current it could be assumed safe. I always say, what decision would you make if all you knew was from a couple meters. Put that into your software.

author: C
author_rank: Super Contributor
timestamp: May 30, 2015, 01:12:44 am
content: For HO trains there is Digital Command Control (DCC)http://en.wikipedia.org/wiki/Digital_Command_ControlC

author: MarkF
author_rank: Super Contributor
timestamp: May 30, 2015, 01:32:51 am
content: Quote from: jamesglanville on May 29, 2015, 11:15:47 pmEver watched the Addams Family TV show when Gomez and Uncle Fester crash 2 engines head-on? The engines and cars can derail at any time with potential track shorts.The track power is a 200VA @ 12VAC transformer with a full-wave bridge and capacitor (no regulation). No need for a lot of regulation just for motors. This transformer will power 30 independent sections of track. Each of which are powered with the circuit we're discussing and each of which need some kind of current limitation.I'm still looking to see if I have enough spare pins on the microcontrollers to sense the current or if I'm forced to implement it in hardware.

author: MarkF
author_rank: Super Contributor
timestamp: May 30, 2015, 01:41:20 am
content: Quote from: C on May 30, 2015, 01:12:44 amI abandoned DCC a long time ago for two reasons. First, is the extra cost associated with DCC modules. Second, I want to run a Gandy Dancer on the layout and as you can see from the image below there's no room for any extra parts.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 30, 2015, 02:15:25 am
content: Quote from: Seekonk on May 30, 2015, 12:54:09 amThis is a big trap for new players: fuses are there only to protect the wiring.It takes serious conscious effort to build an electronic circuit solid enough to trip a fuse without damage, even for "fast blow" types. (The only types that are fast enough are so-called semiconductor fuses, whichareactually capable of saving the most robust kinds -- diodes and SCRs -- but nothing else: BJTs, MOSFETs and IGBTs are all too sensitive or dissipate too much fault power to be protected by them.)Fuses would be excellent if the one transformer is being used to supply the 30 sections of track, directly with no circuitry inbetween. That way, it's 100% electromechanical, from motor to track to transformer, and everything can handle faults for... seconds, minutes at a time maybe. In that case, a polyfuse might indeed be an excellent choice -- e.g., the track shorts momentarily as a car jumps the tracks, or something like that, but as it rolls off, the fault clears, the fuse cools, and normal operation resumes for the next train to come.But we're talking bipolar transistors, with weak drive current, and short-circuit capacities in the 10A range, if that. Put a 2A polyfuse on there and it'll take a solid 10 seconds to go open; in that time, the transistor's been dumping 18V * 10A = 180W into a too-small heatsink, cooked and melted. You save the wiring...but then, the fault current was already limited (until the transistor died, that is), so it would've been fine anyway.So beware -- if your mind goes to thinking about fuses, think very carefully -- and calculate some real numbers to get a feel for it -- about how much delivered energy it takes before the fuse realizes what's going on. You'll be amazed, and shocked! (But hopefully not as shocked as your loads!)Tim

author: eneuro
author_rank: Super Contributor
timestamp: May 30, 2015, 07:04:24 am
content: Quote from: MarkF on May 30, 2015, 01:32:51 amTo sense current with decent ADC speed you would need rather dedicated small MPU like ATTiny available in small packages and write a few lines of code to implement current sense and another logic to output not only PWM to drive mosfet, but eg. something like fault condition state to existing circuit (another oryginal main MPU) based on hall sensor current sensing and voltage measurement if needed.http://www.digikey.com/product-detail/en/ATTINY45-20SU/ATTINY45-20SU-ND/735466Messing with curent sensing on one big ass MPU with shared ADC with other aplication tasks might be too slow to detect danger current levels, so running another small MPU in paraller for this specyfic task or implementing it in hardware if no complicated logic needed for finding this fault condition is probably the only way to ensure fast response to current changes, while hall efect sensors shave very fast response and processing this sensed current in busy MPU with other tasks might be hopeless solution

author: C
author_rank: Super Contributor
timestamp: May 30, 2015, 07:28:24 pm
content: Current senseYou have 0 to X engines on a blockYou have 0 to X cars on a blockYou might like to be able to detect the above while still protecting against shorts.Why not use your current protect circuit to protect as well as sense the above?Just looking, the DAC's you are using are low cost, use a second DAC to set the current limit and a comparator to get the real time detection.By using the power DAC and Current protect DAC you have a simple ohm meter.You could then set a low limit and increase the voltage to the track watching for a trip and detect and count your cars if they have resistor wheels. You could also set a high limit based on number of engines in a block.The response time of your micro then becomes the min time the block's power is off.If you do not like the idea of losing power to a block so often, you could add a second comparator that tracks a little above the first comparator.C.

author: MarkF
author_rank: Super Contributor
timestamp: May 30, 2015, 11:16:56 pm
content: I guess a design overview is in order here.Each of the 15 pic16f876 microcontrollers are responsible for only 2 sections of track. Each is told the voltage amplitude, PWM pulse width, and engine direction. They should be able to sense the current or voltage of the 2 sections of track they are responsible for. It would be nice if they reported their track status back to the laptop. (Requirements creep ).I like the idea of having the microcontrollers sense problems on the track and respond. I would be happy if the voltage is turned off to that section of track and wait for an operator to respond. Automatically restoring power to the track would probably cause bigger issues. For instance, a derailment will not fix itself and the operator would not want power restored while trying to place the cars and engine back on the track.Thanks everyone for your help. This has been an excellent review of my requirements for the circuit.

author: langwadt
author_rank: Super Contributor
timestamp: May 30, 2015, 11:49:12 pm
content: using one of the numerous fully protected switches made for automotive is much simpler and pretty much bulletproofhttp://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/CD00002208.pdf

author: rx8pilot
author_rank: Super Contributor
timestamp: May 31, 2015, 08:06:23 pm
content: Quote from: langwadt on May 30, 2015, 11:49:12 pmI cannot understand why the solutions are looking so complicated. In post #2 I suggested an LT1910 which would solve the problem with flying colors. No special skills and only a few passive parts. No response. Only the solutions that way more complicated are discussed. A little baffled what the goal is - a solution or a lesson.

author: MarkF
author_rank: Super Contributor
timestamp: June 01, 2015, 12:46:17 am
content: Quote from: rx8pilot on May 31, 2015, 08:06:23 pmI haven't ruled anything off the table as yet. But to be honest, I haven't been able to wrap my head around how the LT1910 works and how I'd get the fault indication back into the microcontroller. It also looks like I'd need 2 power transistors to implement?However, I'm quickly seeing that what I need is a short detector and not a typical current limiting circuit. I've been a little side tracked by reassigning the microcontroller pins to sense a fault condition and then power down that track section and report it back the laptop. I'm also modifying the microcontroller code to determine if it is fast enough to detect a fault and the effect on the PWM timing. I started looking at the A/D capabilities of the microcontroller; but I believe the comparator capabilities a better option and would require less processor time.

author: rx8pilot
author_rank: Super Contributor
timestamp: June 01, 2015, 01:22:12 am
content: Quote from: MarkF on June 01, 2015, 12:46:17 amTo be clear, the LT1910 may or may not be perfect. It does, however, show a little of what is out there to simplify a solution like this. I do projects regularly merely to learn something, I just was not sure if this was one of those or if you were looking for the shortest path.Anyhow, the LT1910 is a current sense amplifier with an N-FET driver and some other features rolled into one device. The current sense amplifier could totally be built with more discreet parts if desired but that is a delicate circuit. Tying it into a gate driver with a charge-pump for high side N-FET's is another design challenge. Having logic level enable and fault outputs is another section of the circuit that you would have to design from scratch. In the end, super reliable and easy compared to a discreet approach.Essentially the LT1910 controls an external MOSFET of your choice. The current passes through a sense resistor on it's way to the MOSFET and the internal amplifier compares that with a reference of 65mV (I think). It will turn the MOSFET off very fast if the sense resistor drop exceeds that 65mV threshold which would happen if it was shorted. In real life, it is best to put in some delay so that normal current spikes do not trip the circuit. A resistor and capacitor network on the sense resistor determines how long it will take to react. A minor overload will take longer than a dead short. I have mine setup to turn off very fast during a short - far faster than any traditional fuse. A 43mOhm resistor would trip at 1.5A.The fault is an open collector output that you just pull up with a resistor to the MCU voltage. When a fault happens, it will be pulled low which can trigger an interrupt or however you want to scan that pin. The way my version works is that the LT1910 does all the heavy lifting for sensing and shutting down and the fault output is a simple notification to the MCU about what just happened. There is a capacitor that determines how long til it will retry and turn back on. I have the MCU allow 3 retries and then it turns off until the user pushes a button.I use them commercially for short/overload protection and general purpose load switching from an MCU.

author: C
author_rank: Super Contributor
timestamp: June 01, 2015, 07:32:35 pm
content: Track TalkbackIf you put a low pass filter between R2 and the 10K you would make talk back from the track easer. You could then build a car that talks back with information like a computer mouse. This would give you speed and distance. With the help of the laptop you could then build speed tables for each of your engines, measure the block lengths. Add a temp sensor that you could tape to the pulling/pushing engine and you could compute or find what is best for an engine.Current limit testsIn addition to direct short test, You might think of this as a test. Put all engines in one block not coupled with the end engines pulling/pushing cars. This is not a short, just an extreme load. What will your control system do? Trip out on high current or ramp up to a slow speed creep speed still be safe for the track. A lot happening here to think about. If your feeding a block only from one end, you have very high currents in the rails at one end that decrease to other end of block. Rail temp = Voltage drop * current * time.Note: you could have some engines trying to push some of the engines backwards. If an engine or car does not move in to the adjacent block, you have a fault that is not over current.Is your current limit what you really want and need? Due to the time delays out and back from the track's load/short will that transistor be steady state or will it oscillate? If you set the limit at 1.5A that would allow 1.5W when track voltage is 1V and increase to 18W when at 12V. How much of that goes in to the short or rails? Heat the rails too far and melt the plastic rail ties. I think a great current limit would be one that you could change as needed to be a little more then what is in the current block has as a load. A higher current level that when tripped turns off block power until turned on by the PIC. This could be set by a DAC or PWM. Would be nice to have a feedback on what is happening on the track so that you could try to prevent tripping the shutoff current limit. You could read by ADC or you could have a Pic controlled trip point the PIC can read set with DAC or PWM. One DAC could allow checking many things by using a LM339 to compare DAC output to test point.Note also that you could use the laptop as a very slow slave compute engine for a block PIC.C

author: langwadt
author_rank: Super Contributor
timestamp: June 01, 2015, 10:57:21 pm
content: Quote from: rx8pilot on June 01, 2015, 01:22:12 amI wouldn't even bother with the LT1910, there are tons of single package high and lowside drivers, with current limiting, overload shutdown, over temperature shutdown, status output, current monitor output, you won't even need a sense resistor it is build in.And you don't want to do PWM with a LT1910 it is very slow because the gate drive is really wimpy

author: MarkF
author_rank: Super Contributor
timestamp: June 02, 2015, 01:36:17 am
content: For those of you who are following along, I made some measurements tonight. For a 20 MHz processor clock and a 200 Hz PWM frequency, I only have 10us to 12us to measure the track voltage without effecting the PWM timing. I partially updated the pin assignments and I laid out the pins to use the microcontroller comparators to detect a short on the SENSE_A and SENSE_B pins and turn off the corresponding track block. I just need to limit the voltage of the sense inputs to 5V. This arrangement also allows me to report faults back to the laptop.The track PWM voltage is set during frame 0 and the voltage is reset in one of 1 to 127 frames. I plan on taking the measurements at the beginning of frame 1 to provide some settling time.Output A is set at 1 PWM frames and Output B is set at 2 PWM frames. Maximum frame count is 128.

author: rx8pilot
author_rank: Super Contributor
timestamp: June 02, 2015, 02:08:58 am
content: Quote from: langwadt on June 01, 2015, 10:57:21 pmYou are correct on all those points. I was hoping to make the point that integrated devices are going to be a shorter path. Was only using LT1910 as an example of the benefits of integration. As you pointed out, it would not be a good choice here. My use of the LT1910 is for high current DC load switch - not PWM.I would detect current upstream of the PWM switch and filter it to look at average current. Why measure each pulse? Use a separate MOSFET for the PWM.

author: MarkF
author_rank: Super Contributor
timestamp: June 02, 2015, 02:30:28 am
content: Quote from: rx8pilot on June 02, 2015, 02:08:58 amIt's easiest to measure the track voltage at the beginning of each PWM cycle. That way I don't need to consider how wide the pulse is. Frame 1 will always have the set voltage unless the track block is turned off. Otherwise, I don't know when the PWM is high or low.I'm not sure I understand what you mean by "upstream". The pic16f876 is the only thing that talks directly to the track. The DLP-2232PB master controller only directs message traffic and communicates to the laptop via USB. Handling all the addressing and reading/writing to the entire I/O hardware. The data rates here are low and the response time to a fault would be very long.I'm thinking I just want to measure the voltage at the high side of the motor and trigger a fault if it's below 1 or 2 volts indicating a short. The current may vary a lot depending on how many engines are in the track block. (Thinking out loud here.... so bare with me.)

author: C
author_rank: Super Contributor
timestamp: June 02, 2015, 04:21:29 am
content: Current Sensorhttp://www.allegromicro.com/en/Products/Current-Sensor-ICs/Zero-To-Fifty-Amp-Integrated-Conductor-Sensor-ICs.aspxThe ones I have looked at with more then 8 pins have a latched over current fault output which in addition to informing the PIC could be used to pull down on the base of your 2N1613 giving you a lot of time.The Voc pin sets the current limit which from what I see could be adjusted with a dacDigikeyACS709LLF-6BB-T @ $3.52700ACS716KLATR-6BB-T @4.22700MCP23S17 @ <$1.5016 SPI IOIf you just want a cheap fixed over current shutdown, a lm339 might do it.From the LM358 output drop down 3-4 diodes with a resistor to gnd. Connect one input of lm339 to cathode of bottom diode, the second to 2N3055 emitter. The normal high output of lm339 pulls low when tripped. Use the output of the lm339 to pull down on base of 2n1613 there by latching track power off. Dropping the output of LM358 should allow reset. If not then add a diode or two to ground side of resistor from LM358.C

author: MarkF
author_rank: Super Contributor
timestamp: June 02, 2015, 02:24:46 pm
content: Okay. I like the LM339 idea. Simple circuit and puts the actual work in the processor. It also solves the 5V limit needed if using the comparators in the pic16f876. I can do some filtering or averaging on the SENSE_A signal as needed.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 02, 2015, 05:30:48 pm
content: This is nonsense.

author: C
author_rank: Super Contributor
timestamp: June 02, 2015, 09:40:21 pm
content: A current sensor like the ACS7XX with latched trip could be a great add. It is bidirectional. It would function after your relay direction change. This would allow you to have sub blocks. But not cheap. Might be nice future option.The needed 15X or 30X copies does make cost a big problem.There has to be a change between the LM358 output and 2N3055 emitter based on current from circuit. If not great enough it can be made larger with a 2N3055 emitter series resistor and/or changing R1.LM339Your drawing:What you have in your drawing is compare track voltage to a fixed voltage. An requires PIC to turn off track voltage for current protection. No matter how fast you get the PIC going there is a time delay. If there is a software fault, you melt the track.Change one:LM339 output connected to base of 2N1613.Turn off track on short or over current.The LM339 is tripping with a negative change on the track voltage. Turning off the 2N3055 is a negative change to track voltage. Using the open collector output of the LM339 to pull down on the base of the 2N1613 to turn off the track output keeps the LM339 tripped. This gives you very fast over current protection and keeps the track off. Your PIC can be slow or have a software fault and track voltage is off.Change two:Voltage divider connected to LM339 negative input. Change 18V connection to LM358 Output.Make over current change based on track voltage to improve protection & assist in reset of change one.You now have the trip point changing based on commanded output. You are comparing a ratio of commanded output to actual track voltage. Current limit is getting larger as commanded output gets larger, just like the current draw of a car or engine does.Change three:LM339 positive input connected to anode of diode with 100k pull-up resistor to 18V. Diode's cathode connected to track output.Change one created a problem with getting the LM339 to switch back to normal (not tripped).The cure is to let the LM338 use track voltage + some fixed positive offset.Change two allows the LM358 output effect the LM339. LM358 output needs to go below the positive track offset voltage to undo the over current protected state. A diode or two should be enough. Note that the 100k pull-up will try to increase track output voltage. Empty track = about 1.5V, One car with 10K resistor = 0.8V while an engine would be almost 0V. Should not be a problem. Need enough pull-up to keep LM339 input happy. The 100k is a starting point guess. Replacing the pull-up with a constant current source like LM334 would be better, more cost.Note that commands to the DAC from 0 to X causes little change in the track output. The output of the LM358 output is changing but due to the forward drop of the base diodes of transistors not much happens.The results of these changes.With the PIC measuring track voltage you gain time to handle a short.You are still measuring track voltage so you can make the adjustments needed to keep track voltages constant as load changes. Think of what happens as one or more engines move into a block. With out adjustments, I think the engine speed will change.PIC Over current detect & reset.In the PIC program see three states.1. Output Off.2. Your low voltage start with PWM assist. In the Output high voltage part of PWM, read track ADC. A track voltage of less than X is over current fault. X will be a small value. If true go to over current process.3. Higher Voltage run. The higher voltage is same as pulse section of PWM.Over current Reset, set output DAC to 0.Short Check: To check if short has been removed just try to raise track voltage. The voltage that the trip happens, tells you how bad a short is present. A coin shorting track will not be the same as too many engines.C

author: langwadt
author_rank: Super Contributor
timestamp: June 02, 2015, 10:42:01 pm
content: Quote from: T3sl4co1l on June 02, 2015, 05:30:48 pmyep, Rube goldberg would be proudhttp://en.wikipedia.org/wiki/Rube_Goldberg_machine

author: eneuro
author_rank: Super Contributor
timestamp: June 02, 2015, 10:45:18 pm
content: Quote from: C on June 02, 2015, 09:40:21 pmNope, most of them is birectional, but there are also unidirectional like thishttp://www.allegromicro.com/en/Products/Current-Sensor-ICs/Zero-To-Fifty-Amp-Integrated-Conductor-Sensor-ICs/ACS713.aspx, etcSome of them listed below:http://www.allegromicro.com/en/Products/Current-Sensor-ICs/Zero-To-Fifty-Amp-Integrated-Conductor-Sensor-ICs.aspxAnyway, for really big currents in DIY projects probably SS495A will be quite cheap and integrated with MPU, writting a few lines of code can do the job.For simple overcurrent limit even TL431I voltage reference could be used to feed MPU comparator pin with preset current limits range and probably no need for DAC.As simple as it is: bidirectional current sensor on MPU pin from SS495A radiometric Hall sensor output and optionally voltage sensing on other MPU ADC.Reflow oven 230VAC 1000W bidirectional current sensor galvanic insulated from MPU almost ready and I2C MPU hardware support for other sensors needed and easy scalable solution to many DIY high power current sensing development projects

author: MarkF
author_rank: Super Contributor
timestamp: June 02, 2015, 10:56:37 pm
content: Quote from: C on June 02, 2015, 09:40:21 pmCan you clarify what you mean by this?I realize I'm relying totally on the PIC to protect the track. But, the interrupt service routine examines the track voltage every 10ms and the watchdog timer will reset the PIC and zero the track voltage if the processor hangs for 300ms. Worse case the track power will get turned off within 300ms. The only real problem would be if the PIC lost power.If I connect the output of LM393 to the base of 2N1613, I won't be able to connect it to the PIC because the voltage would exceed 5V.Now a dumb question... Won't R1 to the base of 2N1613 limit the current to some extent?

author: C
author_rank: Super Contributor
timestamp: June 03, 2015, 01:41:36 am
content: Quote from: MarkF on June 02, 2015, 10:56:37 pmYour DAC has 256 steps, 0 to 255, 18V / 255 = 0.07 volt steps. To get 0.5V out would be 7 steps up from 0 on the dac. As you lower the 18V you need more steps to get to 0.5The simple answer is you have two diodes voltage drop before larger current starts to flow.Quote from: MarkF on June 02, 2015, 10:56:37 pmThe above is true, but you do not need the output of the LM339 connected to the PIC to see it's action as the Track Voltage Drops which your PIC can see if the ADC is reading track voltage.Quote from: MarkF on June 02, 2015, 10:56:37 pmThink, V = I * R.connect R1 to X Volts and 0V, as you increase X what happens to current?connect R1 to X Volts and the transistor base. if the transistor base voltage also increases with X how does the first answer change?So YESYou need to work through the numbers for these transistors & the LM358 that drives them.Get the data sheets, check the numbers.For transistors one extreme is Saturation Full ON.This is analog so you are working between Full ON and Full Off.Test it on computer, test real thing.C

author: MarkF
author_rank: Super Contributor
timestamp: June 03, 2015, 07:22:01 am
content: I was having trouble finding a way to measure the track voltage with the PIC since the A/D function and the comparator function built into PIC require that the input voltages not exceed 5V. Needing some kind of level shifting and voltage limiting. When the LM339 was suggested, I saw that it would solve the voltage limitations of the PIC and provide a fault indication to the PIC.Estimating the total gain of the transistors and the desired current limit, I can calculate R1 from the maximum voltage out of the LM358 minus the 2 diode drops from the transistors. This should give me a gross current limit and not dump the entire power supply current when a short occurs.After that the PIC can turn off the track power most likely within 10ms. With the LM393 trigger level set at 30% to 50% of the output of the LM358.As far as loosing power to the PIC, I believe all I need to do is add load resistors to the output of the MCP4802 DACs to pull down the LM358 input if the 5VDC power goes down.I must be over simplifying what's needed. It seems that if I can knock down the power within 1/2sec of a short, any damage would be minimal.

author: C
author_rank: Super Contributor
timestamp: June 03, 2015, 05:44:56 pm
content: Quote from: MarkF on June 03, 2015, 07:22:01 amWhat comparator function? See some time compare functions but no analog voltage compare.What is so hard? Two resistor voltage divider.For 25V which should not be able to happen, look at 5 resistors of the same value or one resistor with the second 4X the first. The 12V would then be 5X less ( 2.4V) and can see a voltage change of 0.0244V if it is not hidden by circuit noise.Not a great divider, but safe.When you start lowering that 25V, would be good idea to protect against the case of the 2N3055 shorting, IT happens. The change could be a divider using three resistors so you have two tap points. Tap one always safe for ADC. Tap two could use a diode starting conduction to prevent unsafe changes at tape one. The diode could connect to a power rail.I see you needing that ADC input with ability to see a fault being more important then just a fault input.To have an idea of what is happening on the track you need E = I * RE is track voltage which changes.I is track current which changes.R is a resistance that changes based on above and what is in block.The change from using your eyes to more computer control needs the above.You still have a lot of unknown things.With out seeing the track changes, how will the computer find out that something is not going to plan.When you control the train, Your eyes and brain close the feedback loop.Think of a track layout that has no dead ends. Set a engine to speed X. If the computer can see when the engine enters and leaves a block, it could compute the ratios of block length. It could also see what block connects to what block just by running the train.Do this again and get ratio of engine_1 vs engine_2QuotetrueQuoteI would not trust the PIC.And why trust the PIC when a few almost no cost changes means you do not have too.QuoteIf you have watched some of Dave's videos you may have seed where the PC board changed color due to a resistor that was in safe limits.Think you will find that while one short may not cause visible damage, repeated shorts will.What is your big picture plan.Are you going to have signal lights?Control track turnouts?Crossing gates?If you keep the PIC's critical time sections to a min, you could do a lot with remaining processor time.To use the remaining processor time in the future you need unused IO.You will have 15 pc boards, how ease will it be to change to add something.Removing the LED would be easy to gain an ADCMoving the reverse relay connections to an IO expander could be easy or hard to do. Changing the IO expander pins would most likely be slower than a IO on PICI note you changed from LM339 to LM393, A quad comparator to a dual comparator.What is the final cost difference?Good protection would do current and voltage for each block.Remember that transistors do fail to a short. A shorted 2N3055 puts close to 18V on the track.What would this do to an engine?Remember it is easy to leave parts off a pcboard. and does not cost much compared to a new pcboard.C

author: MarkF
author_rank: Super Contributor
timestamp: June 03, 2015, 08:49:05 pm
content: Quote from: C on June 03, 2015, 05:44:56 pmThe pic16f876 has an A/D Module and a Comparator Module built in. The Comparator module contains two analog comparators that are multiplexed with the I/O port pins. Using either of these two modules would require 3 pins from port A. Which I don't really have available. After taking some timing measurements generating the PWM waveform, I don't think I have enough processor time to do 2 A/D conversions (Only 35us available between interrupts). Doing a single port read of the LM393 output during the interrupt service and turning off block power is the optimal choice from the PIC standpoint. This is with a 120Hz PWM frequency and reading the port at the beginning of the 2nd PWM segment when track voltage is guaranteed to be at the requested value.QuoteWhy not trust the PIC. The more functionality I can push into the PIC the more flexible the design is and the easier it is to make adjustments.QuoteThe big picture plan is shown in the modified hardware layout below.All of the layout control and oversight is performed in the Laptop. The DLP2232PB module with a pic16f877 is really just a messenger boy. It's the master controller for the address bus, data bus and clocking signals for the rest of the I/O.Control of track turnouts, signal lights, crossing gates and all other accessories are sent by the laptop via the DLP2232PB to the 30 relay drivers. Sensing locomotive location on the layout and any additional sensing requirements are read by the laptop via the DLP2232PB from the 30 sensor inputs.The ONLY function performed by the pic16f876 we been discussing is to control the track power for 2 blocks, set the direction relays of the 2 blocks and detect/report/respond to faults (shorts) on those 2 track blocks. As you can see by the pin assignments on the detailed overview, I don't have any spare pins and these 15 PICs will never take on additional layout functions.We haven't discussed the wireless handheld throttles. But, I hope to have the DLP2232PB communicate to them via a nRF24L01+ radio module and return the throttle position back to the laptop.QuoteThe DLP2232PB, TTL logic for 30 sensors, TTL logic for 30 relay drivers, all 15 pic16f876, MCP4802 D/A convertors and LM358 Op-amps will be on one large wire-wrap board. There will be 30 small track driver boards that will contain the 2N3055 and 2N1613 transistors, direction relay, LM393 comparator and supporting resistors. Each of the 15 PICs will interface with 2 track driver boards. I switched to the LM393 because each board will only control one track block and to save space on the pcb.If the 2N3055 shorts, I don't see that anything can be done. Any locomotive on that block would take off at full speed till it reached the next block or derails. The motor may or may not survive. I don't know what the maximum voltage is for those motors.NOTE. HO DCC track voltages maybe in the range of 16VDC to 18VDC.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 03, 2015, 09:48:53 pm
content: Why are we even talking about getting insufficient processors involved when the complete analog solution has already been posted? Of course the PIC is insufficient, it's software...Tim

author: C
author_rank: Super Contributor
timestamp: June 04, 2015, 02:42:16 am
content: LM393Look at what you have now.Between the output and the 5V pull-up, add a pull-down diode.To verify it still works look at how low that open collector transistor output of LM393 can pull to ground, and add a diode voltage drop. Does it still meet the logic low requirements of the PIC?This change allows the output transistor's collector go higher then 5V with out harm to PIC.You can then use the output to pull-down of base of 2N1613 dropping power now with no waiting.Still fault sense to PIC with added track off. Does what you want with no changes needed to program & turns off track output also.2N3055 Shorting:If you are reading track voltage, would be good idea to protect the ADC input if this happens.Some things you can protect against easy, some are harder. If you wanted to spend the money you could have a SCR turn on at a high track voltage and short the emitter to grown. The result blowing a fuse or tripping the over current protect that protects the transformer. Make this better by connecting the SCR to the 18V incoming power instead of the 2n3055 emitter. Note the SCR would need to handle a lot of current.One thing to think on is adding some over current protection to the supply that feeds all the blocks on drawing. A safe over current limit to protect transformer.Quote from: MarkF on June 03, 2015, 08:49:05 pmI see this in the "Mid-Range MCU Family Reference Manual" but not listed for your chip.Data sheet for PIC16F87X does not list a bunch of things included in above. Different PIC's include different blocks.Best thing I have found for PIC16F87X is when to start ADC conversion.QuoteFrom what I see you have one ADC with a 8 pin source selector. Your ic package prevents access to three sources.PWM, from what you have said, you are using a DAC to output PWM at low train speed setting and shifting to level output for higher train speed. Using a DAC would allow you to adjust the High voltage level & Low voltage level of the PWM as well as time. The same four bytes get sent to the DAC channel many times a second, no need to recompute here.You have connected the LDAC pin so you could output the two bytes needed for a channel level change well before they need to take effect & put them in effect with LDAC.DAC output(s) takes time to change so you could do special things before/after a level change pwm step.Like thisFor PWM go High at start of PWM cycle.Step-2 Check if ADC conversion ready, read and set next ADC channel.Step-1 Output bytes to DAC.Step 0 Start of PWM cycle, toggle LDACStep+1 compute somethingStep+2 start ADC conversionFor PWM go low which could be different for block A & Bstep-1 output bytes to DAC channel.Step toggle LDACStep+1 compute somethingAbove assumes min high or low of three PWM steps.Computing takes time, Don't waste time recomputing the same thing. In tight times spread what you can to other times where it's not so tight.Quote from: MarkF on June 03, 2015, 08:49:05 pmHow are the 30 sensor inputs different from what you could get with little change this block PIC.Sensing locomotive location & sensing cars most times is based on voltage & current. This is Four analog values.If the PIC has the time, what is the cost difference doing in block PIC vs separate.Do you have parts on hand to test with for one block?C

author: MarkF
author_rank: Super Contributor
timestamp: June 04, 2015, 04:52:23 am
content: QuoteThe 18VDC power supply consists of the transformer, full wave bridge, capacitor and fuse for basic overload protection.QuoteThe datasheet for the pic16f87x microcontrollers shows the both the A/D block and the Comparator Block. See Table 1-1 and Figure 1-1 in the device overview section. I know they have them because I've used them both before.The A/D Block relevant options are 1 analog channel or 3 analog channels. There's only one converter that forces you to serially sequence through the channels you want data for as you said.QuoteThe 30 discrete sensors are nothing but 74LS365 Hex Buffers.The 30 relay drivers are 74LS174 Hex D Flip-Flops and ULN2003 Darlington transistor arrays.A small point. The laptop DOES NOT automate any locomotive movement on the layout. It's all under operator control.Also, all of my rolling stock have insulated wheels that would not provide block occupancy sensing. I would be interested in how to do occupancy sensing but I don't want to sidetrack this thread too far from the main objective.QuoteTimer 1 and the Special Event Trigger currently generates a 15625 Hz interrupt used to communicate to the MCP4802 D/A convertor to generate the 128 step 120 Hz PWM output. The voltage is set to the high level during step 1 and reset to the low level during one of steps 2 thru 128 depending on the desired pulse width. The laptop sends the high voltage level, the reset step value and direction bit to the PIC. If the reset step value is 0, no reset occurs and the output is pure DC.If you re-examine the last drawing, the LDAC pin on the MCP4802 is tied to GND so that the voltage change occurs immediately after the PIC sends the new level. This was to meet the required sample time by the PIC before the A/D conversion. I planned on spreading out the A/D sampling and processing in the interrupt routine but I don't think I can meet the time requirements. Also, I don't have enough pins to communicate with the DLP2232PB and laptop without having a lot of extra processing to package the address bits.AS FAR AS PARTS: I have all the parts I need for testing except the LM393 comparators. The code for the 15 PICs is basically complete and I have test code running in the DLP2232PB and laptop that I'm using to try things. I have one block on a breadboard through to one MCP4802 for testing and software development. I have the LM358 chips but haven't wired them up.

author: C
author_rank: Super Contributor
timestamp: June 04, 2015, 05:19:38 am
content: block occupancy sensingQuote from: MarkF on June 04, 2015, 04:52:23 amShort answer as could thinking on block circuit.10k & 20k axles are commonly used. Replace first and last axle. Detect difference of no car on track vs the added resistance of car. Better systems can count cars in block using ADC reading current.Cheap is another lm393 or lm339 that trips when current rises above your current 10K resistor load in drawings. A low current sensor version of present max current sensor.C

author: C
author_rank: Super Contributor
timestamp: June 04, 2015, 12:24:45 pm
content: Quote from: MarkF on June 04, 2015, 04:52:23 amI would start testing block circuit. I would build a test set of programs to test hardware in future if you have a hardware problem and use it now to test design.Being able to use some PC keys to make the dac step up and down would let you control the dac while testing/checking the block IO circuit. I would use two channels of ADC to collect test connection data back to PC.You need to test R1 value and how output transistors function. Would probably like to see that dead zone from DAC value 0. Would be nice to have some voltage measurements from LM358 to track voltage with different loads.C

author: MarkF
author_rank: Super Contributor
timestamp: June 04, 2015, 08:38:46 pm
content: Quote from: C on June 04, 2015, 12:24:45 pmAs far as testing goes. My original version of this block circuit was basically the circuit in my 1st post with a DAC08 driving the Op-amp and driven by my Apple II+. The darlington configuration seemed to work fairly well. I say "seemed" because I could only generate a 10 Hz PWM with 8 steps. As I remember, the R1 value was around 5K. The current limit seemed to be tolerable when shorted with a jumper clip. I did not test it with extended period of shorts however. Through out this discussion, I've realized my first objective is to detect shorts and remove power until the operator corrects the fault. (i.e. No automatic recovery).Bottom line. I have a lot to digest and I need to get enough parts together to do more testing. Thanks to everyone for their great info.

author: C
author_rank: Super Contributor
timestamp: June 04, 2015, 10:47:38 pm
content: Here you are using R1 + base emitter drops to sense currentNeed to have idea of how this is changing. Emitter current vs voltage between R1 & emitter.C

author: MarkF
author_rank: Super Contributor
timestamp: June 08, 2015, 02:56:37 am
content: DESIGN REQUIREMENTS:Detect short on track and turn power off when it occurs. Operator manually re-enables power after track is cleared.DESIGN OPTIONS FOR TESTING:Red: Over current detection to PIC (i.e. sense current)Green: Under voltage detection to PIC (i.e. sense voltage)Blue: Typical hardware current limiting

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 08, 2015, 03:52:13 am
content: Protip: consider the blue section. It sinks current when it goes into current limit. Suppose you had a second output from one of these, so you could connect that output to near +V to generate a voltage drop across a pull-up resistor. Which could in turn be harnessed by a PNP to drive a logic input...Making that second output is the question. Lots of possibilities. You don't want to simply connect another transistor in parallel (with the blue one, B to B and E to E), because it won't necessarily turn on at the same time (difference in Vbe and temp and Ic). But if you added some offset voltage to the existing one (a series base resistor, then a high value pull-down to GND), it will switch on later, enough that the first could be used as a "current limit imminent" warning.Or you could connect another B-E in series with the first (blue) transistor's collector, so you're using that current twice. This could literally be in series (op-amp output - series resistor - added transistor B-E - output transistor base and stuff), as long as you include a B-E resistor across it so the op-amp doesn't get screwed over by the B-E diode action.A more sophisticated form uses two transistors in a current mirror type configuration. You have to arrange it so the emitter-to-emitter voltage stays small (again, allowing the op-amp to do its job).Lots of variations and alternatives are possible.You can also look at the consequences of the current limit circuit. When the blue transistor is on, the voltage drop across the resistor from the op-amp will be large, and sustained. (There may be a voltage drop under normal conditions, when the setpoint changes suddenly -- you'll want to wait for long enough pulses, like, 100s of us, before doing anything. Hey, it's current limited to begin with, so you don't have to worry!) This can be detected with another op-amp or comparator, or a transistor (the voltage difference will be gross enough that a single transistor would make a fine comparator here).Or you could read the op-amp voltage and track voltage with the ADC, and detect if they're very different (again, pulling the output into current limit causes the op-amp to shoot up and produce a large difference over the series resistor).If you'd like the latching behavior to take place all on its own, without having to bug a microcontroller with it, you can use a "protected switch" type circuit, like this,http://seventransistorlabs.com/tmoranwms/Circuits_2008/Electric_Fuse.gifor any of the "protected switch" ICs that are available (some of which, I think, have already been mentioned in this thread!).Tim

author: MarkF
author_rank: Super Contributor
timestamp: June 08, 2015, 10:55:36 pm
content: Quote from: T3sl4co1l on June 08, 2015, 03:52:13 amSorry Tim. I just can't visualize what you're proposing. Maybe you could draw me a little picture with what you think my best option would be. Although I have a B.S.E.E., I'm only following about 80% of what you're proposing. My background is more in digital hardware with 35 years of software development.1) My concern with current sensing is that I'm not sure I can define the set point. For cases where I could have 1 to 4 locomotives, the current could be any where from 0.5A to 5.0A.2) My concern with voltage sensing is that I'm not sure how well it will sense a short. It seems with this I wouldn't need to worry with how many locomotives are being powered.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 09, 2015, 12:34:05 am
content: Here's a visual aid:Also filled in most of the resistors. This is intended for 0-12V range, 2-6A current limit. The 0.33 ohm 10W resistor controls the scale of the current limit. If you want a fixed range instead of adj, delete the bottom stuff (but leave the 100 ohm resistor in the current limit circuit) and use Rshunt = 0.7V / Ilim for the fixed limit.Tim

author: MarkF
author_rank: Super Contributor
timestamp: June 09, 2015, 02:50:31 am
content: Thanks Tim. Now to understand how it worksOne immediate question that I had from before: When you tie the op-amp feedback to the track instead of its output, doesn't that work directly against the current limiting? The op-amp is trying to maintain the voltage while the current limit is trying to shut it down.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 09, 2015, 07:11:36 am
content: Precisely. Which, as long as the dynamics don't upset anything (it's kind of an over-center switch action ), will only make the readout options more solid (the current limit will turn on fairly suddenly, or the voltage detector will see it happen right on the side of the threshold).What will happen is, the current limit pulls in, reducing output voltage; so the op-amp compensates by delivering more output. But its output is decoupled through a current limiting resistor, so it can only have so much effect. If the current limit keeps the output clamped, the op-amp output will quickly swing to positive saturation (which should be around 16V). Which means we can easily detect current limit, thanks to the condition, opamp output != reg output.The divider on the comparator is necessary because, the op-amp output would never be the output voltage anyway, because it's shy by two Vbe drops plus whatever drops across that resistor. Maybe 2-3V in total, depending on load. As shown, it'll probably give flaky results at low output voltages, so it's not a good method. It should be about right if the output is always near +12V.Also, a reminder that you don't need to PWM this thing, since it's linear and regulated. I would imagine you still need a kick to get the motors moving (static friction being what it is), but that will tend to manifest as two things: you can call "zero speed" some positive offset, since it needs to be, say, 2V before it starts moving at all. Or, you can give it a short "kick" pulse, to loosen the friction (maybe 6-12V height, and for some 10s of ms in duration), before going back to a low idle state (1-2V?).Tim

author: eneuro
author_rank: Super Contributor
timestamp: June 09, 2015, 08:49:06 am
content: Quote from: MarkF on June 09, 2015, 02:50:31 amThis is DIY toy project ? Rocket science not needed to limit current and probably hybrid analog /digital solution will be better, since yuo can add logic to MPU and critical overcurrent sensing as analog in hardware to bypass digital MPU code as additional protection,so simply in the case of overcurrent switch off battery and set fault condition in analog circuit, than in a few MPU lines of code look for such condition and let decide to clear and let current fly again or keep this fault condition.Doing it in hardware and messing with analog implemented logic is hopeless solution, when you are good in software programming, unless this is NASA project trying to land humans on the Mars