08M controlled Adjustable Voltage Regulator

BCJKiwi

Senior Member
Description and code/circuit options further revised and posted starting at #5

This post publishes the work discussed in the thread;
http://www.picaxeforum.co.uk/showthread.php?t=10039

NOTE:- Revised description, code, and circuit published 7 August 2008 (BCJ). and incorporates additional contributions from Hippy and further refinement/testing. Updates shown in italics.


The concept is to use an 08M to control the resistance of a MOSFET and use this MOSFET to replace the adjustment Potentiometer (typically 'R2') in the standard circuits for LM317 type adjustable 3 terminal regulators.

A potentiometer is still used to instruct the 08M what output is required. Alternatively the ADC Value - (SetVar, or Target in the MKII code) could be delivered by any mechanism of your choosing.

Why bother?
Program control via the 08M does provide some advantages. As stated by Hippy:- "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."

Wilf_nv published the original circuit
Wapo54001 proposed Wilf's circuit as a possible solution.
Many contributed and, Wapo and BCJ tested different systems.

Debate raged on the best place to pick up the feedback information ~ from the Regulator Vout, or from the Adj Circuit itself.
Vout would appear to be the most logical place as this avoids any issues of the feed back network interacting with the MOSFET variable resistor. In practice, both seem to work well.

The details published below show the Vout sensing circuit and program as tested for 10V output.
The MOSFET seems not to be critical. (Note:- Some "ringing" issues under load have been found with the VN2222L and Vout sensing). The circuit as published was tested using a Bench supply delivering 5V for the PICAXE and 13V Vin for the Regulator for a 1.25 to 10V output.

The regulator tested was an LM317T from ST
Load was applied via resistors.
An LED is required across the Output to provide the required minimum current of 3.5 to 10mA if not using a dummy load else the regulator is unstable.
Tests were carried with out no capacitors on the LM317T.

Minimum Vout for an LM317T is 1.2V
Maximum Output is Vin - 3V, Maximum Vin is 40V
The Data sheet graphs show that once the differential (Vin - Vout) exceeds 12.5V, current capacity drops off rapidly. However the tabulated electrical characteristics show the rated 1.5A for an LM317T is available at Vin - Vout of 15V!
This suggests that for a circuit starting at the minimum 1.2V, 10.8V is the maximum Vout before current reduction starts. (15 - 3 - 1.2 = 10.8V)

The circuit below was tested with two quite different logic level MOSFETS, a Vishay VN2222L and an IRL520N Hexfet. It was also tested with a power (not Logic level) MOSFET MTP3055E TMos 'StripFET'.
All performed admirably with no change to circuit or program although the response varied with the best from the VN2222L and the worst from the MTP3055E. Note some issues found with CRO and the VN2222L

The alternate circuit (obtaining feedback from the adj circuit) was also tested with the VN2222L solely by relocating the wire from the top end of the divider from Vout to Adj.

Please note:-
1. Should the LM317T be powered while the 08M is not, Vout is uncontrolled and floats high. Ensure that the 08M is powered and running first (gate voltage will be 0V) and then turn Vin on, or, turn both on together - i.e derive 08M 5V supply from whatever turns on Vin.

2. Some fine tuning of the Gate Charge Capacitor may be required to obtain smooth and fast tracking of Vout to Adjustment Pot movement depending on MOSFET characteristics. Have had best results with IRL520N and 0.15uF

3. Should you wish to implement this circuit, please read the full thread referenced above, and study all the data sheets.
 
Last edited:

BCJKiwi

Senior Member
ASCII Circuit - FeedBack Vout MKII

Wapo's diagram of the MKI circuit is shown in the attachment.

Code:
'IMPROVED 'MKII' Circuit
'08M controlled 3pin adjustable voltage regulator
'NOTE!! PICAXE supply must be on prior to LM317T Vin else Vout will float to Vin as there is no control on Adj!
'
' INPUT SET POINT ADJUSTMENT
'   V+  --------------------------+
'                                 |
'                                +++
'                                | |
'                          +---->| | Gang1 100k Pot
'                          |     | |
'                          |     +++
'                          |      |
'                          +------+
'                                 |
'                                +++
'           +-----+              | |
'08M Leg3 --+ 10k +--+---------->| | 10k Pot         This circuit provides improved coarse / Fine adjustment.
' (ADC4)    +-----+              | |                 Alternatively use 10k divider Pot only 
'                                +++
'                                 |
'                          +------+
'                          |      |
'                          |     +++
'                          |     | |
'                          +---->| | Gang1 100k Pot
'                                | |
'                                +++
'                                 |
'   0V  --------------------------+
'
'
'
' FEEDBACK and REGULATOR OUTPUT ADJUSTMENT
'           +-----+
'08M Leg6 --+ 10k +---------------+
' (ADC1)    +-----+               |
'                                 |
'                                 |
'                        +-----+  |  +-----+       Divider not required for 5Vout
'   0V  -----------------+ 10k +--+--+ 10k +--+    Divider 0V--10k--+--10k--Vout for 10Vout
'                        +-----+     +-----+  |    Divider 0V--10k--+--20k--Vout for 15Vout
'                                             |    Divider 0V--10k--+--30k--Vout for 20Vout
'                                             |
'                       Leg3+---------+Leg2   |
'   Vin --------------------+ LM317T  +-------+--+ Vout ~ LM317T, A, LM338 or other similar 3 pin regulator
'   Vin = Vout-3V           +----+----+       |  |        Caps may be required for Regulator
'                            Leg1|            |  |       
'                            Adj |  +------+  |  |
'                                +--+ 240R +--+  |
'                                |  +------+
'                     See Notes  |              LOAD (Minimum 3.5 ~ 10mA, MAX 1,5A depending on Vout and HEATSINK)
'                     +--0.2 uF--+
'                     |          |               |
'                     |          |Drain          |
'           +------+  |  Gate+---+----+          |
'08M Leg5 --|  1M  |--+------+ IRL520 |          | low power, logic level, fast switching,
'           +------+         +---+----+          |    enhanced N-Channel MOSFET
'                                |Source         |      Voltage = Vout plus safety
'                                |               |      Current ~ 50 to 100uA Adj Current, check the regulator specs
'                                |               |
'   0V  -------------------------+---------------+
'
' NOTES:-
' MOSFET
'  some MOSFETs seem unstable - 
'  If rate of change of R to Gate voltage is too great oscillation may occur
'  IRL520N and 2N7000 tested well
' Gate Capacitor ~ 0.2uF
'  Change 0.2uF capacitor to suit MOSFET ~ Range from 0.1uF to 0.47uF can be expected
'  High value slows response to step change
'  Low value increases tendency to hunt around set point.
 

Attachments

Last edited:

BCJKiwi

Senior Member
ASCII Circuit - FeedBack Adj

Attached diagram is a real diagram courtesy of Wapo MKI version

ASCII Circuit Diagram MKI
Code:
'08M controlled 3pin adjustable voltage regulator ~ FeedBack from Adj
'
'                      +-+---- V+
'           +-----+    | |
'08M Leg3 --+ 10k +--->| | 10k Pot Linear       Input ~ setting adjustment for Vout
' (ADC4)    +-----+    | |
'                      +-+---- V0
'
'
'           +-----+
'08M Leg6 --+ 10k +---------------+
' (ADC1)    +-----+        _      |
'                     5.1|\ |     |
'               0V  -----+ >|-----+             ZENER not essential - provides additional protection for ADC1 port
'                        |/ |_    |
'                                 |
'                        +-----+  |  +-----+    Divider not required for 5Vout
'               0V  -----+ 10k +--+--+ 10k +--+ Divider 0V--10k--+--10k--Vout for 10Vout
'                        +-----+     +-----+  | Divider 0V--10k--+--20k--Vout for 15Vout
'                                             | Divider 0V--10k--+--30k--Vout for 20Vout
'                                             |
'                                             |
'      +--------------------------------------+
'      |
'      |
'      |                Leg3+---------+Leg2
'      |        Vin---------+ LM317T  +-------+--+ Vout ~ LM317A, LM338 or other similar 3 pin regulator
'      |  Vin = Vout-3V     +----+----+       |  |        Caps may be required for Regulator
'      |                     Leg1|            |  |       
'      |                     Adj |  +------+  |  |
'      +-------------------------+--+ 240R +--+  |
'                                |  +------+
'                        0.33uF  |              LOAD
'                     +--0.47uF--+
'                     |          |               |
'                     |          |Drain          |
'           +------+  |  Gate+---+----+          |
'08M Leg5 --|  1M  |--+------+ IRL520 |          |  Any low power, logic level, fast switching,
'           +------+         +---+----+          |    enhanced N-Channel MOSFET
'                                |Source         |    Voltage = Vout plus safety
'                                |               |    Current ~ 50 to 100uA Adj Current, check the regulator specs
'                                |               |
'                                0V              0V
'
 

Attachments

Last edited:

BCJKiwi

Senior Member
08M Program

MkII Version of the Code.

This code provides;
Improved speed of response to a step change in set value.
Much smoother and better regulated output. Output settles very quickly on set value without 'hunting' around set point.
Fuller documentation of code.
Code:
#PICAXE 08M
setfreq m8
SYMBOL Set  = 4    'ADC4 ~ the voltage setting Pot input
SYMBOL FeedBk  = 1    'ADC1 ~ the feedback loop input
SYMBOL Gate  = 2    'In/Out2 ~ output 'pump' to the R/C network on the MOSFET Gate
High Gate      'Drive Vout to minimum for safety on start-up!
SYMBOL SetVar = w0
SYMBOL FeedBkVar= w1
SYMBOL Target   = w2
SYMBOL SetVar_1 = w3
SYMBOL SetVar_2 = w4
SYMBOL SetVar_3 = w5
SYMBOL Damper = w6
SYMBOL K_Div    = 8    'Max Vout / Min Vout   ~ e.g. 10 / 1.25 = 8. ~ Min Vout is a function of the Regulator
SYMBOL K_Mul    = K_Div - 1  'K_Div - 1
SYMBOL K_Min    = 127   '1023 / Max Vout * Min Vout ~ e.g. 1023 / 10 * 1.25 = 127
'
main:
 readadc10 Set,SetVar  'read setting Pot input voltage, store in SetVar
'Sum the last three ReadADC values to reduce pot inconsistencies and smooth adjustment
'Setvar = 60* average of last three readings
'Adjust Set input value to ensure ouput cannot go below 1.25V minimum, or above MaxVout (1023 on FeedBack ADC)
'Target = adjusted range /60 plus bottom limit offset
'*60 / 60 improves Integer math accuracy (for example ~ 1023/8*7+127=1016 ~ 1023*60/8*7/60+127=1022) 
 SetVar_3 = SetVar_2
 SetVar_2 = SetVar_1
 SetVar_1 = SetVar *20  '* 20 to improve integer Math accuracy for Target calculation
 SetVar = SetVar_1 + SetVar_2 + SetVar_3   'Sum last 4 Readings,  SetVar = 60 * average reading
 Target = SetVar / K_Div * K_Mul / 60 + K_Min
'adjust:
 readadc10 FeedBk,FeedBkVar  'get voltage data from output
 if Target = FeedBkVar then
  input Gate    'hold Gate charge
  goto  main     'return as output matches target
 EndIf
'increase:
 if Target > FeedBkVar then 'Out put is too low so raise output
  Damper = Target - FeedBkVar
  If Damper < 2 then main 'If change is just 1 unit, skip ~ damps out 'hunting' around set point
  low Gate    'lower Gate V = Lower MOSFET R = Higher Current through Adj circuit = higher Vout
  goto main
 EndIf
'decrease:
   'if Target < FeedBkVar then ~ falls through to decrease if not increase! If...Endif not required
  Damper = FeedBkVar - Target
  If Damper < 2 then main 'If change is just 1 unit, skip ~ damps out 'hunting' around set point
  high Gate    'Higher Gate V = Higher MOSFET R = Lower Current through Adj circuit = Lower Vout
  goto main
end

MKI version of the Code.
Code:
#picaxe 08M
setfreq m8
SYMBOL Set  = 4   'ADC4
SYMBOL FeedBk  = 1   'ADC1
SYMBOL Gate  = 2   'In/Out2
SYMBOL SetVar = w1
SYMBOL FeedBkVar = w2
SYMBOL PauseTime = w3
High Gate     'Drive Vout to minimum for safety!
 
main:
readadc10 Set,SetVar        'read setting Pot input voltage
'Adjust Set input value to ensure no attempt made to adjust ouput below 1.2V minimum, or above 5V input to ADC1
'*50 & /50 improve integer math accuracy (for example ~ 1023/8*7+127=1016 ~ 1023*50/8*7/50+127=1022) 
'1.25 ~ 5V
'SetVar = SetVar * 50 / 4 * 3 / 50 + 255
'with Vin 8V, Vout=5V, ADC4 input adjusted between range of 1.25V to 5V
'1.25 ~ 10V
SetVar = SetVar * 50 / 8 * 7 / 50 + 127
'with Vin 13V, Vout=10V, ADC4 input adjusted between range of 1.25V/2 to 10V/2
 
'1.25 ~ 15V
'SetVar = SetVar * 50 / 12 * 11 / 50 + 85
'with  Vin 18V,Vout=15V, ADC4 input adjusted between range of 1.25V/3 to 15V/3
'1.25 ~ 20V
'SetVar = SetVar * 50 / 16 * 15 / 50 + 64
'with  Vin 23V,Vout=20V, ADC4 input adjusted between range of 1.25V/4 to 20V/4
adjust:
 readadc10 FeedBk,FeedBkVar   'get voltage data from output
 if SetVar=FeedBkVar then main  'return if output is correct
 if SetVar > FeedBkVar Then
   pausetime = SetVar - FeedBkVar 'set pause time based on size of offset
 else
   pausetime = FeedBkVar - SetVar
 endIf
 
 if SetVar>FeedBkVar then increase
   'if SetVar < FeedBkVar then decrease ~ falls through to decrease if not increase!
decrease:
 high Gate      'set pin2 high to decrease Vout ~ Higher Gate V, Higher MOSFET R, Lower Vout
 pause pausetime   output  '0.5ms per count @ 8mHz,PICAXE 1ms @ 4mHz poutputer count ~ continue to lower gate voltage
 input Gate      'tri-state pin2 and hold Vout
 goto adjust
increase:
 low Gate      'set pin2 low to increase Vout ~ Lower Gate V, Lower MOSFET R, Higher Vout
 pause pausetime     '0.5ms per count @ 8mHz, 1ms @ 4mHz per count ~ continue to raise gate voltage
 input Gate       'tri-state pin2 and hold Vout
 goto adjust
 
Last edited:

BCJKiwi

Senior Member
Enhanced 08M controlled Adjustable Voltage Regulator

Description, code, and diagrams updated.

This post publishes the work discussed in the thread;
http://www.picaxeforum.co.uk/showthread.php?t=10039

Further evolution has resulted in some changes to the preferred circuit layout and refined program options.

The concept is to use an 08M to control the resistance of a MOSFET and use this MOSFET to replace the adjustment Potentiometer (typically 'R2') in the standard circuits for LM317 type adjustable 3 terminal regulators.

Potentiometer(s) or Push Buttons can be used to instruct the 08M what output is required. Alternatively the ADC Value - (SetVar) could be delivered by any mechanism of your choosing.

Debate raged on the best place to pick up the feedback information ~ from the Regulator Vout, or from the Adj Circuit itself.
Vout would appear to be the most logical place as this avoids any issues of the feed back network interacting with the MOSFET variable resistor. However, as the Adj control is by current, Vout effectively appears at the Adj pin (after the 240R). Using the adjust pin has two advantages;
1. simplified wiring to the LM317T. Only the 240R and the standard Regulator Cap are required to be associated with the regulator itself.
2. simplified math as the minimum offset relating to the minimum Vout no longer needs to be included.

The versions posted here use only feed back sensing from the Adj circuit (not from Vout directly).
The MOSFET seems not to be critical. However some MOSFETS seem less stable than others. The circuit as published was tested using a Bench supply delivering 5V for the PICAXE and 13V Vin for the Regulator ( for a 1.25 to 10V output).

The regulator tested was an LM317T from ST
Load was applied via resistors.
An LED is required across the Output to provide the required minimum current of 3.5 to 10mA if not using a dummy load else the regulator is unstable.
Tests were carried with out with a 1uF capacitor on the LM317T output.

Minimum Vout for an LM317T is 1.2V
Maximum Output is Vin - 3V, Maximum Vin is 40V
The Data sheet graphs show that once the differential (Vin - Vout) exceeds 12.5V, current capacity drops off rapidly. However the tabulated electrical characteristics show the rated 1.5A for an LM317T is available at Vin - Vout of 15V!
This suggests that for a circuit starting at the minimum 1.2V, 10.8V is the maximum Vout before output current capacity reduction starts. (15 - 3 - 1.2 = 10.8V).

The circuit below was tested with two quite different MOSFETS, a logic level IRL520N Hexfet and an MTP3055E TMos 'StripFET'.
Both performed admirably with no change to circuit or program. Wapo uses the 2N7000 low power signal MOSFET which was the MOSFET used in the scheme from which this system evolved - 2N7000 was not available for testing.

Please note:-
1. IF the LM317T be powered while the 08M is not, Vout is uncontrolled and floats high.
Ensure that the 08M is powered and running first (gate voltage will be 0V) and then turn Vin on, or, turn both on together - i.e derive 08M 5V supply from whatever turns on Vin.

2. Some fine tuning of the Gate Charge Capacitor may be required to obtain smooth and fast tracking of Vout to Adjustment Pot movement depending on MOSFET characteristics. Have had best results with 0.15uF when using the IRL520N ~ see the circuit diagram notes for further info.

3. Should you wish to implement this circuit, please read the full thread referenced above, and study all the data sheets.
 
Last edited:

BCJKiwi

Senior Member
Pot input

If the SYMBOL names are unclear, these may readily be replaced with your own by using Edit/Replace in the programming Editor.
Similarly the Symbol names for variables and port numbers can be replaced using Edit/Replace.

Code:
'08M controlled 3pin adjustable voltage regulator
'NOTE!! PICAXE supply must be on prior to LM317T Vin else Vout will float to Vin as there is no control on Adj!
'
' INPUT SET POINT ADJUSTMENT
'   V+  --------------------------+
'                                 |
'                                +++
'                                | |
'                          +---->| | Gang1 100k Pot
'                          |     | |
'                          |     +++
'                          |      |
'                          +------+
'                                 |
'                                +++
'           +-----+              | |
'08M Leg3 --+ 10k +--+---------->| | 10k Pot         This circuit provides improved Coarse / Fine adjustment.
' (ADC4)    +-----+              | |                 Alternatively use 10k divider Pot only.
'                                +++
'                                 |
'                          +------+
'                          |      |
'                          |     +++
'                          |     | |
'                          +---->| | Gang1 100k Pot
'                                | |
'                                +++
'                                 |
'   0V  --------------------------+
'
'
'
' FEEDBACK and REGULATOR OUTPUT ADJUSTMENT
'           +-----+
'08M Leg6 --+ 10k +---------------+
' (ADC1)    +-----+               |
'                                 |
'                                 |
'                        +-----+  |  +-----+       Divider not required for 5Vout
'   0V  -----------------+ 10k +--+--+ 10k +--+    Divider 0V--10k--+--10k--Vout for 10Vout
'                        +-----+     +-----+  |    Divider 0V--10k--+--20k--Vout for 15Vout
'                                             |    Divider 0V--10k--+--30k--Vout for 20Vout
'                                             | Divider 0V--10k--+--30k--Vout for 20Vout
'                                             |
'      +--------------------------------------+
'      |
'      |
'      |                Leg3+---------+Leg2
'      | Vin ---------------+ LM317T  +-------+--+ Vout ~ LM317T, A, LM338 or other similar 3 pin regulator
'      | Vin = Vout-3V      +----+----+       |  |        Caps may be required for Regulator
'      |                     Leg1|            |  |       
'      |                     Adj |  +------+  |  |
'      +-------------------------+--+ 240R +--+  |
'                                |  +------+
'                     See Notes  |              LOAD (Minimum 3.5 ~ 10mA, MAX 1,5A depending on Vout and HEATSINK)
'                     +--0.2 uF--+
'                     |          |               |
'                     |          |Drain          |
'           +------+  |  Gate+---+----+          |
'08M Leg5 --|  1M  |--+------+ IRL520 |          | low power, logic level, fast switching,
'           +------+         +---+----+          |    enhanced N-Channel MOSFET
'                                |Source         |      Voltage = Vout plus safety
'                                |               |      Current ~ 50 to 100uA Adj Current, check the regulator specs
'                                |               |
'   0V  -------------------------+---------------+
'
' NOTES:-
' MOSFET
'  Some MOSFETs seem unstable - 
'  If rate of change of R to Gate voltage is too great oscilation may occur
'  IRL520N and 2N7000 tested well
' Gate Capacitor ~ 0.2uF
'  Change 0.2uF capacitor to suit MOSFET ~ Range from 0.1uF to 0.47uF can be expected
'  High value slows response to step change
'  Low value increases tendency to hunt around set point.
Code:
#PICAXE 08M
setfreq m8
SYMBOL Set      = 4            'ADC4 ~ the voltage setting Pot input
SYMBOL FeedBk   = 1            'ADC1 ~ the feedback loop input
SYMBOL Gate     = 2            'In/Out2 ~ output 'pump' to the R/C network on the MOSFET Gate
High Gate                      'Drive Vout to minimum for safety on start-up!
SYMBOL SetVar_1 = w1           'Variable for FIFO buffer
SYMBOL SetVar_2 = w2           'Variable for FIFO buffer
SYMBOL SetVar_3 = w3           'Variable for FIFO buffer
SYMBOL SetVar   = w4
SYMBOL FeedBkVar= w5
SYMBOL Damper   = w6
main:
   readadc10 Set,SetVar  'read setting Pot input voltage
'Sum the last three ReadADC values to reduce pot inconsistencies and smooth adjustment
'Setvar = 60* average of last three readings
'*60 / 60 improves Integer math accuracy
   SetVar_3 = SetVar_2
   SetVar_2 = SetVar_1
   SetVar_1 = SetVar *20       '* 20 to improve integer Math accuracy for Target calculation
   SetVar = SetVar_1 + SetVar_2 + SetVar_3 / 60  'Sum last 4 Readings,  Setvar = 60 * average reading
 
'adjust:
   readadc10 FeedBk,FeedBkVar  'get voltage data from output
   if SetVar = FeedBkVar then
      input Gate               'hold Gate charge
      goto  main               'return as output matches target
   EndIf
'increase:
   if SetVar > FeedBkVar then  'Out put is too low so raise output
      Damper = SetVar - FeedBkVar
      if Damper < 2 then main  'If change is less than 1 unit, skip ~ damps out 'hunting' around set point
      low Gate                 'lower Gate V = Lower MOSFET R = Higher Current through Adj circuit = higher Vout
      goto main
   EndIf
'decrease:
   'if Target < FeedBkVar then ~ falls through to decrease if not increase! If...Endif not required
   Damper = FeedBkVar - SetVar
   If Damper < 2 then main     'If change is less than 1 unit, skip ~ damps out 'hunting' around set point
      high Gate                'Higher Gate V = Higher MOSFET R = Lower Current through Adj circuit = Lower Vout
      goto main
end
If more variables are required in the program for other code then the following alternative for the FIFO buffer routines may be used, This frees 2 more variables. Caution - Additional code doing other things may slow cycle rate and adversly affect regulation!
Code:
#PICAXE 08M
setfreq m8
SYMBOL Set      = 4             'ADC4 ~ the voltage setting Pot input
SYMBOL FeedBk   = 1             'ADC1 ~ the feedback loop input
SYMBOL Gate     = 2             'In/Out2 ~ output 'pump' to the R/C network on the MOSFET Gate
High Gate                       'Drive Vout to minimum for safety on start-up!
SYMBOL SetVar_1 = 80            'Register address for FIFO buffer
SYMBOL SetVar_2 = 82            'Register address for FIFO buffer
SYMBOL SetVar_3 = 84            'Register address for FIFO buffer
SYMBOL Temp_Var = w3            'working temporary variable for peeks/pokes to FIFO
SYMBOL SetVar   = w4
SYMBOL FeedBkVar= w5
SYMBOL Damper   = w6
'
main:
   readadc10 Set,SetVar         'read setting Pot input voltage, store in SetVar
'Sum the last three ReadADC values to reduce pot inconsistencies and smooth adjustment
'SetVar = 60* average of last three readings
'Adjust Set input value to ensure output cannot go below 1.25V minimum, or above MaxVout (1023 on FeedBack ADC)
'Target = adjusted range /60 plus bottom limit offset
'*60 / 60 improves Integer math accuracy
   peek setvar_2, word Temp_Var : poke SetVar_3, word Temp_Var
   peek setvar_1, word Temp_Var : poke SetVar_2, word Temp_Var
   Setvar = SetVar * 20         : poke SetVar_1, word SetVar   '* 20 to improve integer Math accuracy
   peek setvar_2, word Temp_Var : SetVar = SetVar + Temp_Var
   peek setvar_3, word Temp_Var : SetVar = SetVar + Temp_Var / 60   'SetVar = 60 * average reading
 
'adjust:
   readadc10 FeedBk,FeedBkVar   'get voltage data from output
   if SetVar = FeedBkVar then
      input Gate                'hold Gate charge
      goto  main                'return as output matches target
   EndIf
'increase:
   if SetVar > FeedBkVar then   'Out put is too low so raise output
      Damper = SetVar - FeedBkVar
      If Damper < 2 then main   'If change is just 1 unit, skip ~ damps out 'hunting' around set point
      low Gate                  'lower Gate V = Lower MOSFET R = Higher Current through Adj circuit = higher Vout
      goto main
   EndIf
'decrease:
   'if Target < FeedBkVar then ~ falls through to decrease if not increase! If...Endif not required
      Damper = FeedBkVar - SetVar
      If Damper < 2 then main   'If change is just 1 unit, skip ~ damps out 'hunting' around set point
      high Gate                 'Higher Gate V = Higher MOSFET R = Lower Current through Adj circuit = Lower Vout
      goto main
end
 
Last edited:

BCJKiwi

Senior Member
Push Button Input

Code:
'08M controlled 3pin adjustable voltage regulator
'NOTE!! PICAXE supply must on prior to LM317T Vin else Vout will float to Vin as there is no control on Adj!
'
'   PUSH BUTTON INPUT CIRCUIT
'
'         PB
'         ---   +-----+
'   V+  --+ +---+ 10k +----+
'               +-----+    |
'                          |
' 08M Input ---------------+
'                          |
'               +-----+    |
'   0V  --------+ 10k +----+
'               +-----+
'   (same circuit Legs 3 & 4)
'
'
'
' FEEDBACK and REGULATOR OUTPUT ADJUSTMENT
'           +-----+
'08M Leg6 --+ 10k +---------------+
' (ADC1)    +-----+               |
'                                 |
'                                 |
'                        +-----+  |  +-----+       Divider not required for 5Vout
'   0V  -----------------+ 10k +--+--+ 10k +--+    Divider 0V--10k--+--10k--Vout for 10Vout
'                        +-----+     +-----+  |    Divider 0V--10k--+--20k--Vout for 15Vout
'                                             |    Divider 0V--10k--+--30k--Vout for 20Vout
'                                             |    Divider 0V--10k--+--30k--Vout for 20Vout
'                                             |
'      +--------------------------------------+
'      |
'      |
'      |                Leg3+---------+Leg2
'      | Vin ---------------+ LM317T  +-------+--+ Vout ~ LM317T, A, LM338 or other similar 3 pin regulator
'      | Vin = Vout-3V      +----+----+       |  |        Caps may be required for Regulator
'      |                     Leg1|            |  |       
'      |                     Adj |  +------+  |  |
'      +-------------------------+--+ 240R +--+  |
'                                |  +------+
'                     See Notes  |              LOAD (Minimum 3.5mA ~ 10mA, MAX 1,5A depending on Vout and HEATSINK)
'                     +--0.2 uF--+
'                     |          |               |
'                     |          |Drain          |
'           +------+  |  Gate+---+----+          |
'08M Leg5 --|  1M  |--+------+ IRL520 |          | low power, logic level, fast switching,
'           +------+         +---+----+          |    enhanced N-Channel MOSFET
'                                |Source         |      Voltage = Vout plus safety
'                                |               |      Current ~ 50 to 100uA Adj Current, check the regulator specs
'                                |               |
'   0V  -------------------------+---------------+
'
' NOTES:-
' MOSFET
'  Some MOSFETs seem unstable - 
'  If rate of change of R to Gate voltage is too great oscillation may occur
'  IRL520N and 2N7000 tested OK
' Gate Capacitor ~ 0.2uF
'  Change 0.2uF capacitor to suit MOSFET ~ Range from 0.1uF to 0.47uF can be expected
'  High value slows response to step change
'  Low value increases tendency to hunt around set point.
'
If the SYMBOL names are unclear, these may readily be replaced with your own by using Edit/Replace in the programming Editor.
Similarly the Symbol names for variables and port numbers can be replaced using Edit/Replace
Code:
#PICAXE 08M
setfreq M8
SYMBOL Up_PB     = 4            'Input4 PB Up
SYMBOL Dn_PB     = 3            'Input3 PB Dn
SYMBOL FeedBk    = 1            'ADC1   FeedBack
SYMBOL Gate      = 2            'In/Out2
High Gate                       'Drive Vout to minimum for safety!
SYMBOL Dn_Var    = b8           'Button Command Repeat storage variable
SYMBOL Up_Var    = b9           'Button Command Repeat storage variable
SYMBOL Set_Var   = w5
SYMBOL FeedBk_Var= w6
Set_Var = 1                     'Preset Program to Minimum Vout for safety
 
main:
' These Button Command explanatory notes courstesy of BeanieBots.
' "Delay" is how many times the command must be passed before it does the first repeat.
' "Rate" is how many times the command must be passed before it subsequent repeats.
' "Var" must be set to zero before the command is used (as explained in the manual) but 
'  that must be a once only setting. It must be done before you enter the loop which scans your button.
' Delay = 255 == No repeat
 
 
'BUTTON pin   ,downstate,delay,rate,bytevariable,targetstate,address
Button  Dn_PB ,1        ,200  ,4   ,Dn_Var      ,1          ,Vout_Dn  'Delay ~ Max = 254 = Longest 
Button  Up_PB ,1        ,200  ,4   ,Up_Var      ,1          ,Vout_Up  'Rate  ~ Min = 1   = Fastest

goto adjust      'If no button pressed, goto Adjust:
Vout_Dn:
   Set_Var = Set_Var - 1 Min 1  'If min not set at 1, 0-1=65535 ~ underflows Set_Var to 65535!
   goto Adjust
Vout_Up:
   Set_Var = Set_Var + 1 Max 1023
adjust:
   readadc10 FeedBk,FeedBk_Var  'get voltage data from output via 240R and Vout
   if Set_Var = FeedBk_Var then
      input Gate                'hold Gate charge
      goto  main                'return, output matches target
   EndIf
increase:
   if Set_Var > FeedBk_Var then 'Out put is too low so raise output
      low Gate                  'lower Gate V = Lower MOSFET R = Higher Current through Adj circuit = higher Vout
      goto main
   EndIf
decrease:
   'if Target < FeedBk_Var then ~ falls through to decrease if not increase! If...Endif not required
      high Gate                 'Higher Gate V = Higher MOSFET R = Lower Current through Adj circuit = Lower Vout
      goto main
end
 
Last edited:
Top