Close

beginning reduction of memory usage again. this time with verification

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 08/13/2019 at 12:310 Comments

i have moved the feature of NEW_METHOD true to memCache.h folder, when it is set to true the code now uses 5k less of data here is how.

i have changed the eeprom data either method to get the data from flash memory. the old mem management still collects data into pixel matrix, of float, and int. 

i removed the need for these variables so far. (i made code not use pointers, and i switched code that reads the array to a function that requests data from the cell. since data is in progmem it is almost as fast as a ram read. 

        float alpha[768]; 
        int16_t offset[768]; //we dont need this anymore

ill show the old method of getting offset (but after i removed the struct and pointer 

void ExtractOffsetParameters( )
{
    int occRow[24];
    int occColumn[32];
    int p = 0;
    int16_t offsetRef;
    uint8_t occRowScale;
    uint8_t occColumnScale;
    uint8_t occRemScale;
    

    occRemScale = (eeDataGetStoredInLocalEPROM(16) & 0x000F);
    occColumnScale = (eeDataGetStoredInLocalEPROM(16) & 0x00F0) >> 4;
    occRowScale = (eeDataGetStoredInLocalEPROM(16) & 0x0F00) >> 8;
    offsetRef = eeDataGetStoredInLocalEPROM(17);
    if (offsetRef > 32767)
    {
        offsetRef = offsetRef - 65536;
    }
    
    for(int i = 0; i < 6; i++)
    {
        p = i * 4;
        occRow[p + 0] = (eeDataGetStoredInLocalEPROM(18 +i) & 0x000F);
        occRow[p + 1] = (eeDataGetStoredInLocalEPROM(18 +i) & 0x00F0) >> 4;
        occRow[p + 2] = (eeDataGetStoredInLocalEPROM(18 +i) & 0x0F00) >> 8;
        occRow[p + 3] = (eeDataGetStoredInLocalEPROM(18 +i) & 0xF000) >> 12;
    }
    
    for(int i = 0; i < 24; i++)
    {
        if (occRow[i] > 7)
        {
            occRow[i] = occRow[i] - 16;
        }
    }
    
    for(int i = 0; i < 8; i++)
    {
        p = i * 4;
        occColumn[p + 0] = (eeDataGetStoredInLocalEPROM(24 +i) & 0x000F);
        occColumn[p + 1] = (eeDataGetStoredInLocalEPROM(24 +i)& 0x00F0) >> 4;
        occColumn[p + 2] = (eeDataGetStoredInLocalEPROM(24 +i) & 0x0F00) >> 8;
        occColumn[p + 3] = (eeDataGetStoredInLocalEPROM(24 +i) & 0xF000) >> 12;
    }
    
    for(int i = 0; i < 32; i ++)
    {
        if (occColumn[i] > 7)
        {
            occColumn[i] = occColumn[i] - 16;
        }
    }

    for(int i = 0; i < 24; i++)
    {
        for(int j = 0; j < 32; j ++)
        {
            p = 32 * i +j;
            offset[p] = (eeDataGetStoredInLocalEPROM(64 +p) & 0xFC00) >> 10;
            if (offset[p] > 31)
            {
                offset[p] = offset[p] - 64;
            }
            offset[p] = offset[p]*(1 << occRemScale);
            offset[p] = (offsetRef + (occRow[i] << occRowScale) + (occColumn[j] << occColumnScale) + offset[p]);
        }
    }
}

new method

int16_t ExtractOffsetParametersRawPerPixel(uint16_t value )
{//we get row and collumb data and process from there
  uint8_t col= (value&31) ;//we take bottom 5 bits and add as we use 1-32
  uint8_t row=(value&65504)>>5;;//this should have upper bits only
  
    //int occRow[24];
    //int occColumn[32];
    //we only need to store one word each as conversion done on the fly
    int occRow;
    int occColumn;
   uint8_t p = 0;
    int16_t offsetRef;
   uint8_t occRowScale;
    uint8_t occColumnScale;
    uint8_t occRemScale;
    

    occRemScale = (eeDataGetStoredInLocalEPROM(16) & 0x000F);
    occColumnScale = (eeDataGetStoredInLocalEPROM(16) & 0x00F0) >> 4;
    occRowScale = (eeDataGetStoredInLocalEPROM(16) & 0x0F00) >> 8;
    offsetRef = eeDataGetStoredInLocalEPROM(17);//11hex
    if (offsetRef > 32767)
    {
        offsetRef = offsetRef - 65536;
    }
//we have raw number for offset now
p=row&3;//we have 0-3 for data bits
uint8_t i=row>>2;
   if (p==0) {       occRow = (eeDataGetStoredInLocalEPROM(18 +i) & 0x000F);}
   if (p==1) {       occRow = (eeDataGetStoredInLocalEPROM(18 +i) & 0x00F0) >> 4;}
   if (p==2) {       occRow = (eeDataGetStoredInLocalEPROM(18 +i) & 0x0F00) >> 8;}
   if (p==3) {       occRow = (eeDataGetStoredInLocalEPROM(18 +i) & 0xF000) >> 12;}
   

        if (occRow > 7)
        {
            occRow = occRow - 16;
        }
    
  p=col&3;//we have 0-3 for data bits  
  i=col>>2;
       
  if (p==0) {       occColumn = (eeDataGetStoredInLocalEPROM(24 +i) & 0x000F);}
  if (p==1) {       occColumn = (eeDataGetStoredInLocalEPROM(24 +i)& 0x00F0) >> 4;}
  if (p==2) {       occColumn = (eeDataGetStoredInLocalEPROM(24 +i) & 0x0F00) >> 8;}
  if (p==3) {       occColumn = (eeDataGetStoredInLocalEPROM(24 +i) & 0xF000) >> 12;}
   
 
        if (occColumn > 7)
        {
            occColumn = occColumn- 16;
        }
   

 //   for(int i = 0; i < 24; i++)
 //   {
 //       for(int j = 0; j < 32; j ++)
  //      {
   //         p = 32 * i +j;//this can be directly value
            ;//we have direct cell number

   
           // offset[p] = (eeDataGetStoredInLocalEPROM(64 +p) & 0xFC00) >> 10;

            int16_t temp=(eeDataGetStoredInLocalEPROM(64 +value) & 0xFC00) >> 10;
            if (temp > 31)
            {
               temp = temp- 64;
            }
           temp =temp*(1 << occRemScale);
           temp = (offsetRef + (occRow << occRowScale) + (occColumn << occColumnScale) + temp);
     //   }
  //  }
  return temp;
}

the difference is now rather than pointing to a storeage in an array, i'm running a function that extracts the data from progmem. 

Discussions