Need some help understanding this

oracacle

Senior Member
I have been sifting through some my old stuff, came across the old data logger i got for my GCSE, any how long story short it gets very cold ing my new place and i was think I could log the tempurature - a little more acuratly than before

well any way i went digging for the readtemp12, and have been up most of the night trying to learn and unerstand the commands that you guys have used to get the negative temp readings
Code:
symbol temp		= w0
symbol whole	= b2
symbol deci		= b3
symbol sign		= b4
symbol adjtemp	= w3
symbol com		= 44
symbol ret		= 13
symbol lfeed	= 10

main:
	'let temp = 4095				;test for negative temps
	readtemp12 7, temp			;read 12bit data from DS18B20
	
	sign = 43					;"+"
		
	if temp > 2048 then 			;check for negative temp
	sign = 45					;"-"
	temp = 65535 - temp			;two's complement
	temp = temp and 4095+1			;mask off top 4 bit, add 1 for correction
	end if

	adjtemp = temp *10/16			;x10 for 0.1 resolution
	whole = adjtemp / 10
	deci = adjtemp // 10

	sertxd (sign,#whole,44,#deci,13,10)
	goto main
in particular the lines labelled with two's complement and mask off top 4 bit, add 1 for correction.

any how will i have to store the pre and post decimal number in sperate addresses or can i just store the word and proccess the data when i collect it?
 

westaust55

Moderator
Maybe have a read of the Wiki description for two's complement might give you an understanding of what it is (ie save me typing several paragraphs).

While the code you are using for the two's compliment does work there is a shortcut which is not clearly spelled out in the PICAXE manual.

Code:
	sign = 43					;"+"
	if temp > 2048 then 			;check for negative temp
	  sign = 45					;"-"
	  temp = - temp			        ;two's complement
	end if
the temp = -temp is in effect the twos compliment without worrying about the upper 4 bits.
If you read the DS18B20 datasheet the for the 12 bit mode (as used by the PICAXE) the upper 4 bits are not used so the original code you have found was masking them off.
But the one line version of the two's complement works equally as well.
 

oracacle

Senior Member
thanks for that, its makes a little more snese now, i will update my programme so that it takes in the vode you hvae suggested.

i like the more optimised code, i will be adding the memeroy right and read later
 

oracacle

Senior Member
OK that code seems to work, however, running this morning i get alot of odd readings

Code:
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+20,6
+80,6
-188,1
+16,6
+16,6
-8,9
+16,6
+16,6
-34,5
+16,6
+24,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
-188,1
+16,6
-8,9
-34,5
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+24,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+48,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
-8,9
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
-136,9
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
-34,5
+16,6
+16,6
+80,6
+16,6
-136,9
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
-188,1
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,9
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
-188,1
+16,6
-34,5
+16,6
+16,6
+16,6
+16,6
+16,6
+20,6
+16,6
+16,6
+48,6
+16,6
+17,6
+80,6
+20,6
-188,1
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+18,6
+16,6
+16,6
+16,6
+16,6
+16,6
+18,6
+16,6
+16,6
+16,6
-8,9
+16,6
+16,6
+16,6
+16,6
-188,1
+16,6
+16,6
+16,6
+17,6
+16,6
+16,6
+16,6
+17,6
+16,6
+16,6
+20,6
+48,6
+16,6
+16,6
+16,6
+16,6
+20,6
+17,6
+16,6
+16,6
+18,6
+16,6
+16,6
+24,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
-188,1
+18,6
+16,6
+48,6
+16,6
+16,6
+16,6
-34,5
+16,6
+16,6
+20,6
+16,6
+16,6
+16,6
+16,6
+16,7
+16,7
+17,7
+17,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
-136,8
-156,0
+16,7
+16,7
+16,7
+20,6
+16,6
+16,6
-136,9
+16,6
+16,6
+16,6
+80,6
+16,6
+16,6
+24,6
+18,6
+16,6
+16,6
+16,6
+16,6
-188,1
-188,1
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
-136,9
-34,5
+16,6
+16,6
+16,6
+16,6
-8,9
-8,9
-8,9
-136,9
+16,6
+16,6
+16,6
+16,6
+16,6
+20,6
+16,6
+16,6
+16,6
+16,7
+16,7
+16,7
+17,7
+16,7
+16,7
+16,7
+16,8
+16,7
+16,7
+24,7
+16,7
+16,7
+16,7
+80,7
+16,7
-188,0
+16,7
+16,7
+24,7
-8,8
+16,7
+16,7
-136,8
+16,7
+16,7
+16,7
+16,7
+16,7
-34,4
+16,7
+80,7
-34,4
-136,8
+16,7
+16,7
+16,7
+16,7
-188,0
+16,7
+16,7
+16,7
-136,8
+48,7
+16,7
+16,7
+16,6
+16,6
+16,6
+24,6
+16,6
+16,6
+16,6
+18,6
+16,6
+16,6
-8,9
+16,6
+16,6
-8,9
+16,6
+16,6
+20,6
+24,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,7
+16,7
+80,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
-156,0
+16,6
+16,6
+16,6
-136,9
+16,6
+16,6
-136,9
+16,6
+16,6
+16,6
+16,6
+16,6
+18,6
+16,6
+16,6
+16,6
+80,7
+16,7
+16,7
+16,7
+16,7
-136,8
+16,7
+16,7
+16,8
+16,7
+16,7
+16,7
+16,7
+16,7
-34,4
+16,7
+16,7
-136,8
+16,7
+16,7
+16,7
+16,7
-34,4
+16,7
+16,7
+16,7
+80,7
+16,7
+17,7
+16,7
+16,7
+16,6
+20,6
+16,6
+18,6
-136,9
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+80,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
-188,1
+16,6
+16,6
+16,6
+16,6
+16,6
+20,6
+16,7
+80,7
+24,7
+16,7
-8,8
+16,7
+16,7
-34,4
+16,7
+16,7
-136,8
+16,7
+20,7
+16,7
-136,8
+16,7
+20,7
+16,7
+16,7
+16,7
+16,7
-136,8
+16,7
+16,7
+16,7
+16,7
+16,7
-184,0
+16,7
+16,7
+16,7
-188,1
+16,6
+16,6
-136,9
+16,6
+16,6
+16,6
+16,9
+16,6
+16,6
+16,6
+16,6
+48,6
+16,6
+16,6
+80,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+17,7
+16,8
+16,7
+16,7
+16,7
+18,7
+16,7
+80,7
+16,7
-187,9
-188,0
-136,8
-136,8
+16,7
-136,8
+16,7
+16,7
-136,8
+16,7
+16,7
+16,7
+16,7
-188,1
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,7
+16,7
+16,7
+17,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+80,7
+16,7
+16,7
-136,8
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
-34,4
+16,7
+16,7
+16,8
+16,7
-34,4
+16,7
+18,7
+16,7
+16,7
+16,7
-136,8
+16,7
+16,7
+16,6
-34,5
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
-187,9
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+80,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,8
+16,8
+16,7
+16,7
+20,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+80,7
+48,8
+16,7
+16,7
+16,7
+16,7
+16,7
+17,7
-136,8
+16,7
+16,7
+16,7
+16,7
+16,7
-34,4
+24,7
-34,4
+16,7
+16,7
+16,7
+17,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,8
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+20,7
+16,7
+16,8
+17,7
+16,7
+16,7
+18,7
+20,7
-8,8
+16,7
+16,7
+16,7
+16,7
+17,7
-188,0
+16,7
+16,7
+16,7
+16,7
-8,8
-8,8
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+17,7
+16,7
+16,8
+80,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
-8,8
+16,7
+16,7
+16,7
+80,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+20,7
+16,7
+16,7
+16,8
+16,7
+16,7
+48,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+18,7
+16,7
+16,8
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
-8,8
+16,7
+16,7
+24,7
+16,7
+16,7
+16,7
-188,0
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
-136,8
+16,7
+48,7
+16,7
+16,7
+20,7
+16,7
-136,8
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+48,7
+16,7
+16,7
+18,7
+16,7
+17,8
+16,7
+16,7
+16,7
+16,7
+80,7
-8,8
+16,7
+16,7
+16,7
+24,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
-188,0
+16,7
+16,8
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
-136,9
+16,6
+16,7
+16,7
-188,0
+16,7
+16,7
+16,7
+80,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+16,7
+24,7
+16,8
+16,6
+16,6
+84,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
+16,6
has anoyone seen anything like this before, voltage reading is 4.45v at the pin for the ds18b20.

also while i am here, what sort of readings should i get in the temp word to see low negative numbers (-1,-2,-3 etc)
 
Top