POC1.5 prototype 2 x color sensor 2 x LM75B 3 x AnalogIn 1 x accel

Dependencies:   mbed vt100

Files at this revision

API Documentation at this revision

Comitter:
Rhyme
Date:
Mon Dec 11 05:52:25 2017 +0000
Parent:
10:88e5b8157167
Child:
12:4c0bd7fce2fd
Commit message:
gas pressure linear equation (hopefully) was corrected

Changed in this revision

sensors/PSE530.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/sensors/PSE530.cpp	Mon Dec 11 02:11:50 2017 +0000
+++ b/sensors/PSE530.cpp	Mon Dec 11 05:52:25 2017 +0000
@@ -31,13 +31,30 @@
     }
 }
 
+/**
+ * On FRDM-KL25Z ADC's AREF is about 3.28V
+ * Where the converted pressure output is 0 to 3.21V
+ * So we must map ADC output 0 to 3.21/3.28 as full scale
+ * 
+ * Then according to the datasheet of PSE530
+ * when full range is 0V to 5V
+ * 1V is 0 and 5V is 1MPa which is converted to
+ * 0.642/3.28 to 3.21/3.28 ~ 0.195731 to 0.9786585.
+ * The linear equation of
+ * y = a x + b
+ * 0 = a * 0.195731 + b
+ * 1 = a * 0.978658 + b
+ * results a = 1.277, b = -0.250
+ */
 float PSE530::getPressure(void)
 {
+    float coef_A = 1.277 ;
+    float coef_B = -0.250 ;
     float av = 0.0 ;
     float value = 0.0 ;
-    av = _ain->read() ;
-    printf("Pressure ADC = %.4f\n", av) ;
-    value = 1000000 * (1.25 * (av - 0.2)) ; /* 1MPa at 1.0 */
+    av = coef_A * _ain->read() + coef_B ;
+//    printf("Pressure ADC = %.4f\n", av) ;
+    value = 1000000 * av  ; /* 1MPa at 1.0 */
     value = value / 98066.5 ; /* Pa -> kgf/cm2 */
     return( value ) ;
 }