Skip to content

Commit 7d01af4

Browse files
committed
Add APPS sensors
1 parent 97b2f38 commit 7d01af4

File tree

13 files changed

+79
-10
lines changed

13 files changed

+79
-10
lines changed

sources/bc_input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
/**Declare blink codes. Indexes in the array must correspond to numbers of bits of corresponding CE errors in ce_errors.h */
4848
PGM_DECLARE(uint8_t blink_codes[ECUERROR_NUM]) =
49-
{0x21, 0x13, 0x14, 0x31, 0x32, 0x22, 0x23, 0x24, 0x41, 0x25, 0x26, 0x27, 0x28, 0x51, 0x52, 0, 0x53, 0x54, 0x55, 0x56, 0x33, 0x15, 0x34, 0x16, 0x35};
49+
{0x21, 0x13, 0x14, 0x31, 0x32, 0x22, 0x23, 0x24, 0x41, 0x25, 0x26, 0x27, 0x28, 0x51, 0x52, 0, 0x53, 0x54, 0x55, 0x56, 0x33, 0x15, 0x34, 0x16, 0x35, 0x29};
5050

5151

5252
void bc_init_ports(void)

sources/ce_errors.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,30 @@ void check(ce_sett_t *cesd)
214214
else
215215
{ ce_clear_error(ECUERROR_TPS_SENSOR_FAIL); }
216216

217+
//checking APPS1 & APPS2 sensors (DBW)
218+
#if !defined(SECU3T)
219+
if (IOCFG_CHECK(IOP_APPS1))
220+
{
221+
if (IOCFG_CHECK(IOP_APPS2))
222+
{ //both APPS are present - OK
223+
uint16_t apps1_raw = IOCFG_GETA(IOP_APPS1);
224+
uint16_t apps2_raw = IOCFG_GETA(IOP_APPS2);
225+
uint16_t appsdiff = abs((int16_t)apps1_raw - ((int16_t)apps2_raw * 2));
226+
if (appsdiff > cesd->appsdiff_thrd)
227+
ce_set_error(ECUERROR_APPS);
228+
else
229+
ce_clear_error(ECUERROR_APPS);
230+
}
231+
else
232+
{ ce_set_error(ECUERROR_APPS); } //only 1st APPS
233+
}
234+
else if (IOCFG_CHECK(IOP_APPS2))
235+
{ ce_set_error(ECUERROR_APPS); } //only 2nd APPS
236+
else
237+
{ ce_clear_error(ECUERROR_APPS); } //no APPS at all - no errors
238+
#endif
239+
240+
217241
//checking ADD_I1 sensor
218242
if ((d.sens.add_i1_raw < cesd->add_i1_v_min) || (d.sens.add_i1_raw > cesd->add_i1_v_max))
219243
ce_set_error(ECUERROR_ADD_I1_SENSOR);

sources/ce_errors.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
#define ECUERROR_INJDUTY_LIMIT 22 //!< Injector's duty limit reached
5959
#define ECUERROR_EEPROM_LTFT_BROKEN 23 //!< LTFT table is corrupted
6060
#define ECUERROR_STEPPERIC_FAULT 24 //!< Stepper IC fault
61-
#define ECUERROR_NUM 25 //!< number of ECU error codes
61+
#define ECUERROR_APPS 25 //!< Gas pedal errors (DBW)
62+
#define ECUERROR_NUM 26 //!< number of ECU error codes
6263

6364
/**checks for errors and manages the CE lamp
6465
* Uses d ECU data structure

sources/ecudata.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ typedef struct sensors_t
9696
uint16_t tps; //!< Throttle position sensor (0...100%, x64)
9797
#if !defined(SECU3T)
9898
uint16_t tps_dbw; //!< Throttle position sensor (0...100+%, x64)
99+
int16_t apps1_raw; //!< Voltage on the APPS1
100+
uint16_t apps1; //!< Accelerator pedal position sensor (0...100%, x64)
99101
#endif
100102
uint16_t add_i1; //!< ADD_I1 input voltage
101103
uint16_t add_i2; //!< ADD_I2 input voltage

sources/ioconfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ uint16_t iocfg_g_add_i4i(uint8_t doa); //!< set ADD_I4 input (inverted)
462462
#define IOP_ALTRN_I 100 //!< ALTRN_I (input)
463463
#define IOP_FPS 101 //!< FPS (input)
464464
#define IOP_TPS2 102 //!< TPS2 (input)
465-
#define IOP_RESERVED56 103 //!< reserved plug ()
466-
#define IOP_RESERVED57 104 //!< reserved plug ()
465+
#define IOP_APPS1 103 //!< APPS1 (input)
466+
#define IOP_APPS2 104 //!< APPS2 (input)
467467
#define IOP_RESERVED58 105 //!< reserved plug ()
468468
#define IOP_RESERVED59 106 //!< reserved plug ()
469469
#define IOP_RESERVED60 107 //!< reserved plug ()

sources/magnitude.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
/**One discrete of the system timer is 10ms*/
5151
#define SYSTIM_MULTIPLIER 100
5252

53+
/**APPS multiplier*/
54+
#define APPS_MULT 64
55+
5356
/* Following macros are necessary when transforming floating point constant-values into integers.
5457
* Values of phisical magnitudes stored in integers
5558
*/
@@ -100,4 +103,7 @@
100103
/**VSS distance, value in km*/
101104
#define VSSDIST_MAG(dst) ROUND32((dst)*125)
102105

106+
/**Transforms floating point value of APPS in % to integer value*/
107+
#define APPS_MAG(p) ROUND ((p) * APPS_MULT)
108+
103109
#endif //_MAGNITUDE_H_

sources/measure.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,19 @@ void meas_average_measured_values(ce_sett_t *cesd)
456456
else
457457
d.sens.fps = 0; //input is not selected
458458
#endif
459+
460+
#ifndef SECU3T
461+
if (IOCFG_CHECK(IOP_APPS1))
462+
{//APPS1
463+
d.sens.apps1_raw = IOCFG_GETA(IOP_APPS1);
464+
d.sens.apps1 = tps_adc_to_pc(d.sens.apps1_raw, d.param.apps1_curve_offset, d.param.apps1_curve_gradient);
465+
if (d.sens.apps1 > APPS_MAG(100))
466+
d.sens.apps1 = APPS_MAG(100);
467+
}
468+
else
469+
d.sens.apps1 = 0; //input is not selected
470+
#endif
471+
459472
}
460473

461474
//Call this function for making preliminary measurements before starting engine. Call it only after

sources/ringbuff.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ void init_buffer(struct ringbuff_t* p_rb, uint8_t avnum)
3131
{
3232
p_rb->avnum = avnum;
3333
p_rb->size = 0;
34+
p_rb->idx = 0;
35+
p_rb->sum = 0;
36+
p_rb->buff[0] = 0;
3437
}
3538

3639
void update_buffer(struct ringbuff_t* p_rb, uint16_t value)

sources/ringbuff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
#include <stdint.h>
3131

32-
#define CIRCBUFFMAX 24 //!< Maximum size of ring buffer in items
32+
#define CIRCBUFFMAX 32 //!< Maximum size of ring buffer in items
3333

3434
/**Describes ring buffer for one input*/
3535
typedef struct ringbuff_t

sources/tables.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ PGM_FIXED_ADDR_OBJ(fw_data_t fw_data, ".firmware_data") =
415415
_FNC(iocfg_g_stub), _FNC(iocfg_g_stub), _FNC(iocfg_g_stub), _FNC(iocfg_g_stub),
416416
_FNC(iocfg_g_stub), _FNC(iocfg_g_stub), _FNC(iocfg_g_stub), _FNC(iocfg_g_stub),
417417
_FNC(iocfg_g_stub), _FNC(iocfg_g_stub), _FNC(iocfg_g_stub), _FNC(iocfg_g_stub),
418-
_FNC(iocfg_g_stub), _FNC(iocfg_g_stub), _FNC(iocfg_s_stub), _FNC(iocfg_s_stub),
418+
_FNC(iocfg_g_stub), _FNC(iocfg_g_stub), _FNC(iocfg_g_stub), _FNC(iocfg_g_stub),
419419
_FNC(iocfg_s_stub), _FNC(iocfg_s_stub), _FNC(iocfg_s_stub),
420420
},
421421

@@ -787,6 +787,9 @@ PGM_FIXED_ADDR_OBJ(fw_data_t fw_data, ".firmware_data") =
787787
.ltft_learn_load = {PRESSURE_MAGNITUDE(10.0), PRESSURE_MAGNITUDE(100.0)},
788788
.ltft_dead_band = {EGO_CORR(0.6), EGO_CORR(0.6)}, //+-0.6%
789789

790+
.apps1_curve_offset = VOLTAGE_MAGNITUDE(0.720),
791+
.apps1_curve_gradient = 542, //26.45%/V
792+
790793
.reserved = {0},
791794
.crc = 0
792795
},
@@ -932,7 +935,9 @@ PGM_FIXED_ADDR_OBJ(fw_data_t fw_data, ".firmware_data") =
932935

933936
.stepperic_flg = 1, //process stepper IC fault
934937

935-
.tpsdiff_thrd = VOLTAGE_MAGNITUDE(0.1),
938+
.tpsdiff_thrd = VOLTAGE_MAGNITUDE(0.20),
939+
.appsdiff_thrd = VOLTAGE_MAGNITUDE(0.30),
940+
936941
.reserved = {0}
937942
},
938943

sources/tables.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,9 @@ typedef struct ce_sett_t
407407
uint8_t stepperic_flg; //process stepper IC fault (0 - ignore, 1 - process)
408408

409409
uint16_t tpsdiff_thrd;
410+
uint16_t appsdiff_thrd;
410411

411-
uint8_t reserved[29];
412+
uint8_t reserved[27];
412413
}ce_sett_t;
413414

414415
/**Describes separate tables stored in the firmware
@@ -1027,11 +1028,14 @@ typedef struct params_t
10271028
uint16_t ltft_learn_load[2]; //!< lower and upper thresholds of load for learning, value * 64
10281029
uint8_t ltft_dead_band[2]; //!< EGO correction thresholds (- and +) below which LTFT will not work, value * 512
10291030

1031+
int16_t apps1_curve_offset; //!< offset of curve in volts
1032+
int16_t apps1_curve_gradient; //!< gradient of curve in Percentage/V
1033+
10301034
/**Following reserved bytes required for keeping binary compatibility between
10311035
* different versions of firmware. Useful when you add/remove members to/from
10321036
* this structure. */
10331037

1034-
uint8_t reserved[91];
1038+
uint8_t reserved[87];
10351039

10361040
/**CRC of this structure (for checking correctness of data after loading from EEPROM) */
10371041
uint16_t crc;

sources/uart.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,14 @@ void uart_send_packet(uint8_t send_mode)
470470
build_i16h(d.param.inj_cyl_disp); //used for calculations on SECU-3 Manager side
471471
build_i32h(d.param.mafload_const);
472472
build_i16h(d.sens.tps_raw); //for TPS learning
473+
//
473474
build_i16h(d.param.gps_curve_offset); //GPS
474475
build_i16h(d.param.gps_curve_gradient); //GPS
475476
build_i16h(d.param.fps_curve_offset); //FPS
476477
build_i16h(d.param.fps_curve_gradient); //FPS
478+
build_i16h(d.param.apps1_curve_offset); //APPS1
479+
build_i16h(d.param.apps1_curve_gradient); //APPS1
480+
build_i16h(d.sens.apps1_raw); //Redundant: for APPS1 learning
477481
break;
478482

479483
case STARTR_PAR:
@@ -848,6 +852,11 @@ void uart_send_packet(uint8_t send_mode)
848852
build_i16h(d.sens.fps); //Fuel Pressure Sensor
849853
#else
850854
build_i16h(0);
855+
#endif
856+
#ifndef SECU3T
857+
build_i16h(d.sens.apps1); //APPS1
858+
#else
859+
build_i16h(0);
851860
#endif
852861
break;
853862

@@ -2042,6 +2051,8 @@ uint8_t uart_recept_packet(void)
20422051
d.param.gps_curve_gradient = recept_i16h(); //GPS
20432052
d.param.fps_curve_offset = recept_i16h(); //FPS
20442053
d.param.fps_curve_gradient = recept_i16h(); //FPS
2054+
d.param.apps1_curve_offset = recept_i16h(); //APPS1
2055+
d.param.apps1_curve_gradient = recept_i16h(); //APPS1
20452056
break;
20462057

20472058
case STARTR_PAR:

sources/ufcodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#define CARBUR_PAR 'k' //!< carburetor's parameters
3737
#define IDLREG_PAR 'l' //!< idling regulator parameters
3838
#define ANGLES_PAR 'm' //!< advance angle (ign. timing) parameters
39-
#define FUNSET_PAR 'n' //!< parametersrelated to set of functions (lookup tables)
39+
#define FUNSET_PAR 'n' //!< parameters related to set of functions (lookup tables)
4040
#define STARTR_PAR 'o' //!< engine start parameters
4141

4242
#define FNNAME_DAT 'p' //!< used for transfering of names of set of functions (lookup tables)

0 commit comments

Comments
 (0)