Skip to content

Commit 04b8225

Browse files
committed
Change sampling of sensors. Option added to split MAP sampling from other sensors. Changes in the x-tau algorithm
1 parent 1a8f7ac commit 04b8225

File tree

18 files changed

+399
-167
lines changed

18 files changed

+399
-167
lines changed

sources/adc.c

Lines changed: 269 additions & 92 deletions
Large diffs are not rendered by default.

sources/adc.h

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ uint16_t adc_get_add_i3_value(void);
8989
/** Get latest measured value from throttle gate position sensor
9090
* \return value in ADC discretes
9191
*/
92-
uint16_t adc_get_carb_value(void);
92+
uint16_t adc_get_tps_value(void);
9393

9494
#if defined(FUEL_INJECT) || defined(GD_CONTROL)
9595
/** Get TPSdot value (dv/dt)
@@ -108,24 +108,40 @@ int16_t adc_get_mapdot_value(void);
108108
*/
109109
uint16_t adc_get_knock_value(void);
110110

111-
/**Starts measuring values from sensors, but only in the case when previous measurement has been completed
112-
* \param speed2x Double ADC clock, 0 - normal speed, 1 - double speed
111+
/** Start measuring MAP (standalone). Call this function only if MAP sampling mode is synchronous with CKP (see adc_set_map_to_ckp()
112+
* function for more information). If previous standalone MAP sampling is not finished yet, then this function does nothing.
113113
*/
114-
void adc_begin_measure(uint8_t speed2x);
114+
void adc_begin_measure_map(void);
115+
116+
/**Start of sampling of sensors. If ADC is busy by other sensors, this function sets request flag.
117+
* If MAP measurement mode is regular (not synchronized with CKP), then this function measures MAP too.
118+
*/
119+
void adc_begin_measure(void);
115120

116121
#ifndef TPIC8101
117122
/**Starts measuring value from the knock channel's integrator. As after setting INT/HOLD signal to 0
118-
* INTOUT output go into a fully correct state only after a 20us (approx.), then do first measurement
119-
* dummy, thus our subsequent actual measurement will be correct.
120-
* \param speed2x Double ADC clock, 0 - normal speed, 1 - double speed
123+
* INTOUT output go into a fully correct state only after a 20us (approx.), then do first dummy measurement,
124+
* thus our subsequent actual measurement will be correct.
121125
*/
122-
void adc_begin_measure_knock(uint8_t speed2x);
126+
void adc_begin_measure_knock(void);
123127
#endif
124128

129+
#define ADCRDY_MAP 0 //!< MAP
130+
#ifndef TPIC8101
131+
#define ADCRDY_KNOCK 1 //!< Knock
132+
#endif
133+
#define ADCRDY_SENS 2 //!< rest of the sensors
134+
125135
/**Check if ADC is ready
136+
* \param what See definitions of ADCRDY_* constants
126137
*\return return non-zero value if measuremtnt is ready (ADC is not busy)
127138
*/
128-
uint8_t adc_is_measure_ready(void);
139+
uint8_t adc_is_measure_ready(uint8_t what);
140+
141+
/** Sets sampling mode for MAP sensor
142+
* \param mtckp 0 - measure MAP with other sensors regularly, 1 - measure MAP synchronously with CKP in each stroke
143+
*/
144+
void adc_set_map_to_ckp(uint8_t mtckp);
129145

130146
/**Initialization of ADC and its state variables */
131147
void adc_init(void);

sources/bc_input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void measure_voltage(void)
137137
do
138138
{
139139
adc_measure_voltage();
140-
meas_update_values_buffers(0, &ram_extabs.cesd); //<-- all
140+
meas_update_values_buffers(&ram_extabs.cesd);
141141
_DELAY_US(100);
142142
wdt_reset_timer();
143143
}while(--i);

sources/ckps-cs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,10 +1339,12 @@ static void process_ckps_cogs(void)
13391339
{
13401340
knock_set_integration_mode(KNOCK_INTMODE_HOLD);
13411341
if (CHECKBIT(flags, F_USEKNK))
1342+
{
13421343
knock_start_settings_latching();//start the process of downloading the settings into the HIP9011 (and getting ADC result for TPIC8101)
13431344
#ifndef TPIC8101
1344-
adc_begin_measure_knock(_AB(ckps.stroke_period, 1) < 4);
1345+
adc_begin_measure_knock(); //Sample INTOUT output
13451346
#endif
1347+
}
13461348
}
13471349
}
13481350

@@ -1362,7 +1364,7 @@ static void process_ckps_cogs(void)
13621364
#ifdef SPLIT_ANGLE
13631365
ckps.advance_angle1 = ckps.advance_angle_buffered1; //advance angle with all the adjustments (say, 15°)
13641366
#endif
1365-
adc_begin_measure(_AB(ckps.stroke_period, 1) < 4);//start the process of measuring analog input values
1367+
adc_begin_measure_map(); //start the process of MAP sampling
13661368
#ifdef STROBOSCOPE
13671369
if (0==i)
13681370
ckps.strobe = 1; //strobe!

sources/ckps-odd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ ISR(TIMER1_COMPA_vect)
11031103
}
11041104

11051105
case QID_MEASURE:
1106-
adc_begin_measure(_AB(ckps.stroke_period, 1) < 4);//start the process of measuring analog input values
1106+
adc_begin_measure_map(); //start the process of MAP sampling
11071107
break;
11081108

11091109
case QID_KNKBEG:
@@ -1119,7 +1119,7 @@ ISR(TIMER1_COMPA_vect)
11191119
knock_set_integration_mode(KNOCK_INTMODE_HOLD);
11201120
knock_start_settings_latching();//start the process of downloading the settings into the HIP9011 (and getting ADC result for TPIC8101)
11211121
#ifndef TPIC8101
1122-
adc_begin_measure_knock(_AB(ckps.stroke_period, 1) < 4);
1122+
adc_begin_measure_knock();
11231123
#endif
11241124
break;
11251125

@@ -1355,7 +1355,7 @@ static void process_ckps_cogs(void)
13551355
QUEUE_ADDF(1, ICR1, (uint16_t)delay, QID_RPMSAMP);
13561356
}
13571357

1358-
//program queue for sensors' sample event
1358+
//program queue for MAP's sample event
13591359
if (chanstate[ch].msr_tooth == ckps.cog)
13601360
{
13611361
uint16_t delay = FRAC_TO_TIME(chanstate[ch].msr_frac);

sources/ckps.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,10 +1344,12 @@ static void process_ckps_cogs(void)
13441344
{
13451345
knock_set_integration_mode(KNOCK_INTMODE_HOLD);
13461346
if (CHECKBIT(flags, F_USEKNK))
1347+
{
13471348
knock_start_settings_latching();//start the process of downloading the settings into the HIP9011 (and getting ADC result for TPIC8101)
13481349
#ifndef TPIC8101
1349-
adc_begin_measure_knock(_AB(ckps.stroke_period, 1) < 4);
1350+
adc_begin_measure_knock();
13501351
#endif
1352+
}
13511353
}
13521354
}
13531355

@@ -1367,7 +1369,7 @@ static void process_ckps_cogs(void)
13671369
#ifdef SPLIT_ANGLE
13681370
ckps.advance_angle1 = ckps.advance_angle_buffered1; //advance angle with all the adjustments (say, 15°)
13691371
#endif
1370-
adc_begin_measure(_AB(ckps.stroke_period, 1) < 4);//start the process of measuring analog input values
1372+
adc_begin_measure_map(); //start the process of MAP sampling
13711373
#ifdef STROBOSCOPE
13721374
if (0==i)
13731375
ckps.strobe = 1; //strobe!

sources/ckps2ch.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,10 +946,12 @@ static void process_ckps_cogs(void)
946946
{
947947
knock_set_integration_mode(KNOCK_INTMODE_HOLD);
948948
if (CHECKBIT(flags, F_USEKNK))
949+
{
949950
knock_start_settings_latching();//start the process of downloading the settings into the HIP9011 (and getting ADC result for TPIC8101)
950951
#ifndef TPIC8101
951-
adc_begin_measure_knock(_AB(ckps.stroke_period, 1) < 4); //for HIP9011 only
952+
adc_begin_measure_knock(); //for HIP9011 only
952953
#endif
954+
}
953955
}
954956
}
955957

@@ -969,7 +971,7 @@ static void process_ckps_cogs(void)
969971
#ifdef SPLIT_ANGLE
970972
ckps.advance_angle1 = ckps.advance_angle_buffered1; //advance angle with all the adjustments (say, 15°)
971973
#endif
972-
adc_begin_measure(_AB(ckps.stroke_period, 1) < 4);//start the process of measuring analog input values
974+
adc_begin_measure_map(); //start the process of MAP sampling
973975
#ifdef STROBOSCOPE
974976
if (0==i)
975977
ckps.strobe = 1; //strobe!

sources/ckpsn+1.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ static inline void ProcessCogEdge(uint16_t tmr)
661661
hall.knkwnd_mode = 0;
662662
}
663663

664-
adc_begin_measure(_AB(hall.stroke_period, 1) < 4);//start the process of measuring analog input values
664+
adc_begin_measure_map(); //start the process of MAP sampling
665665

666666
sync_skip:
667667
++hall.cog;
@@ -732,7 +732,7 @@ ISR(TIMER0_COMPA_vect)
732732
knock_set_integration_mode(KNOCK_INTMODE_HOLD);
733733
knock_start_settings_latching();//start the process of downloading the settings into the HIP9011 (and getting of ADC result for TPIC8101)
734734
#ifndef TPIC8101
735-
adc_begin_measure_knock(_AB(hall.stroke_period, 1) < 4);
735+
adc_begin_measure_knock();
736736
#endif
737737
hall.knkwnd_mode = 0;
738738
}

sources/diagnost.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ void diagnost_process(void)
394394
//perform initialization of digital inputs
395395
init_digital_inputs();
396396

397+
//regular mode (sample MAP together with other sensors)
398+
adc_set_map_to_ckp(0);
399+
397400
#ifndef SECU3T
398401
knock_expander_initialize();
399402
#endif
@@ -423,19 +426,15 @@ void diagnost_process(void)
423426
knock_set_channel(diag.ksp_channel);
424427
if (++diag.ksp_channel > KSP_CHANNEL_1)
425428
diag.ksp_channel = KSP_CHANNEL_0;
426-
adc_begin_measure(0); //<--normal speed
427429
++diag.fsm_state;
428430
break;
429431

430-
//wait for completion of measurements, start integration of current knock channel's signal
432+
//start integration of current knock channel's signal
431433
case 1:
432-
if (adc_is_measure_ready())
433-
{
434434
if (!(d.diag_out & _OBV(24)))
435435
knock_set_integration_mode(KNOCK_INTMODE_INT);
436-
_DELAY_US(1000); //1ms
436+
_DELAY_US(2000); //2ms
437437
++diag.fsm_state;
438-
}
439438
break;
440439

441440
//start measurements (knock signal)
@@ -449,7 +448,9 @@ void diagnost_process(void)
449448
#endif
450449
knock_start_settings_latching();
451450
#ifndef TPIC8101
452-
adc_begin_measure_knock(0); //HIP9011 only
451+
_DISABLE_INTERRUPT();
452+
adc_begin_measure_knock(); //HIP9011 only
453+
_ENABLE_INTERRUPT();
453454
#endif
454455
++diag.fsm_state;
455456
break;
@@ -463,7 +464,7 @@ void diagnost_process(void)
463464
{
464465
diag.knock_value[diag.ksp_channel] = knock_get_adc_value(); //get ADC value read from TPIC8101
465466
#else //HIP9011
466-
if (adc_is_measure_ready())
467+
if (adc_is_measure_ready(ADCRDY_KNOCK))
467468
{
468469
diag.knock_value[diag.ksp_channel] = adc_get_knock_value();
469470
#endif
@@ -494,7 +495,7 @@ void diagnost_process(void)
494495
#ifdef TPIC8101
495496
d.diag_inp.add_i4 = _ADC_COMPENSATE(adc_get_knock_value(), ADC_VREF_FACTOR, 0.0);
496497
#endif
497-
d.diag_inp.carb = _ADC_COMPENSATE(adc_get_carb_value(), ADC_VREF_FACTOR, 0.0);
498+
d.diag_inp.carb = _ADC_COMPENSATE(adc_get_tps_value(), ADC_VREF_FACTOR, 0.0);
498499

499500
#if !defined(SECU3T) && defined(MCP3204)
500501
d.diag_inp.add_i5 = _ADC_COMPENSATE(adc_get_add_i5_value(), 0.488, 0.0);

sources/funconv.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,7 +1986,7 @@ uint32_t calc_dist(uint16_t pulse_count)
19861986
#endif
19871987

19881988
#if defined(FUEL_INJECT) && defined(XTAU_CORR)
1989-
//from adc.c
1989+
//from injector.c
19901990
extern volatile uint8_t xtau_str_cnt;
19911991
extern volatile uint32_t xtau_str_int;
19921992

@@ -1995,7 +1995,7 @@ void calc_xtau(int32_t* pw1, int32_t* pw2)
19951995
int16_t s_thrd = -((int16_t)d.param.inj_xtau_s_thrd); //kPa/sec
19961996
int16_t f_thrd = -((int16_t)d.param.inj_xtau_f_thrd); //kPa/sec
19971997
static uint32_t mpw[2] = {0};
1998-
static uint32_t M[2] = {0}; //amuunt of fuel in the film
1998+
static uint32_t M[2] = {0}; //amount of fuel in the film
19991999
static uint16_t xf = 0; //coefficient of fuel falling into the film, value * 1024
20002000
uint16_t tf = 0; //fuel evaporation time constant, value in 0.1024ms units
20012001
uint8_t chnum = (0x00!=d.param.lambda_selch) && !CHECKBIT(d.param.inj_lambda_flags, LAMFLG_MIXSEN) ? 2 : 1;
@@ -2049,7 +2049,7 @@ void calc_xtau(int32_t* pw1, int32_t* pw2)
20492049
tf = simple_interpolation_u(d.sens.mapdot, tfd, tfa, f_thrd, dthrd, 1) >> 0;
20502050
}
20512051

2052-
//obtain value of passed time from interrupt. See adc.c for more information
2052+
//obtain value of passed time from interrupt. See injector.c for more information
20532053
uint32_t dt;
20542054
_DISABLE_INTERRUPT();
20552055
dt = xtau_str_int;

sources/hall.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ static inline void ProcessFallingEdge(uint16_t tmr)
668668
hall.knkwnd_mode = 0;
669669
}
670670

671-
adc_begin_measure(_AB(hall.stroke_period, 1) < 4);//start the process of measuring analog input values
671+
adc_begin_measure_map(); //start the process of MAP sampling
672672
}
673673
#ifdef DWELL_CONTROL
674674
else if (!hall.rising_edge_spark)
@@ -846,7 +846,7 @@ ISR(TIMER0_COMPA_vect)
846846
knock_set_integration_mode(KNOCK_INTMODE_HOLD);
847847
knock_start_settings_latching();//start the process of downloading the settings into the HIP9011 (and getting ADC result from TPIC8101)
848848
#ifndef TPIC8101
849-
adc_begin_measure_knock(_AB(hall.stroke_period, 1) < 4);
849+
adc_begin_measure_knock();
850850
#endif
851851
hall.knkwnd_mode = 0;
852852
}

sources/injector.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
#define INJ_OFF 0 //!< Injector is turned off
5757
#endif
5858

59+
#if defined(XTAU_CORR)
60+
volatile uint8_t xtau_str_cnt = 0;
61+
volatile uint32_t xtau_str_int = 0;
62+
static volatile uint16_t xtau_tcnt = 0;
63+
#endif
64+
5965
//from ckps.c
6066
uint16_t ckps_get_stroke_period(void);
6167

@@ -420,6 +426,13 @@ void inject_start_inj(uint8_t chan)
420426
if (!inj.fuelcut || inj.prime_pulse)
421427
return; //fuel is OFF or prime pulse is active
422428

429+
//calculate "dltau" for X-tau algorithm. See calc_xtau() function for more information
430+
#if defined(XTAU_CORR)
431+
xtau_str_int+=(TCNT1 - xtau_tcnt); //measure time between events and add it to the sum
432+
xtau_tcnt = TCNT1;
433+
++xtau_str_cnt; //update counter of events
434+
#endif
435+
423436
if (CHECKBIT(inj.squirt_mask, chan))
424437
{
425438
if (inj.cfg < INJCFG_2BANK_ALTERN || inj.shrinktime == 2)

0 commit comments

Comments
 (0)