Commit 35a1eab8 authored by Derick Sivakumaran's avatar Derick Sivakumaran

Merge branch 'fix/varying_measurement_frequency' into 'master'

Fixed faulty voltage calculation from ADC

See merge request !1
parents 7cf49327 bd9d0581
Pipeline #800 failed
...@@ -329,7 +329,7 @@ void BreathingLoop::updateCycleReadings() ...@@ -329,7 +329,7 @@ void BreathingLoop::updateCycleReadings()
_ap_readings_N = 0; _ap_readings_N = 0;
_volume_inhale = 0; _volume_inhale = 0;
_volume_exhale = 0; _volume_exhale = 0;
_volume = 0; _volume = 0;
//reset //reset
_cycle_done = true; _cycle_done = true;
...@@ -353,8 +353,8 @@ void BreathingLoop::updateCalculations() { ...@@ -353,8 +353,8 @@ void BreathingLoop::updateCalculations() {
_calculations.flow = getFlow(); // TODO: can be run every 1 ms instead of every arduino cycle _calculations.flow = getFlow(); // TODO: can be run every 1 ms instead of every arduino cycle
//_calculations.flow_calc = calculateFlow(_readings_avgs.timestamp, _readings_avgs.pressure_patient, _readings_avgs.pressure_buffer); //_calculations.flow_calc = calculateFlow(_readings_avgs.timestamp, _readings_avgs.pressure_patient, _readings_avgs.pressure_buffer);
_calculations.flow_calc = calculateFlow(_readings_avgs.timestamp, _readings_avgs.pressure_patient, _readings_avgs.pressure_buffer); _calculations.flow_calc = calculateFlow(_readings_avgs.timestamp, _readings_avgs.pressure_patient, _readings_avgs.pressure_buffer);
_calculations_time = tnow;
_calculations.volume = getVolume(); _calculations.volume = getVolume();
_calculations_time = tnow;
} }
_calculations.pressure_airway = getAirwayPressure(); _calculations.pressure_airway = getAirwayPressure();
// _calculations.flow_calc = calculateFlow(tnow, adcToMillibarFloat(_readings_raw.pressure_patient, _calib_avgs.pressure_patient), adcToMillibarFloat(_readings_raw.pressure_buffer, _calib_avgs.pressure_buffer)); // _calculations.flow_calc = calculateFlow(tnow, adcToMillibarFloat(_readings_raw.pressure_patient, _calib_avgs.pressure_patient), adcToMillibarFloat(_readings_raw.pressure_buffer, _calib_avgs.pressure_buffer));
......
...@@ -221,24 +221,17 @@ float adcToMillibarDPFloat(float adc, float offset) ...@@ -221,24 +221,17 @@ float adcToMillibarDPFloat(float adc, float offset)
// The calibration for the DP sensor is provided by the manufacturer // The calibration for the DP sensor is provided by the manufacturer
// https://docs.rs-online.com/7d77/0900766b81568899.pdf // https://docs.rs-online.com/7d77/0900766b81568899.pdf
float PCB_Gain = 2. ; // real voltage is two times higher thant the measured in the PCB (there is a voltage divider) float PCB_Gain = 2.; // real voltage is two times higher thant the measured in the PCB (there is a voltage divider)
float ADC_to_mVoltage_Gain = 3300./4096.0 ; // maximum Voltage of 3.3V for 4096 ADC counts - (It might need recalibration?) float ADC_to_mVoltage_Gain = 0.788; // this is the measured gain
float ADC_offset = 162.; // this is the measured offset
float zeroDPmvoltageInADC = (2500./PCB_Gain)*(1./ADC_to_mVoltage_Gain); float Aout = PCB_Gain * (ADC_to_mVoltage_Gain * adc + ADC_offset) ;
float Vdd = 5000;
float _voltage = PCB_Gain * ADC_to_mVoltage_Gain * (adc);// - offset + zeroDPmvoltageInADC);
float PaTombar = 0.01; float PaTombar = 0.01;
float sign = 2*((Aout/Vdd-0.5 > 0.)-0.5);
//float AoutVdd = _voltage/5000.; // The board provides 5000 mV to the input of the DP sensor
float AoutVdd = _voltage/(2*PCB_Gain*ADC_to_mVoltage_Gain*offset); // The board provides 5000 mV to the input of the DP sensor
float sign = 2*((AoutVdd-0.5 > 0.)-0.5);
float dp_mbar = PaTombar * sign * pow(((AoutVdd/0.4)-1.25), 2)*525; // same calculation as in the Labview Code float dp_mbar = PaTombar * sign * pow(((Aout/(Vdd*0.4))-1.25), 2)*525; // same calculation as in the Labview Code
//String s = " dp "+String(dp_mbar)+ " off "+String(offset)+" zero "+String(zeroDPmvoltageInADC) +" adc " + String(adc);
//logMsg(s);
return static_cast<float>(dp_mbar); return static_cast<float>(dp_mbar);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment