Picaxe Maths

hippy

Senior Member
I have verified the code with Matlab
Again: How did you calculate / determine your Vref constant to be 1058, and what is your actual Vref voltage ?

Proving that your code produces the same results as MATLAB does not prove you are calculating the supply voltage correctly or accurately.

It seems your results are not that far off but there is increasing discrepancy as the supply voltage drops because you are using a 1058*50 (52900) calculated constant rather than a more accurate 52378 constant.

Assuming your Vref voltage is 1.024V then, for example, your 204 result is 5.18V when it should be 5.12V, your 211 result is 5.01V when it should be 4.96V.
 

BESQUEUT

Senior Member
It seems your results are not that far off but there is increasing discrepancy as the supply voltage drops because you are using a 1058*50 (52900) calculated constant rather than a more accurate 52378 constant.
This will do nothing... but you can try...
Code:
52378			
VoltUnit	Vref/VoltUnit	Temp	Temp*2
204	5,1351	256	512
205	5,1100	255	510
206	5,0852	254	508
207	5,0607	[COLOR="#FF0000"]253	506[/COLOR]
208	5,0363	[COLOR="#FF0000"]251	502[/COLOR]
209	5,0122	250	500
210	4,9884	249	498
211	4,9647	248	496
V=ENT(Vref/VolUnit)+ENT(Vref/(VoltUnit+1)) (AllyCat code)
Code:
52378		
VoltUnit	Vref/VoltUnit   V
204	5,1351	511
205	5,1100	509
206	5,0852	507
207	5,0607	504
208	5,0363	501
209	5,0122	499
210	4,9884	497
211	4,9647	495
 
Last edited:

rmeldo

Senior Member
Again: How did you calculate / determine your Vref constant to be 1058, and what is your actual Vref voltage ?

Proving that your code produces the same results as MATLAB does not prove you are calculating the supply voltage correctly or accurately.

It seems your results are not that far off but there is increasing discrepancy as the supply voltage drops because you are using a 1058*50 (52900) calculated constant rather than a more accurate 52378 constant.

Assuming your Vref voltage is 1.024V then, for example, your 204 result is 5.18V when it should be 5.12V, your 211 result is 5.01V when it should be 4.96V.
I didn't realize that I could be so out in terms of offset and slope. Are you saying that a Vref of 1058 is too far from the usual 1024 to be due just to differences between individual physical chips? In any case I will repeat the calibration procedure.

Also just for kicks I plotted how the error changes with voltage for two different values of Vref (attached).

Vref_0158.jpgVref_0157.jpg

Riccardo
 

hippy

Senior Member
The results you get are different to the ideal results one would expect for a Vref of 1.024V but I would guess that if it is not actually 1.024V then it may be a better match. Vref is specified as something like -8%/+6% so there is some scope for variance.

It was more that I could not see where the 1058 was derived from. If it is from calibration with a specific chip then it likely is more optimal for that.
 

hippy

Senior Member
I decided to run some tests on an actual chip connected to the bench power supply.

Code:
#Picaxe 08M2
#Terminal 4800

Symbol SAMPLES = 128

Symbol Nref    = w0
Symbol total   = w1
Symbol average = w2
Symbol counter = w3

Do
  total = 0
  For counter = 1 To SAMPLES
    CalibAdc10 nref
    total = total + nref
  Next
  average = total / SAMPLES  
  SerTxd( #average, " " )
  Pause 1000
Loop
This gave the following results and what "K" would be to determine the supply voltage from the actual reading using "Vpsu=K/Nref" ...

Code:
Vpsu   Nref     K
5.5    191    1050.5
5.0    211    1055.0
4.5    234    1053.0
4.0    263    1052.0
3.5    301    1053.5
3.0    351    1053.0
2.5    421    1052.5
What a single "K" value should be is rather hard to say, and probably depends upon which range one wanted to have least errors for.

Ignoring above 5V, the K*50 to maximise PICAXE maths resolution for this case would be between 52600 and 52750, 52675 being halfway between the two, somewhat higher than the 52378 the perfect world value would be.

Using 52675 gives an excellent match for the voltage points measured, across the entire 2.5V to 5.5V range.

Using the perfect world 52378 gave results which were 2 or 4 units out (20mv/40mV) against using 52675 so it doesn't seem it really makes much difference what "K" is used nor whether calibrated or not, but it does point to calibration being necessary if hoping to achieve best accuracy.
 

rmeldo

Senior Member
Just checked the voltage: the Picaxe display said 5.02.
The multimeter said 5.013V.
I also checked the multimeter against the a breadboard power supply . I measures 4.95v And 3.3V so I am satisfied that I am in the right ballpark.

Thanks
Riccardo
 
Top