![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
pachas
Dependencies: mbed QEI FastPWM
Diff: pressure_sensors.cpp
- Revision:
- 8:208d965a3bd2
- Parent:
- 7:f4e248182d31
- Child:
- 9:95fdcdc0977e
diff -r f4e248182d31 -r 208d965a3bd2 pressure_sensors.cpp --- a/pressure_sensors.cpp Mon Apr 20 21:58:36 2020 +0000 +++ b/pressure_sensors.cpp Thu Apr 23 17:05:36 2020 +0000 @@ -1,6 +1,7 @@ #include "mbed.h" #include "stdint.h" +#include "math.h" #include "project_defines.h" #include "pressure_sensors.h" @@ -10,9 +11,11 @@ I2C pressure_sensor_02(PRESSURE_SENSOR_02_SDA_PIN, PRESSURE_SENSOR_02_SCL_PIN); /* Global variable definition */ -uint16_t pressure_01_bin, pressure_02_bin, diff_pressure_bin; -float pressure_01_psi, pressure_02_psi; -float diff_pressure_psi; +int16_t pressure_01_bin, pressure_02_bin; +float pressure_01_psi, pressure_02_psi; +float flow_lpm, volume_ml; + +//float diff_pressure_psi; char sensor_read_data_buffer[2]; @@ -31,13 +34,47 @@ pressure_01_bin = ((sensor_read_data_buffer[0] << 8) | sensor_read_data_buffer[1]) & 0x3FFF; pressure_sensor_02.read(PRESSURE_SENSOR_02_SRA, sensor_read_data_buffer, 2); pressure_02_bin = ((sensor_read_data_buffer[0] << 8) | sensor_read_data_buffer[1]) & 0x3FFF; - diff_pressure_bin = pressure_01_bin - pressure_02_bin; /* Calculate pressure values in PSI */ pressure_01_psi = (5.0 * pressure_01_bin) / 16383; pressure_02_psi = (5.0 * pressure_02_bin) / 16383; - diff_pressure_psi = (5.0 * diff_pressure_bin) / 16383; + } +void Calculate_Flow_From_Pressure(void){ + + int16_t diff_pressure_bin; + float diff_pressure_psi; + + diff_pressure_bin = pressure_02_bin - pressure_01_bin; + diff_pressure_psi = (5.0 * diff_pressure_bin) / 16383; + + if(diff_pressure_psi < 0){ + flow_lpm = -SPIROMETER_SENSOR_CONSTANT * sqrt(-diff_pressure_psi); + }else{ + flow_lpm = SPIROMETER_SENSOR_CONSTANT * sqrt(diff_pressure_psi); + } +} +void Calculate_Volume_From_Flow(void){ + + static float previous_flow_lpm = 0.0; + float delta_volume_ml; + + delta_volume_ml = (PRESSURE_SENSOR_READ_PERIOD_MS * (flow_lpm + previous_flow_lpm)) / 60.0; + + volume_ml = volume_ml + delta_volume_ml; + + previous_flow_lpm = flow_lpm; + +} + +void Pressure_01_LPF(void){ + +} + + +void Pressure_02_LPF(void){ + +}