Task A+B concurrency <check ok without ADC
This commit is contained in:
3
RotaxMonitorTester/.vscode/extensions.json
vendored
3
RotaxMonitorTester/.vscode/extensions.json
vendored
@@ -1,8 +1,7 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"Jason2866.esp-decoder",
|
||||
"pioarduino.pioarduino-ide",
|
||||
"platformio.platformio-ide"
|
||||
"pioarduino.pioarduino-ide"
|
||||
],
|
||||
"unwantedRecommendations": [
|
||||
"ms-vscode.cpptools-extension-pack"
|
||||
|
||||
@@ -18,15 +18,16 @@ static uint32_t count = 0;
|
||||
#define SPARK_DLY_MAX 490
|
||||
|
||||
#define PAUSE_LONG_MIN 5000
|
||||
#define PAUSE_LONG_MAX PAUSE_LONG_MIN*100
|
||||
#define PAUSE_LONG_MAX PAUSE_LONG_MIN * 100
|
||||
|
||||
#define RPM_MIN 800
|
||||
#define RPM_MIN 250
|
||||
#define RPM_MAX 5500
|
||||
|
||||
void clearScreen(){
|
||||
Serial.print("\033[2J"); // clear screen
|
||||
Serial.print("\033[H"); // cursor home
|
||||
Serial.flush();
|
||||
void clearScreen()
|
||||
{
|
||||
Serial.print("\033[2J"); // clear screen
|
||||
Serial.print("\033[H"); // cursor home
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
static double filtered_rpm = 0;
|
||||
@@ -48,45 +49,44 @@ static const std::map<const uint32_t, const char *> pin2Name = {
|
||||
{State::S_WAIT_10MS, "S_WAIT_10MS"}};
|
||||
|
||||
static timerStatus stsA = {
|
||||
.clock_period_us = (uint32_t)PERIOD_US,
|
||||
.pause_long_us = 10000,
|
||||
.pause_short_us = 1000,
|
||||
.coil_pulse_us = 1000,
|
||||
.spark_pulse_us = 100,
|
||||
.spark_delay_us = 50,
|
||||
.pins = {
|
||||
.clock_period_us = (uint32_t)PERIOD_US,
|
||||
.pause_long_us = 10000,
|
||||
.pause_short_us = 1000,
|
||||
.coil_pulse_us = 1000,
|
||||
.spark_pulse_us = 100,
|
||||
.spark_delay_us = 50,
|
||||
.pins = {
|
||||
.pin_trig_12p = PIN_TRIG_A12P,
|
||||
.pin_trig_12n = PIN_TRIG_A12N,
|
||||
.pin_trig_34p = PIN_TRIG_A34P,
|
||||
.pin_trig_34n = PIN_TRIG_A34N,
|
||||
.pin_spark_12 = SPARK_A12,
|
||||
.pin_spark_34 = SPARK_A34
|
||||
},
|
||||
.main_task = NULL};
|
||||
.pin_spark_34 = SPARK_A34},
|
||||
.main_task = NULL};
|
||||
|
||||
static timerStatus stsB = {
|
||||
.clock_period_us = (uint32_t)PERIOD_US,
|
||||
.pause_long_us = 10000,
|
||||
.pause_short_us = 1000,
|
||||
.coil_pulse_us = 1000,
|
||||
.spark_pulse_us = 100,
|
||||
.spark_delay_us = 50,
|
||||
.pins = {
|
||||
.clock_period_us = (uint32_t)PERIOD_US,
|
||||
.pause_long_us = 10000,
|
||||
.pause_short_us = 1000,
|
||||
.coil_pulse_us = 1000,
|
||||
.spark_pulse_us = 100,
|
||||
.spark_delay_us = 50,
|
||||
.pins = {
|
||||
.pin_trig_12p = PIN_TRIG_B12P,
|
||||
.pin_trig_12n = PIN_TRIG_B12N,
|
||||
.pin_trig_34p = PIN_TRIG_B34P,
|
||||
.pin_trig_34n = PIN_TRIG_B34N,
|
||||
.pin_spark_12 = SPARK_B12,
|
||||
.pin_spark_34 = SPARK_B34
|
||||
},
|
||||
.main_task = NULL};
|
||||
.pin_spark_34 = SPARK_B34},
|
||||
.main_task = NULL};
|
||||
|
||||
static bool isEnabled = false;
|
||||
static bool isEnabled_A = false;
|
||||
static bool isEnabled_B = false;
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
Serial.begin(921600);
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
LOG_ATTACH_SERIAL(Serial);
|
||||
|
||||
@@ -107,7 +107,8 @@ void setup()
|
||||
pinMode(SPARK_DELAY_POT, ANALOG);
|
||||
pinMode(FREQ_POT, ANALOG);
|
||||
|
||||
pinMode(ENABLE_PIN, INPUT_PULLUP);
|
||||
pinMode(ENABLE_PIN_A, INPUT_PULLUP);
|
||||
pinMode(ENABLE_PIN_B, INPUT_PULLUP);
|
||||
|
||||
// get the task handle for the main loop
|
||||
stsA.main_task = xTaskGetCurrentTaskHandleForCore(1);
|
||||
@@ -135,40 +136,58 @@ void loop()
|
||||
LOG_INFO("Loop: ", count++);
|
||||
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 > (SPARK_DLY_MIN + SPARK_DLY_MAX) / 2) {
|
||||
if (stsA.spark_delay_us > (SPARK_DLY_MIN + SPARK_DLY_MAX) / 2)
|
||||
{
|
||||
stsA.soft_start = true;
|
||||
stsA.spark_delay_us -= (SPARK_DLY_MIN + SPARK_DLY_MAX) / 2;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
stsA.soft_start = false;
|
||||
}
|
||||
stsB.soft_start = stsA.soft_start;
|
||||
stsB.spark_delay_us = stsA.spark_delay_us;
|
||||
stsB.soft_start = stsA.soft_start;
|
||||
stsB.spark_delay_us = stsA.spark_delay_us;
|
||||
|
||||
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);
|
||||
stsB.pause_long_us = stsA.pause_long_us;
|
||||
|
||||
if (isEnabled) {
|
||||
LOG_INFO("==== System is ENABLED ====");
|
||||
} else {
|
||||
LOG_INFO("==== System is DISABLED ====");
|
||||
}
|
||||
if (isEnabled_A)
|
||||
LOG_INFO("==== System A is ENABLED ====");
|
||||
else
|
||||
LOG_INFO("==== System A is DISABLED ====");
|
||||
|
||||
if (isEnabled_B)
|
||||
LOG_INFO("==== System B is ENABLED ====");
|
||||
else
|
||||
LOG_INFO("==== System B 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) {
|
||||
|
||||
if (digitalRead(ENABLE_PIN_A) == LOW && !isEnabled_A)
|
||||
{
|
||||
timerStart(timerA);
|
||||
delayMicroseconds(50);
|
||||
isEnabled_A = true;
|
||||
}
|
||||
else if (digitalRead(ENABLE_PIN_A) == HIGH && isEnabled_A)
|
||||
{
|
||||
timerStop(timerA);
|
||||
isEnabled_A = false;
|
||||
}
|
||||
|
||||
if (digitalRead(ENABLE_PIN_B) == LOW && !isEnabled_B)
|
||||
{
|
||||
timerStart(timerB);
|
||||
isEnabled = true;
|
||||
} else if (digitalRead(ENABLE_PIN) == HIGH && isEnabled) {
|
||||
timerStop(timerA);
|
||||
timerStop(timerA);
|
||||
isEnabled = false;
|
||||
isEnabled_B = true;
|
||||
}
|
||||
else if (digitalRead(ENABLE_PIN_B) == HIGH && isEnabled_B)
|
||||
{
|
||||
timerStop(timerB);
|
||||
isEnabled_B = false;
|
||||
}
|
||||
|
||||
delay(100);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
// Enable Pin
|
||||
#define ENABLE_PIN 16
|
||||
#define ENABLE_PIN_A 16
|
||||
#define ENABLE_PIN_B 15
|
||||
|
||||
///// Ignition Box A /////
|
||||
#define PIN_TRIG_A12P 18
|
||||
|
||||
Reference in New Issue
Block a user