software:firmware
MakAir Firmware
parameters.h
Go to the documentation of this file.
1 
7 #pragma once
8 
9 // INCLUDES ===================================================================
10 
11 // External
12 #include "Arduino.h"
13 
14 // Internal
15 #include "../includes/config.h"
16 
17 // PARAMETERS =================================================================
18 
20 #define VERSION "dev"
21 
26 
27 // Main controller computes period in millisecond: minimum 1 ms, maximum 10 ms
28 #define MAIN_CONTROLLER_COMPUTE_PERIOD_MS 10u
29 // cppcheck-suppress misra-c2012-5.4
30 #define MAIN_CONTROLLER_COMPUTE_PERIOD_MICROSECONDS (1000u * MAIN_CONTROLLER_COMPUTE_PERIOD_MS)
31 
32 // Minimum and maximum bounds of execution parameters
33 #define CONST_MAX_PEAK_PRESSURE 700 // arbitrary [mmH2O]
34 #define CONST_MIN_PEAK_PRESSURE 100 // arbitrary [mmH2O]
35 #define CONST_MAX_PLATEAU_PRESSURE 400 // PP MAX ARDS = 300 [mmH2O]
36 #define CONST_MIN_PLATEAU_PRESSURE 50 // arbitrary [mmH2O]
37 #define CONST_MAX_PEEP_PRESSURE 300 // PP MAX = 300, or PEEP < PP [mmH2O]
38 #define CONST_MIN_PEEP_PRESSURE 0 // arbitrary but > 0 [mmH2O]
39 #define CONST_MIN_TRIGGER_OFFSET 0u // [mmH2O]
40 #define CONST_MAX_TRIGGER_OFFSET 100u // [mmH2O]
41 #define CONST_INITIAL_ZERO_PRESSURE 0u // [mmH2O]
42 #define CONST_INITIAL_ZERO_VOLUME 0u // [mL]
43 #define CONST_MIN_TIDAL_VOLUME 50u // [mL]
44 #define CONST_MAX_TIDAL_VOLUME 2000u // [mL]
45 #define CONST_MAX_INSPIRATORY_TRIGGER_FLOW 100u // [%]
46 #define CONST_MIN_INSPIRATORY_TRIGGER_FLOW 0u // [%]
47 #define CONST_MAX_EXPIRATORY_TRIGGER_FLOW 100u // [%]
48 #define CONST_MIN_EXPIRATORY_TRIGGER_FLOW 0u // [%]
49 #define CONST_MIN_MIN_INSPIRATION_DURATION 100u // [in ms]
50 #define CONST_MAX_MIN_INSPIRATION_DURATION 3000u // [in ms]
51 #define CONST_MIN_MAX_INSPIRATION_DURATION 200u // [in ms]
52 #define CONST_MAX_MAX_INSPIRATION_DURATION 5000u // [in ms]
53 #define CONST_MIN_PLATEAU_DURATION 0u // [in ms]
54 #define CONST_MAX_PLATEAU_DURATION 2000u // [in ms]
55 #define CONST_MIN_INSPIRATORY_FLOW 5000 // [in ml/min]
56 #define CONST_MAX_INSPIRATORY_FLOW 80000 // [in ml/min]
57 #define CONST_MIN_INSPIRATORY_DURATION 200u // [in ms]
58 #define CONST_MAX_INSPIRATORY_DURATION 3000u // [in ms]
59 #define CONST_MIN_LOW_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 0u // [in L/min]
60 #define CONST_MAX_LOW_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 20u // [in L/min]
61 #define CONST_MIN_LOW_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 0u // [in L/min]
62 #define CONST_MAX_LOW_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 20u // [in L/min]
63 #define CONST_MIN_HIGH_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 1u // [in L/min]
64 #define CONST_MAX_HIGH_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 40u // [in L/min]
65 #define CONST_MIN_HIGH_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 1u // [in L/min]
66 #define CONST_MAX_HIGH_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 40u // [in L/min]
67 #define CONST_MIN_LOW_RESPIRATORY_RATE_ALARM_THRESHOLD 5u // [in cpm]
68 #define CONST_MAX_LOW_RESPIRATORY_RATE_ALARM_THRESHOLD 25u // [in cpm]
69 #define CONST_MIN_HIGH_RESPIRATORY_RATE_ALARM_THRESHOLD 15u // [in cpm]
70 #define CONST_MAX_HIGH_RESPIRATORY_RATE_ALARM_THRESHOLD 35u // [in cpm]
71 #define CONST_MIN_LOW_TIDAL_VOLUME_ALARM_THRESHOLD 0u // [in mL]
72 #define CONST_MAX_LOW_TIDAL_VOLUME_ALARM_THRESHOLD 1000u // [in mL]
73 #define CONST_MIN_HIGH_TIDAL_VOLUME_ALARM_THRESHOLD 50u // [in mL]
74 #define CONST_MAX_HIGH_TIDAL_VOLUME_ALARM_THRESHOLD 2000u // [in mL]
75 #define CONST_MIN_LEAK_ALARM_THRESHOLD 0u // [in cL/min]
76 #define CONST_MIN_LEAK_ALARM_THRESHOLD 10000u // [in cL/min]
77 #define CONST_MIN_PEAK_PRESSURE_ALARM_THRESHOLD 50 // [in mmH2O]
78 #define CONST_MAX_PEAK_PRESSURE_ALARM_THRESHOLD 700 // [in mmH2O]
79 #define CONST_MIN_PATIENT_HEIGHT 30 // [in cm]
80 #define CONST_MAX_PATIENT_HEIGHT 250 // [in cm]
81 #define CONST_MIN_PATIENT_GENDER 0 // [male]
82 #define CONST_MAX_PATIENT_GENDER 1 // [female]
83 
84 // Expiration term in the "Inspiration/Expiration" ratio given that Inspiration = 10
85 #define CONST_MIN_EXPIRATORY_TERM 10u
86 #define CONST_MAX_EXPIRATORY_TERM 60u
87 
88 #define DEFAULT_PEEP_COMMAND 50u // in mmH2O
89 #define DEFAULT_PLATEAU_COMMAND 200u // in mmH2O
90 #define DEFAULT_PEAK_PRESSURE_COMMAND 200u // in mmH2O
91 #define DEFAULT_EXPIRATORY_TERM_COMMAND 20u // 20 means I:E = 10:20 = 1:2
92 #define DEFAULT_TIDAL_VOLUME_COMMAND 400u // in mL
93 #define DEFAULT_PLATEAU_DURATION_COMMAND 200u // in ms
94 #define DEFAULT_TRIGGER_OFFSET 20u // in mmH2O
95 #define DEFAULT_INSPIRATORY_TRIGGER_FLOW_COMMAND 10u // in percent of current flow
96 #define DEFAULT_EXPIRATORY_TRIGGER_FLOW_COMMAND 30u // in percent of max inspirated flow
97 #define DEFAULT_MIN_INSPIRATION_DURATION_COMMAND 200u // in ms
98 #define DEFAULT_MAX_INSPIRATION_DURATION_COMMAND 1000u // in ms
99 #define DEFAULT_TARGET_FLOW_COMMAND 40000u // in mL/min
100 #define DEFAULT_INSPIRATORY_DURATION 800u // in ms
101 #define DEFAULT_LOW_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 3000u // [in mL/min]
102 #define DEFAULT_LOW_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 3000u // [in mL/min]
103 #define DEFAULT_HIGH_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 20000u // [in mL/min]
104 #define DEFAULT_HIGH_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 20000u // [in mL/min]
105 #define DEFAULT_LOW_RESPIRATORY_RATE_ALARM_THRESHOLD 16u // [in cpm]
106 #define DEFAULT_HIGH_RESPIRATORY_RATE_ALARM_THRESHOLD 24u // [in cpm]
107 #define DEFAULT_LOW_TIDAL_VOLUME_ALARM_THRESHOLD 200u // [in mL]
108 #define DEFAULT_HIGH_TIDAL_VOLUME_ALARM_THRESHOLD 1000u // [in mL]
109 #define DEFAULT_LEAK_ALARM_THRESHOLD 2000u // [in mL/min]
110 #define DEFAULT_PEAK_PRESSURE_ALARM_THRESHOLD 500u // [in mmH2O]
111 #define DEFAULT_PATIENT_HEIGHT 170u // [in cm]
112 #define DEFAULT_PATIENT_GENDER 0u // [0 = male, 1 = female]
113 
114 #define PEAK_PRESSURE_ALARM_THRESHOLD_OFFSET_FROM_PLATEAU 150 // [in mmH2O]
115 #define AIR_EXHAUST_THRESHOLD_FROM_PEAK_PRESSURE_ALARM 100 // [in mmH2O]
116 
117 #define DEFAULT_CYCLE_PER_MINUTE_COMMAND 20u
118 #define CONST_MAX_CYCLE 35u
119 #define CONST_MIN_CYCLE 5u
120 
121 #define DEFAULT_PEAK_PRESSURE_DELTA 10u
122 
123 #define MAX_PRESSURE_OFFSET 40
124 
125 #define MIN_EXPIRATORY_FLOW_OFFSET 2.5
126 
127 #define TRIGGER_MODE_ENABLED_BY_DEFAULT false
128 
130 
135 
136 static const int32_t PID_BLOWER_KP = 2000;
137 static const int32_t PID_BLOWER_KI = 50;
138 static const int32_t PID_BLOWER_KD = 0;
139 static const int32_t PID_BLOWER_INTEGRAL_MAX = 1000;
140 static const int32_t PID_BLOWER_INTEGRAL_MIN = -1000;
141 
142 static const int32_t PID_PATIENT_KP = 15000;
143 static const int32_t PID_PATIENT_KI = 200;
144 static const int32_t PID_PATIENT_KD = 110;
145 static const int32_t PID_PATIENT_INTEGRAL_MAX = 1000;
146 static const int32_t PID_PATIENT_INTEGRAL_MIN = -1000;
147 
150 static const int32_t PID_PATIENT_SAFETY_PEEP_OFFSET = 0;
151 
152 #define PC_NUMBER_OF_SAMPLE_DERIVATIVE_MOVING_MEAN 10u
153 
154 #define NUMBER_OF_SAMPLE_LAST_VALUES 20u
155 
157 #define NUMBER_OF_BREATH_PERIOD 3u
158 
160 
165 
167 #define VALVE_OPEN_STATE 0u
168 
170 #define VALVE_CLOSED_STATE 125u
171 #define VALVE_PERIOD 1000 // 1 kHz Faulhaber motors are controlled with a 1 kHz PWM
172 #define FAULHABER_OPENED 660 // PWM duty cycle 64% -> open
173 #define FAULHABER_CLOSED 900 // PWM duty cycle 90% -> closed
174 
175 #define VALVE_RESPONSE_TIME_MS 50 // estimated response time for going to open state to close state
176 
177 #define PIN_INSPIRATORY_VALVE D5 // PB4 / TIM3_CH1
178 #define PIN_EXPIRATORY_VALVE D4 // PB5 / TIM3_CH2
179 #define TIM_CHANNEL_INSPIRATORY_VALVE 1
180 #define TIM_CHANNEL_EXPIRATORY_VALVE 2
181 #define ESC_PPM_PERIOD \
182  10000 // ESC should be driven in 50 Hz. 100 Hz is a security against ESC or nucleo bugs. Some
183  // ESC stops very quickly
184 
186 
191 
192 #define MIN_BLOWER_SPEED 300u
193 #define MAX_BLOWER_SPEED 1800u
194 #define DEFAULT_BLOWER_SPEED 900u
195 
197 
202 
203 #define PIN_LCD_RS PA8
204 #define PIN_LCD_RW PC12
205 #define PIN_LCD_EN PA5
206 #define PIN_LCD_D4 PC7 // PC7
207 #define PIN_LCD_D5 PB10 // PB6
208 #define PIN_LCD_D6 PA7 // PA7
209 #define PIN_LCD_D7 PA6 // PA6
210 
212 #define SCREEN_LINE_NUMBER 4
213 
215 #define SCREEN_LINE_LENGTH 20
216 
219 #define LCD_UPDATE_PERIOD_US 300000u
220 
222 #define LCD_RESET_PERIOD 5
223 
225 
230 
231 #define PIN_BTN_ALARM_OFF PB2
232 #define PIN_BTN_START PC13
233 #define PIN_BTN_STOP PB15
234 // other buttons are in a 3x3 matrix
235 #define PIN_OUT_COL1 PC2
236 #define PIN_OUT_COL2 PC3
237 #define PIN_OUT_COL3 PC6
238 #define PIN_IN_ROW1 PC9
239 #define PIN_IN_ROW2 PC10
240 #define PIN_IN_ROW3 PC11
241 // expander used to read AC status
242 #define PIN_IN_MAINS_CONNECTED PB1
243 #define PIN_IN_CONNECTION_TO_SUPPLY_OK PB6
244 
246 
251 
252 #define PIN_LED_START PC8 // below start button, close to START label
253 #define PIN_LED_GREEN PB13 // "alarm off"
254 #define PIN_LED_YELLOW PB14 // "alarm med"
255 #define PIN_LED_RED PC4 // "alarm high"
256 
257 #define LED_START_ACTIVE HIGH
258 #define LED_START_INACTIVE LOW
259 #define LED_RED_ACTIVE HIGH
260 #define LED_RED_INACTIVE LOW
261 #define LED_YELLOW_ACTIVE HIGH
262 #define LED_YELLOW_INACTIVE LOW
263 #define LED_GREEN_ACTIVE HIGH
264 #define LED_GREEN_INACTIVE LOW
265 
267 
272 
273 #define PIN_PRESSURE_SENSOR PA1
274 #define PIN_BUZZER PB7 // TIM4_CH2
275 #define PIN_ESC_BLOWER PA10 // PA10 / TIM1_CH3
276 #define TIM_CHANNEL_ESC_BLOWER 3
277 #define PIN_TEMP_BLOWER PC1
278 #define PIN_BATTERY PA4
279 #define PIN_TELEMETRY_SERIAL_RX PB3 // UART1
280 #define PIN_TELEMETRY_SERIAL_TX PA9 // UART1
281 #define PIN_ENABLE_PWR_RASP PD2 // Raspberry Power Supply. High is OFF.
282 #define PWR_RASP_ACTIVE LOW
283 #define PWR_RASP_INACTIVE HIGH
284 
286 
291 
292 #ifdef MASS_FLOW_METER_ENABLED
293 #define MASS_FLOW_TIMER TIM10
294 #define MASS_FLOW_CHANNEL 1
295 #define PIN_I2C_SDA PB9
296 #define PIN_I2C_SCL PB8
297 #define MFM_ANALOG_INPUT A3
298 #define MFM_POWER_CONTROL PC0
299 #define MFM_POWER_OFF LOW
300 #define MFM_POWER_ON HIGH
301 #endif
302 #define MASS_FLOW_ERROR_VALUE 999999
303 
305 
310 
311 #define ALARM_THRESHOLD_MIN_PRESSURE 20 // RCM-SW-2 + RCM-SW-19
312 #define ALARM_THRESHOLD_DIFFERENCE_PERCENT 20 // RCM-SW-1 + RCM-SW-14
313 #define ALARM_THRESHOLD_DIFFERENCE_PRESSURE 20 // RCM-SW-3 + RCM-SW-15
314 
316 
317 #define ADC_RESOLUTION_MAKAIR 12
static const int32_t PID_PATIENT_KP
Definition: parameters.h:142
static const int32_t PID_PATIENT_INTEGRAL_MIN
Definition: parameters.h:146
static const int32_t PID_BLOWER_INTEGRAL_MAX
Definition: parameters.h:139
static const int32_t PID_BLOWER_KI
Definition: parameters.h:137
static const int32_t PID_PATIENT_INTEGRAL_MAX
Definition: parameters.h:145
static const int32_t PID_BLOWER_INTEGRAL_MIN
Definition: parameters.h:140
static const int32_t PID_PATIENT_KD
Definition: parameters.h:144
static const int32_t PID_BLOWER_KP
Definition: parameters.h:136
static const int32_t PID_PATIENT_KI
Definition: parameters.h:143
static const int32_t PID_PATIENT_SAFETY_PEEP_OFFSET
Increase target pressure by an offset (in mmH2O) for safety, to avoid going below the target pressure...
Definition: parameters.h:150
static const int32_t PID_BLOWER_KD
Definition: parameters.h:138