From 48df6a509d6aa55ab3130684d59a6ae551f7c641 Mon Sep 17 00:00:00 2001 From: Emanuele Trabattoni Date: Wed, 1 Apr 2026 12:31:29 +0200 Subject: [PATCH] Test OK Channel A --- RotaxMonitorTester/src/main.cpp | 17 +++++++++-------- RotaxMonitorTester/src/pins.h | 3 +++ RotaxMonitorTester/src/timer.cpp | 16 ++++++++-------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/RotaxMonitorTester/src/main.cpp b/RotaxMonitorTester/src/main.cpp index ae8b2c1..1985d2f 100644 --- a/RotaxMonitorTester/src/main.cpp +++ b/RotaxMonitorTester/src/main.cpp @@ -10,9 +10,11 @@ TaskHandle_t main_t = NULL; static uint32_t count = 0; #define FREQUENCY 100000 // 100 KHz -//#define PERIOD_US 1000000 / FREQUENCY #define PERIOD_US 10 +#define SPARK_DLY_MIN 10 +#define SPARK_DLY_MAX 490 + static const std::map pin2Name = { {PIN_TRIG_A12P, "HIGH_PIN_TRIG_A12P"}, {~PIN_TRIG_A12P, "LOW_PIN_TRIG_A12P"}, @@ -34,8 +36,8 @@ static timerStatus stsA = { .pause_long_us = 10000, .pause_short_us = 1000, .coil_pulse_us = 500, - .spark_pulse_us = 100, - .spark_delay_us = 100, + .spark_pulse_us = 50, + .spark_delay_us = 10, .main_task = NULL}; void setup() @@ -58,10 +60,9 @@ void setup() pinMode(SPARK_B12, OUTPUT); pinMode(SPARK_B34, OUTPUT); - pinMode(12, ANALOG); + pinMode(SPARK_DELAY_POT, ANALOG); stsA.main_task = xTaskGetCurrentTaskHandleForCore(1); - // Timer: 80MHz / 80 = 1MHz → 1 tick = 1 µs timerA = timerBegin(FREQUENCY); timerAttachInterruptArg(timerA, &onTimer, (void *)&stsA); timerAlarm(timerA, 1, true, 0); @@ -72,11 +73,11 @@ void setup() void loop() { LOG_INFO("Loop: ", count++); - uint32_t spark_delay = (uint32_t)(map(analogRead(12), 0, 4096, 100, 800) / PERIOD_US); + uint32_t spark_delay = (uint32_t)(map(analogRead(SPARK_DELAY_POT), 0, 4096, SPARK_DLY_MIN, SPARK_DLY_MAX) / PERIOD_US); stsA.spark_delay_us = spark_delay * PERIOD_US; - if (stsA.spark_delay_us > 500) { + if (stsA.spark_delay_us > (SPARK_DLY_MIN + SPARK_DLY_MAX) / 2) { stsA.soft_start = true; - stsA.spark_delay_us -= 500; + stsA.spark_delay_us -= (SPARK_DLY_MIN + SPARK_DLY_MAX) / 2; } else { stsA.soft_start = false; } diff --git a/RotaxMonitorTester/src/pins.h b/RotaxMonitorTester/src/pins.h index aaa91db..a0b8c36 100644 --- a/RotaxMonitorTester/src/pins.h +++ b/RotaxMonitorTester/src/pins.h @@ -17,3 +17,6 @@ #define SPARK_B12 4 #define SPARK_B34 5 + +// Pot +#define SPARK_DELAY_POT 12 diff --git a/RotaxMonitorTester/src/timer.cpp b/RotaxMonitorTester/src/timer.cpp index 8de38d1..6504230 100644 --- a/RotaxMonitorTester/src/timer.cpp +++ b/RotaxMonitorTester/src/timer.cpp @@ -105,17 +105,10 @@ void onTimer(void *arg) { // xTaskNotifyFromISR(task, PIN_TRIG_A34P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken); digitalWrite(PIN_TRIG_A34P, HIGH); - params->coil34p_high; + params->coil34p_high = true;; wait_sent = false; } - if (params->state_time >= params->coil_pulse_us && params->coil34p_high) - { - // xTaskNotifyFromISR(task, ~PIN_TRIG_A34P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken); - digitalWrite(PIN_TRIG_A34P, LOW); - params->coil34p_high = false; - } - if (!params->soft_start) { if (params->state_time == params->spark_delay_us) @@ -131,6 +124,13 @@ void onTimer(void *arg) } } + if (params->state_time >= params->coil_pulse_us && params->coil34p_high) + { + // xTaskNotifyFromISR(task, ~PIN_TRIG_A34P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken); + digitalWrite(PIN_TRIG_A34P, LOW); + params->coil34p_high = false; + } + if (params->state_time >= params->pause_short_us) { params->state = S_34N;