Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
fhksc.cpp
00001 /* Copyright (c) 2017 Philippe Kalaf, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00005 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00006 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00007 * furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 /* Digmesa FHKSC flowmeter driver */ 00020 #include "fhksc.h" 00021 00022 FHKSC::FHKSC(PinName pin) : _interrupt(pin) { // create the InterruptIn on the pin specified to FHKSC 00023 _interrupt.mode(PullDown); // an internal pull up is used, otherwise disable here 00024 _interrupt.rise(callback(this, &FHKSC::increment)); // attach increment function of this counter instance 00025 _flow_rate_timer.start(); 00026 _time_last_increment_us = 0; 00027 } 00028 00029 void FHKSC::increment() 00030 { 00031 int time_us = _flow_rate_timer.read_us(); 00032 // Every 1925 pulses is 1L 00033 // Each pulse is 1000000/1925 = 520 ul or 0.52 ml 00034 _flow_ul += 520; 00035 _interval_between_increments_us = time_us - _time_last_increment_us; 00036 _time_last_increment_us = time_us; 00037 } 00038 00039 // return in ml 00040 float FHKSC::get_volume() 00041 { 00042 return float(_flow_ul)/1000; 00043 } 00044 00045 uint32_t FHKSC::get_volume_ul() 00046 { 00047 return _flow_ul; 00048 } 00049 00050 void FHKSC::reset_count() 00051 { 00052 _flow_ul = 0; 00053 // reset timer since it can only run for 30 mins 00054 _flow_rate_timer.reset(); 00055 _time_last_increment_us = 0; 00056 } 00057 00058 // flow rate in ml per second 00059 float FHKSC::get_flow_rate() 00060 { 00061 int time_us = _flow_rate_timer.read_us(); 00062 // if we got no incremenet in 2 seconds, flowrate is 0 00063 if (time_us - _time_last_increment_us > 2000000) 00064 return 0; 00065 00066 if (_interval_between_increments_us) 00067 return float(0.52 / (float(_interval_between_increments_us)/1000000)); 00068 else 00069 return 0; 00070 }
Generated on Thu Jul 14 2022 00:36:34 by
1.7.2