Fast ADC readings ok, to verify timing and settling time

This commit is contained in:
2026-04-05 17:05:10 +02:00
parent a2d0afa0c9
commit 5c9ef7e93b
8 changed files with 66 additions and 82 deletions

View File

@@ -16,7 +16,7 @@ lib_deps =
hideakitai/DebugLog@^0.8.4
board_build.flash_size = 4MB
board_build.partitions = default.csv
monitor_speed = 115200
monitor_speed = 921600
build_type = release
[env:esp32-devtest-debug]
@@ -27,7 +27,7 @@ lib_deps =
hideakitai/DebugLog@^0.8.4
board_build.flash_size = 4MB
board_build.partitions = default.csv
monitor_speed = 115200
monitor_speed = 921600
build_type = debug
build_flags =
-O0

View File

@@ -18,13 +18,16 @@ static uint32_t count = 0;
#define PAUSE_LONG_MIN 5000
#define PAUSE_LONG_MAX PAUSE_LONG_MIN*100
#define RPM_MIN 800
#define RPM_MAX 5500
void clearScreen(){
Serial.print("\033[2J"); // clear screen
Serial.print("\033[H"); // cursor home
Serial.flush();
}
static double filtered = 0;
static double filtered_rpm = 0;
static const std::map<const uint32_t, const char *> pin2Name = {
{PIN_TRIG_A12P, "HIGH_PIN_TRIG_A12P"},
@@ -54,7 +57,7 @@ static timerStatus stsA = {
void setup()
{
Serial.begin(115200);
Serial.begin(921600);
delay(1000);
LOG_ATTACH_SERIAL(Serial);
@@ -94,11 +97,11 @@ void loop()
stsA.soft_start = false;
}
double new_val = (float)(map(analogRead(FREQ_POT), 0, 4096, PAUSE_LONG_MIN, PAUSE_LONG_MAX));
filtered = filtered + 0.1 * (new_val - filtered);
stsA.pause_long_us = (uint32_t)filtered;
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);
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("Engine Rpm: ", (uint32_t)(filtered_rpm));
LOG_INFO("Coil Pulse: ", stsA.coil_pulse_us, "us");
LOG_INFO("Spark Pulse: ", stsA.spark_pulse_us, "us");