/*
 * id.h
 *
 *  Created on: Jul 28, 2025
 *      Author: herli
 */

#ifndef INC_ID_H_
#define INC_ID_H_

/* DEBUG PARAMETERS*/

#define ENABLE_AUDI_IMMO 0

#define HAS_PREINJECTION 0

#define CYLINDERS 4

/* TIMING COMPENSATIONS */
#define PHI1 41.05

#define TEIN_NOMINAL 1550
#define TEIN_FAULT 986.5

/* ALL FBKW */
#define FBKW_DEM_M 0.5
#define FBKW_DEM_N 8.05
#define FBKW_DEM_MIN -6.0

#define FBKW_FEEDBACK_ZERO 59.1 //58.4
#define FBKW_FEEDBACK_MIN -3.35
#define FBKW_FEEDBACK_MAX 30.13
#define FBKW_FEEDBACK_IC_DT 27

#define FBKW_PID_KP 5	//14
#define FBKW_PID_KI 20	//24
#define FBKW_PID_KD 0
#define FBKW_PID_KAW 20	//24
#define FBKW_PID_BIAS 20
#define FBKW_PID_INTEGRAL 00
#define FBKW_PID_MAXRATE 10000

#define FBKW_PWM_MAX 95
#define FBKW_PWM_MIN 5

/* CAN DEFINITIONS */
#define CAN_BAUDRATE 500
#define CAN_RPM_SEND_ASYNC 250
#define CAN_EMPF2_INSTANT 1

/* ALL FUELMAP */
#define FM_N_RPM 6
#define FM_N_ME 10
#define FM_N_T 2


/* PEAK AND HOLD */
#define PH_PEAK_DEF 600

/* ANALOG CALIBRATION PARAMETERS */
// MOSFET
#define V_PEAK 2.94
#define V_HOLD 1.94

#define INJ_CLOSING_MARGIN 0 //o cero, o 20

// TOOTHED WHEEL
#define TW_MT_THRESHOLD 2.4 //sacado del original
#define TW_THEETHS 120
#define TW_TOOTH_ALPHA 3
#define TW_STARTED_RPM 400

#define MIN_RPM 20

#define USTODEG 0.000006

// TIMINGS
#define TEIN_READING_OFFSET 8

/* ifdef things */

#if CYLINDERS == 4
    #define TW_PERCYL_TEETH 26
#elif CYLINDERS == 6
    #define TW_PERCYL_TEETH 16
#else
	#define TW_PERCYL_TEETH 26
    #error "Unsupported number of cylinders"
#endif


#endif /* INC_ID_H_ */
