40 #ifndef FILE_SCALERDEFINES_H_SEEN
41 #define FILE_SCALERDEFINES_H_SEEN
45 #define ROUND(FLOATING_POINT_VALUE) ((FLOATING_POINT_VALUE) + 0.5) // Note, if integer math is used to generate the argument, it won't work.
49 #define IGNITION_TIMING_FACTOR 1024
50 #define TEMPERATURE_K_FACTOR 100
51 #define PRESSURE_KPA_FACTOR 100
52 #define VOLTAGE_FACTOR 1000
53 #define LAMBDA_FACTOR 32768
55 #define ANGLE_FACTOR 50U
57 #define AFR_FACTOR 1024
58 #define FUEL_DENSITY_FACTOR 32
59 #define PW_TICK_FACTOR 1250
60 #define PERCENT_FACTOR 640
61 #define CYLINDER_VOLUME_LIMIT 2000
62 #define INJECTOR_FLOW_LIMIT 3840
63 #define WARM_UP_LIMIT 400
66 #define TEMPERATURE_C_TO_K_OFFSET 273.15
67 #define FUEL_DENSITY_UNIT_FACTOR 1000
74 #define KPA(PRESSURE) (signed long)ROUND((PRESSURE) * (double)PRESSURE_KPA_FACTOR)
75 #define DEGREES_K(TEMPERATURE) (unsigned long)ROUND((TEMPERATURE) * (double)TEMPERATURE_K_FACTOR)
76 #define CC_PER_MINUTE(FLOW_RATE) (unsigned long)ROUND(((FLOW_RATE) / (double)INJECTOR_FLOW_LIMIT) * 65536)
77 #define CYLINDER_VOLUME(VOLUME_IN_CC) (unsigned long)ROUND(((VOLUME_IN_CC) / (double)CYLINDER_VOLUME_LIMIT) * 65536)
78 #define VOLTS(VOLTAGE) (unsigned long)ROUND((VOLTAGE) * (double)VOLTAGE_FACTOR)
79 #define LAMBDA(LAMBDA_VALUE) (unsigned long)ROUND((LAMBDA_VALUE) * (double)LAMBDA_FACTOR)
80 #define RPM(ENGINE_SPEED) (unsigned long)ROUND((ENGINE_SPEED) * (double)RPM_FACTOR)
81 #define ANGLE(CRANK_DEGREES) (unsigned long)ROUND((CRANK_DEGREES) * (double)ANGLE_FACTOR)
82 #define STOICH_AFR(AIR_FUEL_RATIO) (unsigned long)ROUND((AIR_FUEL_RATIO) * (double)AFR_FACTOR)
83 #define FUEL_DENSITY(DENSITY) (unsigned long)ROUND((DENSITY) * (double)FUEL_DENSITY_FACTOR)
84 #define PW_MS(PW_MILLISECONDS) (unsigned long)ROUND((PW_MILLISECONDS) * (double)PW_TICK_FACTOR)
85 #define PERCENT(PERCENTAGE) (unsigned long)ROUND((PERCENTAGE) * (double)PERCENT_FACTOR)
86 #define ACCEL_TIME_TOL(PERCENTAGE) (unsigned long)((100/(100 + (double)PERCENTAGE)) * 1000) // This code is getting changed a lot, hence literals
87 #define DECEL_TIME_TOL(PERCENTAGE) (unsigned long)(((100 + (double)PERCENTAGE)/100) * 1000) // This code is getting changed a lot, hence literals
90 #define SCI_BAUD_DIVISOR(BAUD) (unsigned long)ROUND(40000000 / ((double)(BAUD) * 16)) // 40MHz / (16*115.2kHz) TODO pull 40MHz out of clock rate stuff
93 #define IT(TIMING_BTDC) (unsigned long)ROUND((TIMING_BTDC) * (double)IGNITION_TIMING_FACTOR)
94 #define VE(VOLUMETRIC_EFFICIENCY) (unsigned long)ROUND((VOLUMETRIC_EFFICIENCY) * (double)VE_FACTOR)
95 #define AF(PERCENTAGE) PERCENT(PERCENTAGE) // Shortcut for table use, same as above
96 #define LR(LAMBDA_RATIO) LAMBDA(LAMBDA_RATIO) // Shortcut for table use, same as above
97 #define AP(AFR) LR((double)AFR / 14.7) // AFR Petrol, alternative unit for table use
98 #define PC(PERCENTAGE) PERCENT(PERCENTAGE) // Shortcut for table use, same as above
99 #define C(TEMPERATURE) DEGREES_C(TEMPERATURE) // Shortcut for table use, same as below
100 #define V(VOLTAGE) VOLTS(VOLTAGE) // Shortcut for table use, same as above
101 #define W(PERCENTAGE) (unsigned long)ROUND(((PERCENTAGE) / (double)WARM_UP_LIMIT) * 65536)
102 #define T(PW_MILLISECONDS) PW_MS(PW_MILLISECONDS) // Shortcut for table use, same as above
105 #define CC_PER_MINUTE_85(FLOW_RATE) CC_PER_MINUTE((FLOW_RATE) * (100 / 85.0))
106 #define DEGREES_C(TEMPERATURE) DEGREES_K((TEMPERATURE) + TEMPERATURE_C_TO_K_OFFSET)
111 #warning "Header file SCALERDEFINES_H seen before, sort it out!"