Implemented "full" ignition timing system

This is a first implementation of a "full" timing system, with proper
handling for cases wher the ignition charge time overlaps with the
compression pulse, the spark has a more complex state machine system
with the option to defer charge from the intake pulse to the compression
pulse, and further defferal of the spark release schedule to the ISR
that triggers when the output compare triggers for the charge

Preliminary error counters have been put in place, they still require
handling error conditions that would force a soft shutdown on the
ignition IC. Alongside this the code still needs to be verified so that
all non critical errors (ie missed charge schedules) reset the state
machine and increment a global spark miss counter to avoid having these
errors breaking the state machine as they can easily be recovered from

Cases where the coil would already be charging and an error occurs
require as stated above a full recovery procedure with soft shutdown of
the ignition IC and a clean cycle of the state machine to ensure a full
recovery
This commit is contained in:
h3cx committed 2026-09-26 22:11:51 +02:00
1 parent 0ea7b83bea
commit 7502b354dc
15 files changed
+444 -195

No files matched your search

+19 -3
View File
@@ -7,7 +7,8 @@
#include <stdint.h>
#define MAX_CAM_MISS 2
#define SPARK_ADVANCE 40
#define SPARK_ADVANCE 30
#define SPARK_CHARGE_TIME 3000
#define INJECTION_PHASE 0
typedef enum { SYNC_OK = 0, SYNC_PENDING = 1, SYNC_NOT_OK = 2 } sync_state_t;
@@ -24,10 +25,21 @@ typedef enum { CAM_IDLE = 0, CAM_TRIGD = 1 } cam_state_t;
typedef enum {
SPARK_IDLE = 0,
SPARK_CHARGING = 1,
SPARK_NONE = 2
SPARK_PENDING_CHARGE = 1,
SPARK_CHARGING = 2,
SPARK_PENDING_RELEASE = 3,
SPARK_NONE = 4
} spark_state_t;
typedef struct {
uint32_t overspeed_error_ctr;
uint32_t defer_charge_error_ctr;
uint32_t revised_charge_error_ctr;
uint32_t task_release_error_ctr;
uint32_t state_error_ctr;
uint32_t isr_release_error_ctr;
} spark_errors_t;
typedef struct {
crank_state_t crank_state;
cam_state_t cam_state;
@@ -37,4 +49,8 @@ typedef struct {
ring_buffer_t cam_RB;
spark_state_t next_spark_state;
spark_state_t current_spark_state;
bool charge_defer;
bool spark_defer;
uint32_t t_defer_spark;
spark_errors_t spark_errors;
} global_state_t;