ds1620 and negative temperatures
ChristianG
Posts: 29
In case somebody is using the ds1620 with negative temperatures:·The DS1620 class suddenly returns high values like 127 (-1 degr.C), 126(-2 degr C).
I had to correct the ·getTempRaw()-method to make it work, and change the interpretation of the “sign” variable:
·
·public int getTempRaw(){
··· CPU.writePin(enablePin,true);
··· CPU.shiftOut(dataPin,clockPin,8,CPU.SHIFT_LSB,READ_TEMP);
··· tempIn = (CPU.shiftIn(dataPin,clockPin,9,CPU.POST_CLOCK_LSB) >> 7);
··· CPU.writePin(enablePin,false);
··· sign = (tempIn >> 8);························ // isolate sign bit
··· tempIn = (tempIn & 0x00FF);·················· // mask sign bit from temp
·
··· ·······
··· //if (sign == 1) // temp is negative
··· // for negative temp sign is 0xFFFF, the correct test that is working is: ·········· ····
· ··if (sign != 0) // temp is negative
····· return (tempIn | -256);···················· // tempIn | 0xFF00
··· else
····· return tempIn;
· }
Christian
I had to correct the ·getTempRaw()-method to make it work, and change the interpretation of the “sign” variable:
·
·public int getTempRaw(){
··· CPU.writePin(enablePin,true);
··· CPU.shiftOut(dataPin,clockPin,8,CPU.SHIFT_LSB,READ_TEMP);
··· tempIn = (CPU.shiftIn(dataPin,clockPin,9,CPU.POST_CLOCK_LSB) >> 7);
··· CPU.writePin(enablePin,false);
··· sign = (tempIn >> 8);························ // isolate sign bit
··· tempIn = (tempIn & 0x00FF);·················· // mask sign bit from temp
·
··· ·······
··· //if (sign == 1) // temp is negative
··· // for negative temp sign is 0xFFFF, the correct test that is working is: ·········· ····
· ··if (sign != 0) // temp is negative
····· return (tempIn | -256);···················· // tempIn | 0xFF00
··· else
····· return tempIn;
· }
Christian