CALIBADC & CALIBADC10

Aries

New Member
I've been using a slightly modified version of AllyCat's I2C scanner (https://picaxeforum.co.uk/threads/i2c-bus-search-program-for-slaves.32149/ - post #4) on a 28X2 and a 40X2. I've not touched the calibadc section for determining the voltage of the power supply, but it consistently gives me about half what I read with a voltmeter. It looks for all the world as if the reference voltage is 2.048 instead of 1.024. Has anybody else had this experience? Am I right, or am I missing something?
 

AllyCat

Senior Member
Hi,

The code that I used there reads CALIBADC10 twice to give double the resolution/value, so maybe one of those reads is being "lost"? I never use X2 chips but note that the 28/40X2-5v chips don't support CALIBADC. Also, IIRC that CALIBADC{10} (in M2s) may give incorrect results after any FVR commands have been used. EDIT: Or maybe it was the ADCCONFIG command that caused problems (in not being re-initialised properly by CALIBADC). So try putting an ADCCONFIG 0 and both a FVRSETUP FVR1024 and then a FVRSETUP FVR2048 (separately) before the Calibadc code.

Sorry I can't write more at the moment, so try those few "tweaks" to my basic code:
Code:
    Calibadc10 w0
    w0 = w0 / 2 + 52378 / w0
    Calibadc10 w1            ; Sample again to average and give 10mV resolution
    w0 = 52378 / w1 + w0
Cheers, Alan.
 
Last edited:

Aries

New Member
Both calibadc10s were executed (I put in sertxds to make sure) and gave results around 400.
This is the section of code from the I2C scanner. The voltmeter reads 4.53V.
Code:
    Calibadc10 w0
        sertxd(13,10,"w0=",#w0)
    w0 = w0 / 2 + 52378 / w0
        sertxd(" -> ",#w0)
    Calibadc10 w1            ' Sample again to average and give 10mV resolution
    w0 = 52378 / w1 + w0
        sertxd(" w1=",#w1," -> ",#w0)
and the output:
Code:
SCL= 11  SDA= 12  V+= 0  GND=0

w0=410 -> 128 w1=394 -> 260
Vpsu = 2.60 Volts
Looking for Devices ...

   0  2  4  6  8  A  C  E      0  2  4  6  8  A  C  E
0 XX XX XX XX XX XX XX XX   1 -- -- -- -- -- -- -- --
2 -- -- -- -- -- -- -- --   3 -- -- -- -- -- -- -- --
4 -- -- -- -- -- -- -- --   5 -- -- -- -- -- -- -- --
6 -- -- -- -- -- -- -- --   7 -- -- -- -- -- -- -- --
8 -- -- -- -- -- -- -- --   9 -- -- -- -- -- -- -- --
A A0 -- -- -- -- -- -- --   B -- -- -- -- -- -- BC --
C -- -- -- -- -- -- -- --   D -- -- -- -- -- -- -- --
E E0 -- -- -- -- -- -- --   F XX XX XX XX XX XX XX XX

Device found at A0 (10100000) = EEPROM 24LCxxx
Device found at BC (10111100) =   (Unknown)
Device found at E0 (11100000) =   (Unknown)
I've tried with fvrsetup but no difference - this is my code:
Code:
#no_data
#terminal 9600

pause 5000

setfreq m8
do
sertxd(13,10,13,10,"1024")
for b20 = 0 to 7
     pause 1000
     adcconfig 0
     fvrsetup fvr1024
     pause 100
     Calibadc10 w0
     fvrsetup fvr1024
     pause 100
     Calibadc10 w1
     adcconfig 0
     pause 100
     Calibadc10 w2
     fvrsetup fvr1024
     pause 100
     Calibadc10 w3
     sertxd(13,10,#w0," ",#w1," ",#w2," ",#w3)
next b20
... repeated with fvr2048 and fvr4096
loop
and the results:
Code:
1024
392 391 400 408
389 395 402 403
409 398 407 417
395 405 416 401
413 414 389 399
402 408 419 420
395 399 404 402
396 419 390 403

2048
416 397 410 405
414 400 408 403
400 419 399 421
399 415 399 418
398 414 392 414
408 416 413 403
410 408 396 406
402 391 410 414

4096
414 398 406 421
407 399 420 393
415 400 410 408
401 421 390 421
392 417 397 407
418 400 411 412
404 419 419 417
399 418 395 410

1024
422 409 406 392
418 416 416 417
406 396 405 413
410 400 403 400
418 405 401 393
402 392 392 395
404 399 395 398
401 399 407 421

2048
409 398 401 420
411 404 420 401
415 396 416 418
421 407 417 389
406 417 389 413
394 410 417 393
403 406 413 400
392 399 391 403

4096
414 393 421 405
420 422 398 409
404 403 400 420
398 414 403 406
409 404 413 402
394 419 397 409
399 411 409 405
412 398 422 406
Incidentally, the manual says that fvr is reset to 1.024 by the calibadc anyway.

It's not in any way holding me up, but if there is either something I am doing wrong or something wrong in the manual, I (and maybe others) would like to know.
 

AllyCat

Senior Member
Hi,

Yes, values of around 400 indicates that the FVR is about 40% of the supply rail, which suggests that FVR2048 is being used. But I can't see anything in the "Revision History" (aka bugs) tab for a typical X2 chip

I can only suggest that you examine the VREFCON0 SFR (in particular) after a Calibadc has been executed. From the (28X2) data sheet, it appears that bits 5:4 should be set to 0:1 to select the FVR1024 (the PICaxe SFR address appears to be $42). This is different to the M2 chips which use bits 3:2 and 1:0 for different purposes (and calls it the FVRCON SFR).

I've also documented alternative code snippets for example HERE to measure the PICaxe supply rail, but I believe it's been identified that they can't be used with the X2 chips. :(

Cheers, Alan.
 

Aries

New Member
Interesting result - the output for
Code:
peeksfr $42,b0
sertxd(13,10,"VREFCON0 at start ",#bit7,#bit6,#bit5,#bit4,#bit3,#bit2,#bit1,#bit0)

sertxd(13,10,13,10,"1024")
     pause 1000
     adcconfig 0
     fvrsetup fvr1024
     peeksfr $42,b10
     pause 100
     Calibadc10 w0
     peeksfr $42,b11
     fvrsetup fvr1024
     pause 100
     Calibadc10 w1
     adcconfig 0
     pause 100
     Calibadc10 w2
     fvrsetup fvr1024
     pause 100
     Calibadc10 w3
     sertxd(13,10,#w0," ",#w1," ",#w2," ",#w3)
     b0 = b10
     b1 = b11
     sertxd(" VREFCON0 before ",#bit7,#bit6,#bit5,#bit4,#bit3,#bit2,#bit1,#bit0," after ",#bit15,#bit14,#bit13,#bit12,#bit11,#bit10,#bit9,#bit8)

... and repeat for 2048, 4096
gives
Code:
VREFCON0 at start 01010000

1024
485 485 486 477 VREFCON0 before 11010000 after 01010000

2048
464 496 464 471 VREFCON0 before 11100000 after 01010000

4096
480 484 473 483 VREFCON0 before 11110000 after 11110000
- i.e. it doesn't get cleared by calibadc10 when set to 4.096 (which, if it thinks the power supply is less than 4 volts, is not a valid setting anyway).
 

AllyCat

Senior Member
Hi,

Your CALIBADC10 is now producing values around 480, so presumably the supply voltage is now a little lower? But still a "missing" a factor of 2, and the "spread" in values is much worse than I would expect (normally perhaps +/-1).

When I encountered "issues" with the (M2) "readinternaltemp" feature, I emulated the command with a sequence of POKE/PEEKSFR commands (including reading the ADC registers directly) which showed that the instruction wasn't doing what was claimed! It's not too difficult to emulate the PICaxe commands by referring to the base PIC data sheet (e.g. the PICaxe command parameters are often quite similar to the SFR values), which might show that something isn't working "as expected". Sorry, I can't try it myself as I don't have any X2 chips. However, the subroutine "readitemp" in post #10 of this Code Snippet (for M2s) may give an indication how to read ADC values using only SFR commands.

Cheers, Alan.
 

Aries

New Member
Alan,

Thanks for your thoughts, and the time you have spent on it. This is now getting rather beyond me and, as I said, it's not important to what I really need to do, so I'm going to have to set it to one side - for now, at least.
 
Top