LM317 digital control - Page 1
Forum section: electronics / projects

author: Maobuff
author_rank: Contributor
timestamp: May 19, 2016, 09:33:27 am
content: Im working on my own power supply project. I want to control output voltage of LM317 via microcontroller (PWM or DAC). Can some one help me with it?

author: jdraughn
author_rank: Regular Contributor
timestamp: May 19, 2016, 10:20:16 am
content: All the datasheets I have seen for the LM317 cover this. The schematic shows a few transistors which pull different value resistors to ground to change the output voltage. You could get 256 values with 8 transistors. Using a buffered DAC would give you finer control with less parts.

author: danadak
author_rank: Super Contributor
timestamp: May 19, 2016, 10:42:11 am
content: One limitation of the DAC approach is the min output voltage of a LM317 willbe ~ >-1.25V, its reference voltage. On way of handling this is an OpAmp summer,operating off split supplies, with 2 inputs, DAC and an offset you generate of 1.25V.Regards, Dana.

author: Maobuff
author_rank: Contributor
timestamp: May 19, 2016, 02:06:44 pm
content: Quote from: jdraughn on May 19, 2016, 10:20:16 amCan you show a circuit for solution with dac

author: danadak
author_rank: Super Contributor
timestamp: May 19, 2016, 02:16:05 pm
content: Very simple. take the V output of the DAC and tie it to the LM317 ref pin.Regards, Dana.

author: Maobuff
author_rank: Contributor
timestamp: May 19, 2016, 02:30:16 pm
content: I used a potentiometer as a voltage divider that give output from 0 to 5V. So this circuit will work?

author: danadak
author_rank: Super Contributor
timestamp: May 19, 2016, 04:34:00 pm
content: Yes circuit will work.If LM358 powered off split supplies then you could get LM317 output to go to 0.Also if you use a RRIO OpAmp then you will get a little better range.Regards, Dana.

author: Maobuff
author_rank: Contributor
timestamp: May 19, 2016, 04:44:14 pm
content: Quote from: danadak on May 19, 2016, 04:34:00 pmI think i used a broken one lm317.... I ll buy new one and report if it will work

author: StillTrying
author_rank: Super Contributor
timestamp: May 19, 2016, 04:55:56 pm
content: Quote from: Maobuff on May 19, 2016, 04:44:14 pmWhat's wrong with it?Without it's voltage setting resistors it will need a minimum load of 3.5mA - else it's output will float a lot higher than 1.25V.What are the supply rails for the LM358?

author: jose347
author_rank: Contributor
timestamp: May 19, 2016, 05:00:29 pm
content: you could also use a digital pot for the resistances that control the output voltage and use spi or ic2 to control the pot

author: danadak
author_rank: Super Contributor
timestamp: May 19, 2016, 07:19:10 pm
content: Actually min load worst case to stay in regulation is min of 10 mA. This compounds thedesign. But graph of load regulation shows min load going to 0, not quite consistent.Here are some notes on min load -http://electronics.stackexchange.com/questions/11919/is-it-normal-for-lm317-to-give-a-higher-voltage-without-a-loadWhat you might do is terminate the LED to the - supply you are going touse to get output to go to 0 so that it still draws current when output goes to 0.If you look at this datasheet fig 9 notice the protection diodes.Regards, Dana.

author: Maobuff
author_rank: Contributor
timestamp: May 19, 2016, 07:39:00 pm
content: Quote from: jose347 on May 19, 2016, 05:00:29 pmThey are pretty expensiveQuote from: StillTrying on May 19, 2016, 04:55:56 pmThey are connected directly to input

author: Maobuff
author_rank: Contributor
timestamp: May 19, 2016, 07:58:15 pm
content: Quote from: StillTrying on May 19, 2016, 04:55:56 pmI added a 249Ohm load to output, and get 1.25V out. And its didn't change at all. I checked op amp output and its looks normal (0-5V).Then i tried to use "classic" circuit for LM317 with two resistors, I chose 10k. From datasheet Vout = Vref*(1+R1/R2) so i expected to get ~2.5V but i get close to input voltage

author: Zero999
author_rank: Super Contributor
timestamp: May 19, 2016, 08:43:08 pm
content: Quote from: Maobuff on May 19, 2016, 02:30:16 pmThat circuit won't go down to 0V. The LM317 keeps the voltage on its output 1.25V above the adjust pin so it will vary from 1.25V to5V6.25V. That circuit has no advantages over the traditional LM317 circuit, using two resistors and the disadvantage of requiring an additonal minimum load of 10mA to regulate properly.If you need it do go down to 0V, then the adjustment pin of the LM317 needs to be connected to -1.25V. The simplest way to do this is to use the LM337L. Another way is to use an op-amp to invert the voltage between the LM315's output and adjust pin. It's more complicated but the most accurate.

author: Maobuff
author_rank: Contributor
timestamp: May 19, 2016, 08:53:54 pm
content: Quote from: Hero999 on May 19, 2016, 08:43:08 pmI know, its not a problem for my supply, and i think if i feed 0-5V to ADJ I will get 1.25-6.25 on the output

author: Zero999
author_rank: Super Contributor
timestamp: May 19, 2016, 09:00:44 pm
content: Quote from: Maobuff on May 19, 2016, 08:53:54 pmYes, you're right, it will go from 1.25V to 6.25, not 5V. Post edited.

author: StillTrying
author_rank: Super Contributor
timestamp: May 19, 2016, 09:04:06 pm
content: If the ouput of the LM317 is 1.25V with a few mA load, then the LM317 must be working OK.If you can see the op amp output varying 0 to 5V but the output of the LM317 doesn't change from 1.25V then there's a wiring error such as the LM317's Adj pin incorrectly connected to GND.The output voltage range of your circuit is going to be only min 2.2V to max 6.25V.

author: danadak
author_rank: Super Contributor
timestamp: May 19, 2016, 10:06:51 pm
content: Looking at two different datasheets they show output C of 1 uF.Makes me wonder what the phase margin is if 10 uF like you have.Note there is a graph of Zo vs f for 1 uF, maybe an estimate canbe done from that. This affects transient response, ringing due toload changes.Regards, Dana.

author: StillTrying
author_rank: Super Contributor
timestamp: May 19, 2016, 10:24:06 pm
content: You might be able to do something like this. The transistor helps to pull the ADJ pin and min load current ( 8 ma?)down to 0V. The 2 2K2s multiply the 0-5V input by 2 to give a max output voltage of 11.25V - depending on V+.

author: ZeTeX
author_rank: Frequent Contributor
timestamp: May 20, 2016, 09:55:22 am
content: dont forget your bypass caps and protection diodes if needed.R1 and R2 have a gain of 2, your buffer output goes instead of V2.

author: Maobuff
author_rank: Contributor
timestamp: May 20, 2016, 12:42:04 pm
content: Quote from: ZeTeX on May 20, 2016, 09:55:22 amI get a new LM317T.I used 249Ohm resistors. i get from 2 to 6.25V on adjust pin, and 3.25 to 7.5V on output. every thing is nice but I want to get output voltage as low as possible, any ways to do this?

author: ZeTeX
author_rank: Frequent Contributor
timestamp: May 20, 2016, 02:19:09 pm
content: Quote from: Maobuff on May 20, 2016, 12:42:04 pmHow low? if you want less then 1.25V you are going to need a very small current negative supply. there are many ways to generate a negative a supply. just google it.

author: Maobuff
author_rank: Contributor
timestamp: May 20, 2016, 02:25:05 pm
content: Quote from: ZeTeX on May 20, 2016, 02:19:09 pm1.25V its fine for me

author: Maobuff
author_rank: Contributor
timestamp: May 20, 2016, 04:17:29 pm
content: I just breadboarded my previous design at its work perfectly. 1.25 to 6.25V on output.

author: ZeTeX
author_rank: Frequent Contributor
timestamp: May 20, 2016, 05:00:34 pm
content: Quote from: Maobuff on May 20, 2016, 04:17:29 pmDon't forget minimum load requirements (the circuit I posted covers that) , capacitors and protections. read very carefully the datasheet.I don't think you need the op amp as a buffer because the adj pin is going to and internal op amp.just because you got it working without minimum load does not mean it is stable, especially if this is your bench power supply you want to build it as stable as possible.

author: Maobuff
author_rank: Contributor
timestamp: May 20, 2016, 06:32:32 pm
content: Quote from: ZeTeX on May 20, 2016, 05:00:34 pmYea but later I can use op amp as an amplifier to adjust output range of supply. Im planning to use MCP4821(DAC) which have output range of 0 to 2.048V, then i just amplify it to get a range of 0-10.75V (~5.25 gain). Which give me a output voltage 1.25-12V.I put a 750Ohm dummy load in my test.BTW can I use this circuit in my power supply for constant load?

author: ZeTeX
author_rank: Frequent Contributor
timestamp: May 20, 2016, 08:41:23 pm
content: Quote from: Maobuff on May 20, 2016, 06:32:32 pmYes, you can use this circuit with slight modification to test a variable load.C1 + R15 Is there for compensation, without them the circuit might oscillate.https://www.eevblog.com/forum/projects/yes-another-dummy-load-%29/?action=dlattach;attach=59947;image

author: Maobuff
author_rank: Contributor
timestamp: May 21, 2016, 08:47:43 am
content: This is my finnal design. IC is current control, VC is voltage control, I is measuring current.What about heat generating from Q1 and Q2. I think for Q1 it is 1.2Ohm * Icoil^2 which is around 0.012watts.And for Q2 its (Vmax-1V)*I=(12-1)*0.01=0.11watts. From datasheet i get junction to ambient which is 150K/W. So Q1 get 1.8K hotter that ambient and 16.5K for Q2. Is it true?

author: Maobuff
author_rank: Contributor
timestamp: May 21, 2016, 12:16:07 pm
content: And here is my controller board

author: Kleinstein
author_rank: Super Contributor
timestamp: May 22, 2016, 09:03:29 am
content: The analog part has a few problems: the OP does not like a 100 nF cap at it's output. So some additions are needed here, to alow the OP to drive such a capacitive load.Turning of the supply to the regulator in case of over-current is risky. A inductive load might give quite some kickback and thus damage the regulator. So there should be some over-voltage protection, at least a diode from the input to main filter cap.The way the current is measured is also not that great: the resistive divider introduces quite some error and reduces the already small voltage at the shunt. So errors are rather large. To prevent the overcurrent turn off part to activate directly when turning it on, there likely need some filtering caps / delay. With a relay you also need to have this part to be latching - otherwise the relay will immediately turn on again.The µC might need a crystal to reliably work with the UART. With some tweaking it works without if the temperature range is not to large. The 2 DACs would need separate latching / CS signals to give different outputs.

author: ZeTeX
author_rank: Frequent Contributor
timestamp: May 22, 2016, 12:35:52 pm
content: I really recommend you to build the circuit in ltspice and test test your control loop, I bet it will oscillate a lot.just wondering, how are you limiting the current? I don't know a lot about logic gates so as and interest I would like to understand what exactly are you pulling down to limit the current.(I might be wrong but it seems like the relay you are switching on with Q1 does nothing?)

author: Maobuff
author_rank: Contributor
timestamp: May 22, 2016, 01:49:49 pm
content: Quote from: ZeTeX on May 22, 2016, 12:35:52 pmR1-10 are current sense resistors, IC2A is diff amp that give voltage proportional to current (1V=1A), IC2B is comparator which compare voltage drop in those resistors and set one by DAC. If powered circuit consume more current that was set output of IC2B is high, which feed in CLK pin of flipflop. When CLK changes from LOW to HIGH value from D is pushed in to Q. Than its turning on transistor and relay disconect reguator. To turn on back relay, i need reset flipflop(basically put LOW on to CLP). Swtch part of relay is K1 near LM317.

author: Maobuff
author_rank: Contributor
timestamp: May 22, 2016, 02:00:58 pm
content: Quote from: Kleinstein on May 22, 2016, 09:03:29 amChip select pins are separate, one have IC name and other is VC. And yea its mine mistake to join latch of both dacs together. i know about current measuring error. I can minimize it by using 0.1% resistors. I will add crystal to my design. I will reduce or remove cap from adj pin of LM317, Thanks.

author: ZeTeX
author_rank: Frequent Contributor
timestamp: May 22, 2016, 02:02:23 pm
content: Quote from: Maobuff on May 22, 2016, 01:49:49 pmSo basically you just disconnect the power to the LM317? I dont think it is that good, the caps need to discharge and the regulator need to turn on \ off if you have something that gets current limited in a very fast pulses. I will test it in ltspice

author: Maobuff
author_rank: Contributor
timestamp: May 22, 2016, 02:05:53 pm
content: Quote from: Kleinstein on May 22, 2016, 09:03:29 amCan i move relay to output of supply?Quote from: ZeTeX on May 22, 2016, 02:02:23 pmYes, that why im thinking of moving relay to output

author: ZeTeX
author_rank: Frequent Contributor
timestamp: May 22, 2016, 02:22:20 pm
content: Quote from: Maobuff on May 22, 2016, 02:05:53 pmrelay for current limiting is very slow, when I build a circuit using the LT317 I got the current limiting 300us to start limiting.(the circuit needs to be redesigned, but you can get the idea).

author: Maobuff
author_rank: Contributor
timestamp: May 22, 2016, 03:24:32 pm
content: Quote from: ZeTeX on May 22, 2016, 02:22:20 pmUsing one LM317 for CC and CV is not a good solution, its lowing voltage to lower current, but what if i short wires? Its gonna drop voltage to minimum (1.25) but resistance is low enough to consume more current that I set with CC part of circuit. And relay speed is fine.

author: ZeTeX
author_rank: Frequent Contributor
timestamp: May 22, 2016, 03:41:31 pm
content: Quote from: Maobuff on May 22, 2016, 03:24:32 pmno no no, its gonna drop the voltage to 0V because I'm using negative supply. Its a closed loop feedback, the op amp is going to do whatever it has to do to get 0V output.relay is too slow for current limiting for sure.

author: Maobuff
author_rank: Contributor
timestamp: May 22, 2016, 03:52:58 pm
content: Quote from: ZeTeX on May 22, 2016, 03:41:31 pmWhy relay is slow? In my design if load consume more current its disconnect load from PSU.To connect it back i need to reset flipflop manually (or with help of MCU).

author: ZeTeX
author_rank: Frequent Contributor
timestamp: May 22, 2016, 05:44:11 pm
content: Quote from: Maobuff on May 22, 2016, 03:52:58 pmso lets say your circuit tell the relay to switch off or switch on.Relay takes some time to switch off or on because the mechanical pin has to move a couple of mm in the air, it might sound like really fast, but really if its over 1ms its too much. not to mention that a relay is kinda loud and you will probably hear it every time your PSU will go into cc mode and you will want to destroy it.Also you circuit will oscillate badly, because when lets say your load want to draw 3A while your CC set to 1.5A so the relay is gonna disconnect the load, so the cc circuit will see 0A doe gonna switch the relay on, so the current is going to shoot up to 3A and then over and over again, with NPN or MOSFET his happens much faster that it is easy to stabilize, with a relay.. not really.

author: Maobuff
author_rank: Contributor
timestamp: May 22, 2016, 06:13:45 pm
content: Quote from: ZeTeX on May 22, 2016, 05:44:11 pmSorry but you dont understand how flipflop works, if load draw more than I set its turn on relay and disconects output, and ONLY ONE WAY to connect it is to reset flipflop and turn relay off. Its acts like a RCD(Residual-current device).

author: ZeTeX
author_rank: Frequent Contributor
timestamp: May 22, 2016, 06:29:29 pm
content: Quote from: Maobuff on May 22, 2016, 06:13:45 pmThat's great, but that does not change anything I said, so you are going to need to reset the relay, you want other loop \ micro controller to do that? that is just slower.if you want your power supply to limit the current to any value then 0A you are going to need a feedback that maintenes this current, usually by an op amp controlling the the pass transistor, but if you have a relay that takes a couple of ms to switch you cc will be really, really slow.So lets say that you want to maintain an CC of 1.5A, you relay will have to turn off and on very very very fast, or else you are going to have a very slow current limit, because until the relay switch on or off the current shoot up and the poor op amp cant do nothing because a slow relay is limting the speedBest way is to simulate it or build your schematic and see the result. There is a reason no power supply ever in a world uses a relay to pull down or turn off the output. (its also much expensive then a MOSFET or NPN).

author: Maobuff
author_rank: Contributor
timestamp: May 22, 2016, 06:39:53 pm
content: Quote from: ZeTeX on May 22, 2016, 06:29:29 pmBut i dont need a CC in my PSU, just overcurrent protection.Quote from: ZeTeX on May 22, 2016, 06:29:29 pmRelay make thinks little bit easy. And im currently using power supply with sama overcurrent protection.

author: ZeTeX
author_rank: Frequent Contributor
timestamp: May 22, 2016, 06:50:16 pm
content: Quote from: Maobuff on May 22, 2016, 06:39:53 pmif you only need overcurrent and not constant current then relay is fine, for a bench power supply I was pretty sure you are going to use constant current. anyway relay is fine then.

author: Liv
author_rank: Regular Contributor
timestamp: May 22, 2016, 10:22:24 pm
content: Quote from: Maobuff on May 22, 2016, 03:24:32 pmUsing LM317 beyond its standard features is a bad idea. I recently made a PSU adjustable 0..±15 V and 0..+5 V based on LM317/337. The number of auxiliary parts was larger. In addition, it was necessary to add the supervisor scheme, since the power is turned off at the output there was a voltage surge. If you need a power supply with CC and CV modes, properly do it on discrete components.Hereis a good example of a simple power supply with the processor control.

author: Maobuff
author_rank: Contributor
timestamp: May 23, 2016, 09:57:04 am
content: Quote from: Liv on May 22, 2016, 10:22:24 pmNice PSU there. Actually its ok to use lm317 as CC, there a circuit in datasheet. But its hard to control it digitally.

author: ZeTeX
author_rank: Frequent Contributor
timestamp: May 23, 2016, 11:46:40 am
content: Quote from: Maobuff on May 23, 2016, 09:57:04 amUsing LM317 As constant current and other LM317 as CV is using it standard features, they give you a schematic with CC + CV in the datasheet.

author: ZayneTech
author_rank: Contributor
timestamp: February 02, 2019, 10:02:52 pm
content: http://www.circuitstoday.com/few-lm317-voltage-regulator-circuitsCheck out this picture

author: RES
author_rank: Regular Contributor
timestamp: February 04, 2019, 09:12:41 am
content: Another idea.

author: Zero999
author_rank: Super Contributor
timestamp: February 04, 2019, 12:02:33 pm
content: Quote from: ZeTeX on May 23, 2016, 11:46:40 amYes that works, but a big downside of using two LM317s in series is the huge drop-out voltage, as they both add together. The CC circuit will need the usual 3V of headroom plus 1.25V, giving 4.25V, plus the CV circuit requiring the usual 3V: a total of 7.25V!Quote from: ZayneTech on February 02, 2019, 10:02:52 pmThe base resistors are missing.It works better with MOSFETs.

author: spec
author_rank: Frequent Contributor
timestamp: February 04, 2019, 12:58:15 pm
content: Below is yet another schematic for a DAC controlled LM317 PSU which is scaled for 0V to 3V input to 0V to 30V output. Although the output goes down to 0V, a separate negative power supply is not required.The scaling can easily be changed according to the formula Vout = Vin * (1+ R4/R8)The three diodes must be 1N540x types and should be mounted in cool free air for heat dissipation.The schematic is an outline, so decoupling compactors, frequency compensation (if required), etc are not shown.Also there is no optimization, or fault analysis, and there is probably an issue if the LM317 goes into constant current, but nothing that can't be sorted.

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 04, 2019, 06:04:29 pm
content: Technically, you're still generating a negative supply.(It's going to make a nice heater...)You can probably get away with a higher value for R2, so the opamp will have to sink a bit less current.As a remark, we can see that whereas the opamp sinks ~7mA when the LM317 is not limiting current, when it starts limiting current, depending on your input voltage, the opamp could start sourcing current instead of sinking, and depending on the input/output voltage/and how much current the opamp is able to source, it could get pretty hot in this situation.

author: spec
author_rank: Frequent Contributor
timestamp: February 04, 2019, 10:22:50 pm
content: Quote from: SiliconWizard on February 04, 2019, 06:04:29 pmVery profoundThe heat generated by the diodes, will be insignificant compared to the heat generated by the LM317 itself, not to mention the heat generated by the other four diodes in the bridge rectifier and the load itself.Quote from: SiliconWizard on February 04, 2019, 06:04:29 pmThe opposite is true. From the LM317 data sheet (link below), the minimum output current for an LM317 is 10mA, so R2 should be 125R maximum rather than 180R. A practical worst-case opamp dissipation would then be 36V x 10mA = 360mW, which is hardly a problem, especially if you use a decent opamp. Anyway, there are probably simple methods of reducing the opamp dissipation if absolutely necessary.Quote from: SiliconWizard on February 04, 2019, 06:04:29 pmI already said it was an outline schematic and there could be an issue if the LM317 went into constant current. It is not exactly a difficult problem to sort though: a Schottky diode may do the job. The purpose of the outline schematic is illustrate the principle of the design: it is the architecture that counts.http://www.ti.com/lit/ds/slvs044x/slvs044x.pdf

author: iMo
author_rank: Super Contributor
timestamp: February 04, 2019, 10:53:59 pm
content: Quote from: spec on February 04, 2019, 10:22:50 pmYou may have 317' 10mA min current and 50uA opamp current (the ADJ current).

author: spec
author_rank: Frequent Contributor
timestamp: February 04, 2019, 10:54:40 pm
content: Quote from: SiliconWizard on February 04, 2019, 06:04:29 pmVery profoundThe heat generated by the diodes, will be insignificant compared to the heat generated by the LM317 itself, not to mention the heat generated by the other four diodes in the bridge rectifier and the load itself. And then there would be the heat generated by the user: 100W.Quote from: SiliconWizard on February 04, 2019, 06:04:29 pmThe opposite is true. From the LM317 data sheet (link below), the minimum output current for an LM317 is 10mA, so R2 should be 125R maximum rather than 180R. A practical worst-case opamp dissipation would then be 36V x 10mA = 360mW, which is hardly a problem, especially if you use a decent opamp. Anyway, there are probably simple methods of reducing the opamp dissipation if absolutely necessary.Or are you suggesting that the LM317 output has current drawn off it by another means, so that R2 can be an open circuit, when the tail current would be only 50uA or so.Quote from: SiliconWizard on February 04, 2019, 06:04:29 pmI already said it was an outline schematic and there could be an issue if the LM317 went into constant current. It is not exactly a difficult problem to sort though: a Schottky diode may do the job. The purpose of the outline schematic is to illustrate the principle of the design: it is the architecture that counts.http://www.ti.com/lit/ds/slvs044x/slvs044x.pdf

author: spec
author_rank: Frequent Contributor
timestamp: February 04, 2019, 11:05:14 pm
content: Quote from: imo on February 04, 2019, 10:53:59 pmOur posts crossed.Yes you are quite right: 10mA is the minimum current for an LM317, not 7mA as I indicated on the schematic of reply #52. You can reduce the LM317 tail current by connecting a current mirror of 10mA to the output of the LM317, or you may get away with just a resistor, depending on the output voltage range in use.

author: not1xor1
author_rank: Frequent Contributor
timestamp: February 05, 2019, 08:55:39 am
content: Quote from: spec on February 04, 2019, 10:54:40 pmMost LM317 work flawlessly with just 3-4mA of load. If one just needs to build 1-2 PSUs can test the ICs for stability on a breadboard.A different but still valid approach is to provide a 10mA constant current sink for the LM317. Then the value of the resistor between output and adjust is no longer critical.BTW a relative high power dissipation in opamps affects their performance.

author: Zero999
author_rank: Super Contributor
timestamp: February 05, 2019, 09:27:26 am
content: not1xor1,The LM317 definitely is specified for a minimum load of 10mA. Most devices will work with much lower minimum load currents, but relying on 4mA is marginal design.Quote from: spec on February 04, 2019, 10:22:50 pmP = IV so irrespective of where the voltage is dropped, the same amount of heat, in terms of Watts, will be dissipated. I know what you mean though: it won't be as hot as dissipating all of the power in the LM317, as it's more spread out.QuoteYes,a current sink could be added, but in this case it's not needed: the resistor is fine since the op-amp effectively has a negative supply.The main issue with this circuit isn't the power dissipation or LM317's minimum load current, but the voltage ratings of the components. What transformer voltage do you recommend? The original schematic showed a 22-0-22V primary, but no secondary voltage. Presumably it was inadvertently drawn mirrored and you meant 22V-0-22V secondary? That would give a DC bus voltage of nearly 62V, which would be far too high, so that doesn't seem right either.To get 30V out, the LM317 needs at least 33V in, plus five diode drops, nearly 1V each at full load, giving a minimum DC bus voltage of around 38V. At first glance, a 30V transformer looks like a good fit, as it would give just over 42V out. The trouble is it's a marginal design. When unloaded, the transformer voltage will be around 10% higher than its fully loaded rating, the diodes will drop less voltage and the mains voltage could also be on the high end of the tolerance band, another 10% in the UK, causing the DC bus voltage to be much higher. VDC= 30*√2*1.1*1.1* - 1.2 = 50V. The LM317HV could be used, which is rated to 60V, but finding op-amps, which can do this is more challenging.Another problem with the LM317 is its safe operating area protection kicks in when the voltage difference between its input and output exceeds around 15V. Using a centre tapped transformer and a relay or transistor to select between the centre tap, depending on the output voltage will alleviate this to some degree.