Close

i now have ambient temperature of silicone measurements

A project log for mlx90640 sensor works w 800 bytes

Everywhere i read people are excited to get mlx90640 working. here are examples using arduino w 800bytes ram, and 1k with calibrated DEG C

jamesdanielvjamesdanielv 12/03/2018 at 07:370 Comments

i have the ambient temperature of silicone measurements. this is important for calibration of gain and using difference to cal a individual cells temp. so i'm getting closer. below i show code used, and an image of output to terminal. this is an important step to having sensor work on arduino. 

i will also show the math required to get it working. i don't know why they made it so complex. it didn't need to be. i did also reference Melexis driver code to speed things along, so i'm grateful that they did document it. the Melexis code however uses heavy use of ram, and there is little reason to do so. most of the values are from calibration and several values are fixed once calculated. some calc and conversions are done on the compiler side and never done on Arduino.

to get ambient temp of silicone these values are needed to be calculated

KVPTAT

KTPTAT

VPTAT25

ALPHAPTAT

ptat

ptatArt

Vdd (we use the stored value we have for this already)

the sensor assumes its base temp to be +/- from 25 deg C so offsets to calculate it are from there.

here is my ruff code. i try to use reads from stored data from flash whenever possible but this code needed several reads. good news is that this code can run every frame or only twice per full scan of sensors.

void ExtractAmbientTemp()
{

worddata[0]= pgm_read_word_near(factoryCalData+0x0032);//we can get this value from eeprom, faster and more reliably

   worddata[0]=worddata[0] & 0xFC00;// as per 11.2.2.3
   KVPTAT=worddata[0]>>10;
   if (KVPTAT<31) {KVPTAT-=64;}   
   KVPTAT = KVPTAT/4096;
   
worddata[0]= pgm_read_word_near(factoryCalData+0x0032);//we can get this value from eeprom, faster and more reliably

    KTPTAT = worddata[0]& 0x03FF;
    if(KTPTAT > 511)
    {
        KTPTAT = KTPTAT - 1024;
    }
    KTPTAT= KTPTAT/8;

VPTAT25= pgm_read_word_near(factoryCalData+0x0031);//we can get this value from eeprom, faster and more reliably
  

worddata[0]= pgm_read_word_near(factoryCalData+0x0010);//we can get this value from eeprom, faster and more reliably

    ALPHAPTAT=(worddata[0] & 0xF000)/pow(2, (double)14) + 8.0f;//as per documentation. wil simplify later on
    float ptat;
    float ptatArt;
    float vdd;
    float ta;   
    vdd = Vdd;//Vdd has already been calculated or should have been
    MLX90640_I2CRead(MLX90640_address, 0x0720, 1, worddata);//we read register memory
    ptat= worddata[0];
    if (ptat> 32767 ){ptat = ptat - 65536;}//documented method
    
    MLX90640_I2CRead(MLX90640_address, 0x0700, 1, worddata);//we read register memory
    ptatArt =worddata[0];
   if(ptatArt > 32767){ptatArt = ptatArt - 65536;}
       ptatArt = (ptat / (ptat * ALPHAPTAT + ptatArt)) * pow(2, 18);
    
    ta = (ptatArt / (1 + KVPTAT * (vdd - 3.3)) - VPTAT25);

    
    ta = ta / KTPTAT + 25;
    AmbientTemp=ta;
}

and the math

Discussions