READINTERNALTEMP RAW clarification needed

premelec

Senior Member
In trying to use internal temperature sense on 08M2 using the RAW Low setting I get a figure about 444 + CDeg [room temp 13...] in the word variable. I'm not understanding just what the reading represents or if it is directly related to CDeg. I looked at the thread from July when the M2 parts were first introduced and the AP note referred to but haven't got a definite answer other than the reading must be individually calibrated per chip... Thanks...
 

jtcurneal

Senior Member
As I understand it, the RAW Low ( IT_RAW_L ) represents the ADC result of the voltage drop across 2 on chip diodes.

That word value would have to be compared to the chip voltage ( v+ )
and have other computations to give an indication of the temperature of the Picaxe chip.

Joel
 

premelec

Senior Member
Thanks... would an internal ref V like 1.024 be in play on the LOW function? I'm trying to avoid my changing battery voltage being involved... :)
 

jtcurneal

Senior Member
As I read the manual,

READINTERNALTEMP voltage, - offset, variable
- Voltage is a constant that indicates the power supply voltage.

and

The readinternaltemp command reads the analogue voltage drop across 2 (low)
or 4 (high) internal diodes. This gives a very approximate temperature indicator.

I do not see any option to use any reference voltage other than the power supply voltage.
The only difference between LOW and HIGH is the number of diodes involved.

Joel
 

jtcurneal

Senior Member
@premelec - I'm trying to avoid my changing battery voltage being involved... :)

Microchip application note AN1333 does give a procedure for doing the calculations when the supply voltage is changing.

Joel
 

hippy

Ex-Staff (retired)
I'm not understanding just what the reading represents or if it is directly related to CDeg.
The IT_RAW_L and IT_RAW_H options give 'some value' for a specific temperature. Take two readings at different temperatures, plot the results, draw a line between the two points and you can translate any value read to a temperature. Determine the equation for the line and you can do that programmatically.

The line will be offset ( shifted up or down ) depending on chip, and the slope of the line changes depending on supply voltage.

As the line is linear, readings are proportional to centigrade, it's just having to determine the slope and offset of the line to create an appropriate translation equation that is a little complicated.

The IT_5V0 and other options apply an appropriate equation which converts the raw temperature reading to an approximate temperature for a specific voltage and an offset can be applied as part of those commands.
 

eclectic

Moderator
Cheers hippy.
I now have a better understanding of the "K"
on p.176 of Manual 2

Advanced information:​
The mathematical equations used to attempt to convert the raw values intodegrees Celsius are:

5V0 RAW_H +/- K -508 * 14 / 13 + 5​
and so on
 

g6ejd

Senior Member
And I believe the CALIBADC can be used to determnine supply voltage changes (derived from the internal reference) to correct for supply voltage changes under programme control by varying m in y = mx + c for the line.

I use CALIBADC10 to compensate for supply variation in my PICAXE pressure gauge, works really well - the benefit of many years of experience to generate the need for the command, which become largely apparent when you look at some of these commands, initally why? then of course...that's why it's there.
 

premelec

Senior Member
OK thanks for all the good advice - I was hoping that the voltage used in CALIBADC10 might be applied to the diodes for temperature - it looks like I'll need to work up a somewhat complicated procedure for CALIBADC10, then two temperature points and an linear interpolation... it may be easier to regulate the voltage supply... at least the M2 parts have enough program space to pull that off and have some room for more stuff... I also have AD590s... :)
 

g6ejd

Senior Member
Yes, it might be easier to regulate the supply, but then that's no fun :)

The output of 'calibadc10' is as follows:

Vreading = Vref x 1024 / Vsupply (or for calibadc Vreading = Vref x 256 / Vsupply)

On my 5V system with the 10bit variant of the command I get a reading of 209, at 5.1V 205 and 4.9 V 213.

So what I do is take a reading using 209 as my reference and then in your your example if the supply climbed to 5.1V, I would modify (y=mx+c) m by a factor 205/209 and 213/209 if 4.9V

Not that difficult to do, all you need to do is get your temperature reading working correctly; as described above, then add to your routine a calibadc command then modify your gradient with the result.
 

premelec

Senior Member
@g6ejd some get fun from hardware and some from software - well as some from a mix... considering the complication of calibration per chip as well as chip tmperature from self heating being unknown if driving any load I think I'll reserve this particular measurement for what it was intended for - IS MY PICAXE ON FIRE??! IF THEN make lots of beeps before it dies... :) Thanks for your detailed remarks above in regard to the necessary calculations - I'm thinking it should have Vref X 1023 and 255 but of course I could be confused... I laid out a row of 255 jelly beans representing the voltage steps - but I may have lost count at some point.... [I was eating some ] :) 73...
 

g6ejd

Senior Member
Well they are 8-bit or 10-bit so 256 and 1024 respectively, so that's why I used those values. The question is, do you put a jelly bean where 0 is - is there a bean or not... :)
73 my friend
 

premelec

Senior Member
double post or only one... "leave the page" query unclear...

added remarkHi OT, there's the rub... 2^8 = 256 but %11111111 = 255... I sent a long time looking for the 0 jelly bean and reduced the consideration to 2 bits as I was eating too many jelly beans... with 2 bit ADC and a 3 volt supply we have

%00 = 0v
%01 = 1v
%10 = 2v
%11 = 3 volts

if you want full scale at full # of bits.... I think this is the way the ADC is set up - full scale at full bits and full bits is 2^bits -1 in terms of number of voltage steps to get you to full scale... i guess the real issue is knowing how the convertors are actually set up in reality - having played with electronics for over 60 years I would go with tracking actual measurements - and go empirical. I've got to get down on the floor and find that zero jelly bean before the ants move in... 73... Thanks for your input...

I just tried an 08M in a test board and learned two things - V+ to READADC = 255 and my pot on that board is defective...:)
 
Last edited:

g6ejd

Senior Member
double post or only one... "leave the page" query unclear...

So if you tie ADC input to Gnd you will get 0, so that makes 0 to 255 = 256

BTW the US jelly beans (Jelly Belly's) are far tastier than the UK variants, although we don't have so many exotic flavours and I've never seen pepper flavour yet, but of course have in the USA. The prank flavours are a great concept e.g. earwax, vomit and acid...
 

hippy

Ex-Staff (retired)
So if you tie ADC input to Gnd you will get 0, so that makes 0 to 255 = 256
That's correct ...

8-bit ADC gives 256 possible values, 0 to 255

10-bit ADC gives 1024 possible values, 0 to 1023

So if you connect the ADC to +V then the value returned will be 255 or 1023. If we call that Nadc, and know the +V supply of the PICAXE (Vpsu), we can calculate the voltage to the ADC (Vadc) by one of ...

Vadc = ( Nadc / 255 ) * Vpsu

Vadc = ( Nadc / 1023 ) * Vpsu

Rearranging that; if we know the voltage being input to the ADC (Vadc), such as when reading the internal voltage reference (CALIBADC), we can calculate what the power supply voltage (Vpsu) is, one of ...

Vpsu = ( Vadc * 255 ) / Nadc

Vpsu = ( Vadc * 1023 ) / Nadc

It's possible to use 256 or 1024 in those calculations instead of 255 and 1023 when that makes them easier to implement if the loss of accuracy is acceptable.
 

premelec

Senior Member
"It's possible to use 256 or 1024 in those calculations instead of 255 and 1023 when that makes them easier to implement if the loss of accuracy is acceptable. "

@Hippy I certainly respect your great knowledge and opinions however I think suggesting loss of accuracy being acceptable when either number is usable is not going in a good direction philosophically.... though it's certainly IS _possible_ :) [BTW are you going into politics? Then any number works...]

@g6ejd I didn't know that UK JBs were different flavored... we have quite a few varieties and I'll keep my eye out for those wonderful flavors you mentioned... We do have chocolates that incorporate pepper - can't wait for the cayenne Jelly Beans...
 

Technical

Technical Support
Staff member
A reason to / 256 on a micro would be for speed - if you have a word variable dividing by 256 is the same as just reading the top byte of the word - hence instant without any maths.
 

hippy

Ex-Staff (retired)
Divide by 1023 has to be done by division but divide by 1024 can be achieved by a shift right by 10 on PICAXE which support that, which is a bit quicker, or by taking the MSB byte and a shift right by 2 which shaves another few microseconds off that calculation.
 
Last edited:

premelec

Senior Member
AD590...

@John West - complication with the AD590s is that they have a 3.5 volt operating minimum voltage - so with a 5 volt supply that gives you 1.5 volts to measure the temperature - 1ua per degK so at 373 degK and 1.5 volts that's about a 4K resistor but you've also cut into the resolution per PICAXE reading.... a solution is to have a higher voltage supply - 8.5 volts - for the AD590 or to use op amps appropriately to condition the AD590 signal. The 18B20s are good though a bit slow on conversion time... thermistors and thermocouples still work - the perfect temperature unit has yet to arrive...whatever works... :) Happy PICAXEing have fun!
 
Remember too that you are measuring a PN junction and the I/V curve of the diode (Generic Assumed) is anything but linear.
If the curve was repeatable in shape and magnitude... (it varies due to process variations at chip level)
It would be the Temp Measuring Device of choice... instead of the LM34-LM35 AD592...
Or any of the other Linear Temp measuring devices. The PN junction voltage must be "Linearised" and "Scaled" which means
controlling the PN Junction Current (curve linearization) and the gain of the (usually) Op-Amp that interfaces the junction
(temperature measuring) device to the Real World...
Robert K. Johnson Sr. WA7EMS
 
Top