Module Name:    src
Committed By:   kardel
Date:           Wed May 14 08:14:56 UTC 2014

Modified Files:
        src/sys/dev/onewire: owtemp.c

Log Message:
calculate extended precision as per DS1920/DS1820 data sheets


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/onewire/owtemp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/onewire/owtemp.c
diff -u src/sys/dev/onewire/owtemp.c:1.16 src/sys/dev/onewire/owtemp.c:1.17
--- src/sys/dev/onewire/owtemp.c:1.16	Mon Jun 20 17:24:16 2011
+++ src/sys/dev/onewire/owtemp.c	Wed May 14 08:14:56 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: owtemp.c,v 1.16 2011/06/20 17:24:16 pgoyette Exp $ */
+/*	$NetBSD: owtemp.c,v 1.17 2014/05/14 08:14:56 kardel Exp $ */
 /*	$OpenBSD: owtemp.c,v 1.1 2006/03/04 16:27:03 grange Exp $	*/
 
 /*
@@ -22,7 +22,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: owtemp.c,v 1.16 2011/06/20 17:24:16 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: owtemp.c,v 1.17 2014/05/14 08:14:56 kardel Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -64,7 +64,7 @@ CFATTACH_DECL_NEW(owtemp, sizeof(struct 
 extern struct cfdriver owtemp_cd;
 
 static const struct onewire_matchfam owtemp_fams[] = {
-	{ ONEWIRE_FAMILY_DS1920 },
+	{ ONEWIRE_FAMILY_DS1920 }, /* also DS1820 */
 	{ ONEWIRE_FAMILY_DS18B20 },
 	{ ONEWIRE_FAMILY_DS1822 },
 };
@@ -235,6 +235,21 @@ owtemp_decode_ds1920(const uint8_t *buf)
 	temp = (int8_t)buf[1];
 	temp = (temp << 8) | buf[0];
 
-	/* Convert to uK */
-	return (temp * 500000 + 273150000);
+	if (buf[7] != 0) {
+		/*
+	 	 * interpolate for higher precision using the count registers
+	 	 *
+	 	 * buf[7]: COUNT_PER_C(elsius)
+	 	 * buf[6]: COUNT_REMAIN
+	 	 *
+	 	 * T = TEMP - 0.25 + (COUNT_PER_C - COUNT_REMAIN) / COUNT_PER_C
+	 	 */
+		temp &= ~1;
+        	temp += 500000 * temp + (500000 * (buf[7] - buf[6])) / buf[7] - 250000;
+	} else {
+		temp *= 500000;
+	}
+
+	/* convert to uK */
+	return (temp + 273150000);
 }

Reply via email to