Compare commits
2 Commits
0dc5d1ce79
...
38c595fd7b
| Author | SHA1 | Date | |
|---|---|---|---|
| 38c595fd7b | |||
| b0842aadef |
@@ -21,12 +21,12 @@ lib_deps =
|
|||||||
|
|
||||||
;Upload protocol configuration
|
;Upload protocol configuration
|
||||||
upload_protocol = esptool
|
upload_protocol = esptool
|
||||||
upload_port = /dev/ttyACM1
|
upload_port = /dev/ttyACM2
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
|
|
||||||
;Monitor configuration
|
;Monitor configuration
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
monitor_port = /dev/ttyACM1
|
monitor_port = /dev/ttyACM2
|
||||||
|
|
||||||
; Build configuration
|
; Build configuration
|
||||||
build_type = debug
|
build_type = debug
|
||||||
@@ -39,12 +39,12 @@ lib_deps = ${env:esp32-s3-devkitc1-n16r8.lib_deps}
|
|||||||
|
|
||||||
;Upload protocol configuration
|
;Upload protocol configuration
|
||||||
upload_protocol = esptool
|
upload_protocol = esptool
|
||||||
upload_port = /dev/ttyACM1
|
upload_port = /dev/ttyACM2
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
|
|
||||||
;Monitor configuration
|
;Monitor configuration
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
monitor_port = /dev/ttyACM1
|
monitor_port = /dev/ttyACM2
|
||||||
|
|
||||||
; Debug configuration
|
; Debug configuration
|
||||||
debug_tool = esp-builtin
|
debug_tool = esp-builtin
|
||||||
@@ -58,4 +58,5 @@ build_flags =
|
|||||||
-ggdb3
|
-ggdb3
|
||||||
-DCORE_DEBUG_LEVEL=5
|
-DCORE_DEBUG_LEVEL=5
|
||||||
-DARDUINO_USB_CDC_ON_BOOT=0
|
-DARDUINO_USB_CDC_ON_BOOT=0
|
||||||
|
-DARDUINO_USB_MODE=0
|
||||||
-fstack-protector-all
|
-fstack-protector-all
|
||||||
|
|||||||
@@ -7,12 +7,11 @@
|
|||||||
void trig_isr(void *arg)
|
void trig_isr(void *arg)
|
||||||
{
|
{
|
||||||
const int64_t time_us = esp_timer_get_time();
|
const int64_t time_us = esp_timer_get_time();
|
||||||
|
static uint8_t isr_firing_count = 0;
|
||||||
|
|
||||||
// exit if invalid args
|
// exit if invalid args
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return;
|
return;
|
||||||
// FOR TESTING ONLY
|
|
||||||
digitalWrite(POT_A_CS, HIGH);
|
|
||||||
|
|
||||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||||
isrParams *params = (isrParams *)arg;
|
isrParams *params = (isrParams *)arg;
|
||||||
@@ -23,37 +22,55 @@ void trig_isr(void *arg)
|
|||||||
if (!task_handle)
|
if (!task_handle)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// reset spark flags, cannot be same time as trigger flags
|
|
||||||
box->coils12.spark_ok = false;
|
|
||||||
box->coils34.spark_ok = false;
|
|
||||||
|
|
||||||
switch (params->flag)
|
switch (params->flag)
|
||||||
{
|
{
|
||||||
case TRIG_FLAG_12P:
|
case TRIG_FLAG_12P:
|
||||||
case TRIG_FLAG_12N:
|
case TRIG_FLAG_12N:
|
||||||
box->coils12.trig_time = time_us;
|
// if (isr_firing_count == 0)
|
||||||
xTaskNotifyFromISR(task_handle, params->flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
{
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case TRIG_FLAG_34P:
|
case TRIG_FLAG_34P:
|
||||||
case TRIG_FLAG_34N:
|
case TRIG_FLAG_34N:
|
||||||
box->coils34.trig_time = time_us;
|
// if (isr_firing_count == 0)
|
||||||
xTaskNotifyFromISR(task_handle, params->flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
{
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SPARK_FLAG_12:
|
case SPARK_FLAG_12:
|
||||||
box->coils12.spark_ok = true;
|
// if (isr_firing_count > 0) // only consider spark if a trigger has been detected, otherwise noise on spark pin can cause false positives
|
||||||
box->coils12.spark_time = time_us;
|
{
|
||||||
vTaskNotifyGiveFromISR(task_handle, &xHigherPriorityTaskWoken);
|
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);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SPARK_FLAG_34:
|
case SPARK_FLAG_34:
|
||||||
box->coils34.spark_ok = true;
|
// if (isr_firing_count > 0) // only consider spark if a trigger has been detected, otherwise noise on spark pin can cause false positives
|
||||||
box->coils34.spark_time = time_us;
|
{
|
||||||
vTaskNotifyGiveFromISR(task_handle, &xHigherPriorityTaskWoken);
|
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);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// FOR TESTING ONLY
|
|
||||||
digitalWrite(POT_A_CS, LOW);
|
|
||||||
|
|
||||||
if (xHigherPriorityTaskWoken)
|
if (xHigherPriorityTaskWoken)
|
||||||
portYIELD_FROM_ISR();
|
portYIELD_FROM_ISR();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
// Arduino Libraries
|
// Arduino Libraries
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "soc/gpio_struct.h"
|
#include "soc/gpio_struct.h"
|
||||||
|
#include <map>
|
||||||
#ifndef TEST
|
#ifndef TEST
|
||||||
#include "pins.h"
|
#include "pins.h"
|
||||||
#else
|
#else
|
||||||
@@ -45,34 +46,58 @@ enum sparkStatus
|
|||||||
SPARK_SYNC_FAIL,
|
SPARK_SYNC_FAIL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const std::map<const sparkStatus, const char *> sparkStatusNames = {
|
||||||
|
{SPARK_POS_OK, "SPARK_POS_OK"},
|
||||||
|
{SPARK_NEG_OK, "SPARK_NEG_OK"},
|
||||||
|
{SPARK_POS_SKIP, "SPARK_POS_SKIP"},
|
||||||
|
{SPARK_NEG_SKIP, "SPARK_NEG_SKIP"},
|
||||||
|
{SPARK_POS_WAIT, "SPARK_POS_WAIT"},
|
||||||
|
{SPARK_NEG_WAIT, "SPARK_NEG_WAIT"},
|
||||||
|
{SPARK_POS_FAIL, "SPARK_POS_FAIL"},
|
||||||
|
{SPARK_NEG_FAIL, "SPARK_NEG_FAIL"},
|
||||||
|
{SPARK_POS_UNEXPECTED, "SPARK_POS_UNEXPECTED"},
|
||||||
|
{SPARK_NEG_UNEXPECTED, "SPARK_NEG_UNEXPECTED"},
|
||||||
|
{SPARK_SYNC_FAIL, "SPARK_SYNC_FAIL"},
|
||||||
|
};
|
||||||
|
|
||||||
enum softStartStatus
|
enum softStartStatus
|
||||||
{
|
{
|
||||||
NORMAL,
|
NORMAL,
|
||||||
SOFT_START
|
SOFT_START,
|
||||||
|
ERROR,
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::map<const softStartStatus, const char *> softStartStatusNames = {
|
||||||
|
{NORMAL, "NORMAL"},
|
||||||
|
{SOFT_START, "SOFT_START"},
|
||||||
|
{ERROR, "ERROR"},
|
||||||
};
|
};
|
||||||
|
|
||||||
struct coilsStatus
|
struct coilsStatus
|
||||||
{
|
{
|
||||||
int64_t trig_time;
|
int64_t trig_time = 0;
|
||||||
int64_t spark_time;
|
int64_t spark_time = 0;
|
||||||
int64_t spark_delay;
|
int64_t spark_delay = 0; // in microseconds
|
||||||
sparkStatus spark_status;
|
sparkStatus spark_status = sparkStatus::SPARK_POS_OK;
|
||||||
softStartStatus sstart_status;
|
softStartStatus sstart_status = softStartStatus::NORMAL;
|
||||||
float peak_p_in, peak_n_in;
|
float peak_p_in = 0.0, peak_n_in = 0.0;
|
||||||
float peak_p_out, peak_n_out;
|
float peak_p_out = 0.0, peak_n_out = 0.0;
|
||||||
float trigger_spark;
|
float trigger_spark = 0.0;
|
||||||
bool spark_ok;
|
bool spark_ok = false;
|
||||||
|
uint32_t n_events = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Task internal Status
|
// Task internal Status
|
||||||
struct ignitionBoxStatus
|
struct ignitionBoxStatus
|
||||||
{
|
{
|
||||||
int64_t timestamp;
|
int64_t timestamp = 0;
|
||||||
// coils pairs for each ignition
|
// coils pairs for each ignition
|
||||||
coilsStatus coils12;
|
coilsStatus coils12;
|
||||||
coilsStatus coils34;
|
coilsStatus coils34;
|
||||||
// voltage from generator
|
// voltage from generator
|
||||||
float volts_gen = 0.0;
|
float volts_gen = 0.0;
|
||||||
|
uint32_t n_queue_errors = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct isrParams
|
struct isrParams
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ void printTaskList()
|
|||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(921600);
|
||||||
delay(250);
|
delay(250);
|
||||||
|
|
||||||
// Setup Logger
|
// Setup Logger
|
||||||
@@ -168,46 +168,58 @@ void loop()
|
|||||||
LOG_INFO("Real Time Tasks A & B initialized");
|
LOG_INFO("Real Time Tasks A & B initialized");
|
||||||
|
|
||||||
////////////////////// MAIN LOOP //////////////////////
|
////////////////////// MAIN LOOP //////////////////////
|
||||||
uint32_t count(0);
|
|
||||||
clearScreen();
|
clearScreen();
|
||||||
setCursor(0, 0);
|
setCursor(0, 0);
|
||||||
|
ignitionBoxStatus ignA;
|
||||||
|
int64_t last = esp_timer_get_time();
|
||||||
|
uint32_t missed_firings12 = 0;
|
||||||
|
uint32_t missed_firings34 = 0;
|
||||||
|
|
||||||
while (running)
|
while (running)
|
||||||
{
|
{
|
||||||
ignitionBoxStatus ignA;
|
if (xQueueReceive(rt_taskA_queue, &ignA, pdMS_TO_TICKS(1000)) == pdTRUE)
|
||||||
if (xQueueReceive(rt_taskA_queue, &ignA, pdMS_TO_TICKS(100)) == pdTRUE)
|
|
||||||
{
|
{
|
||||||
if (count++ % 10000 == 0)
|
if (ignA.coils12.spark_status == sparkStatus::SPARK_NEG_FAIL || ignA.coils12.spark_status == sparkStatus::SPARK_POS_FAIL)
|
||||||
{
|
missed_firings12++;
|
||||||
firstRun = true;
|
if (ignA.coils34.spark_status == sparkStatus::SPARK_POS_FAIL || ignA.coils34.spark_status == sparkStatus::SPARK_NEG_FAIL)
|
||||||
clearScreen();
|
missed_firings34++;
|
||||||
setCursor(0, 0);
|
clearScreen();
|
||||||
printField("++ Timestamp", (uint32_t)ignA.timestamp, 0, 0);
|
setCursor(0, 0);
|
||||||
Serial.println("========== Coils 12 =============");
|
printField("++ Timestamp", (uint32_t)ignA.timestamp, 0, 0);
|
||||||
printField("Pickup Tim", (uint32_t)ignA.coils12.trig_time, 0, 1);
|
Serial.println("========== Coils 12 =============");
|
||||||
printField("Spark Tim", (uint32_t)ignA.coils12.spark_time, 0, 2);
|
printField("Events", (uint32_t)ignA.coils12.n_events, 0, 1);
|
||||||
printField("Spark Dly", (uint32_t)ignA.coils12.spark_delay, 0, 3);
|
printField("Missed Firing", missed_firings12, 0, 2);
|
||||||
printField("Spark Sts", (uint32_t)ignA.coils12.spark_status, 0, 4);
|
printField("Spark Dly", (uint32_t)ignA.coils12.spark_delay, 0, 3);
|
||||||
printField("Peak P_IN", ignA.coils12.peak_p_in, 0, 5);
|
printField("Spark Sts", sparkStatusNames.at(ignA.coils12.spark_status), 0, 4);
|
||||||
printField("Peak P_OUT", ignA.coils12.peak_p_out, 0, 6);
|
// printField("Peak P_IN", ignA.coils12.peak_p_in, 0, 5);
|
||||||
printField("Peak N_IN", ignA.coils12.peak_n_in, 0, 7);
|
// printField("Peak P_OUT", ignA.coils12.peak_p_out, 0, 6);
|
||||||
printField("Peak N_OUT", ignA.coils12.peak_n_out, 0, 8);
|
// printField("Peak N_IN", ignA.coils12.peak_n_in, 0, 7);
|
||||||
printField("SoftStart ", (uint32_t)ignA.coils12.sstart_status, 0, 9);
|
// printField("Peak N_OUT", ignA.coils12.peak_n_out, 0, 8);
|
||||||
|
printField("Soft Start ", softStartStatusNames.at(ignA.coils12.sstart_status), 0, 9);
|
||||||
|
|
||||||
Serial.println("========== Coils 34 =============");
|
Serial.println("========== Coils 34 =============");
|
||||||
printField("Pickup Tim", (uint32_t)ignA.coils34.trig_time, 0, 11);
|
printField("Events", (uint32_t)ignA.coils34.n_events, 0, 11);
|
||||||
printField("Spark Tim", (uint32_t)ignA.coils34.spark_time, 0, 12);
|
printField("Missed Firing", missed_firings34, 0, 12);
|
||||||
printField("Spark Dly", (uint32_t)ignA.coils34.spark_delay, 0, 13);
|
printField("Spark Dly", (uint32_t)ignA.coils34.spark_delay, 0, 13);
|
||||||
printField("Spark Sts", (uint32_t)ignA.coils34.spark_delay, 0, 14);
|
printField("Spark Sts", sparkStatusNames.at(ignA.coils34.spark_status), 0, 14);
|
||||||
printField("Peak P_IN", ignA.coils34.peak_p_in, 0, 15);
|
// printField("Peak P_IN", ignA.coils34.peak_p_in, 0, 15);
|
||||||
printField("Peak P_OUT", ignA.coils34.peak_p_out, 0, 16);
|
// printField("Peak P_OUT", ignA.coils34.peak_p_out, 0, 16);
|
||||||
printField("Peak N_IN", ignA.coils34.peak_n_in, 0, 17);
|
// printField("Peak N_IN", ignA.coils34.peak_n_in, 0, 17);
|
||||||
printField("Peak N_OUT", ignA.coils34.peak_n_out, 0, 18);
|
// printField("Peak N_OUT", ignA.coils34.peak_n_out, 0, 18);
|
||||||
printField("SoftStart ", (uint32_t)ignA.coils34.sstart_status, 0, 19);
|
printField("Soft Start ", softStartStatusNames.at(ignA.coils34.sstart_status), 0, 19);
|
||||||
|
|
||||||
Serial.println("========== END =============");
|
Serial.println("========== END =============");
|
||||||
count = 0;
|
Serial.println();
|
||||||
}
|
auto delta = (esp_timer_get_time() - last) / 1000000.0f; //in seconds
|
||||||
|
delta = delta > 0 ? 1.0f / delta : 0; // Calculate frequency (Hz)
|
||||||
|
printField("Frequency (Hz)", delta, 0, 21);
|
||||||
|
printField("Queue Errors", (uint32_t)ignA.n_queue_errors, 0, 22);
|
||||||
|
last = esp_timer_get_time();
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
setCursor(0, 22);
|
||||||
|
Serial.print("Waiting for data... ");;
|
||||||
|
Serial.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,16 +59,16 @@
|
|||||||
// =====================
|
// =====================
|
||||||
// DIGITAL POT
|
// DIGITAL POT
|
||||||
// =====================
|
// =====================
|
||||||
#define POT_A_CS 1
|
//#define POT_A_CS 1
|
||||||
#define POT_B_CS 2
|
//#define POT_B_CS 2
|
||||||
|
|
||||||
// =====================
|
// =====================
|
||||||
// TRIGGER INPUT INTERRUPTS
|
// TRIGGER INPUT INTERRUPTS
|
||||||
// =====================
|
// =====================
|
||||||
#define TRIG_PIN_A12P 18
|
#define TRIG_PIN_A12P 18
|
||||||
#define TRIG_PIN_A12N 21
|
#define TRIG_PIN_A12N 21
|
||||||
#define TRIG_PIN_A34P 38 // ATTENZIONEEEEEEEEEEE
|
#define TRIG_PIN_A34P 1
|
||||||
#define TRIG_PIN_A34N 39 // ATTENZIONEEEEEEEEEEE
|
#define TRIG_PIN_A34N 2
|
||||||
#define TRIG_PIN_B12P 38
|
#define TRIG_PIN_B12P 38
|
||||||
#define TRIG_PIN_B12N 39
|
#define TRIG_PIN_B12N 39
|
||||||
#define TRIG_PIN_B34P 40
|
#define TRIG_PIN_B34P 40
|
||||||
@@ -78,9 +78,9 @@
|
|||||||
// SPARK DETECT INPUTS
|
// SPARK DETECT INPUTS
|
||||||
// =====================
|
// =====================
|
||||||
#define SPARK_PIN_A12 42
|
#define SPARK_PIN_A12 42
|
||||||
#define SPARK_PIN_A34 42 // OK (strapping ma consentito) 45
|
#define SPARK_PIN_A34 45 // OK (strapping ma consentito) 45
|
||||||
#define SPARK_PIN_B12 42 // OK (strapping ma consentito) 46
|
#define SPARK_PIN_B12 46 // OK (strapping ma consentito) 46
|
||||||
#define SPARK_PIN_B34 42
|
#define SPARK_PIN_B34 47
|
||||||
|
|
||||||
// =====================
|
// =====================
|
||||||
// PCA9555 (I2C EXPANDER)
|
// PCA9555 (I2C EXPANDER)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
ADS1256 *adc = dev->adc_a;
|
ADS1256 *adc = dev->adc_a;
|
||||||
PCA9555 *io = dev->io;
|
PCA9555 *io = dev->io;
|
||||||
|
|
||||||
static ignitionBoxStatus ign_box_sts;
|
ignitionBoxStatus ign_box_sts;
|
||||||
|
|
||||||
// Variables for ISR, static to be fixed in memory locations
|
// Variables for ISR, static to be fixed in memory locations
|
||||||
static isrParams isr_params_t12p{
|
static isrParams isr_params_t12p{
|
||||||
@@ -51,8 +51,6 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
|
|
||||||
LOG_INFO("rtTask ISR Params OK");
|
LOG_INFO("rtTask ISR Params OK");
|
||||||
|
|
||||||
pinMode(POT_A_CS, OUTPUT);
|
|
||||||
|
|
||||||
// Attach Pin Interrupts
|
// Attach Pin Interrupts
|
||||||
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12p), rt_int.isr_ptr, (void *)&isr_params_t12p, RISING);
|
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12p), rt_int.isr_ptr, (void *)&isr_params_t12p, RISING);
|
||||||
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12n), rt_int.isr_ptr, (void *)&isr_params_t12n, RISING);
|
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12n), rt_int.isr_ptr, (void *)&isr_params_t12n, RISING);
|
||||||
@@ -71,8 +69,9 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
|
|
||||||
LOG_WARN("rtTask Init Correct");
|
LOG_WARN("rtTask Init Correct");
|
||||||
// Global rt_task_ptr variables
|
// Global rt_task_ptr variables
|
||||||
uint32_t it = 0;
|
bool first_cycle = true;
|
||||||
uint32_t q_fail_count = 0;
|
bool cycle12 = false;
|
||||||
|
bool cycle34 = false;
|
||||||
|
|
||||||
while (params->rt_running)
|
while (params->rt_running)
|
||||||
{
|
{
|
||||||
@@ -85,6 +84,11 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
ULONG_MAX, // pulisci i primi 8 bit
|
ULONG_MAX, // pulisci i primi 8 bit
|
||||||
&pickup_flag, // valore ricevuto
|
&pickup_flag, // valore ricevuto
|
||||||
portMAX_DELAY);
|
portMAX_DELAY);
|
||||||
|
|
||||||
|
if (first_cycle && pickup_flag != TRIG_FLAG_12P) // skip first cycle because of possible initial noise on pickup signals at startu
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.print("\033[2J"); // clear screen
|
Serial.print("\033[2J"); // clear screen
|
||||||
@@ -103,12 +107,26 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// WAIT FOR SPARK TO HAPPEN
|
// WAIT FOR SPARK TO HAPPEN OR TIMEOUT
|
||||||
auto spark_timeout = ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(spark_timeout_max));
|
// auto spark_timeout = ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(spark_timeout_max));
|
||||||
if (ign_box_sts.coils12.spark_ok || ign_box_sts.coils34.spark_ok) // otherwise timeout if none is set in the ISR
|
// if (ign_box_sts.coils12.spark_ok || ign_box_sts.coils34.spark_ok) // otherwise timeout if none is set in the ISR
|
||||||
spark_flag = ign_box_sts.coils12.spark_ok ? SPARK_FLAG_12 : SPARK_FLAG_34;
|
// spark_flag = ign_box_sts.coils12.spark_ok ? SPARK_FLAG_12 : SPARK_FLAG_34;
|
||||||
else
|
// else
|
||||||
|
// spark_flag = SPARK_FLAG_NIL;
|
||||||
|
|
||||||
|
spark_flag = SPARK_FLAG_NIL; // default value in case of timeout, to be set by ISR if spark event occours
|
||||||
|
// WAIT FOR SPARK TO HAPPEN OR TIMEOUT
|
||||||
|
auto sp = xTaskNotifyWait(
|
||||||
|
0x00, // non pulire all'ingresso
|
||||||
|
ULONG_MAX, // pulisci i primi 8 bit
|
||||||
|
&spark_flag, // valore ricevuto
|
||||||
|
pdMS_TO_TICKS(spark_timeout_max)); // wait for spark event or timeout
|
||||||
|
|
||||||
|
// timeout occurred, set spark flag to nil
|
||||||
|
if (sp == pdFALSE)
|
||||||
|
{
|
||||||
spark_flag = SPARK_FLAG_NIL;
|
spark_flag = SPARK_FLAG_NIL;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// LOG_INFO("Spark Flags: ", printBits(spark_flag).c_str());
|
// LOG_INFO("Spark Flags: ", printBits(spark_flag).c_str());
|
||||||
@@ -121,11 +139,9 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
ulTaskNotifyValueClear(NULL, 0xFFFFFFFF);
|
ulTaskNotifyValueClear(NULL, 0xFFFFFFFF);
|
||||||
|
|
||||||
// A trigger from pickup 12 is followed by a spark event on 34 or vice versa pickup 34 triggers spark on 12
|
// A trigger from pickup 12 is followed by a spark event on 34 or vice versa pickup 34 triggers spark on 12
|
||||||
if ((pickup_flag == TRIG_FLAG_12P || pickup_flag == TRIG_FLAG_12N) && spark_flag != SPARK_FLAG_12)
|
if ((pickup_flag == TRIG_FLAG_12P || pickup_flag == TRIG_FLAG_12N) && (spark_flag != SPARK_FLAG_12 && spark_flag != SPARK_FLAG_NIL))
|
||||||
{
|
{
|
||||||
ign_box_sts.coils12.spark_status = ign_box_sts.coils34.spark_status = sparkStatus::SPARK_SYNC_FAIL;
|
ign_box_sts.coils12.spark_status = ign_box_sts.coils34.spark_status = sparkStatus::SPARK_SYNC_FAIL;
|
||||||
// Save error on circular buffer and skip to next cycle //
|
|
||||||
LOG_ERROR("Spark Mismatch");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,6 +149,7 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
switch (pickup_flag)
|
switch (pickup_flag)
|
||||||
{
|
{
|
||||||
case TRIG_FLAG_12P:
|
case TRIG_FLAG_12P:
|
||||||
|
first_cycle = false;
|
||||||
case TRIG_FLAG_12N:
|
case TRIG_FLAG_12N:
|
||||||
coils = &ign_box_sts.coils12;
|
coils = &ign_box_sts.coils12;
|
||||||
break;
|
break;
|
||||||
@@ -142,22 +159,20 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool new_data = false;
|
|
||||||
switch (pickup_flag)
|
switch (pickup_flag)
|
||||||
{
|
{
|
||||||
case TRIG_FLAG_12P:
|
case TRIG_FLAG_12P:
|
||||||
case TRIG_FLAG_34P:
|
case TRIG_FLAG_34P:
|
||||||
{
|
{
|
||||||
LOG_INFO("POSITIVE Edge");
|
|
||||||
// Timeout not occourred, expected POSITIVE edge spark OCCOURRED
|
// Timeout not occourred, expected POSITIVE edge spark OCCOURRED
|
||||||
if (spark_flag != SPARK_FLAG_NIL)
|
if (spark_flag != SPARK_FLAG_NIL)
|
||||||
{
|
{
|
||||||
coils->spark_delay = coils->trig_time - coils->spark_time;
|
coils->spark_delay = coils->spark_time - coils->trig_time;
|
||||||
coils->sstart_status = softStartStatus::NORMAL; // because spark on positive edge
|
coils->sstart_status = softStartStatus::NORMAL; // because spark on positive edge
|
||||||
coils->spark_status = sparkStatus::SPARK_POS_OK; // do not wait for spark on negative edge
|
coils->spark_status = sparkStatus::SPARK_POS_OK; // do not wait for spark on negative edge
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
LOG_INFO("Spark on POSITIVE pulse");
|
LOG_INFO("Spark on POSITIVE pulse");
|
||||||
LOG_INFO("Spark Delay Timer: ", (int32_t)coils->spark_delay);
|
LOG_INFO("Spark Delay Time: ", (int32_t)coils->spark_delay);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
// Timeout occourred, expected POSITIVE edge spark NOT OCCOURRED
|
// Timeout occourred, expected POSITIVE edge spark NOT OCCOURRED
|
||||||
@@ -166,30 +181,28 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
coils->spark_status = sparkStatus::SPARK_NEG_WAIT;
|
coils->spark_status = sparkStatus::SPARK_NEG_WAIT;
|
||||||
coils->sstart_status = softStartStatus::NORMAL;
|
coils->sstart_status = softStartStatus::NORMAL;
|
||||||
}
|
}
|
||||||
new_data = false;
|
continue; // Do nothing more on positive pulse
|
||||||
break; // Do nothing more on positive pulse
|
|
||||||
}
|
}
|
||||||
// CASES for NEGATIVE cycle triggering of pickup and sparks 12 & 34
|
// CASES for NEGATIVE cycle triggering of pickup and sparks 12 & 34
|
||||||
case TRIG_FLAG_12N:
|
case TRIG_FLAG_12N:
|
||||||
case TRIG_FLAG_34N:
|
case TRIG_FLAG_34N:
|
||||||
{
|
{
|
||||||
LOG_INFO("NEGATIVE Edge");
|
|
||||||
const bool expected_negative = coils->spark_status == sparkStatus::SPARK_NEG_WAIT;
|
const bool expected_negative = coils->spark_status == sparkStatus::SPARK_NEG_WAIT;
|
||||||
// Timeout not occourred, expected NEGATIVE edge spark OCCOURRED
|
// Timeout not occourred, expected NEGATIVE edge spark OCCOURRED
|
||||||
if (spark_flag != SPARK_FLAG_NIL && expected_negative)
|
if (spark_flag != SPARK_FLAG_NIL && expected_negative)
|
||||||
{
|
{
|
||||||
coils->spark_delay = coils->trig_time - coils->spark_time;
|
coils->spark_delay = coils->spark_time - coils->trig_time;
|
||||||
coils->sstart_status = softStartStatus::SOFT_START;
|
coils->sstart_status = softStartStatus::SOFT_START;
|
||||||
coils->spark_status == sparkStatus::SPARK_NEG_OK;
|
coils->spark_status = sparkStatus::SPARK_NEG_OK;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
LOG_INFO("Spark on NEGATIVE pulse");
|
LOG_INFO("Spark on NEGATIVE pulse");
|
||||||
LOG_INFO("Spark Delay Timer: ", (int32_t)coils->spark_delay);
|
LOG_INFO("Spark Delay Time: ", (int32_t)coils->spark_delay);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
// Timeout occourred, expected POSITIVE edge spark NOT OCCOURRED
|
// Timeout occourred, expected POSITIVE edge spark NOT OCCOURRED
|
||||||
else if (spark_flag == SPARK_FLAG_NIL && expected_negative)
|
else if (spark_flag == SPARK_FLAG_NIL && expected_negative)
|
||||||
{
|
{
|
||||||
coils->sstart_status = softStartStatus::NORMAL;
|
coils->sstart_status = softStartStatus::ERROR;
|
||||||
coils->spark_status = sparkStatus::SPARK_NEG_FAIL;
|
coils->spark_status = sparkStatus::SPARK_NEG_FAIL;
|
||||||
}
|
}
|
||||||
// Timeout not occouured, unexpected negative edge spark
|
// Timeout not occouured, unexpected negative edge spark
|
||||||
@@ -199,7 +212,11 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
coils->spark_status = sparkStatus::SPARK_NEG_UNEXPECTED;
|
coils->spark_status = sparkStatus::SPARK_NEG_UNEXPECTED;
|
||||||
}
|
}
|
||||||
// Wait for finish of negative pulse to save data to buffer
|
// Wait for finish of negative pulse to save data to buffer
|
||||||
new_data = true;
|
coils->n_events++;
|
||||||
|
if (pickup_flag == TRIG_FLAG_12N)
|
||||||
|
cycle12 = true;
|
||||||
|
else
|
||||||
|
cycle34 = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -211,8 +228,10 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_data)
|
if (cycle12 && cycle34) // wait for both 12 and 34 cycles to complete before sending data to main loop and resetting peak detectors
|
||||||
{
|
{
|
||||||
|
cycle12 = false;
|
||||||
|
cycle34 = false;
|
||||||
// vTaskDelay(pdMS_TO_TICKS(1)); // delay 1ms to allow peak detectors to charge for negative cycle
|
// vTaskDelay(pdMS_TO_TICKS(1)); // delay 1ms to allow peak detectors to charge for negative cycle
|
||||||
// read adc channels: pickup12, out12 [ pos + neg ]
|
// read adc channels: pickup12, out12 [ pos + neg ]
|
||||||
if (adc) // read only if adc initialized
|
if (adc) // read only if adc initialized
|
||||||
@@ -245,10 +264,10 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
// send essage to main loop with ignition info, by copy so local static variable is ok
|
// send essage to main loop with ignition info, by copy so local static variable is ok
|
||||||
if (rt_queue)
|
if (rt_queue)
|
||||||
ign_box_sts.timestamp = esp_timer_get_time(); // update data timestamp
|
ign_box_sts.timestamp = esp_timer_get_time(); // update data timestamp
|
||||||
if (xQueueSendToBack(rt_queue, (void *)&ign_box_sts, pdMS_TO_TICKS(1)) != pdPASS)
|
if (xQueueSendToBack(rt_queue, (void *)&ign_box_sts, 0) != pdPASS)
|
||||||
{
|
{
|
||||||
q_fail_count++;
|
ign_box_sts.n_queue_errors++;
|
||||||
// LOG_ERROR("Failed to send to rt_queue");
|
LOG_ERROR("Failed to send to rt_queue");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#define DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG
|
#define DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG
|
||||||
|
|
||||||
// Serial debug flag
|
// Serial debug flag
|
||||||
#define DEBUG
|
//#define DEBUG
|
||||||
|
|
||||||
// Arduino Libraries
|
// Arduino Libraries
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
#include "devices.h"
|
#include "devices.h"
|
||||||
|
|
||||||
// Global Variables and Flags
|
// Global Variables and Flags
|
||||||
const uint8_t spark_timeout_max = 2; // in milliseconds
|
const uint8_t spark_timeout_max = 1; // in milliseconds
|
||||||
|
|
||||||
// Debug Variables
|
// Debug Variables
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|||||||
@@ -45,4 +45,15 @@ void printField(const char name[], const float val, const uint8_t x, const uint8
|
|||||||
setCursor(x+16, y);
|
setCursor(x+16, y);
|
||||||
Serial.print(val);
|
Serial.print(val);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
void printField(const char name[], const char *val, const uint8_t x, const uint8_t y) {
|
||||||
|
if (firstRun) {
|
||||||
|
setCursor(x,y);
|
||||||
|
Serial.printf("%15s: %s\n", name, val);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setCursor(x+16, y);
|
||||||
|
Serial.print(val);
|
||||||
|
Serial.flush();
|
||||||
}
|
}
|
||||||
4
RotaxMonitorTester/.vscode/extensions.json
vendored
4
RotaxMonitorTester/.vscode/extensions.json
vendored
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
|
||||||
// for the documentation about the extensions.json format
|
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
|
"Jason2866.esp-decoder",
|
||||||
|
"pioarduino.pioarduino-ide",
|
||||||
"platformio.platformio-ide"
|
"platformio.platformio-ide"
|
||||||
],
|
],
|
||||||
"unwantedRecommendations": [
|
"unwantedRecommendations": [
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
[env:esp32-devtest-release]
|
[env:esp32-devtest-release]
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.37/platform-espressif32.zip
|
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps =
|
lib_deps =
|
||||||
hideakitai/DebugLog@^0.8.4
|
hideakitai/DebugLog@^0.8.4
|
||||||
@@ -21,8 +21,8 @@ build_type = release
|
|||||||
|
|
||||||
[env:esp32-devtest-debug]
|
[env:esp32-devtest-debug]
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.37/platform-espressif32.zip
|
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
|
||||||
framework = arduino
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
hideakitai/DebugLog@^0.8.4
|
hideakitai/DebugLog@^0.8.4
|
||||||
board_build.flash_size = 4MB
|
board_build.flash_size = 4MB
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ static uint32_t count = 0;
|
|||||||
#define SPARK_DLY_MIN 10
|
#define SPARK_DLY_MIN 10
|
||||||
#define SPARK_DLY_MAX 490
|
#define SPARK_DLY_MAX 490
|
||||||
|
|
||||||
#define PAUSE_LONG_MIN 10000
|
#define PAUSE_LONG_MIN 5000
|
||||||
#define PAUSE_LONG_MAX PAUSE_LONG_MIN*100
|
#define PAUSE_LONG_MAX PAUSE_LONG_MIN*100
|
||||||
|
|
||||||
void clearScreen(){
|
void clearScreen(){
|
||||||
@@ -46,15 +46,16 @@ static timerStatus stsA = {
|
|||||||
.clock_period_us = (uint32_t)PERIOD_US,
|
.clock_period_us = (uint32_t)PERIOD_US,
|
||||||
.pause_long_us = 10000,
|
.pause_long_us = 10000,
|
||||||
.pause_short_us = 1000,
|
.pause_short_us = 1000,
|
||||||
.coil_pulse_us = 500,
|
.coil_pulse_us = 1000,
|
||||||
.spark_pulse_us = 50,
|
.spark_pulse_us = 100,
|
||||||
.spark_delay_us = 10,
|
.spark_delay_us = 50,
|
||||||
.main_task = NULL};
|
.main_task = NULL};
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
delay(1000);
|
||||||
LOG_ATTACH_SERIAL(Serial);
|
LOG_ATTACH_SERIAL(Serial);
|
||||||
|
|
||||||
pinMode(PIN_TRIG_A12P, OUTPUT);
|
pinMode(PIN_TRIG_A12P, OUTPUT);
|
||||||
@@ -98,6 +99,9 @@ void loop()
|
|||||||
stsA.pause_long_us = (uint32_t)filtered;
|
stsA.pause_long_us = (uint32_t)filtered;
|
||||||
LOG_INFO("Spark Delay uS: ", stsA.spark_delay_us, "\tSoft Start: ", stsA.soft_start ? "TRUE" : "FALSE");
|
LOG_INFO("Spark Delay uS: ", stsA.spark_delay_us, "\tSoft Start: ", stsA.soft_start ? "TRUE" : "FALSE");
|
||||||
LOG_INFO("Pause: ", (uint32_t)(stsA.pause_long_us / 1000), "ms");
|
LOG_INFO("Pause: ", (uint32_t)(stsA.pause_long_us / 1000), "ms");
|
||||||
|
LOG_INFO("Coil Pulse: ", stsA.coil_pulse_us, "us");
|
||||||
|
LOG_INFO("Spark Pulse: ", stsA.spark_pulse_us, "us");
|
||||||
|
|
||||||
|
|
||||||
delay(100);
|
delay(100);
|
||||||
clearScreen();
|
clearScreen();
|
||||||
|
|||||||
@@ -19,5 +19,5 @@
|
|||||||
#define SPARK_B34 5
|
#define SPARK_B34 5
|
||||||
|
|
||||||
// Pot
|
// Pot
|
||||||
#define SPARK_DELAY_POT 12
|
#define SPARK_DELAY_POT 13
|
||||||
#define FREQ_POT 14
|
#define FREQ_POT 14
|
||||||
|
|||||||
Reference in New Issue
Block a user