Files
h3cx 7502b354dc 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
2026-09-26 22:11:51 +02:00

17 lines
552 B
C

// Copyright (C) 2026 Hector van der Aa <hector@h3cx.dev>
// Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
// SPDX-License-Identifier: GPL-3.0-or-later
#include "timer_utils.h"
#include "stm32h7xx.h"
#include <stdbool.h>
void TIM2_CH3_SetOCMode(uint32_t oc_mode) {
MODIFY_REG(TIM2->CCMR2, TIM_CCMR2_OC3M | TIM_CCMR2_OC3M_3, oc_mode);
}
bool timer_safe_to_arm(uint32_t deadline, TIM_HandleTypeDef *tim) {
uint32_t time_left = deadline - __HAL_TIM_GET_COUNTER(tim);
return time_left > 100U && time_left < 0x80000000U;
}