picaxe controlled variable power supply

hax

New Member
Hi all,

The LM338 is a relatively standard 5 amp adjustable linear regulator.

It has three pins. Vin, Vout and Adj. The Adj pin simply connects to two resistors, the value of which determines the output voltage.

This is all pretty standard but I was wanting to build an 8 bit interface to control the voltage through a picaxe.

Any thoughts on a circuit diagram that would allow this?


The datasheet to the LM338 is here

http://www.datasheetcatalog.org/datasheets/400/63928_DS.pdf


Here are my thoughts but if you think I am tackling this the wrong way, I am very open to ideas.

I was thinking of using a DS1666 which is essentially designed to be an audio digital potentiometer. It is Log, not linear. I could then control the resistor value through the picaxe.
 

Texy

Senior Member
8 bits as in, you'd like 256 levels of voltage?
If it was a lot less, I was gonna suggest using relays to switch resistors,
a bit old-tech, I know:D

Texy
 

Tom2000

Senior Member
The only thing that popped into my mind was the digital pot solution, too, short of looking for a regulator IC that is actually meant to support programmability.

I guess the thing you need to determine is your application. If you're building something like an automated test fixture that needs to switch to a few different voltages, over and over, the digital pots would be the way to go. You'd be more interested in repeatability than resolution.

If you're thinking about a bench supply, I think an analog model would be more suitable, with maybe provisions to manually switch in the fixed voltages that you use most often.

Good luck with your project!

Tom
 

hax

New Member
I don't need 256 levels of discreet voltage. I just need a more or less linear output voltage at a reasonable current. Resolution is not too important.

Has anyone seen a programmable IC that can do this? I need around 3 to 4 amps at 0 to 12V.
 

hippy

Technical Support
Staff member
I think you need to clarify exactly what you do need and what "more or less linear output voltage" means; linear to what ?

You could stick a programmable pot in where the voltage adjustment R is or, looking at the bottom right diagram on page 9 of the linked datasheet control the voltage digitally. You might have to use open-collector drivers as shown in the diagram ( standard ULN darlingtons perhaps ) or you may be able to use blocking diodes to fake PICAXE I/O pins as open collector and drve it direct.

With the 18X the PORTB can be made inputs by poking SFR's so they can be used as open collector outputs ( output low or input ) but don't know how well they'd work in this case.

You will also have to consider what happens at power-up, how whatever controls the voltage behaves. You probably don't want Vout jumping to Vin at turn-on.
 

Andrew Cowan

Senior Member
For my adjustable power supply, I just use a 5K ten turn 'normal' pot, connected up to a LM317 (3A max). I also have a voltage display - the 10 turn pot means you can adjust the ouput to exactly the voltage you need.

If you tell us what you want this, we can help think of some solutions for the project. Does it have to be PIC controlled?

Andrew
 

Dippy

Moderator
Oh Andrew really - he wants to make one :)

I'd just be concerned with the wiper voltage rating as Vref is across the top resistor. I haven't looked at that particular Data Sheet (I confess) but a lot of digital pots are pretty limited. Iadj looks pretty low so I wuldn't worry about that.
 

leftyretro

New Member
The biggest problem I see is that using an 'external' D/A or other method (digital programmable pot, etc) Picaxe developed voltage or resistance to control the regulator is that you will not then have a regulated output voltage. Any change in source input or load change will not be sensed and feedback to the regulator. You will have created an open loop control rather then a closed loop feedback control. The Picaxe would have to 'measure' the actual regulator output voltage and factor that into it's D/A output (or digital) to actually regulate at the desired 'setpoint' voltage.

Or am I all wet :rolleyes:

Lefty
 

Dippy

Moderator
Well, I must be missing something here but I don't really (I admit) understand your post retroL:

1. The proposed regulator is just a standard regulator where the output voltage is merely a relationship between the two Rs. And your digital pot is one of them. So, you set a resistance from PICAXE - Job done. The regulator with it's own Vref does the regulation. My only concern (without in-depth study) is whether the digital pot is electrically up to the job.

2. If you wanted a feedback style regulator you simply have a PICAXE on a separate fixed regulator and have the output feeding back to the ADC and adjust in your feedback loop.

But this is not the proposed idea here. It is a simple linear adjustable regulator.
 

hippy

Technical Support
Staff member
I think you could say that the LMxxx is the closed-loop with feedback, the pot setting simply telling it what it should be outputting . Regardless of load or input voltage, the LMxxx will then do the tracking as required.

Somewhat like controlling a servo; you simply say "go there" and it will. You'll need to know what the "there" has to be to get what you want out as an end result but that can be pre-determined and doesn't need a feedback loop.
 

papaof2

Senior Member
How adjustable does it need to be?

In rounded figures:

256 steps from 0-5 volts is 0.02 volts/step.

256 steps from 0-24 volts is 0.1 volts/step.

John
 

leftyretro

New Member
I think you could say that the LMxxx is the closed-loop with feedback, the pot setting simply telling it what it should be outputting . Regardless of load or input voltage, the LMxxx will then do the tracking as required.

Somewhat like controlling a servo; you simply say "go there" and it will. You'll need to know what the "there" has to be to get what you want out as an end result but that can be pre-determined and doesn't need a feedback loop.
As I think more about it the case of a digitally controlled pot should work. While the Pic would be sending a 'setpoint' to set the resistance ratio, the top connection of the pot would still be connected to the regulator output and would therefore still be able to sense source/load changes that would require a change in the regulator's output.

However the original idea I was trying to bring up is that just supplying the regulator's adjustment pin with a programmable adjustable but then fixed voltage/current to set a given regulator output would not be able to correct for source/load changes unless the supplier of the voltage/current (the Pic) also read the actual output voltage being generated at any given min. Regulators themselves are just adjustable resistors that increase or decrease it's voltage drop to maintain the desired output voltage. They use closed loop feedback by design.

Lefty
 
Last edited:

Dippy

Moderator
"As I think more about it the case of a digitally controlled pot should work. While the Pic would be sending a 'setpoint' to set the resistance ratio, the top connection of the pot would still be connected to the regulator output and would therefore still be able to sense source/load changes that would require a change in the regulator's output.
"

- well, er.. um... apart from the fact that in this case you have fixed res between Vout and Adj, this is precisely how they work. All you are doing is replacing a resistor or twiddly-pot with a digital pot. PICAXE has nothing to do with voltage sensing or feedback. Where is the confusion?

The other bit of what you say is a hard way of doing the above. Doing it with a S/mode technique is easier, but still not fast enough to provide a regulation or load/transient response value good enough for a high quality bench power supply.
Anyway, that is not the question asked here, which has, turned from a molehill into a mountain.
 
Last edited:

Mad Professor

Senior Member
I was just about to start my own Topic and saw this one.

I own a (Watson W-10AM) 0-15v 10AMP Bench Power Supply Unit.


This unit uses a simple Variable Resistor to adjust the output voltage.

I want to remove the Variable Resistor and replace it with four buttons, 1st two to increase & decrease the voltage by 1.00v per press and the 2nd two to increase & decrease the voltage by 0.05v per press.

I am already in the middle of replacing the analog Ampmeter & Voltmeter with digital ones.

I will be keeping a close eye on this topic.
 

hax

New Member
Alas it looks like Dippy is right. There is no problem with current rating, but the DS1666 can only have a max 5V analog line.

I wanted to have a power supply that is capable of 15V or so. That means the programmable resistor will see 1.25V less than the supply voltage.

I will be looking for different digital potentiometer ICs for now. My eye is on the AD5280 from Analog Technologies. It's surface mount only but has a 0 to 15V range.
 

boriz

Senior Member
No need for a digital pot or D-to-A converter. Any PICAXE can do the job using an R2R ladder. The better the resolution you need, the more outputs you use.

EG: 256 levels = 8 outputs. 16 levels = 4 outputs.

Like this for 16 levels (OP=Output):

OP1 - R
OP2 - 2R
OP3 - 4R
OP4 - 8R

With one end of each resistor connected to a PICAXE OP, and the other end tied to the regulator adjust pin. (all resistors meet at the adjust pin).

When all OPs are HIGH, no current flows to ground through the regulators adjust pin and the regulator is thus set for max output voltage. Different binary combinations of LOW on the OPs will sink different amounts of current from the adjust pin, setting the regulators output to various levels. In this case OP1 is the MSB and OP4 is the LSB.

In this simple form, the HIGH output from each PICAXE pin is only 5v, limiting your regulator to voltages below 5v. But using the same system with an additional transistor on each output to isolate the R2R network resistors from the PICAXE, you can program any voltage. Note: Using a transistor inverts the logic, so you use OP HIGH to sink current.
 

hax

New Member
Hi Boriz,

So say I want to have 8 bit operation with a sweep from 0 ohms to 10K ohms. What resistor values should I use?
 

Dippy

Moderator
Yes, I'm surprised R2R ladders aren't more commonly used. That is a good idea Boriz. I guess you could have quite a neat arrangement with DIL res networks and DIL tran array. Obv a little thought will be needed for the Vce but I'm guesng this would be no big deal?
 

hax

New Member
Correct me if i am wrong but I dont think I can get a linear resistance output as the combination of resistors won't just add together nicely. They are inversely related to the total resistance.
So a bank of 8 resistors won't give me 256 equal steps.
 

hippy

Technical Support
Staff member
If one looks at the LMxxx equation for Vout it's approximately ...

Code:
               /     Rref  \
Vout = 1.25 * |  1 + ----   |
               \     Rpot  /
That's very non-linear as I found when building a variable voltage PSU with an LM318. I cannot find my graph but should be fairly easy to determine.

Could this not be a case of using the wrong tool for the job ? It would certainly explain why most variable voltage PSU's aren't $10 and don't consist of a single chip plus heatsink.

It's not impossible to do what's required but it does seem to be a case of trying to 'do it on the cheap' and running into the limitations of the device chosen. I'd suggest heading towards a search engine to see how others have done it. A couple I found ...

http://www.circuitcellar.com/library/print/0702/rios144/2.htm
http://www.linuxfocus.org/English/November2002/article251.shtml
 

Dippy

Moderator
Well, if everyone else is 'alas'-ing I'll join in. Looks easier than it is. Yes, you're quite right.

I was going to suggest using the NSL-32 LED/LDR optocoupler + PWM/RC/op-amp but we're back to feedback, speed and stability all of which will compromise the regulation accuracy and transient response.
I'm sure you could make something vaguely reasonable but nothing that would get TTi worried.
Good luck.
 

wapo54001

Senior Member
Perhaps I'm misunderstanding your goal, but I'd use a different approach.

I currently use a circuit that does a very similar task with an 08M and a 2N7000 mosfet, and I can set output levels very precisely and with great stability. In my case, I only need 0~5 volts output, but the circuit could easily handle a higher voltage by using a voltage divider on the output feedback so the picaxe never sees more than five volts there.

If you do a search on "Driving low impedance with pwmout" -- you will find three threads revolving around using an integrator circuit to control an output voltage. It works like a charm. The integrator solution caused me to abandon pwm for setting output levels. I'd encourage you to read all of the threads to best understand it, but

The schematic is here:

http://www.user.dccnet.com/wrigter/powerd2a.gif

This is the code:

Code:
main:
readadc10 4,w1 ;read sensor input voltage (Vin)

adjust:
readadc10 1,w2 ;read output voltage (Vout)
if w1=w2 then main ;skip if no adjustment required
if w1>w2 then increase

decrease:
high 2 ;set pin2 high to decrease Vout
input 2 ;tri-state pin2 and hold Vout
goto adjust

increase:
low 2 ;set pin2 low to increase Vout
input 2 ;tri-state pin2 and hold Vout
goto adjust
With this circuit, you can use a pot or fixed resistors to set an input voltage anywhere 0~5v, read it with readADC10 (5v/1023 = 5mV steps), then use that value to drive an output integrator and mosfet circuit with feedback to control output with high precision and stability. The secret is in the remarkably simple but effective code that compares the input value to the output value and drives the integrator up or down until they match then tri-states the pin.

In your case, the mosfet would be part of the regulator sense pin circuit, changing the resistance from the sense pin to ground. By using a voltage divider for feedback, the picaxe only sees voltages in the range of zero to 5 volts while the regulator sense pin sees the full range voltage swing to whatever you need.

Although my implementation is via readADC10 input, you can set output levels with any method that is capable of storing a numerical value in a word variable so that this variable can be compared to the outback feedback variable and output adjusted so they match.

BTW, if you have a small minus voltage available, you could tie the mosfet to 1.25volts below power ground, and you'd have a regulator that will actually go down to 0.0 volts out if that's of any value to you.

BTW2, someone mentioned voltage instability at turn on. For a power supply, I always plan on the regulator circuit being always powered on, and the "power" switch is actually in the line between the regulator output capacitor and the load. Thus "off" means instant disconnect of power to the load, not gradual drop as capacitors dischanrge.
 
Last edited:

hax

New Member
Thanks for the ideas gents.


Hippy says:

If one looks at the LMxxx equation for Vout it's approximately ...


Code:
/ Rref \
Vout = 1.25 * | 1 + ---- |
\ Rpot /



That's very non-linear....



I disagree. I see this as being very linear. With nice 0.0488 volt steps if I graph it in excel using a 2K Rpot and a 0 to 20K variable pot with 256 steps.

Wapo, I like the simplicity of your code and its great that you have a proven design but as your supply is switching I think the ripple will increase as the load increases. I am after 3A at least.

Best thing to do now is to build the circuit and see.
 

wapo54001

Senior Member
Wapo, I like the simplicity of your code and its great that you have a proven design but as your supply is switching I think the ripple will increase as the load increases. I am after 3A at least.

Best thing to do now is to build the circuit and see.
I'm sorry, I must not have explained it well. I may be beating a dead horse, but this circuit absolutely is NOT switching -- it is linear and voltage is controlled by a mosfet acting as a variable resistor.

The 08M drives the mosfet to a resistance that is controlled by the 08M, and the mosfet takes the place of the second resistor in the R1/R2 divider that is used with most variable output linear regulators. Feedback to the 08M comes directly from the mosfet to tell the 08M whether the mosfet needs more or less gate drive, and responds appropriately.

There will be NO ripple to speak of. The only variation to the circuit drawing that you will have to implement is a voltage divider to drive the feedback to the 08M, with the divider calculated to deliver the maximum 5.0V to the 08M when your linear regulator is delivering it's maximum output voltage.

Of course, your mileage may vary.

BTW the code and the hardware design, as far as I know, originated with wilf_nv, they are not mine. When he introduced me to this circuit, I was struggling with trying to drive a digital panel meter to an accurate value with pwm and having no luck; his suggestion made it easy. This circuit is so slick because it is dead accurate and is very, very smooth.
 

hippy

Technical Support
Staff member
I've mis-copied the equation in the manual, it should be Rpot at the top ...

Code:
               /     Rpot  \
Vout = 1.25 * |  1 + ----   |
               \     Rref  /
I agree, it should be linear ( I'm actually using LM317 but it's the same ). So I wonder why mine isn't ? My best guess is I've used the wrong equation, made the linear pot into log/anti-log to compensate and that's introduced the non-linearity. Could it be the fact that I've had to parallel the pot with a 100K to stop 'track skip' problems of output voltage jumping full on while setting the voltage limit required ? Have I got log pots ?

I'll have to investigate, but it should be linear, you're right.

http://www.hippy.freeserve.co.uk/psu.htm
 

wapo54001

Senior Member
Could it be the fact that I've had to parallel the pot with a 100K to stop 'track skip' problems of output voltage jumping full on while setting the voltage limit required ? Have I got log pots ?

I'll have to investigate, but it should be linear, you're right.

http://www.hippy.freeserve.co.uk/psu.htm
Hippy, if you feed the output of the potentiometer into a readADC10 and use a rather long averaging period (100~200ms?), wouldn't that eliminate 'track skip' as a problem area?

On a pump pressure readout system, I use code to average the sensor input over a fairly long period of time (100ms) so that spikes (pump strokes and pressure variation) coming from the sensor causes virtually no jitter in the readout DPM and this makes the display very readable. This same approach could keep your 'track skip' from affecting voltage output on a variable supply.

Also, it occurs to me that you could include code that tells the 08M to ignore step changes of less than say, 3 steps, and this will eliminate vacillation between two adjoining steps.

I had been thinking about building a couple of bench power supplies with LM317s with conventional resistor controls, but this thread has really got me thinking about using an 08M to drive an integrator/mosfet control circuit. And, why not use a second 08M and similar circuit to monitor and control a current limiter as well?

Potentiometer absolute value and small track anomalies become non-issues because if the wiper is driving a readADC10 and that input is smoothed in software by averaging, the value of the pot is immaterial as long as it will handle 5v across it, and minor glitches in the track will be ignored by the averaging code in the 08M.

If the 08M output is controlled by 1023 steps, at 15V output, each step would be 0.0147 volts, which should be sufficient resolution.
 
Last edited:

kevrus

New Member
Ok, maybe i'm missing something, but a pot is quite a simple control to have, (just rotate a knob clockwise or anti-clockwise). Using a picaxe may be possible, but what tells the picaxe what to do?....A knob maybe?
Please tell me that i'm missing something
 

wapo54001

Senior Member
Kevrus, I've added a schematic to my last post which shows the basic circuit that I'm talking about.

The beauty of using a picaxe here is that it allows processing of the signal to remove glitches, and averages input values to create a very smooth output so that potentiometer noise is removed, and the potentiometer can be of any value that will carry 5V across it and deliver a usable voltage to a Picaxe readADC10 pin.

Furthermore, you can program it to deliver a specific range of values. For example, using an 08M, I built a low power regulated power supply board which uses a potentiometer which, regardless of the precision of the pot, delivers an exact range of .5V ~ 4.5V within a few millivolts. I use this to simulate the output of sensors which deliver .5V at 0psi and 4.5V at max psi.

Before I came across the picaxe solution, I was constantly fiddling with resistor pads on either side of a pot to output exactly .5~4.5, and each pot required a different pad, and the top and bottom had to match exactly, and it was a pain in the neck.

Now, with pot to minimum, the picaxe with integrator puts out almost exactly .500 volts, and at maximum, 4.500 volts. I don't have to worry about the value of the pot and it's rock steady. Furthermore, once your board is built, you can create any range of output simply by reprogramming the picaxe. You could, for example, program the picaxe to prevent the regulator output from going above 10.000 volts, or dropping below 3.35 volts, or straying from any range you choose.

To insure the accuracy of my output, I do use a trim pot to get exactly 5.00 volts off the regulator that feeds the picaxe.
 

hippy

Technical Support
Staff member
@ wapo54001 : I really like what you have there. If I'd have been capable of designing something ike that I'd have probably done it myself. Just to check I've read it right, this is tried and tested and works ?

Assuming it is and does, it would be ideal in the Finished Project sections or even tarted-up a bit and sent off to one of the Magazine Publishers or to Instructables etc.

For the benefit of others; the 'track skip' problem is if the pot wiper comes off the track at any point the LMxxx output soars Vout to Vin and that can of course be catastrophic for anything connected. A simple C across the pot might help there but I don't really understand how the pot / current control works :)

I like the idea of PICAXE control to (1) smooth out the pot and stop 'track skip', (2) allow arbitrary pots to be used ( even log / anti-log ), (3) the ability to set voltage limits and (4) the ability to set voltage ranges. It's particularly useful to prevent the output going above a certain voltage and stops accidentally connecting high voltages to low voltage circuits when the pot gets knocked.

This is perhaps the best PSU designs I've seen based around the LMxxx without any real complexity in the circuit and I'd be quite willing to throw a bigger PICAXE at it to get more functionality.
 

wapo54001

Senior Member
Hippy, this circuit is in use in my systems except I have yet to drive an LM317 with it so the voltage divider for the feedback to allow higher output voltages is a new idea for me.

I can confirm that the integrator circuit and software work a dream. If you do anything with this, you need to get wilf_nv's involvement because it's his basic scheme, not mine, I've just made it into a practical circuit.
 
Last edited:

hippy

Technical Support
Staff member
A question on the code in post #23 earlier ...

How fast does the code have to execute ? I'm thinking that it would be possible to off-load the voltage control to an 08M ( or even 08 ) as per circuit and rather than have it READADC from a pot, get its value from another PICAXE.

I can see two ways of doing that; a SERIN to read a byte ( 0.0V to 25.5V in 0.1V steps ) but that adds a fair bit of delay and the master has to frequently send data, or to use signals on pin 3 and 4 as increment and decrement and the Master can also READADC what the Slave is seeing to get to what's required and should know what it's told the slave to set to anyway. The only question on the later is how long it would take to send increments to change the output to what's required as the control pot changed.

Doing this and the Master PICAXE can do all sorts of fancy things and take as long as it needs while the Slave keeps the voltage as required at high-speed.
 

wapo54001

Senior Member
The code is set up so that it stays in the "adjust" loop until the input value and output value match, then returns control to the main program for another round of input readADC10 and whatever else you do in the main loop. Because the 08M does both the pull-up and pull-down duty on the mosfet gate and then tri-states to hold the level, the adjustment is so fast that it is unnoticeable except when you're making a very big change in the input.

In my case, the main delay is the 100ms for averaging the input. In the meantime, the mosfet setting is held by the .47uF capacitor.

If you use two picaxes, and one dedicated to maintaining the voltage level, of course you'll hold it rock-steady, but I'm not even sure if this is necessary, since it works fine for me with the 100ms delay built in between adjustments.
 

hippy

Technical Support
Staff member
The going tri-state and pulsed operation make a lot more sense now; keep nudging the cap up or down to get the right level then leave it sitting where it is until it needs adjusting again. I hadn't appreciated there'd be that much time between having to re-adjust but there should be an eternity in terms of program execution. No problem for a single PICAXE then.

This is looking better and better !
 

BCJKiwi

Senior Member
@Wapo54001
Would you please explain "use a rather long averaging period (100~200ms?)".

The approach I have used has always been to take multiple readings and average them.
This sample code is from a one-time startup routine. Normally the number of readings and the pause would be much reduced.
e.g.
Code:
'28X1 @ 16mHz
 ReadADC10 2, w1
for b1 = 1 to 49     'accumulate 50 readings
 ReadADC10 2, w2
 w1 = w1 +w2
 pause 25
next
 w1 = w1 /50      'Average calibration reading over 50 samples
Is this what you mean or do you have a different technique?
 

wapo54001

Senior Member
BCJ -

Yes, exactly what I'm talking about. I add multiple readings with a 'pause' between each reading, and divide by the number of readings. You can over do it, so I use trial and error going up and down until I find the shortest total time for a steady reading, then try to get squeeze in a reasonable number of readings. I've found that it's better to have more readings with a shorter delay between readings because that tends to reduce the impact of one or two readings that aren't similar to the others.
 

boriz

Senior Member
@Dippy

“LED/LDR”. I like it. No transistors required and only a single PWM output used. A single capacitor across the LDR should be enough to smooth the regulation but may not even be necessary due to the relatively slow response of LDRs. With some feedback you should be able to get serious resolution/accuracy. Cool.

Now which draw did I put the LDRs in…
 

Dippy

Moderator
Boriz: LED-LDR like this http://uk.farnell.com/3168773/optoelectronics/product.us0?sku=silonex-nsl-32

Wapo et al. Using a MOSFET as variable resistance.
I must admit when I tried it a few years ago I had all sorts of issues mainly to do with temperature related instability. A MOSFET used in that ''resistive' region is very sensitive to temperature. I realise that your feedback will adjust for that but there are limits. For my education, what is the overall output voltage range it can achieve in conjunction with a LT317 with the components specced in your drawing?
 

boriz

Senior Member
Hey. That thing has an input current of 40mA! Wouldn’t an LED do the same job at <15mA? And a low current LED at <5mA? What’s the scam?
 
Top