para el ventilador

Dependencies:   QEI FastPWM

Revision:
11:5cb7ae8bd831
Parent:
10:b2d87404309a
Child:
12:3bc2465b034a
--- a/project_defines.h	Mon Apr 27 19:52:02 2020 +0000
+++ b/project_defines.h	Thu May 07 03:52:31 2020 +0000
@@ -2,14 +2,13 @@
 #ifndef PROJECT_DEFINES_H_
 #define PROJECT_DEFINES_H_
 
-/* File inclusion */
-
-/* Pin definition */
+/******************************************************************************/
+/*************************** PIN DEFINITION ***********************************/
+/******************************************************************************/
 
 // Switches and buttons
 #define ENTER_SW_PIN                            PA_15
 #define LIMIT_SW_01_PIN                         PB_7
-#define GAS_INPUT_SW_PIN                        PC_13
 
 // Rotary encoder
 #define ENCODER_A_SIGNAL                        PA_13
@@ -25,23 +24,28 @@
 #define PRESSURE_SENSOR_02_SCL_PIN              PB_8
 #define PRESSURE_SENSOR_02_SDA_PIN              PB_9
 
-//Stepper motor
+
+// Stepper motor
 #define STEPPER_PULSE_PIN                       PC_8
 #define STEPPER_ENABLE_PIN                      PC_6
 #define STEPPER_DIRECTION_PIN                   PC_5
 #define STEPPER_PULSE_FEEDBACK_PIN              PA_12
 
+// Electric valves
+#define INSPIRATION_VALVE_PIN                   PF_0               
+#define EXPIRATION_VALVE_PIN                    PF_1
 
-/* Constants and macros */
+/******************************************************************************/
+/************************* CONSTANTS AND MACROS *******************************/
+/******************************************************************************/
 
-/* Defines for the switches and buttons */
+// ------------------ Defines for the switches and buttons ---------------------
+
 #define ENTER_SW                                0
 #define LIMIT_SW_01                             1
-#define GAS_INPUT_SW                            2
 
-#define DEBOUNCE_PERIOD_MS                      10
+// ----------------- Defines for the encoder user interface --------------------
 
-/* Defines for the encoder user interface */
 #define ENCODER_THRESHOLD                       8
 
 #define PARAMETER_SELECTION_INDEX_LIMIT         3
@@ -54,24 +58,25 @@
 #define RESP_FREQUENCY_INDEX_DEFAULT            10
 #define I_E_RATIO_INDEX_DEFAULT                 0
 
-#define ENCODER_READ_PERIOD_MS                  10
+// ------------- Defines for the Nextion display user interface ----------------
 
-/* Defines for the Nextion user interface */
-
-#define NEXTION_DISPLAY_BAUD_RATE               256000
+#define NEXTION_DISPLAY_BAUD_RATE               250000
 
-#define BLACK                                   0
-#define BLUE                                    31
-#define BROWN                                   48192
-#define GREEN                                   2016
-#define YELLOW                                  65504
-#define RED                                     63488
-#define GRAY                                    33840
-#define WHITE                                   65535
+#define BLACK                                   0x0000
+#define BLUE                                    0x001F
+#define BROWN                                   0xBC40
+#define GREEN                                   0x07E0
+#define YELLOW                                  0xFFE0
+#define RED                                     0xF800
+#define GRAY                                    0x8430
+#define WHITE                                   0xFFFF
+#define DARK_BLUE                               0x218F
 
 #define NORMAL_COLOR                            WHITE
 #define SELECT_COLOR                            BLUE
 #define ADJUST_COLOR                            GREEN
+#define BACKGROUND_COLOR                        BLACK
+#define WAVEFORM_BACKGROUND_COLOR               DARK_BLUE     
 
 #define VOLUME_SETPOINT_VALUE_DEFAULT           500
 #define RESP_FREQUENCY_VALUE_DEFAULT            20
@@ -81,57 +86,75 @@
 #define VOLUME_SETPOINT_MINIMUM_VALUE           250
 #define VOLUME_SETPOINT_STEP                    50
 
-#define AIR_INPUT                               0
-#define OXYGEN_INPUT                            1
-
 #define MAIN_SCREEN_DEFAULT_STATE               Main_Screen_Cursor_Disable
 
 #define VOLUME_WAVEFORM_X0                      200
 #define VOLUME_WAVEFORM_Y0                      3
 #define VOLUME_WAVEFORM_WIDTH                   400
 #define VOLUME_WAVEFORM_HEIGHT                  157
+#define VOLUME_WAVEFORM_OFFSET                  79
+#define VOLUME_WAVEFORM_GAIN                    0.5
 
 #define FLOW_WAVEFORM_X0                        200
 #define FLOW_WAVEFORM_Y0                        162
 #define FLOW_WAVEFORM_WIDTH                     400
 #define FLOW_WAVEFORM_HEIGHT                    157
+#define FLOW_WAVEFORM_OFFSET                    79
+#define FLOW_WAVEFORM_GAIN                      5.0
 
 #define PRESSURE_WAVEFORM_X0                    200
 #define PRESSURE_WAVEFORM_Y0                    321
 #define PRESSURE_WAVEFORM_WIDTH                 400
 #define PRESSURE_WAVEFORM_HEIGHT                157
+#define PRESSURE_WAVEFORM_OFFSET                0
+#define PRESSURE_WAVEFORM_GAIN                  157
 
-#define SENSOR_WAVEFORM_PLOT_PERIOD_MS          25
-#define SENSOR_DISPLAY_PERIOD_MS                100
+// ---------------------- Defines for pressure sensors -------------------------
 
-/* Defines for the pressure sensors */
 #define PRESSURE_SENSOR_I2C_CLK_HZ                      200000
+
 #define PRESSURE_SENSOR_01_SLAVE_ADDRESS                0x28
-#define PRESSURE_SENSOR_02_SLAVE_ADDRESS                0x28
 #define PRESSURE_SENSOR_01_SWA                          (PRESSURE_SENSOR_01_SLAVE_ADDRESS << 1)
+#define PRESSURE_SENSOR_01_SRA                          (PRESSURE_SENSOR_01_SWA  | 1)
+
+#define PRESSURE_SENSOR_02_SLAVE_ADDRESS                0x28
 #define PRESSURE_SENSOR_02_SWA                          (PRESSURE_SENSOR_02_SLAVE_ADDRESS << 1)
-#define PRESSURE_SENSOR_01_SRA                          (PRESSURE_SENSOR_01_SWA  | 1)
 #define PRESSURE_SENSOR_02_SRA                          (PRESSURE_SENSOR_02_SWA  | 1)
 
 #define PRESSURE_SENSOR_OUTPUT_MAX                      14745
 #define PRESSURE_SENSOR_OUTPUT_MIN                      1638
 #define PRESSURE_SENSOR_PRESSURE_MAX                    1.0f
 #define PRESSURE_SENSOR_PRESSURE_MIN                    0.0f
-#define PRESSURE_SENSOR_OFFSET_PSI                      0.0284467f
+
+#define PRESSURE_SENSOR_01_OFFSET_PSI                   0.0f
+#define PRESSURE_SENSOR_02_OFFSET_PSI                   0.0f
 
 #define VOLUME_DISPLAY_THRESHOLD                        0.1f
 #define FLOW_DISPLAY_THRESHOLD                          0.01f
 #define PRESSURE_DISPLAY_THRESHOLD                      0.001f
 
 #define PSI_TO_CMH2O_CONSTANT                           70.306957829636f
-#define SPIROMETER_SENSOR_CONSTANT                      476.9584277f
+#define SPIROMETER_SENSOR_CONSTANT_OXYGEN               36.1f
+#define SPIROMETER_SENSOR_CONSTANT_AIR                  (SPIROMETER_SENSOR_CONSTANT_OXYGEN * 1.08006)
+
+// ----------------------- Defines for digital filters -------------------------
+
+#define P1_LPF_CUTOFF_FREQ_HZ                           20.0f
+#define P1_LPF_RC_CONSTANT_SEC                          (1/(6.2832*P1_LPF_CUTOFF_FREQ_HZ))
+
+#define P2_LPF_CUTOFF_FREQ_HZ                           20.0f
+#define P2_LPF_RC_CONSTANT_SEC                          (1/(6.2832*P2_LPF_CUTOFF_FREQ_HZ))
 
-#define PRESSURE_SENSOR_READ_PERIOD_MS                  1
-#define LPF_CUTOFF_FREQ_HZ                              10.0f
-#define LPF_RC_CONSTANT_SEC                             (1/(6.2832*LPF_CUTOFF_FREQ_HZ))
+#define F_HPF_CUTOFF_FREQ_HZ                            0.01f
+#define F_HPF_RC_CONSTANT_SEC                           (1/(6.2832*F_HPF_CUTOFF_FREQ_HZ))
 
+#define PRESSURE_01_LPF_N                               4
+#define PRESSURE_02_LPF_N                               4
+#define FLOW_HPF_N                                      3
+#define FLOW_LPF_N                                      25
 
-/* Defines for the stepper motor control */ 
+// -------------------- Defines for the stepper motor driver -------------------
+
 #define TO_HOME                                         0
 #define TO_AIRBAG                                       1
 #define STEPPER_ENABLED                                 0
@@ -141,30 +164,20 @@
 #define STEPPER_DRIVER_PULSE_HOME_PERIOD_US             1000  
 #define STEPPER_DRIVER_DEFAULT_PULSE_PERIOD_US          1000  
  
-#define STEPPER_DRIVER_MAX_PULSES                       200 // Limite de pasos cuando no encuentra el sensor    
-#define STEPPER_DRIVER_MIN_PULSES                       (2*RAMP_STEPS + 2)
+#define STEPPER_DRIVER_MAX_PULSES                       200    
 #define STEPPER_DRIVER_INSPIRATION_PULSES_DEFAULT       2000
    
 #define STEPPER_DRIVER_DEFAULT_STATE                    Stepper_Driver_Home_Ramp
 
 #define STEPPER_CALIBRATION_FREQUENCY_HZ                200
-
-// Number of steps used for the speed ramp, can be either 50 or 100  
-#define RAMP_STEPS                                      50
-
-#if RAMP_STEPS  == 50
-    #define STEPPER_START_BRAKE_FREQUENCY_HZ            300 
-#elif RAMP_STEPS == 100
-    #define STEPPER_START_BRAKE_FREQUENCY_HZ            500 
-#else
-    #error "Select a valid value for RAMP_STEPS: either 50 or 100"    
-#endif
-
 #define STEPPER_MAX_FREQUENCY_HZ                        3000
 
-#define STEPPER_START_BRAKE_PERIOD_US                   (1000000.0/STEPPER_START_BRAKE_FREQUENCY_HZ)
-#define SHORT_RAMP_STEPS                                25
+// ---------------------- Time period for every action -------------------------
 
-#define TUNING_FACTOR                                   1.2
+#define DEBOUNCE_PERIOD_MS                              10
+#define ENCODER_READ_PERIOD_MS                          10
+#define PRESSURE_SENSOR_READ_PERIOD_MS                  10
+#define SENSOR_WAVEFORM_PLOT_PERIOD_MS                  25
+#define SENSOR_DISPLAY_PERIOD_MS                        500
 
 #endif