Author Topic: AVR Controlled LM317  (Read 14982 times)

0 Members and 1 Guest are viewing this topic.

Offline themacman33Topic starter

  • Contributor
  • Posts: 19
  • Country: us
AVR Controlled LM317
« on: April 23, 2014, 09:30:28 pm »
I need to make a portable, low part power supply based on the LM317. I have worked it out where I can change R2 with NPN transistors (2n2222) from an output on an ATMEGA328. The schematic is the basic premise of it. It is powered from a laptop brick at 19VDC.


I tested this and it just gave me 6V, with some fluctuations as it changed. Why is this?
Should I use MOSFETS?
I know I should put current-limiting resistors in series with the base, I just forgot to draw it in.
:P

Thanks!
-Mac
</Mac>
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: AVR Controlled LM317
« Reply #1 on: April 23, 2014, 09:44:48 pm »
The classic way to do this is:

- ATMEGA, or any MCU, outputting a PWM signal

- An RC filter to convert the PWM signal to a reference voltage

- A (typically rather old) opamp to buffer and amplify the reference voltage. Rather old because of the relative large supply voltage it must work with, and the modern ones often can't stand large supply voltages.  Also see the next item, too. But one including the negative supply rail in the input and output is beneficial.

- The opamp driving the ADJ pin of the LM317. To do so the opamp needs to be capable of sinking (not sourcing) the current from the resistor between the OUT and ADJ pin - typically 10 mA.

Potential issues with your current circuit:

- The 19V laptop power supply might generate a lot of noise. You might need to filter it.

- No resistors in the connection from the AVR to the base of the transistors

- The individual resistors are on the wrong side of the transistors, move them from emitter to collector

- You require resistor values and accuracy unlikely to be easily and cheaply available

- The 480 Ohm resistor between OUT and ADJ is too large for a general purpose LM317 circuit with no other guaranteed load. Change it to 120 Ohm.
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: AVR Controlled LM317
« Reply #2 on: April 23, 2014, 09:45:14 pm »
Would the resistors be better placed in the collector rather then emitter?
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: AVR Controlled LM317
« Reply #3 on: April 23, 2014, 09:48:42 pm »
Quote
Should I use MOSFETS?

MOSFETs would work better here - use a logic level mosfet.

Also, put the resistors to the collector / drain instead - if you continue to use a bjt, put a base resistor there too. 1k - 10k would work.
================================
https://dannyelectronics.wordpress.com/
 

Offline FrankenPC

  • Supporter
  • ****
  • Posts: 335
  • Country: us
Re: AVR Controlled LM317
« Reply #4 on: April 23, 2014, 10:38:05 pm »
The 317's adjust pin is in the micro amp range according to the datasheet.   
I wonder if you could use one of these?  Digital potentiometer. The 0-10K end-to-end model with a resolution of 256 positions. Uses SPI.  They have others with different interface options.

http://www.analog.com/en/digital-to-analog-converters/digital-potentiometers/ad5160/products/product.html

It looks like they're only about $2USD each.  Hmmm...Makes me want to try this.


Chinglish poetry: In the hot summer. In the car ran full steam. It tastes strange. For this worry? With this fan will bring you a cool summer. Suitable for all kinds of cars. Agricultural vehicles. Van. Tricycle.
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5018
  • Country: ro
  • .
Re: AVR Controlled LM317
« Reply #5 on: April 23, 2014, 10:58:12 pm »
Microchip has some cheaper digital potentiometers, with anything between 32 taps and 256 taps and common sizes (10k , 50k, 100k etc)... for example see here 4in1 IC for $1.6: http://www.digikey.com/product-detail/en/MCP4451-103E%2FST/MCP4451-103E%2FST-ND/2601449

You have to be careful a bit because there's something in the datasheets about maximum voltage on terminals for resistors up to the input voltage, which is up to about 5.5v
So not really sure you can use them in a sort of voltage divider configuration with high voltages. 
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: AVR Controlled LM317
« Reply #6 on: April 23, 2014, 11:02:42 pm »
The 317's adjust pin is in the micro amp range according to the datasheet.   
I wonder if you could use one of these?  Digital potentiometer.

It is typical pointless to use them. Low voltage and +/-20% resistor tolerance. Digital pots are a band aid. If you find yourself using one you probably messed something up.
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline FrankenPC

  • Supporter
  • ****
  • Posts: 335
  • Country: us
Re: AVR Controlled LM317
« Reply #7 on: April 23, 2014, 11:12:58 pm »
The 317's adjust pin is in the micro amp range according to the datasheet.   
I wonder if you could use one of these?  Digital potentiometer.

It is typical pointless to use them. Low voltage and +/-20% resistor tolerance. Digital pots are a band aid. If you find yourself using one you probably messed something up.

Yeah.  I see that.   There are plenty of PWM -> op-amp solutions out there anyway. 
Chinglish poetry: In the hot summer. In the car ran full steam. It tastes strange. For this worry? With this fan will bring you a cool summer. Suitable for all kinds of cars. Agricultural vehicles. Van. Tricycle.
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16607
  • Country: us
  • DavidH
Re: AVR Controlled LM317
« Reply #8 on: April 24, 2014, 05:33:45 am »
It will work fine if you move the resistors from the emitter to the collector and add base resistors although as shown, the output voltage should rise if only one of the transistors is turned on.
 

Offline Richard Head

  • Frequent Contributor
  • **
  • Posts: 685
  • Country: 00
Re: AVR Controlled LM317
« Reply #9 on: April 24, 2014, 05:53:07 am »
Digital pots may not be appropriate in this application but they are definately very useful in many other applications.
The 20% tolerance can be managed if correctly designed. Very often the pot is only ever adjusted once and the tolerance is simply trimmed out. Digital pots allow the calibration to be performed by the ATE so no physical pot need to be adjusted.
Incidently, I have used a similar arrangement with bipolar transistors switching voltage divider resistors and haven't had a problem with them, however definately locate the resistors in the collector lead. MOSFETS will also work (maybe even better) but are much more expensive than a BC817 or similar. Try a BSN20.

Dick
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: AVR Controlled LM317
« Reply #10 on: April 24, 2014, 10:59:33 am »
Quote
There are plenty of PWM -> op-amp solutions out there anyway.

That creates a host of other issues that may not be desirable here.
================================
https://dannyelectronics.wordpress.com/
 

Offline themacman33Topic starter

  • Contributor
  • Posts: 19
  • Country: us
Re: AVR Controlled LM317
« Reply #11 on: April 24, 2014, 09:46:15 pm »
Which of these two schematics looks best? "B" is preferred because I'm more of a hardware guy, and "A" is more programming-based.

Feedback?
</Mac>
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: AVR Controlled LM317
« Reply #12 on: April 24, 2014, 10:03:54 pm »
Quote
Which of these two schematics looks best?

Depending on what you mean by "best":

1) A is unnecessarily complex; open loop; but offers stepless control of the output;
2) B is closed loop; but has only 2^n steps.

================================
https://dannyelectronics.wordpress.com/
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: AVR Controlled LM317
« Reply #13 on: April 24, 2014, 11:54:32 pm »
Quote
Which of these two schematics looks best?

Depending on what you mean by "best":

1) A is unnecessarily complex; open loop; but offers stepless control of the output;
2) B is closed loop; but has only 2^n steps.

 Well 'A', being driven by a PWM signal, will still be using discrete steps, just with a larger 2^n value.
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1310
  • Country: 00
Re: AVR Controlled LM317
« Reply #14 on: April 25, 2014, 01:44:08 am »
Here's a circuit I've played around with before.  Vin would be your filtered PWM. 

The negative supply isn't necessary but if you have it handy then you can adjust the output down to 0V.  You can likely get by with just a -5V supply even.  Without the negative supply the output can only be adjusted down to 1.25V.

I'm not sure if R1 is necessary or not.  I seem to remember looking at the schematic for the LM317 and thinking it was necessary but I'm not so sure now.

Note the 10mA current sink.  As B@W pointed out the LM317 requires a minimum output current to maintain regulation.
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16607
  • Country: us
  • DavidH
Re: AVR Controlled LM317
« Reply #15 on: April 25, 2014, 02:50:28 am »
I'm not sure if R1 is necessary or not.  I seem to remember looking at the schematic for the LM317 and thinking it was necessary but I'm not so sure now.

Note the 10mA current sink.  As B@W pointed out the LM317 requires a minimum output current to maintain regulation.

This circuit is a small step from the standard high stability regulator with remote sense using an LM317 (or any positive 3 terminal regulator), operational amplifier, and self biased reference.  I have used it to get low noise, low temperature coefficient, and load and line regulation better than 1 microvolt from 0 to 1.5 amps.  Using a monolithic regulator also makes it short circuit protected and practically blow out proof.

R1 and R2 are only needed if you want the LM317 output to be more than 1.25 volts above the operational amplifier output.  With R1 equal to 10k, they basically do nothing.

R1 can replace the 10mA current sink which generates the minimum load if necessary.  Since 1.25 volts will always be across it, the current is 1.25/resistance so if R1 is 125 ohms, the extra current sink is not needed.  One reason not to do this is that the 10 milliamps goes directly into the operational amplifier output.  I usually include a PNP transistor to unload the output of the operational amplifier in which case the extra 10 milliamps serves to bias the transistor and never makes it to the operational amplifier neatly solving two problems.
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: AVR Controlled LM317
« Reply #16 on: April 25, 2014, 05:46:47 am »
Which of these two schematics looks best?
A) Lacks a resistor between OUT and ADJ pin. Then this is where the current the opamp needs to sink comes from. The MOSFET is unnecessary, instead the buffer should get some gain to increase the MCU's output voltage. Didn't check the RC filter, but the cap seems low.

More trickery is possible, e.g. powering the opamp from a negative rail so its output can be taken to -1.25V. With this a power supply can be build with the output starting at 0V, not at 1.25V. Requires to configure the opamp as a difference amplifier with a small fixed offset voltage at its input.

B) The gate resistors are not necessary if the MCU can provide sufficient current, even in the worst case of switching all pins at once.

Quote
"B" is preferred because I'm more of a hardware guy, and "A" is more programming-based.
All reasonably modern MCUs have a PWM output module. It just needs to be set up once, then it does its thing on its own. Changing the duty cycle is typically just writing a single value to a register.

Quote
Feedback?

Prototype both. Debug and measure both. Twice the fun. Then build a third one. Three times the fun. Somewhere in between build an adjustable load. More fun.
« Last Edit: April 25, 2014, 05:51:20 am by Bored@Work »
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline Richard Head

  • Frequent Contributor
  • **
  • Posts: 685
  • Country: 00
Re: AVR Controlled LM317
« Reply #17 on: April 25, 2014, 06:05:22 am »
The first circuit won't work. The reason being that there is an internal error amp and control loop in the LM317 that expects feedback from the output voltage.
What you have with the PWM and filter/buffer is open loop with no feedback of the controlled parameter (output voltage).
If you desire stepless control using PWM then toss the LM317 and use something like a TIP 122 as a series pass element fed by an op-amp. Then use the filtered PWM signal as your reference input to the non-invering input and the inverting input for your voltage feedback, via a resistor divider of course. That is essentially a programmable power supply. I have omitted the control loop compensation toy simplify the desription a little but it will be needed. A single pole placed at about 10khz will probably be fine.
I'de draw a schematic for you but I don't know how to attach it!

Dick
 

Offline Lizerd

  • Contributor
  • Posts: 36
  • Country: se
    • www.lizerd.se
Re: AVR Controlled LM317
« Reply #18 on: April 25, 2014, 06:47:33 am »
Quote
Which of these two schematics looks best? "B" is preferred because I'm more of a hardware guy, and "A" is more programming-based.

The LM317 do not need external feedback, the output voltage are always (when it can be) 1.25v higher then the adjust pin.
So the A solution works fine with LM317 because it uses a internal feedback, but with other regulators that use external feedback it do not work !!

I know this because a have done the A solution and it works just fine.
But its better to set a gain to the oamp, because if you like to be able to adjust to 20v and the MCU uses 5v logic you have to have a gain of 4 on the oamp.

Check this block diagram of a LM317, you can see it uses a internal feedback oamp




and i have made a test setup based on Solution A so i do know it works
« Last Edit: April 25, 2014, 06:54:22 am by Lizerd »
 

Offline Richard Head

  • Frequent Contributor
  • **
  • Posts: 685
  • Country: 00
Re: AVR Controlled LM317
« Reply #19 on: April 25, 2014, 06:57:49 am »
Ok, perhaps it will work to a degree, but certainly not closed loop as one desires. As soon as you load the output the voltage will drop as there is no feedback.
I generally try to use semiconductors as they were intended to be used when designed.
 

Offline Lizerd

  • Contributor
  • Posts: 36
  • Country: se
    • www.lizerd.se
Re: AVR Controlled LM317
« Reply #20 on: April 25, 2014, 07:17:56 am »
But if you check the LM317 block diagram, you can see it uses a internal feedback oamp.
So it works even if i put a heavy load on it
 

Offline Richard Head

  • Frequent Contributor
  • **
  • Posts: 685
  • Country: 00
Re: AVR Controlled LM317
« Reply #21 on: April 25, 2014, 08:56:10 am »
Lizerd

Apologies, I see it has the feedback internally. Also, the filtered PWM signal will simply add to the internal reference and the error amplifier will see the sum of the two.
I have never used an LM317 in this way but it seems fine.
Of course, the reference voltage to the micro must be stable so the PWM supply doesn't vary.

Dick
 

Offline Lizerd

  • Contributor
  • Posts: 36
  • Country: se
    • www.lizerd.se
Re: AVR Controlled LM317
« Reply #22 on: April 25, 2014, 09:28:10 am »
Dick: Sorry if i sounded harsh, was not on purpose.

Yes the noise from the PWM * gain will add on the output voltage.
But if you use a really big slow RC filter between the PWM and input on the oamp you will be fine.
 

Offline Richard Head

  • Frequent Contributor
  • **
  • Posts: 685
  • Country: 00
Re: AVR Controlled LM317
« Reply #23 on: April 25, 2014, 10:55:08 am »
Lizard

No problem.
The method works well and I've done it on a couple of occasions.
With my applications I've had to place a 4001 CMOS between the micro and the LPF. The supply voltage to the 4001 is adjustable thereby making the PWM amplitude adjustable over a small range. This is used to trim the output voltage at a given duty cycle. Maybe in future I'll try a software trim.

Dick
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: AVR Controlled LM317
« Reply #24 on: April 25, 2014, 11:20:32 am »
Quote
Feedback?

A simpler approach for B is to tie the resistors directly to the output pins. Output a '0' put that resistor in the divider; Float that pin takes the resistor out of the divider.

However, it does put some limitations on the output voltage.
================================
https://dannyelectronics.wordpress.com/
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf