Enable/Disable pickup simulation

This commit is contained in:
Emanuele Trabattoni
2026-04-08 10:26:44 +02:00
parent 7c96101cdd
commit 481f12f526
2 changed files with 25 additions and 1 deletions

View File

@@ -54,6 +54,8 @@ static timerStatus stsA = {
.spark_delay_us = 50,
.main_task = NULL};
static bool isEnabled = false;
void setup()
{
@@ -76,9 +78,14 @@ void setup()
pinMode(SPARK_B34, OUTPUT);
pinMode(SPARK_DELAY_POT, ANALOG);
pinMode(FREQ_POT, ANALOG);
pinMode(ENABLE_PIN, INPUT_PULLUP);
stsA.main_task = xTaskGetCurrentTaskHandleForCore(1);
timerA = timerBegin(FREQUENCY);
timerStop(timerA);
timerAttachInterruptArg(timerA, &onTimer, (void *)&stsA);
timerAlarm(timerA, 1, true, 0);
@@ -100,11 +107,25 @@ void loop()
double new_rpm = (double)(map(analogRead(FREQ_POT), 0, 4096, RPM_MIN, RPM_MAX));
filtered_rpm = filtered_rpm + 0.1 * (new_rpm - filtered_rpm);
stsA.pause_long_us = (uint32_t)(60000000.0f / filtered_rpm / 2.0f);
if (isEnabled) {
LOG_INFO("==== System is ENABLED ====");
} else {
LOG_INFO("==== System is DISABLED ====");
}
LOG_INFO("Spark Delay uS: ", stsA.spark_delay_us, "\tSoft Start: ", stsA.soft_start ? "TRUE" : "FALSE");
LOG_INFO("Engine Rpm: ", (uint32_t)(filtered_rpm));
LOG_INFO("Coil Pulse: ", stsA.coil_pulse_us, "us");
LOG_INFO("Spark Pulse: ", stsA.spark_pulse_us, "us");
if (digitalRead(ENABLE_PIN) == LOW && !isEnabled) {
timerStart(timerA);
isEnabled = true;
} else if (digitalRead(ENABLE_PIN) == HIGH && isEnabled) {
timerStop(timerA);
isEnabled = false;
}
delay(100);
clearScreen();

View File

@@ -1,5 +1,8 @@
#pragma once
// Enable Pin
#define ENABLE_PIN 16
///// Ignition Box A /////
#define PIN_TRIG_A12P 18
#define PIN_TRIG_A12N 19