measure ohm of HS15P
Fork of Frequency_counter by
This test program measures ohm of HS15P, humidity sensor.
C(micro F) with LMC555 | 0.1 | 0.15 | 0.22 | 0.33 | 0.47 | 0.68 | 1 |
CONV_KILO_OHM | 0.0072 | 0.0048 | 0.0033 | 0.0022 | 0.0015 | 0.0011 | 0.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/
main.cpp@6:7f90a61e1a69, 2013-08-11 (annotated)
- Committer:
- strysd
- Date:
- Sun Aug 11 08:34:00 2013 +0000
- Revision:
- 6:7f90a61e1a69
- Parent:
- 5:9be3080ca8ba
- Child:
- 7:42e7f18361c8
separate defines
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
strysd | 6:7f90a61e1a69 | 1 | //see mbed.org/users/strysd/notebook/measure_humidity_with_hs15p_and_lmc555/ |
Neel | 0:c5bcf643a8b1 | 2 | #include "mbed.h" |
strysd | 6:7f90a61e1a69 | 3 | #include "main.h" |
strysd | 1:e2034bcdb101 | 4 | |
strysd | 4:64d9c0bed75b | 5 | InterruptIn in(p8); //connect to the Discharge of 555 |
strysd | 5:9be3080ca8ba | 6 | DigitalOut run555(p9);//connect to the Reset of 555 |
Neel | 0:c5bcf643a8b1 | 7 | DigitalOut led(LED1); |
Neel | 0:c5bcf643a8b1 | 8 | Timer t1; |
Neel | 0:c5bcf643a8b1 | 9 | |
strysd | 4:64d9c0bed75b | 10 | float my_interval = 0;//between interrupts in microseconds |
strysd | 1:e2034bcdb101 | 11 | float my_freq = 0;//Hz |
strysd | 4:64d9c0bed75b | 12 | float my_ohm = 0;//ohm for HS15P |
strysd | 4:64d9c0bed75b | 13 | int rest_in = 0;//rest of interrupt times |
Neel | 0:c5bcf643a8b1 | 14 | |
Neel | 0:c5bcf643a8b1 | 15 | void flip(void) |
Neel | 0:c5bcf643a8b1 | 16 | { |
strysd | 6:7f90a61e1a69 | 17 | if(rest_in < READ_TIMER){ |
strysd | 6:7f90a61e1a69 | 18 | my_interval = t1.read_us();// Get time since last interrupt |
strysd | 4:64d9c0bed75b | 19 | } |
strysd | 5:9be3080ca8ba | 20 | |
strysd | 6:7f90a61e1a69 | 21 | t1.reset();// Reset timer and wait for next interrupt |
strysd | 6:7f90a61e1a69 | 22 | rest_in--; |
strysd | 6:7f90a61e1a69 | 23 | |
strysd | 6:7f90a61e1a69 | 24 | if(rest_in <= 0){ |
strysd | 1:e2034bcdb101 | 25 | //No use interrupt |
strysd | 4:64d9c0bed75b | 26 | run555 = led = 0; |
strysd | 1:e2034bcdb101 | 27 | t1.stop(); |
strysd | 1:e2034bcdb101 | 28 | } |
Neel | 0:c5bcf643a8b1 | 29 | } |
Neel | 0:c5bcf643a8b1 | 30 | |
Neel | 0:c5bcf643a8b1 | 31 | int main() { |
strysd | 4:64d9c0bed75b | 32 | run555 = led = 0; |
strysd | 5:9be3080ca8ba | 33 | // Set up the interrupt |
strysd | 2:c4d4f0f9d77c | 34 | in.mode(PullUp); |
strysd | 6:7f90a61e1a69 | 35 | in.rise(&flip); |
strysd | 1:e2034bcdb101 | 36 | |
strysd | 3:bf0a5effbed2 | 37 | printf("\rStarting measure\n"); |
strysd | 5:9be3080ca8ba | 38 | |
Neel | 0:c5bcf643a8b1 | 39 | while (1) { |
strysd | 1:e2034bcdb101 | 40 | //Use interrupt |
strysd | 4:64d9c0bed75b | 41 | my_interval = 0; |
strysd | 1:e2034bcdb101 | 42 | t1.start(); |
strysd | 4:64d9c0bed75b | 43 | rest_in = IN_TIMES; |
strysd | 4:64d9c0bed75b | 44 | run555 = led = 1; |
strysd | 4:64d9c0bed75b | 45 | wait_ms(WAIT_IN); |
strysd | 6:7f90a61e1a69 | 46 | run555 = led = 0;//force stop |
strysd | 3:bf0a5effbed2 | 47 | |
strysd | 4:64d9c0bed75b | 48 | if (my_interval < MIN_INTERVAL || my_interval > MAX_INTERVAL){ |
strysd | 3:bf0a5effbed2 | 49 | printf("\r not ready\n"); |
strysd | 1:e2034bcdb101 | 50 | } else { |
strysd | 4:64d9c0bed75b | 51 | my_freq = ONESEC_BY_MICRO / my_interval; // Convert to Hz |
strysd | 4:64d9c0bed75b | 52 | my_ohm = my_interval * CONV_KILO_OHM;// Convert to kilo ohm |
strysd | 6:7f90a61e1a69 | 53 | printf("\r %.0f Hz, %.0f micro sec, %.1f kilo ohm \n", |
strysd | 6:7f90a61e1a69 | 54 | my_freq, my_interval, my_ohm); |
strysd | 1:e2034bcdb101 | 55 | } |
strysd | 3:bf0a5effbed2 | 56 | |
strysd | 4:64d9c0bed75b | 57 | wait_ms(WAIT_NEXT); |
Neel | 0:c5bcf643a8b1 | 58 | } |
Neel | 0:c5bcf643a8b1 | 59 | } |