15 #include "../includes/config.h"
28 #define MAIN_CONTROLLER_COMPUTE_PERIOD_MS 10u
30 #define MAIN_CONTROLLER_COMPUTE_PERIOD_MICROSECONDS (1000u * MAIN_CONTROLLER_COMPUTE_PERIOD_MS)
33 #define CONST_MAX_PEAK_PRESSURE 700
34 #define CONST_MIN_PEAK_PRESSURE 100
35 #define CONST_MAX_PLATEAU_PRESSURE 400
36 #define CONST_MIN_PLATEAU_PRESSURE 50
37 #define CONST_MAX_PEEP_PRESSURE 300
38 #define CONST_MIN_PEEP_PRESSURE 0
39 #define CONST_MIN_TRIGGER_OFFSET 0u
40 #define CONST_MAX_TRIGGER_OFFSET 100u
41 #define CONST_INITIAL_ZERO_PRESSURE 0u
42 #define CONST_INITIAL_ZERO_VOLUME 0u
43 #define CONST_MIN_TIDAL_VOLUME 50u
44 #define CONST_MAX_TIDAL_VOLUME 2000u
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
50 #define CONST_MAX_MIN_INSPIRATION_DURATION 3000u
51 #define CONST_MIN_MAX_INSPIRATION_DURATION 200u
52 #define CONST_MAX_MAX_INSPIRATION_DURATION 5000u
53 #define CONST_MIN_PLATEAU_DURATION 0u
54 #define CONST_MAX_PLATEAU_DURATION 2000u
55 #define CONST_MIN_INSPIRATORY_FLOW 5000
56 #define CONST_MAX_INSPIRATORY_FLOW 80000
57 #define CONST_MIN_INSPIRATORY_DURATION 200u
58 #define CONST_MAX_INSPIRATORY_DURATION 3000u
59 #define CONST_MIN_LOW_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 0u
60 #define CONST_MAX_LOW_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 20u
61 #define CONST_MIN_LOW_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 0u
62 #define CONST_MAX_LOW_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 20u
63 #define CONST_MIN_HIGH_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 1u
64 #define CONST_MAX_HIGH_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 40u
65 #define CONST_MIN_HIGH_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 1u
66 #define CONST_MAX_HIGH_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 40u
67 #define CONST_MIN_LOW_RESPIRATORY_RATE_ALARM_THRESHOLD 5u
68 #define CONST_MAX_LOW_RESPIRATORY_RATE_ALARM_THRESHOLD 25u
69 #define CONST_MIN_HIGH_RESPIRATORY_RATE_ALARM_THRESHOLD 15u
70 #define CONST_MAX_HIGH_RESPIRATORY_RATE_ALARM_THRESHOLD 35u
71 #define CONST_MIN_LOW_TIDAL_VOLUME_ALARM_THRESHOLD 0u
72 #define CONST_MAX_LOW_TIDAL_VOLUME_ALARM_THRESHOLD 1000u
73 #define CONST_MIN_HIGH_TIDAL_VOLUME_ALARM_THRESHOLD 50u
74 #define CONST_MAX_HIGH_TIDAL_VOLUME_ALARM_THRESHOLD 2000u
75 #define CONST_MIN_LEAK_ALARM_THRESHOLD 0u
76 #define CONST_MIN_LEAK_ALARM_THRESHOLD 10000u
77 #define CONST_MIN_PEAK_PRESSURE_ALARM_THRESHOLD 50
78 #define CONST_MAX_PEAK_PRESSURE_ALARM_THRESHOLD 700
79 #define CONST_MIN_PATIENT_HEIGHT 30
80 #define CONST_MAX_PATIENT_HEIGHT 250
81 #define CONST_MIN_PATIENT_GENDER 0
82 #define CONST_MAX_PATIENT_GENDER 1
85 #define CONST_MIN_EXPIRATORY_TERM 10u
86 #define CONST_MAX_EXPIRATORY_TERM 60u
88 #define DEFAULT_PEEP_COMMAND 50u
89 #define DEFAULT_PLATEAU_COMMAND 200u
90 #define DEFAULT_PEAK_PRESSURE_COMMAND 200u
91 #define DEFAULT_EXPIRATORY_TERM_COMMAND 20u
92 #define DEFAULT_TIDAL_VOLUME_COMMAND 400u
93 #define DEFAULT_PLATEAU_DURATION_COMMAND 200u
94 #define DEFAULT_TRIGGER_OFFSET 20u
95 #define DEFAULT_INSPIRATORY_TRIGGER_FLOW_COMMAND 10u
96 #define DEFAULT_EXPIRATORY_TRIGGER_FLOW_COMMAND 30u
97 #define DEFAULT_MIN_INSPIRATION_DURATION_COMMAND 200u
98 #define DEFAULT_MAX_INSPIRATION_DURATION_COMMAND 1000u
99 #define DEFAULT_TARGET_FLOW_COMMAND 40000u
100 #define DEFAULT_INSPIRATORY_DURATION 800u
101 #define DEFAULT_LOW_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 3000u
102 #define DEFAULT_LOW_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 3000u
103 #define DEFAULT_HIGH_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 20000u
104 #define DEFAULT_HIGH_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD 20000u
105 #define DEFAULT_LOW_RESPIRATORY_RATE_ALARM_THRESHOLD 16u
106 #define DEFAULT_HIGH_RESPIRATORY_RATE_ALARM_THRESHOLD 24u
107 #define DEFAULT_LOW_TIDAL_VOLUME_ALARM_THRESHOLD 200u
108 #define DEFAULT_HIGH_TIDAL_VOLUME_ALARM_THRESHOLD 1000u
109 #define DEFAULT_LEAK_ALARM_THRESHOLD 2000u
110 #define DEFAULT_PEAK_PRESSURE_ALARM_THRESHOLD 500u
111 #define DEFAULT_PATIENT_HEIGHT 170u
112 #define DEFAULT_PATIENT_GENDER 0u
114 #define PEAK_PRESSURE_ALARM_THRESHOLD_OFFSET_FROM_PLATEAU 150
115 #define AIR_EXHAUST_THRESHOLD_FROM_PEAK_PRESSURE_ALARM 100
117 #define DEFAULT_CYCLE_PER_MINUTE_COMMAND 20u
118 #define CONST_MAX_CYCLE 35u
119 #define CONST_MIN_CYCLE 5u
121 #define DEFAULT_PEAK_PRESSURE_DELTA 10u
123 #define MAX_PRESSURE_OFFSET 40
125 #define MIN_EXPIRATORY_FLOW_OFFSET 2.5
127 #define TRIGGER_MODE_ENABLED_BY_DEFAULT false
152 #define PC_NUMBER_OF_SAMPLE_DERIVATIVE_MOVING_MEAN 10u
154 #define NUMBER_OF_SAMPLE_LAST_VALUES 20u
157 #define NUMBER_OF_BREATH_PERIOD 3u
167 #define VALVE_OPEN_STATE 0u
170 #define VALVE_CLOSED_STATE 125u
171 #define VALVE_PERIOD 1000
172 #define FAULHABER_OPENED 660
173 #define FAULHABER_CLOSED 900
175 #define VALVE_RESPONSE_TIME_MS 50
177 #define PIN_INSPIRATORY_VALVE D5
178 #define PIN_EXPIRATORY_VALVE D4
179 #define TIM_CHANNEL_INSPIRATORY_VALVE 1
180 #define TIM_CHANNEL_EXPIRATORY_VALVE 2
181 #define ESC_PPM_PERIOD \
192 #define MIN_BLOWER_SPEED 300u
193 #define MAX_BLOWER_SPEED 1800u
194 #define DEFAULT_BLOWER_SPEED 900u
203 #define PIN_LCD_RS PA8
204 #define PIN_LCD_RW PC12
205 #define PIN_LCD_EN PA5
206 #define PIN_LCD_D4 PC7
207 #define PIN_LCD_D5 PB10
208 #define PIN_LCD_D6 PA7
209 #define PIN_LCD_D7 PA6
212 #define SCREEN_LINE_NUMBER 4
215 #define SCREEN_LINE_LENGTH 20
219 #define LCD_UPDATE_PERIOD_US 300000u
222 #define LCD_RESET_PERIOD 5
231 #define PIN_BTN_ALARM_OFF PB2
232 #define PIN_BTN_START PC13
233 #define PIN_BTN_STOP PB15
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
242 #define PIN_IN_MAINS_CONNECTED PB1
243 #define PIN_IN_CONNECTION_TO_SUPPLY_OK PB6
252 #define PIN_LED_START PC8
253 #define PIN_LED_GREEN PB13
254 #define PIN_LED_YELLOW PB14
255 #define PIN_LED_RED PC4
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
273 #define PIN_PRESSURE_SENSOR PA1
274 #define PIN_BUZZER PB7
275 #define PIN_ESC_BLOWER PA10
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
280 #define PIN_TELEMETRY_SERIAL_TX PA9
281 #define PIN_ENABLE_PWR_RASP PD2
282 #define PWR_RASP_ACTIVE LOW
283 #define PWR_RASP_INACTIVE HIGH
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
302 #define MASS_FLOW_ERROR_VALUE 999999
311 #define ALARM_THRESHOLD_MIN_PRESSURE 20
312 #define ALARM_THRESHOLD_DIFFERENCE_PERCENT 20
313 #define ALARM_THRESHOLD_DIFFERENCE_PRESSURE 20
317 #define ADC_RESOLUTION_MAKAIR 12
static const int32_t PID_PATIENT_KP
static const int32_t PID_PATIENT_INTEGRAL_MIN
static const int32_t PID_BLOWER_INTEGRAL_MAX
static const int32_t PID_BLOWER_KI
static const int32_t PID_PATIENT_INTEGRAL_MAX
static const int32_t PID_BLOWER_INTEGRAL_MIN
static const int32_t PID_PATIENT_KD
static const int32_t PID_BLOWER_KP
static const int32_t PID_PATIENT_KI
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...
static const int32_t PID_BLOWER_KD