picaxe controlled variable power supply

Dippy

Moderator
Boriz, thats it's ABSOLUTE MAXIMUM rating.
Run it at 1mA if you want.
No scam.

____________________
Thank you for not reading.
 

BCJKiwi

Senior Member
@ Wapo, Dippy,

Been trying to get my head around that control circuit and with my limited knowledge on transistors/mosfets had wondered about using a mosfet in that situation.

Presumably it works by the cap holding the voltage on the gate (with nowhere to go as the PICAXE port is tristated but the gate level will be raised/lowered by the output voltage. Wouldn't a regular transistor normally be used (and be more stable) in this application or am I just showing my ignorance?
 

Dippy

Moderator
I dunno. Try it. But with a MOSFET Gate being very resistance the cap dicharge would be much lower than a bjt. The problems I encountered were related to tempcoeffs. Maybe wap has found a solution. Have a go, let us know.
 

wapo54001

Senior Member
BJC,

This circuit originated when I was looking for something to control with great precision an input that was being pulled to +5 by a 300 ohm resistor. I needed a circuit that would pull that voltage down with great precision so that I could set input voltages between about .5V and 5V.

This is the circuit that I eventually found. I never had the need to control a voltage above 5 volts until now. The 2N7000 was there, it was cheap, it worked.

I never thought about controlling voltages above 5 volts until this thread came along. If the requirement to control a greater voltage also suggests the need for a different semiconductor to take the place of the 2N7000, so be it as long as it does not allow the charge on the capacitor to leak out through it's gate/base.
 

wapo54001

Senior Member
I don't have a solution to the temperature coefficient issue since I've not experienced it. Would a more frequent adjustment to the gate voltage based on the readADC10 feedback keep the mosfet under control? If this is a problem, perhaps Hippy's idea of offloading the control to a second chip dedicated to the purpose might be a good idea after all.
 

Dippy

Moderator
Well, if it's not a problem in room temp conditions then it sounds good.

Oh yes, you can 'cure' it within limits and as long as your control resolution is appropriate.

As I assumed this would be a purpose built PSU controller thing I can't see the point of offloading anything onto another chip (??) - maybe I didn't get your drift (no tempcoeff pun intended) :)
 

hippy

Technical Support
Staff member
Offloading voltage tracking would help get round drift because the control is being kicked into shape more frequently but I wouldn't expect temperature change to affect anything suddenly or drastically. The faster one can kick the control the better and the less drift of output voltage there would be but if it's fairly stable anyway.

I only considered offloading because I thought the tracking and kicking had to be done at high-speed and didn't understand how it worked :)

Another way of updating more frequently without offloading would be to have the control kicking done in an interrupt which can be fired at a reasonably fast rate so kicking is effectively done in parallel with other ( longer processing time ) activities. Or use interleaved activities; read the pot, kick control, read pot, kick control, repeat N times, do the averaging, kick control, update LCD's and LED's etc, kick control, repeat.

As long as the need to kick the control is 10ms or more that shouldn't impact too heavily on other processing. Any averaging shouldn't be greatly affected by a delay between samples as most interrupts will simply return.
 

wapo54001

Senior Member
OK, I wasn't familiar with the temperature issue, but it sounded like if there was one, the quick and dirty answer was to step up the feedback.

I'm in the process of re-engineering a circuit card I already have to see if I can't do a quick rewiring to test this circuit out. Need to cut a trace or two and use existing resistor locations for different purposes, but doesn't look too hard. I'll let you know how it turns out.
 

Dippy

Moderator
Oh dear, I have completely misunderstood your control.

I had assumed you were PWMing your MOSFET and the cap was just a smoother to provide an 'average' Gate voltage (thus adjusting the Drain-Source resistance).

Now that hippy seems to want to kick everything I confess I don't know what everyone is on about.

As far as I was concerned once you have set your MOSFET res to provide the necessary output then the regulator does the regulating and the PICAXE merely reads the control, displays and adjusts the DSr when requested. After all, under normal circs you just twiddle the POT until you got the desired voltage-out and let the regulator do it's job.

Why do you want to read a Pot? If you've got a Pot you may as well just have it stuck to the regulator as per normal???

I think it's time for coffee. You boys have lost me in haze... I'll stick to Switchers.
 

hippy

Technical Support
Staff member
@ Dippy : It was a circuit I'd mis-understood at first, not PWM but more like Sigma-Delta for ADC. It is similar to PWM but using a sample and hold rather than an RC integrator. To set the voltage the charge on C is added to or taken from but only a tiny bit at a time, hence my terminology of 'kicking it', like moving a football around by nudging it forward or backwards as needed, leaving it alone when it doesn't need to be moved.

Assuming I have now understood it right.
 
Last edited:

wapo54001

Senior Member
Yes, that's it.

I've looked at an existing circuit card I've designed and find I can modify it by omitting three parts, cutting one trace, changing a resistor value, and turning one resistor 90 degrees.

All the input/output including the control and feedback is through a DB-9 connector, so dead easy to solder up. I just need to find an LM317 and a couple of caps for a first test. . .
 

inglewoodpete

Senior Member
This is an interesting thread. I'm getting ideas of a PICAXE controlled dual tracking supply. PWM is not required, is that correct? A 14M should be all that is required.
 

wapo54001

Senior Member
Inglewood -

I did some experimenting today and ran into problems with the higher voltage. My original "works perfectly" circuit was for an output of 0.0~5.00V, and included a 10K ohm pullup connected to +5V for the mosfet.

The modified circuit with voltage divider that I proposed does not include pullup to the power supply, but instead relies on the voltage supplied by the LM317 for the mosfet to work against. That is a proposal that needs to be tested and confirmed. I don't see why it shouldn't work, but maybe there is a "gotcha" in there somewhere.

I did not have time today to test the new circuit; I did a "quickie" rework of an existing board design but didn't have time to finish. Maybe tomorrow.
 

Dippy

Moderator
Does it make any difference if you have a slightly higher Rref fixed res. so that the gate voltage doesn't need to get so high? ie your R1/R2 term.
 

wapo54001

Senior Member
Dippy,

Not sure I understand you question, but are you referring to the 10K and 5K? If so, good question, I just threw those values in because they were approximately the right proportion. I'm really backing into this project from the wrong end. I should have gone to the spreadsheet and calculated the R2 requirement for some maximum voltage, and worked from there.

I think:

In order to achieve maximum output voltage, the mosfet must be at high resistance, and at maximum output the voltage is controlled by the sum resistance of the two resistors in the divider acting as R2 in a standard LM317 circuit.

My LM317 spreadsheet says that R2 must be 2640 ohms for a 15 volt output from the LM317, and the voltage drop across R2 is 13.75 volts. The 2640 ohms must be divided up so that of the 13.75 volts, 5 volts is delivered to the 08M feedback, and the rest dropped across the other resistor.

It looks like standard 1% values of 1690 and 953 would be close at 2643 ohms for 15.02 volts, with the voltage drop across the feedback pin at 4.958 volts.

So, the mosfet would then be expected to reduce output voltage by reducing the overall resistance from 2643 down to zero for a minimum output voltage of 1.25V.

So, the 15K total resistance is wrong -- I think the 2643 ohms is the correct value for a 15 volt maximum output circuit.

Was this your question, or did I totally misunderstand? In any event, your query caused me to rethink that resistor string and come up with better values.
 

Dippy

Moderator
Um no, though I do see your point on that.

I was referring to the 240R.
You must remember that I've never tried that circuit or that MOSFET so was merely thinking out aloud.
I was just thinking that if you had to set the Gate voltage higher and higher to get the MOSFET-R to a particular value that you may be straying out of the resistance region for the FET. And that if you changed that res a bit then you could back-off Vgate and would be operating over a different range based on the Vout calc for the LT317. And also I don't know if the wide range of Vdrain has an effect, never tried it. Just a casual thought t'was all.
 

wapo54001

Senior Member
I believe that if you turn the mosfet full OFF (no gate drive) the 317 output is at maximum, controlled by the 2643 ohms value.

As you increase gate voltage, the mosfet conducts and resistance drops until it is finally at Rds=1.8 ohms at 4.5V for the 2N7000, and that will give you about 1.260 volts output on the LM317.
 
Last edited:

Dippy

Moderator
Well, I hope it's OK then. I'm genuinely impressed how you can hold the MOSFET impedance in the kOhms range with such stability without compensation.

And one thing I must ask for my own education; why do you take your pot-div feedback from where you have? Why not from the Output?
 

wapo54001

Senior Member
Well, I hope it's OK then. I'm genuinely impressed how you can hold the MOSFET impedance in the kOhms range with such stability without compensation.

And one thing I must ask for my own education; why do you take your pot-div feedback from where you have? Why not from the Output?
It seems to me that the objective is to control the voltage at the adjustment pin and to let the LMXXX do its job of regulating. The mosfet's sole job is to control the resistance between adjust and ground. The high end is controlled by the fixed resistance, and the mosfet pulls down from that maximum value. So the feedback must be based on the voltage existing at the adjustment pin.

I'm certainly open to correction, it just seems right this way.
 

Dippy

Moderator
But isn't the Voltage at 'adj' simply Vout - Vref?
I thought it's regulation was to do with constant current flows across resistors rather than 'voltages at'...?

I'm sure it doesn't make much difference in practice, just intrigued me that's all.

Oh well, all good stuff. I'll leave you to it.
 

BCJKiwi

Senior Member
It seems the circuit has been complicated by adding the MOSFET AND the current sense. These two are effectively in parallel.

The 10k/5k or 1690R/953R ratio needs to be correct to get a 0 to 5V swing on the PICAXE ADC port to suit the Vout of the regulator.

The values used need to consider the parallel nature of MOSFET in this circuit as the MOSFET resistance is in parallel with the sum of these two resistors. The MOSFET R swings from Rds On (~1.8R to 3R) to 48M (data sheet says 1uA at 48V and 0V gate)

At the low end of the adjustment the difference between 10k/5k or 1690R/953R when in parallel with 1.8R is negligible.

However at the high end of the Mosfet range, it is important that the 10k/5k or 1690R/953R be made much higher as the parallel resistance formula shows that the value never rises above the lower R value;
e.g.
15k in parallel with 2R = 1.9997R
15k in parallel with 15k = 7500R
15k in parallel with 2M = 14888R
15k in parallel with 48M = 14995R
This indicates that the 10k/5K set should be as high as practical to achieve a true high resistance approaching that of the MOSFET.
Perhaps a 390M/220M set giving;
610M in parallel with 48M = 44.4M at the high end and, 610M in parallel with 2R = 2R at the low end would be a better setup.
How high does it need to be to maintain stable control???

This is all very different from the original circuit without the LM317T as there was no parallel path to 0V in that circuit.
 
Last edited:

wapo54001

Senior Member
BCJ -

We may be looking at the fixed resistance from two different perspectives -- on the one hand, if the purpose of the resistor string is only to deliver a maximum of 5V to readADC10, then it can be a fairly high value (10K/5K). However, if you also use that resistor string to set a ceiling on the output that the LM317 can deliver, then you need to use the resistor value from the LM317 application notes -- 2640 ohms for 15 volts (2643 with 1% values).

As I see it, at no time do you want the R2 resistance (from the adjust pin to ground) to go above 2643 ohms, given a desired maximum regulator output of 15 volts, because that is what the LM317's formula calls for, if R1=240 ohms.

At the low end, with the mosfet in parallel and conducting fully, the total circuit impedance is about 1.8 ohms, giving an output of 1.26 volts at the regulator, or only .01V more than a dead short to ground and this is quite satisfactory.

At the upper end, if the mosfet has a maximum Rds of 48M ohms when turned off, (your number, I haven't checked), when placed in parallel with the fixed resistance, the circuit closely approaches the desired limit of 2643 ohms by achieving a theoretical resistance of 2642.85 ohms. That resistance creates a regulator output voltage that is very close to the desired 15 volts.

That should enable the regulator to deliver its intended voltage swing of 1.25~15volts without difficulty.

Practical values may differ a bit -- perhaps R2 should have slightly more total resistance so that 15V can be achieved with a less-than-perfect mosfet -- but given that the LM317 requires a fairly low resistance of 2643 to deliver our target maximum voltage output of 15 volts, I don't see why we should be trying to get the resistor/mosfet parallel resistance any higher than that, or be concerned with the high meg ohm values you propose. Am I missing something here?
 

Mycroft2152

Senior Member
I've been following this trhread witgh some interest, mostly because I've never seen Hippy so excited about a PICAXE project.

I have 2 questions. first, what is the significant advantage / justification for adding the PICAXE and extra components. Second, if the PICAXE ADC is referencing a variable V+, how does that effect the circuit?

myc
 

wapo54001

Senior Member
I'm feeling a little trapped, here! I'm not an electronics guru, my job is to ask stupid questions for others to answer! But I'll try.

Your first question:

If you go back to the beginning of this thread, Haxby asks for a way to control an LM338 with a picaxe, using an electronically-controlled variable resistor.

Various folks offered suggestions; mine was an approach that uses a mosfet as the variable resistor, and addresses known issues (lousy pots with bad wipers) and offers real advantages (use any value of pot, set upper and lower limits with great precision, potential ability to enter values, limits, etc. from a keypad or computer) with picaxe software.

That's how we got onto this!

Your second question:

The two readADC10s used here -- both input and output -- reference the internal +5v, so they share a fixed reference.

The whole point of this circuit is to drive the resistance of the mosfet up or down until the output readADC10 value matches the input readADC10 value. It does that by driving the midpoint of the divider (where the readADC10 is connected) to the value that matches the input. Thus, the change in voltage is, in fact, one of the keys to this circuit. If the voltage didn't vary, the circuit wouldn't work. At minimum regulator output, the readADC10 should be near zero, at maximum regulator output (whatever you chose by selecting resistor values for the divider) the readADC10 count should be around 1023.
 

hippy

Technical Support
Staff member
I've been following this trhread witgh some interest, mostly because I've never seen Hippy so excited about a PICAXE project.

I have 2 questions. first, what is the significant advantage / justification for adding the PICAXE and extra components. Second, if the PICAXE ADC is referencing a variable V+, how does that effect the circuit?

myc
The main advantages are back in post #30 ... 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.

That gives me lots of things I'd like in a variable voltage PSU I could nver work out how to achieve. Yes, I really am excited :)

@ wapo54001 : I've noticed something going back to your circuit ...

http://www.picaxeforum.co.uk/attachment.php?attachmentid=1337&d=1216657436

You're trying to determine the voltage across the MOSFET but if as Dippy says it's all about balancing current, the varying R of the MOSFET won't necessarily change the voltage across it. Maybe move the ADC to the LM317T output ?
 

wapo54001

Senior Member
Hippy, my memory of the current issue in 3-pin regulators is that you should select R1/R2 carefully so that feedback current through R1 is adequate for the regulator to work properly.

R2 plays in that scenario too, but looking at the application notes, R2 can be a 5K potentiometer. We're simply replacing the pot with the mosfet and applying automatic control/feedback to the mosfet to control the "on" resistance.

Does that sound OK?
 

hippy

Technical Support
Staff member
Yes, that side of it sounds fine. It's what you're then monitoring, ie the ADC voltage divider is across the MOSFET.
 

BCJKiwi

Senior Member
OK Wapo,
take your point about the 15V max and the R2Max.
However the divider string to 0V in parallel with the MOSFET is a completely different circuit proposition from a variable resistor only (i.e. a pot).

If there is a total R2 (2640) to ground to achieve 15V out, then is there is no effective control in most of the MOSFET range as once the combined R2/MOSFET R approaches R2, there is a very long way for the MOSFET to go with no real effect. If control gets the MOSFET into that region it may not know where to go to recover as continued movement will not make any change.
Not really clear how this would work - just don't know what would happen.

As I think Dippy and Hippy are suggesting, monitoring Vout with the divider string (with high values), and making R2 the MOSFET alone would seem a more logical circuit.
 

wapo54001

Senior Member
BCJ,

I take your point. I haven't tried it either way, yet.

Tomorrow I will give it a try with a high value divider string connected to the regulator output and separate mosfet control of the adjust pin.
 

BCJKiwi

Senior Member
Tested this setup on a breadboard.
Using;
08M
LM317T - NO smoothing caps on Vin or Vout - data sheet says they are not required!
R1 240R
R2 IRL520NPBF
10K pot on the setting ADC4
10K from Vout to Sensing ADC1
0.5uF (2 1uFs in series) G to D
Power to O8M and LM317T - 3 AA dry cells delivering 4.2V (a bit used!).
These were the components at hand.
Circuit as posted by Wapo (post#27) but with sense circuit moved from Adj to Vout, just a 10K between Vout and ADC1 as Vin below 5V for test.
Code as posted by Wapo (Post #23)

No Load test (Digital Multimeter and CRO the only load)
Regulation was excellent and very stable from 1.23V thru 3.9V but response was slower than expected - voltage lagged pot movement even when moving pot slowly. Settling took approx 5 secs for a step change.
Below 1.227V output locked and could not be adjusted any more until pot moved and circuit reset.
Above 3.9V output locked and could not be adjusted any more until pot moved and circuit reset.

Load Test (added LED and 330R)
Above 2.8V output locked and could not be adjusted any more until pot moved and circuit reset.
 
Last edited:

Dippy

Moderator
Oh, so we're sensing the output now then.

That doesn't look too good BCJ. I know this was just a quick test, but can you try it over a decent range from a >15V power supply?
And you'll need a dead steady supply to PICAXE for meaningful tests, well you know that already I know.
I thought wapo's circuit was a tried and tested jobby?
 
Last edited:

BCJKiwi

Senior Member
@ Dippy,
If you go back a few posts you will see there is fresh debate on sensing the Adj vs sensing Vout. Wapo plans to test both. I figured I do some testing as well since i seemed to have enough stuff to do it on a breadboard.

Ran out of time for further tests earlier and plan further tests tomorrow (10:30pm in NZ right now!)
 

hippy

Technical Support
Staff member
The sluggish response to pot change could be down to the way the capacitor voltage is kicked. In the original code it's ...

HIGH pin : INPUT pin / LOW Pin : INPUT pin

That's just a pulse of about 150us to move the voltage up or down. Add a short pause using PULSOUT before becoming input again and the amount of kick can be varied. The bigger ( longer ) the kick the more the change, the faster it gets where it should be. That pause time could be varied proportionally to the error between read and desired.
 

Dippy

Moderator
How often do you do the refresh 'kick'? Can you vary that time too?
I do a similar proportional refresh on a S/Mode design and it works quite well.
When someone does a test over a decent V range can they also do a quick rough temp coeff type test too please?
 

wapo54001

Senior Member
Dippy:

You must not have read all the posts. I have said repeatedly that this is tried and true WITH AN OUTPUT THAT RANGED FROM 0~5VOLTS ONLY. The two-resistor feedback circuit is entirely new to me, suggested by this thread's requirement to handle more than five volts and is untested. I have said that.

In my proven circuit, from 0~5 volts out, I have total control of output from 0 volts to 5.0 volts with precision and stability. and fast response -- the circuit can go from minimum to maximum in two or three seconds, small changes are virtually instantaneous.

BCJ:

1. try using setfreq to 8MHz to speed things up though I have not had to do that myself.

2. Your circuit is locking up at the top and bottom because you are asking the voltage to go where it is physically impossible, given the voltages you are using. Notice that the correction circuit goes into a loop and stays there trying to adjust to the voltage you have commanded until the objective is achieved. If it can never achieve the level, it will sit there and never return control to the main program, so your pot becomes inoperative.

At the low end, because the LM317 is not able to meet any demand for a voltage below 1.25 volts out, when you read the pot you must do some additional math. Average the pot reading as often as you like, then add a number equal to, say, 1.27 volts -- 260 count. This will prevent the 08M from commanding a voltage lower than you can get with the lm317 (1.25 volts).

Not sure what, if any, math adjustments are needed at the high end of your circuit. But don't set your pot to a value that the output can't deliver. Keep in mind that the control circuit must stay 1.25 volts below the 317 output in order to function properly.

3. Sounds like your circuit might be suffering somewhat from inadequate power supply. I use a single LM317 type regulator set to 5.00 volts.

4 Could you post the software code you are using in its entirety, it sounds like something is slowing things down unnecessarily, unless it's your weak power supply.

Overall, it sounds to me like you have proven the circuit capable of working with the input to the feedback separate from the mosfet. Clearly, resistor values and the implications of the 1.25v differential have to be considered and dealt with. The divider resistor values will always have to be determined based on maximum output value so as to deliver proper voltage to the 08M readADC (staying within the 0~5volt limits).

Good work so far, I'd say.

This afternoon I will go to my workshop and devise a circuit that separates the control circuit from the feedback circuit and see how it goes. I will use a 24V input to the 317 and regulated +5 for the control circuitry, and try to accomodate the 1.25v minimum voltage in my code.
 

hippy

Technical Support
Staff member
There are also three parts to this -

1) Getting the MOSFET to vary the output of the LM317T

2) Creating a control loop to lock the LM317T output to what's required.

3) Getting that control loop working at an acceptable rate to track changes.

I'm a bit confused as to wher we are with this and don't have the hardware to try it for myself. The first thing I would do is start with (1), READADC is of the LM317T output ...

Code:
SetFreq M8
Do
  ReadAdc adc,w0
  SerTxd( #w0, CR, LF )
  High pin
  Input pin
  Pause time
Loop
Does that slowly increase the LM317T output over time and does a 'Low' reduce it ( or vice-versa if that's the case ) ? What are the effects of altering the pause time and adding pauses between the High/Low and Input ?

It seems to me that only when we understand how the control needs to work can we set about doing more with that.

On the issue of latch-up, trying to take the LM317T too low or too high and getting stuck in a loop, as well as limiting what levels are to be matched it's possible to have a kick counter so the kicking bales out even if not going anywhere. That's typical "fail safe design"; even if it isn't doing what is hoped for at least it still keeps running.
 

Dippy

Moderator
Yes, good points and I just realised this method intrinsically compensates for temp drift anyway. So unless Rds goes out of bounds it looks like a winner.

And the delay(s) question crossed my mind. Is the default (steady state) for refresh and charge length just right to 'top up' and then a proportional change for discharging/charging to vary the res=o/p volts?
 
Top