measure ohm of HS15P

Dependencies:   mbed

Fork of Frequency_counter by Neel Shah

This test program measures ohm of HS15P, humidity sensor.

/media/uploads/strysd/hs_15p_try4a.png

C(micro F) with LMC5550.10.150.220.330.470.681
CONV_KILO_OHM0.00720.00480.00330.00220.00150.00110.00072

If you get 2500 microseconds as interrupt time interval , it means 18 kilo ohm when 0.1 micro F. ( = 2500 * 0.0072 )

  • ohm of HS15P is calculated from pulse interval of LMC555.
    • CONV_KILO_OHM will be used.
  • this program reads interval time.between interrupt in the P8.
  • takes ON the P9 to oscillate LMC555 as short as enough to measure interval time
  • last several interval times will be used for calculation.
    • the time is defined as READ_TIMER .
  • In current circit, VDD of LMC555 is about 1.55V, AC 0.4V between pins of HS15P.
    • LMC555 consumes 120 micro A while oscillation, 90 micro A when level of P9 is OFF. (reset is ON)
    • Total 1-2mA is consumed in the circit.

Related nootbook : https://mbed.org/users/strysd/notebook/measure_humidity_with_hs15p_and_lmc555/

Revision:
6:7f90a61e1a69
Parent:
5:9be3080ca8ba
Child:
7:42e7f18361c8
--- a/main.cpp	Tue Jun 04 06:14:19 2013 +0000
+++ b/main.cpp	Sun Aug 11 08:34:00 2013 +0000
@@ -1,14 +1,6 @@
+//see mbed.org/users/strysd/notebook/measure_humidity_with_hs15p_and_lmc555/
 #include "mbed.h"
-
-//see mbed.org/users/strysd/notebook/measure_humidity_with_hs15p_and_lmc555/
-#define CONV_KILO_OHM 0.0072 //if use 0.1 micro F
-#define IN_TIMES  10 //interrupt times
-#define READ_TIMER 3 //rest times when reads timer
-#define WAIT_IN   1000 //wait interrupts       in msec
-#define WAIT_NEXT 4000 //wait next measurement in msec
-#define MAX_INTERVAL 100000 //  > 0.1 sec ( < 10 Hz)  in microseconds
-#define MIN_INTERVAL 20 // < 20 micro sec ( > 50 kHz) in microseconds
-#define ONESEC_BY_MICRO 1000000//   1 sec             in microseconds
+#include "main.h"
 
 InterruptIn in(p8);   //connect to the Discharge of 555
 DigitalOut run555(p9);//connect to the Reset     of 555
@@ -22,15 +14,14 @@
 
 void flip(void)
 {
-    if(rest_in > 0){
-        if(rest_in < READ_TIMER){
-            my_interval = t1.read_us();// Get time since last interrupt
-        }
-        t1.reset();// Reset timer and wait for next interrupt
-        rest_in--;
+    if(rest_in < READ_TIMER){
+        my_interval = t1.read_us();// Get time since last interrupt
     }
 
-    if(rest_in == 0){
+    t1.reset();// Reset timer and wait for next interrupt
+    rest_in--;
+
+    if(rest_in <= 0){
         //No use interrupt
         run555 = led = 0;
         t1.stop();
@@ -41,7 +32,7 @@
     run555 = led = 0;
     // Set up the interrupt
     in.mode(PullUp);
-    in.fall(&flip);
+    in.rise(&flip);
 
     printf("\rStarting measure\n");
 
@@ -52,14 +43,15 @@
         rest_in = IN_TIMES;
         run555 = led = 1;
         wait_ms(WAIT_IN);
+        run555 = led = 0;//force stop
 
         if (my_interval < MIN_INTERVAL || my_interval > MAX_INTERVAL){
             printf("\r not ready\n");
         } else {
             my_freq = ONESEC_BY_MICRO / my_interval;  // Convert to Hz
             my_ohm  = my_interval     * CONV_KILO_OHM;// Convert to kilo ohm
-            printf("\r %d Hz, %d micro sec, %4.1f kilo ohm \n",
-                   (int)my_freq, (int)my_interval, my_ohm);
+            printf("\r %.0f Hz, %.0f micro sec, %.1f kilo ohm \n",
+                   my_freq, my_interval, my_ohm);
         }
 
          wait_ms(WAIT_NEXT);