Sync 12 and 34 working

This commit is contained in:
2026-04-04 16:27:52 +02:00
parent 0dc5d1ce79
commit b0842aadef
8 changed files with 93 additions and 41 deletions

View File

@@ -51,8 +51,6 @@ void rtIgnitionTask(void *pvParameters)
LOG_INFO("rtTask ISR Params OK");
pinMode(POT_A_CS, OUTPUT);
// Attach Pin Interrupts
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12p), rt_int.isr_ptr, (void *)&isr_params_t12p, RISING);
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12n), rt_int.isr_ptr, (void *)&isr_params_t12n, RISING);
@@ -73,6 +71,7 @@ void rtIgnitionTask(void *pvParameters)
// Global rt_task_ptr variables
uint32_t it = 0;
uint32_t q_fail_count = 0;
bool first_cycle = true;
while (params->rt_running)
{
@@ -85,6 +84,11 @@ void rtIgnitionTask(void *pvParameters)
ULONG_MAX, // pulisci i primi 8 bit
&pickup_flag, // valore ricevuto
portMAX_DELAY);
if (first_cycle && pickup_flag != TRIG_FLAG_12P) // skip first cycle because of possible initial noise on pickup signals at startu
{
continue;
}
#ifdef DEBUG
Serial.print("\033[2J"); // clear screen
@@ -105,6 +109,7 @@ void rtIgnitionTask(void *pvParameters)
// WAIT FOR SPARK TO HAPPEN
auto spark_timeout = ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(spark_timeout_max));
//auto spark_timeout = ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
if (ign_box_sts.coils12.spark_ok || ign_box_sts.coils34.spark_ok) // otherwise timeout if none is set in the ISR
spark_flag = ign_box_sts.coils12.spark_ok ? SPARK_FLAG_12 : SPARK_FLAG_34;
else
@@ -121,7 +126,7 @@ void rtIgnitionTask(void *pvParameters)
ulTaskNotifyValueClear(NULL, 0xFFFFFFFF);
// A trigger from pickup 12 is followed by a spark event on 34 or vice versa pickup 34 triggers spark on 12
if ((pickup_flag == TRIG_FLAG_12P || pickup_flag == TRIG_FLAG_12N) && spark_flag != SPARK_FLAG_12)
if ((pickup_flag == TRIG_FLAG_12P || pickup_flag == TRIG_FLAG_12N) && (spark_flag != SPARK_FLAG_12 && spark_flag != SPARK_FLAG_NIL))
{
ign_box_sts.coils12.spark_status = ign_box_sts.coils34.spark_status = sparkStatus::SPARK_SYNC_FAIL;
// Save error on circular buffer and skip to next cycle //
@@ -133,6 +138,7 @@ void rtIgnitionTask(void *pvParameters)
switch (pickup_flag)
{
case TRIG_FLAG_12P:
first_cycle = false;
case TRIG_FLAG_12N:
coils = &ign_box_sts.coils12;
break;
@@ -148,16 +154,15 @@ void rtIgnitionTask(void *pvParameters)
case TRIG_FLAG_12P:
case TRIG_FLAG_34P:
{
LOG_INFO("POSITIVE Edge");
// Timeout not occourred, expected POSITIVE edge spark OCCOURRED
if (spark_flag != SPARK_FLAG_NIL)
{
coils->spark_delay = coils->trig_time - coils->spark_time;
coils->spark_delay = coils->spark_time - coils->trig_time;
coils->sstart_status = softStartStatus::NORMAL; // because spark on positive edge
coils->spark_status = sparkStatus::SPARK_POS_OK; // do not wait for spark on negative edge
#ifdef DEBUG
LOG_INFO("Spark on POSITIVE pulse");
LOG_INFO("Spark Delay Timer: ", (int32_t)coils->spark_delay);
LOG_INFO("Spark Delay Time: ", (int32_t)coils->spark_delay);
#endif
}
// Timeout occourred, expected POSITIVE edge spark NOT OCCOURRED
@@ -173,17 +178,16 @@ void rtIgnitionTask(void *pvParameters)
case TRIG_FLAG_12N:
case TRIG_FLAG_34N:
{
LOG_INFO("NEGATIVE Edge");
const bool expected_negative = coils->spark_status == sparkStatus::SPARK_NEG_WAIT;
// Timeout not occourred, expected NEGATIVE edge spark OCCOURRED
if (spark_flag != SPARK_FLAG_NIL && expected_negative)
{
coils->spark_delay = coils->trig_time - coils->spark_time;
coils->spark_delay = coils->spark_time - coils->trig_time;
coils->sstart_status = softStartStatus::SOFT_START;
coils->spark_status == sparkStatus::SPARK_NEG_OK;
coils->spark_status = sparkStatus::SPARK_NEG_OK;
#ifdef DEBUG
LOG_INFO("Spark on NEGATIVE pulse");
LOG_INFO("Spark Delay Timer: ", (int32_t)coils->spark_delay);
LOG_INFO("Spark Delay Time: ", (int32_t)coils->spark_delay);
#endif
}
// Timeout occourred, expected POSITIVE edge spark NOT OCCOURRED
@@ -248,7 +252,7 @@ void rtIgnitionTask(void *pvParameters)
if (xQueueSendToBack(rt_queue, (void *)&ign_box_sts, pdMS_TO_TICKS(1)) != pdPASS)
{
q_fail_count++;
// LOG_ERROR("Failed to send to rt_queue");
LOG_ERROR("Failed to send to rt_queue");
}
}
}