Constant current source adjustable by PWM - Page 1
Forum section: electronics / projects

author: delphes123
author_rank: Contributor
timestamp: June 07, 2023, 01:36:06 pm
content: DearI would like to get Constant current source, but the level of current needs to be adjustable (from 0 to 20 MA approx), I need to have very low cost of BOM, best is to avoid OP Amps if possible.R3 is the charge where I need constant current.The idea is to replace V2 source by MCU PWM outputHow this schematic could be improved? Does Q2 needs to be replaced by Mosfet ?Thanks

author: paulca
author_rank: Super Contributor
timestamp: June 07, 2023, 01:53:48 pm
content: 20MA ... that's a lot of current! I assume you mean "mA".

author: schmitt trigger
author_rank: Super Contributor
timestamp: June 07, 2023, 03:53:13 pm
content: Why are you against using an opamp? Why are you restricting the use of a component which will make your life easier and performance better?

author: delphes123
author_rank: Contributor
timestamp: June 07, 2023, 04:30:13 pm
content: Yes sorry typo is mA of course

author: delphes123
author_rank: Contributor
timestamp: June 07, 2023, 04:31:18 pm
content: Not using OP Amps is mainly cost problem with this project, but if there are no solutions why not ?

author: magic
author_rank: Super Contributor
timestamp: June 07, 2023, 04:53:47 pm
content: This may work. The PWM signal should be filtered with an RC circuit, unless the load can tolerate pulsed current rather than DC.Accuracy won't be ideal because Vbe of a transistor varies from specimen to specimen and over temperature. There will be some minimum PWM level required to reach ~0.6V at the base and start conducting anything at all.BJT is probably better than FET due to lower Vbe. FET has the benefit of no base current and higher accuracy, but that's important for more "high end" circuits.

author: schmitt trigger
author_rank: Super Contributor
timestamp: June 07, 2023, 05:14:26 pm
content: It can work, but the performance will be reduced. Meaning the temperature dependency and larger filter components for a given ripple level.Everything depends on your exact requirements.

author: Benta
author_rank: Super Contributor
timestamp: June 07, 2023, 06:27:44 pm
content: It'll work, provided you include a series resistor between MCU and the diodes.But it won't work well, the 1N4148 VFcurve is extremely soft. How precise does this need to be?

author: delphes123
author_rank: Contributor
timestamp: June 07, 2023, 06:34:30 pm
content: Thanks for all answer, the precision is not so important, the most important is to be sure PWM signal can offers a wide range of mA on the output, I mean from 2 to 20 mA for example.How you will place the filter to avoid too much ripple ?

author: Benta
author_rank: Super Contributor
timestamp: June 07, 2023, 07:31:08 pm
content: What filter?You didn't mention that you want a DC output. PWM is PWM.

author: delphes123
author_rank: Contributor
timestamp: June 07, 2023, 08:16:59 pm
content: The 12 Volts source provide DC voltage for the constant current circuit, the PWM source (5V source on schematic) is independent but PWM will reject on the 12 volts source, so RC filter is needed.

author: Benta
author_rank: Super Contributor
timestamp: June 07, 2023, 09:26:30 pm
content: Ah, power supply decoupling. That's a different issue.Concerning the CC driver, I looked through my archives, as I had to do the same a couple of years back.This circuit works well and is reasonably precise. Increase R1 to 3k3 for 5 V PWM:

author: pqass
author_rank: Super Contributor
timestamp: June 07, 2023, 09:50:02 pm
content: See attached schematic and play with it via link below.The first circuit uses a pot adjusted Vbe multiplier.The second circuit uses a PWM@1kHz that can be adjusted from 12% to 70% to achieve 200mA to below 1mA CC.The smoothed PWM may be a little wiggly and slow but you can work on that.Or, via the SPST, use a DAC that can be adjusted from 1V to 2.8V for the same range.http://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWEAmA7NVbnIBwBYFkBmMIogThxAUmutoQFMBaMMAKABcVMQjlaRSHj4Co4EK2gIauVKhz9iNSMijSE5SKjxhcANjLJ9+tWDggAJowBmAQwCuAG07swOkDkH6qYPCNxfcHhaGGE8fRAABQB7TkYAO04ASxiAW0Z4gCd2LM9abBEwfQLkEUEtSHYAdz5hPh86kTJIqtqhZvqOnjUq7haekH8qLHEIZnJoHC1DLxwcP34icox+E2QtMBx9cjI2YNpre2dXPOGUeaG8KiJG2n0pmqubxoHbqiqiVFpzvSpz5AISIQULsABKz3AuEhXnEP1oejh6gQ7AA5pD3pC8BZQRDumw1N1YaEhgwkTAUV9BPUCU1wCUJKC8viGd1CmN4E83q8uncubdBmzeFUAA58AWjbk3OHsSx09lCtRqI6OFzsKngVCRfgFXg6xlQdhi9zasQmhrS0G1c2Y7qYtr5FBlR2jT7feXO4qlIoyvKwzE2u7iuBPG1m-yiUFi-TYob8EAxhjQogy2qJuNqEr-eMO9OEKhZ6jQqp5Qv6sv4DkhjWF0Zls0yiG13i12Mk2NIEkUtEgVCEItUPtqIFd8G9-uBcdKtviWOIrvSdXuocXQf93TA1NTgcJjvF3Lb84r-PiB44Li7n7xld4HMSCZTHAIBTaIiKPwrVD8If8BDDbH6BA5iHLYqquGmkD-DGCaQRmhoQVQJ6Fng5CtBez6RNc9ywVhYySGA0jYHouzYmwXyaOQyLkAI0zUWAz5bNiKbAVYoEnAeCCIrhG5DMSQzfCGeLrtckaQu2CKwL0cKLhqnFqLhGG8QiMpinJSnUIiJ4plaGnDtChYnrmsFviIyE5mOH7qbSuEQGY8AoNIDmduopDIOwADKQzFEM0FEOu0EkvYTgAM6MOIbm1DxJ5qYZB6AphsLmrhCKcgAxigQLqfFO6hLAITkAVhVFcVlEEXAQjEGAWhvrcujaXlHBijx3HeVpW7ZVpAqxZF3kRCIzXEvyCWCOug3tF10JRfucqWTZWpZaxxxqsyAq4QMhlOiGtTZWtq2DapiKTmptpbsdjTnPaTxqZOAKXA6CyYSJN4ifdrXQse+5ig9MJvZahoxD5QziO8JjBOocCmM58nauwAMICm5SkpQ4DQIC4PwOQWpAmjBTUCmRDqv8EAAGIgsD+EgAAwjESRZDETgADrBQAavTnB2KijCE4DpN0OYIBaBTlMADIANJMwAIg4nAAJ5M5TMupU4XNAAEDIT:I forgot to change the beta (to 25) of the main (right) transistor to better reflect that of a power transistor so a few resistors in the BJT version would need tweaking from what is shown.Additionally, I've attached a MOSFET version. Simulator link below.I think the values chosen should work for a logic-level MOSFET like the IRLZ44.http://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWEAmA7NVbnIBwBYFkBmMIogThxAUmutoQFMBaMMAKABcVMQjlaRSHj4Co4EMyLQAbHn5g8+IqhzlUCckSjQEctoWR4ZqyAiIiwcEABNGAMwCGAVwA2ndmFQicgmVUURXADweFoYMwIQAAUAe05GADtOAEtYgFtGBIAndmyQXxQjcDwg4to0eHYAdz5hPn86kTIZKBqmjqEg3kg8kFKqYP6lBqpaK3aB0b4iVtmx9hVaKbBcYcG9CXD2ACV18DWpwvD+8eRxcN12AHN9+f28a229rvBVjuPxR7oTmARF1CCepsc6vMAycYXPpgiEdbAicZVWotaave69ZGzHig+pYNoABxmrTxKPu2m2S3AqDmYhJYgg20JXhp42pqKhtWZqPq6PahXhBQqPQBQLKllKRUsUPyhXuXPR-UBGKpLJKzTEvUJcmW-BA2uoa3JbVq+vk5whVDNxr130IVAtBoW+Qd-FoLvw4iscBFesgg14LvpUL2Drxoe+J1tFx0-1uGnOdpA8eosOeScIKBwVGTRl+pwO0b+PpzWfT5zw4K21uTif1id6+WTUxra0R7QdxhEHd1yodtb9-XIrV63AQbKUboHE89kmk-jwyBMXSHs3IMf8mn4FlQqCEgPOXtsDhc7j6CHe04rrWntBwAm9LwzU1d+0jgkLV0p5-LhTH18KDIEtQF6-u8iZGsq36Or6VD1rsar9ABIGQge8AoLo6FIJcVi+GEeHwBwADK-SVp2fBPnI0ZOK4ADOjDiMgkyVomUFwfkyCbNOXI3qE3oAMYoJx-KbPWOh4eQEmSVJ0lrjAOB-mQeDqDIhBKVoYmQBwhJXohyzMYaHKCa04FYnBtQ6WRFnHO0KLTkQT7WZixmHPpCw2AhXHjvyR5OG4Hj5LZsqma2RTerUHH-oIWI3uwhJQUMUFkoZiWNM+jSQe8QxTEMyo4KRIxNiMuWuWW0GagU+VUHlzlUBB7D2DaOrnE2uq6geCDQGA57nvVRLYvsdIoOAHVdaN7Dua8AqTbw5x2L5p7ue6XZTm1Pknh4sT9OW4jzDIrRWBpMgcQxW18Owm1Kf0XyQJQPywPAyl6MdFSDmdRC1VQABigHvqwIAAMKxMk2SxK4AA6NEAGqg5wjjXIwiyWuc310Ad5C0H9-0ADIANIQwAIs4nAAJ4Q-9xN8a4CNAA

author: Benta
author_rank: Super Contributor
timestamp: June 07, 2023, 10:01:07 pm
content: I count 9 parts instead of just 5.And I see no CC functionality at all. Cute graphics, though.

author: pqass
author_rank: Super Contributor
timestamp: June 07, 2023, 11:07:45 pm
content: Quote from: Benta on June 07, 2023, 10:01:07 pmWah?You've proposed a fixed current LED flasher.The PWM just shuts off the LED in the low state or enables the transistors to pass a fixed 18mA in the high state.I proposed (1st circuit) a Vbe multiplier that behaves like a variable zener between base-emitter of the main (right most) transistor. Or, (2nd circuit) turns a voltage into a current (through the 47K) into the base of the left transistor that varies the voltage between base-emitter of the main (right) transistor. In both cases, the main (right) transistor base -0.7V over the 6.8R produces a true variable current.Yes, there's 4 more  parts. But the current through the 6.8R emitter resistor can be varied via the pot, DAC, or PWM duty cycle.http://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWc0DMAmALGNkdgJxgIBsCaaICkll1CApgLRhgBQALiBhgBwhoB2Cr2qCK1CIx7QePbJAT40KYvh4pIEGMQEL8KHphTGBGFBDBwQAE3oAzAIYBXADbsOXHtWPEQKMn4qUOAgjDACGsRgsmBROKqCUNDECgLEaEr4JAoIQuBWto6u7gDunqKy5YG+kKwATlU+VRhW3iisAObNViJcscG1Zf4Uw34BLdSDY8I9Xlyt9Vy8-HmjYsHGtQ1reWgkK+L8OFM7IwHok6yxwnNgaVV7vhSFzm6MLvTWIZNJmqwASlVsHxesQMAN5uBDpNoAgAfx9utYqI8hAKJYrGhYfxsTC0qwULogWgQbd7looKwAPZQ75+Yg8Yi+JAwODpFn8WkoEAAYQAMgBpal+OkqRk1ZJ7X5S0Qi7nGf4EvjYEAAMQgHIxoQg-IFAB0AM4AESc7AAnoaeWaAMYfVhAA

author: Benta
author_rank: Super Contributor
timestamp: June 08, 2023, 12:18:59 am
content: Quote from: pqass on June 07, 2023, 11:07:45 pmYes. Which is exactly what the OP asked for.A constant-current source that can be PWM'ed from a microcontroller output pin. In the simplest and cheapest way possible.The circuit I posted is pulsed at 10 kHz, 30% in the schematic. Dunno if that counts as a "flasher".The blinking LED in your "falstaff simulation" is somewhat off.Here's a pro simulation (Spice) of the load current:

author: PCB.Wiz
author_rank: Super Contributor
timestamp: June 08, 2023, 01:04:25 am
content: Quote from: delphes123 on June 07, 2023, 01:36:06 pmQuote from: delphes123 on June 07, 2023, 08:16:59 pmQuote from: delphes123 on June 07, 2023, 06:34:30 pmThe lowest BOM, and best precision and stability, will be if you can use an ADC channel on that MCU, and read the current resistor.The transistor or MOSFET Vbe/Vgs then do not matter, nor does the temperature variations.Then you just need a PWM filter, commonly two stages of RC.Otherwise, just use an opamp. They come in SOT25 packages, at low cost, and you do not need to calibrate a less-ideal transfer graph.

author: pqass
author_rank: Super Contributor
timestamp: June 08, 2023, 01:34:14 am
content: Quote from: Benta on June 08, 2023, 12:18:59 amWell, I guess we have different ideas on what "...but the level of current needs to beadjustable(from 0 to 20 MA approx)," means; digital vs analog. In that case, his original circuit only lacked a base resistor.Falstad (or similar) shouldn't be taken as gospel but just as starting point before the breadboard/prototype stage.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: June 08, 2023, 02:24:40 am
content: Quote from: delphes123 on June 07, 2023, 01:36:06 pmI love how spice lets you whack 5V across two series diodes.You seem to be ok with large drop across the emitter resistor, which is the most temperature tolerant, so the simplest filter-able circuit would be to ditch the 2 diodes and replace with a PNP emitter follower, and a pullup on the NPN base. (That can pullup to 12V)That gives you 'nominal' vbe tracking and a high input impedance at the PNP base, where you place the PWM filter.A dual transistor package would improve that tracking.It may not drive fully down to 0mA, but it could manage 2mA~20mA.You can nudge the lowest current down, by connecting the PNP collector to the NPN emitter, instead of the more usual GND.Now, base current steered by the PNP, subtracts from the NPN Vbe.

author: delphes123
author_rank: Contributor
timestamp: June 08, 2023, 07:30:00 am
content: Thanks to all for the discussion which gives me more information, however I am little confuse now and the reason is that I was probably not enough clear, let me explain again please.the level of current needs to be adjustable (from 0 to 20 MA approx) should bethe level of current needs to be adjustable (from 0 to 20 MA approx) by PWM from MCUIn fact the PWM (on V2 supply) will be use only only to determine the value of constant currentMy application will needs like (this is just an example)PWM = 30% Constant current = 8 mAPWM = 60 % Constant Current = 16 mAetcIn all your ideas what solutions can achieve this ?

author: tszaboo
author_rank: Super Contributor
timestamp: June 08, 2023, 07:57:18 am
content: Buy a 20mA current regulator diode/led driver and place it in series with your transistor.Like NSI45020A

author: PCB.Wiz
author_rank: Super Contributor
timestamp: June 08, 2023, 08:02:22 am
content: Quote from: delphes123 on June 08, 2023, 07:30:00 amThose are non-linear PWMs, for full scale of 20mA = 100% ?This latest post does not mention PWM filtering, but previous ones do ?Suggestions have already been made above.If you really need to cover 0mA (or let's say 5uA) to 20mA, just use an OpAmp.Otherwise, you will need to calibrate the transfer of a bipolar design.

author: magic
author_rank: Super Contributor
timestamp: June 08, 2023, 08:04:22 am
content: Quote from: tszaboo on June 08, 2023, 07:57:18 am20 mA ± 10%? OP's circuit can do better than that if the 5V rail is any good.And this thread is going nowhere without the OP clarifying if it's supposed to be a DC current source adjusted by PWM or a PWM'd 20mA current source.

author: delphes123
author_rank: Contributor
timestamp: June 08, 2023, 08:08:32 am
content: It's a DC current source adjusted by PWM

author: magic
author_rank: Super Contributor
timestamp: June 08, 2023, 08:27:32 am
content: So it looks like you need to RC filter it down to the average DC voltage and then do something with it.The "something" could indeed be as simple as 2N3904 with 220Ω from the emitter to ground, if this level of accuracy doesn't bother you.One completely different option is "open loop buck" - i.e. a buck converter with the switch transistor driven directly by the PWM signal. But this needs an inductor instead of capacitors and may or may not be cost effective; I'm not very familiar with volume pricing of passives.

author: tszaboo
author_rank: Super Contributor
timestamp: June 08, 2023, 09:23:57 am
content: Quote from: magic on June 08, 2023, 08:04:22 amHave you seen any specifications?

author: delphes123
author_rank: Contributor
timestamp: June 08, 2023, 01:19:19 pm
content: NS145020A is a good component but it has fixed 20 mA constant current, how I can manage with this component any other value of current between 0 and 20 mA ?

author: magic
author_rank: Super Contributor
timestamp: June 08, 2023, 04:06:39 pm
content: You could PWM the power supply to this chip and get a lower average current, but it would be pulsed 20mA rather than constant 5mA, 15mA or whatever.Some people assumed that you are OK with the output being PWM'd, hence such suggestions.It seems you are not, so filtering is the way to go. Maybe 1kΩ and 1μF would be good enough for Australia? Two easily available passives, not too expensive in SMD...

author: PCB.Wiz
author_rank: Super Contributor
timestamp: June 09, 2023, 05:36:28 am
content: Quote from: delphes123 on June 08, 2023, 01:19:19 pmWhat exactly do you need to drive with this? LEDs are quite different from instruments 4~20mA.What precision and temperature variation do youneed?

author: DavidAlfa
author_rank: Super Contributor
timestamp: June 09, 2023, 01:46:16 pm
content: Trying to do this with discretes makes no sense at all, you'll end using more parts, making the design more complex and perform a lot worse.You have LM324 / LM358 op-amps for 3 cents in lcsc, or around 10 cents in normal distributors.

author: magic
author_rank: Super Contributor
timestamp: June 09, 2023, 04:57:50 pm
content: Nope, it's making the design more complex with more parts OR perform worse. The latter may be acceptable.And LM358 can't implement this kind of current sink by itself, not without ugly kludges which may or may not work (tie OUT to V+ and IN- to GND, minimum current is 1mA, no warranty). So you are looking at more external components and more than 3 cents.

author: delphes123
author_rank: Contributor
timestamp: June 09, 2023, 06:10:37 pm
content: In order to clarify , it is not a led driving, it is more complex to describe the use case, but it is a resistive charge (with probably a very very low capacitive)I need to produce a constant current at different level between 0 to 20 mA max during a certain amount of time (very slow events)like 0 to 2 sec = 20 mA2 to 4 sec = 10 mAetcPrecision is not very impressive let say 10% is ok.I would prefer for many reasons a very simple transistor solution with PWM to control the level of mA.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: June 09, 2023, 08:18:49 pm
content: Quote from: delphes123 on June 09, 2023, 06:10:37 pmIs that 10% of full scale, or 10% of output, meaning 2mA is within 200uA , or now 1% of full scale.What voltage(s) is across your ‘resistive charge’ ? The power in the output device needs to be considered.How many of these will you make ? What is operating temperature range?Are you ok with a calibrate curve (look up table ) in flash ? That will be needed to get 2mA@10%.You probably would not need to curve re-calibrate every single unit, but single point calibratewillgive you better performance, so you should allow for that, in your production costing spreadsheet and jigs.In practical terms, I’d expect same-reel calibrate to be ok here.An opamp does not need a look-up-table, but you ( or your tutor ?) has excluded the opamp.

author: delphes123
author_rank: Contributor
timestamp: June 09, 2023, 08:23:38 pm
content: Is 10 % of ouput 10mA +- 1 mAVoltage with be variable due to constant current, but it is powered by 12 Volts initiallyit will operate between 10 and 30 °cYes of course I can have a lookup table and calibration can be made for each.

author: tszaboo
author_rank: Super Contributor
timestamp: June 09, 2023, 10:54:07 pm
content: Quote from: delphes123 on June 08, 2023, 01:19:19 pmYou drive it with a transistor, which has the PWM signal on it's base/drain, and then smooth the signal (bypass it) with a capacitor.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: June 10, 2023, 12:04:04 am
content: Quote from: delphes123 on June 09, 2023, 08:23:38 pmGood, here are a couple of options. They assume you have access to the 12V and it is regulated.Test is by a linear ramp, with 5ms == 5V and R1 is used as an ideal-load check, allows simple error as a difference plot I(R1)-I(R2)First is a classic/simple PNP.NPN pair that gives nominal VBE compensation, but it cannot quite get to 0mA, min is around 100uA, due to Vbe effects. 100uA may be 'good enough' for your needs.Second design splits the emitter resistor, and steers some base current to allow a reverse offset effect and that can get closer to 0mAHere, I've adjusted it for a ballpark 12 bit ADC 1-LSB as a zero-point.The error curves that you need to compensate, in a table, you can see in the graphs.You should closely thermally couple the Q1.Q2, and Q1 needs to have decent HFE.Addit : added a 5V bias version, does not need 12V connection, and the lower RE does not need a split to give ~5uA zero compensate.Drive is divided by 2, to give some bias on R2, which also improves the Q1.C load-range to below 5V

author: delphes123
author_rank: Contributor
timestamp: June 10, 2023, 09:10:06 am
content: Thanks alot I did simulation and it works, just last question remember V2 is from PWM (MCU) does it needs any filter on the output to drive transistor base ?

author: PCB.Wiz
author_rank: Super Contributor
timestamp: June 10, 2023, 07:34:31 pm
content: Quote from: delphes123 on June 10, 2023, 09:10:06 amYes, I just left that off to allow simple ramp testing.The 10k PNP base resistor can split to a double RC filter to suit your Pwm.If you only slow change this, there is plenty of scope to filter.

author: delphes123
author_rank: Contributor
timestamp: July 20, 2023, 07:27:18 pm
content: @pcb.wizThe first solution you give me works perfect as same as simulation you did , could you change V1 to 5 V for me and tell me what value of R4 need to be there ?ThanksRegards

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 20, 2023, 07:55:50 pm
content: Quote from: delphes123 on July 20, 2023, 07:27:18 pm#35 above already has a 5V sim, with other minor changes too. R4=3k3

author: delphes123
author_rank: Contributor
timestamp: July 22, 2023, 01:27:47 pm
content: on #35 I only see V1 = 12V

author: Zero999
author_rank: Super Contributor
timestamp: July 22, 2023, 04:16:30 pm
content: The circuit attached to the original post won't work. D1 & D2 will blow up, as there's nothing to limit the current.Is it really PWM to a linear constant current, or just PWM'd constant current which is required? Is the 5V supply well-regulated?Is it a purely resistive load?

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 22, 2023, 08:24:42 pm
content: Quote from: delphes123 on July 22, 2023, 01:27:47 pmPNP_NPN_current_Sink_5.PNG has a new V3 added, for 5V supply to R4