Thans to copilot, microsecond resolution to wait for spark.

no missing firings detected
This commit is contained in:
2026-04-04 22:12:53 +02:00
parent 38c595fd7b
commit c5d80052e5
6 changed files with 64 additions and 55 deletions

View File

@@ -7,7 +7,6 @@
void trig_isr(void *arg)
{
const int64_t time_us = esp_timer_get_time();
static uint8_t isr_firing_count = 0;
// exit if invalid args
if (!arg)
@@ -26,47 +25,29 @@ void trig_isr(void *arg)
{
case TRIG_FLAG_12P:
case TRIG_FLAG_12N:
// if (isr_firing_count == 0)
{
// only on first trigger to avoid multiple firing due to noise, to be fixed with hardware debounce
isr_firing_count++;
box->coils12.spark_ok = false; // reset spark ok flag on new trigger event
box->coils12.trig_time = time_us;
xTaskNotifyFromISR(task_handle, params->flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
}
// only on first trigger to avoid multiple firing due to noise, to be fixed with hardware debounce
box->coils12.trig_time = time_us;
xTaskNotifyFromISR(task_handle, params->flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
break;
case TRIG_FLAG_34P:
case TRIG_FLAG_34N:
// if (isr_firing_count == 0)
{
// only on first trigger to avoid multiple firing due to noise, to be fixed with hardware debounce
isr_firing_count++;
box->coils34.spark_ok = false; // reset spark ok flag on new trigger event
box->coils34.trig_time = time_us;
xTaskNotifyFromISR(task_handle, params->flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
}
// only on first trigger to avoid multiple firing due to noise, to be fixed with hardware debounce
box->coils34.trig_time = time_us;
xTaskNotifyFromISR(task_handle, params->flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
break;
case SPARK_FLAG_12:
// if (isr_firing_count > 0) // only consider spark if a trigger has been detected, otherwise noise on spark pin can cause false positives
{
isr_firing_count = 0; // reset trigger timeout counter on spark event
box->coils34.spark_ok = false;
box->coils12.spark_ok = true;
box->coils12.spark_time = time_us;
xTaskNotifyFromISR(task_handle, params->flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
// vTaskNotifyGiveFromISR(task_handle, &xHigherPriorityTaskWoken);
}
box->coils34.spark_ok = false;
box->coils12.spark_ok = true;
box->coils12.spark_time = time_us;
xTaskNotifyFromISR(task_handle, params->flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
// vTaskNotifyGiveFromISR(task_handle, &xHigherPriorityTaskWoken);
break;
case SPARK_FLAG_34:
// if (isr_firing_count > 0) // only consider spark if a trigger has been detected, otherwise noise on spark pin can cause false positives
{
isr_firing_count = 0; // reset trigger timeout counter on spark event
box->coils12.spark_ok = false;
box->coils34.spark_ok = true;
box->coils34.spark_time = time_us;
xTaskNotifyFromISR(task_handle, params->flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
// vTaskNotifyGiveFromISR(task_handle, &xHigherPriorityTaskWoken);
}
box->coils12.spark_ok = false;
box->coils34.spark_ok = true;
box->coils34.spark_time = time_us;
xTaskNotifyFromISR(task_handle, params->flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
// vTaskNotifyGiveFromISR(task_handle, &xHigherPriorityTaskWoken);
break;
default:
break;