Shop OBEX P1 Docs P2 Docs Learn Events
ds1620 and negative temperatures — Parallax Forums

ds1620 and negative temperatures

ChristianGChristianG Posts: 29
edited 2004-11-22 07:53 in General Discussion
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
Sign In or Register to comment.