Lab Bench with PicAxe controlling Voltage & Current

albatros

New Member
Hello,

in advance - please appologize my english - I'm not a native english speaker.
Regarding my question, I searched already this Forum and the WEB - I wasn't able to find a concret hint,
how to solve.
It is clear, that it is much cheaper to buy a LAB bench from Ebay or anywhere else - no doubt.
I setup this project bring my "LearnCurve" up in programming a picaxe AND electronic belongings.:eek:

Now - coming to my question::confused:
I build up a LabBench which shall control Voltage and Current by a PicAxe (and later on showing the values on a display)

I pick up the idea from Guido Socher (http://tuxgraphics.org/common/src2/article379/powersupply.pdf) and
EEVBblog (http://www.eevblog.com/projects/usupply/)
- preset of a Voltage and Current value by setting the µController internal values (via buttons) [as Guido]
- output of a PWM-Signal through a low pass filter (to reduce the ripple) [as EEVBlog]
- Control the voltage and current as in [Guidos schematic / Gain ~4-5]


I prepared that circuit (shown below) and set it up on a breadboard.
I already programmed the Picaxe to send out a PWM.
The PWM is filtered by a low pass order - and the output of the lowpass filter has less then
10mV ripple and a range from 0V up to 4,4V. - so thats OK

I'm struggling now with the following topics:
1. I measured that the voltage amplification is not linear - so - how can I allign an output-voltage to a preset
Voltage ? I (tried to ) read the C-program of Guido - but I didn't get it. There are some magic values in the hardware_settings.h (U_divider 10.75 - which do not match to his circuit - R7/R8 )

What I mean is:
I have a resolution of 10Bits; If I preset a duty of lets say 512 - then it is 50% of 4,4V

My first assumptions was:
He measured the output of the R2R-Ladder and adjusted the resistor-divider at the output - so that the two
values can be compared directly.
But - as the amplification is NON-Linear - there must be an other trick.

My 2nd assumption and try was to read back the voltage after the lowpass filter and compare it with the
output-voltage (which has been adjusted before to the same value as the lowpass filter)
This worked 50:50 - because -
yes: it was now possible to control and allign the output to the value of the LowPass-Filter, BUT
the relation beween the preSetValue and the lowpass-Filter/output are not corresponding any more.
These are my measured values:
Assumption: 15V <=> 1000 (not 1023, because I wanted to keep some digits in reserve for controlling)

My 3rd assumption is: I will measure the voltage on the divider;
I know the divider-term: Lets assume it will be R17=4k / R18=1k => Divider-Term = 5
That means: at an output of 15V - R18 will have 3V.
3V are corresponding to a resoultionvalue of 614 (if 5V <=> 1024).
But this needs a absolute stable reference for the PicAxe ? Doesn't it ?

It would be great, if anybody can help me or give me some hints.

Thanks in advance
Albatros

Remark:
Instead of the Transistor-Amplifier - I tried also a similar circuit with OpAmps - with the same result)

And here the circuit
VA_Reg_Picaxe_V01_Circuit.png
 
Last edited:

erco

Senior Member
Albatros: Your English is better than most us here! Your post is very well written with excellent technical details. Smarter people than me (I?) will jump in to help you. :)
 

albatros

New Member
Thanks a lot in advance ....
Currently I try to check my 3rd assumption .....but I'm struggling with the reference ...hope you and other members can help me :)
 

AllyCat

Senior Member
Hi,

Yes, there is no problem with your English. But I am a little confused with your use of symbols such as <=> and <> (in the way that they are used). Also, I can't download your attachment 19113 which is described as "not valid".

So I can't comment on your circuit, but I do think that there are a few details with Guido's design which are "not very good". If you have replaced his "ladder" with a PWM output, then that is a good improvement.

However, the amplifier shown should be linear, with a gain of about 6. But the output (terminal) may not follow very well unless there is a load (current) at the output. Have you tested with a reasonable load (e.g. > 10 mA) ? His 10k + 1k divider is perhaps not taking enough current for the output stage to work well.

Cheers, Alan.
 

albatros

New Member
Hello AllyCat,

I updated now the attachement - and I hope that it is working now.
Jipp - I replaced the r2r-ladder by a PWM-Circuit.

According my 3rd assumption I replaced his 10k+1k diverder by a 4k+1k divider.
I also adapted the a Gain of 4 as my source deliveres maximum 22V - and I want to have at the output a maximum of 18V (15V is also fine for me).

I did now some test measurements - regarding how can I align a digitvalue to a voltage value ?
This is still a big qustion mark in my brain ?

I did the following measurement
I connected the Base of T4 (Transistor amplifier) to a poti.
I adjusted the Base-Voltage/Current of T4 to defined Output Voltage- and read back the ADC-values of the Picaxe (connecting the U_Feedback signal to an ADC-Pin and wrote a small programm)
What I expected and what I measured is shown here .. and it is not exactly reproduceable after power off/on.
Always some digits beside.

PwrOut [V] ... ADC-Value expected ... ADC-value measured
15 ..................... 613 ..................... 628-637
10 ..................... 409 ..................... 419 - 427
5 ..................... 204 ..................... 210 -215
1 ..................... 41 ..................... 43 - 44


The expteced values are calculated like this:
The output-divider is 1/5 (so means if 15V are at the output / UR18 is 3V)
if PicAxe maps 5V to 1023 (by a ReadADC10), then 3V are related to 613.

So - is this the wrong way ?

Albatros
 
Last edited:

AllyCat

Senior Member
Hi,

Perhaps you are overlooking the main purpose of the feedback. Your program might have something like (pseudocode):

Code:
DO
   IF feedback_voltage < required_voltage THEN
      pwm_value = pwm_value + 1 MAX 1023
   ELSE IF  feedback_voltage > required_voltage THEN
      pwm_value = pwm_value - 1 MIN 1         ; Not MIN zero !
   ENDIF
    PAUSE  ???
LOOP
Such a system often works remarkably well but it may be necessary to optimise the PAUSE to make the system stable but reasonably fast-acting. There are better (but more complex) calculations that can be done in the software loop if necessary.

Another factor to consider is that there is a voltage drop which depends on the current in the sensing resistor. Therefore you typically first might calculate: feedback_voltage = output_voltage - current_sense_voltage .

The "reference" voltage should be quite accurate because your supply rail uses a regulator. But PICAXE's Fixed Voltage Reference (FVR) can be useful, particularly for the current measurement.

Cheers, Alan.
 

albatros

New Member
Hi AllyCat,

thats perfekt -thanks a lot.
I will use it to adjust the output if there is a load on it (because then the voltage will go down - and must be adjusted;
if the current will not be exceeded)
Thanks also for the hint regarding the Voltage-Drop over the Current sensor (R19).

Where I still have no glue - what is the mathematic term to adjust/align the required_voltage to a relation of the feedback_voltage;
Regarding the measurement above - there is no linearity (still some bits difference - in the higher values more, then in the lower values../
factor seems not be constant ..)

kind regards,
albatros
 

AllyCat

Senior Member
Hi,

All of the resistor-dividers and the PWM should be "linear" and you seem to understand the calculations. But the amplifier has a number of transistor base-emitter junctions which have a typical "silicon diode" characteristic. This has two main features, a forward voltage drop (or "offset") of about 600 mV and then a logarithmic characteristic (where the voltage increases less steeply with increasing current). Also, the current-gain of the transistors changes over the range of currents, which may produce some more non-linear variations.

It looks as if you will need a PWM duty cycle of around 10% to overcome the Vbe of TR4 before there is any output voltage. Then maybe some non-linearity until the output transistors get up to their peak current-gain. Finally, the current gain can fall considerably if the transistors are being used near to their "maximum" current rating. That's the reason for using "feedback". ;)

But you are correct to question these issues. So many people are satisfied when "it works", without considering if it will still work tomorrow or next year.

Cheers, Alan.
 

albatros

New Member
Hi,

thanks for that explanation. If I understodd correctly, I need to prepare a kind of term/alorithm, which takes an offset
into account for the "lower" values.

In the mean time, I wrote a small testprogram to check the feedback loop.
It'll work fine if there is no load on it.

Then I put a 47 Ohm resistor on the output.
In the higher voltage values I had a drop of nearly 2Volts, in the lower values (<11V) I measured a drop of ~0,7-0,9V.
I expected, that the feedback loop will cover this drop - but nothing happened.
The values read from the feedback loope do match exactly to the voltage Set-values.


I added the code - maybe I made a mistake in the feedback loop -

kind regards
Pierre

Code:
; Testprogram:
; Tasks / idea:
; - output of a PWM-Signal corresponding to a value (voltage preset)
; - different presets can be selected (reading a input button)
; - reading the feedback voltage value of the output (UFeedback)
; - adjust the PWM-Signal (Uout) so that UFeedback will match to Uset
;
; Assumption: UoutMax = 15V <=> 1000 (value of duty) / if linear
; => duty-value 666 => 10V
; => duty-value 333 => 5V ...etc
;
; to be clarified / done
; calibration ?
; how can these values be alligned to a Voltage value
; 

{; pin order & values/variables
; currently tested with a 14M2
Symbol pUout = C.2        ;M20=C.3 / M14: C.2
Symbol pButton = C.1        ;M20=C.0 / M14: C.1

Symbol pUFeedback = B.4        ;readback of Voltage at PwrOut

Symbol vUSet = w0
Symbol vUout = w2            ;value for PWM-Duty
Symbol vUFeedback = w3        ;Voltage at output

Symbol vTmp1 = w10
Symbol vTmp2 = w9
Symbol vTmp3 = w8
}

{; Setup
setup:
setfreq M32
fvrsetup 4096;  1024
pwmout pUout, 255, vUout ; perm. pwm output; 31250 Hz / 32Mhz
vUset = 628
vTmp1 = 1    
}

main:
    ;check if a button is pressed 
    if pinC.0 = 1    then    ;yes, then define 
        inc vTmp1
        pause 1000
    
        select vTmp1
            case 1 : vUSet = 628    ;15V
            case 2 : vUSet = 419    ;10V
            case 3 : vUSet = 210    ;5V
            case 4 : vUSet = 47    ;1V
            case 5 : vUSet = 26    ;0,5V
            case 6 : vUSet = 7    ;0,1V
            case 7:  vUSet = 0    ;0V
            else
            vTmp1=0
        end select
    else ; no button pressed, adjustment shall be done 
        gosub adjustment
    end if

    debug
    pause 500
goto main


adjustment:
    ;adjust Uout until the readback value shows vUset ;
    ; this shall be done in 20 fast loops, then back to check
    ; if the preset has been changed / button has been pressed
    vTmp2 = 0
    for vTmp2 = 1 to 20 Step 1
        readADC10 pUFeedback, vUFeedback    ;read U_feedback
        ;check if adjustement is needed / if UpwrO diff > 2
        if vUFeedback < vUset then
            vUout = vUout +1 MAX 1023
        else if vUFeedback > vUset then
            vUout = vUout -1 MIN 1
        end if 
        pwmduty pUout, vUout
        pause 4        ;1ms/4 = 0,25m at 32Mhz
    next vTmp2
    return
 

AllyCat

Senior Member
Hi,

I haven't read your program in great detail, but perhaps you can correct for the initial voltage offset (bias) by adding (approximately) 100 to the PWM value. Then the gradient (calculated from the amplifier/feedback and gain/attenuation) should be linear enough.

I don't think your feedback is correcting for (i.e. subtracting) the voltage drop across the current-sense resistor?

Finally, I see you use a FVRSETUP command, but not an ADCCONFIG to apply it to the ADC ?

Cheers, Alan.
 

fernando_g

Senior Member
I actually upgraded a plain-vainilla Elenco with a Picaxe.

For starters, I used an adjustable regulator to power the Picaxe with exacly 5.120 volts, which gives a 10 bit conversion a simple and straightforward 5 millivolt per bit. Makes the Picaxe's integer maths far, far easier. Bonus: Some of the better adjustable regulators have a much better temperature and load regulation than a plain vainilla 7805.

Second, your current sampling resistor is way too large and will cause errors. Make it smaller, let's say 100 times smaller, and amplify it with an 100X gain opamp before feeding it back to the Picaxe. Or use a high side current sampling circuit.

Third, make sure that you use star ground techniques.
 

albatros

New Member
Hi,

@Alan: thanks for that hint. I added now the adcconfig %011, but now the vlaue of UFeedback is always 1023 - even, when I connect the input pin to GND ?
If I add adcconfig %000 - then the input values are different? Any idea what I have to look on?

@Fernando_G
Very usefull hints - and I will realize them in my next design step.

So the plan is:
1) Find,create a design to control voltage & current by a PicAxe (easy and understandable)
up to now - not focusing on speed - but have a look on resolution
2) build it up on a breadboard to
test the HW
test the PicAxe-programm
Here I learned a lot about LTSpice, noise, ripples and offset voltage coming from the universe ;-)
(In deed - I searched 2w why I have an offset of 300mv on the PicAxe PWM-Output pin, even if I command a duty of zero..;
result: I had the PicAxe 20M2 mounted on the breadboard - then I tried a 14M2 on the PCB - and voila - no offset anymore ...)

3) manage to control voltage
This is where I'm currently in ...
4) manage to control current
5) combine current & voltag-Control
6) add a display and buttons
7) update design and create PCB
....
 
Top