Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d0db29bba | ||
| 5c9ef7e93b | |||
| a2d0afa0c9 | |||
| 1109681eb5 |
@@ -25,8 +25,8 @@ upload_port = /dev/ttyACM2
|
|||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
|
|
||||||
;Monitor configuration
|
;Monitor configuration
|
||||||
monitor_speed = 115200
|
|
||||||
monitor_port = /dev/ttyACM2
|
monitor_port = /dev/ttyACM2
|
||||||
|
monitor_speed = 921600
|
||||||
|
|
||||||
; Build configuration
|
; Build configuration
|
||||||
build_type = release
|
build_type = release
|
||||||
@@ -49,8 +49,8 @@ upload_port = /dev/ttyACM2
|
|||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
|
|
||||||
;Monitor configuration
|
;Monitor configuration
|
||||||
monitor_speed = 115200
|
|
||||||
monitor_port = /dev/ttyACM2
|
monitor_port = /dev/ttyACM2
|
||||||
|
monitor_speed = 921600
|
||||||
|
|
||||||
; Debug configuration
|
; Debug configuration
|
||||||
debug_tool = esp-builtin
|
debug_tool = esp-builtin
|
||||||
|
|||||||
@@ -120,14 +120,14 @@ void ADS1256::setDRATE(uint8_t drate) //Setting DRATE (sampling frequency)
|
|||||||
{
|
{
|
||||||
writeRegister(DRATE_REG, drate);
|
writeRegister(DRATE_REG, drate);
|
||||||
_DRATE = drate;
|
_DRATE = drate;
|
||||||
delay(200);
|
delayMicroseconds(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ADS1256::setMUX(uint8_t mux) //Setting MUX (input channel)
|
void ADS1256::setMUX(uint8_t mux) //Setting MUX (input channel)
|
||||||
{
|
{
|
||||||
writeRegister(MUX_REG, mux);
|
writeRegister(MUX_REG, mux);
|
||||||
_MUX = mux;
|
_MUX = mux;
|
||||||
delay(200);
|
//delayMicroseconds(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ADS1256::setPGA(uint8_t pga) //Setting PGA (input voltage range)
|
void ADS1256::setPGA(uint8_t pga) //Setting PGA (input voltage range)
|
||||||
@@ -138,7 +138,7 @@ void ADS1256::setPGA(uint8_t pga) //Setting PGA (input voltage range)
|
|||||||
_ADCON = (_ADCON & 0b11111000) | (_PGA & 0b00000111); // Clearing and then setting bits 2-0 based on pga
|
_ADCON = (_ADCON & 0b11111000) | (_PGA & 0b00000111); // Clearing and then setting bits 2-0 based on pga
|
||||||
|
|
||||||
writeRegister(ADCON_REG, _ADCON);
|
writeRegister(ADCON_REG, _ADCON);
|
||||||
delay(200);
|
delayMicroseconds(1000); //Delay to allow the PGA to settle after changing its value
|
||||||
|
|
||||||
updateConversionParameter(); //Update the multiplier according top the new PGA value
|
updateConversionParameter(); //Update the multiplier according top the new PGA value
|
||||||
}
|
}
|
||||||
@@ -501,8 +501,6 @@ void ADS1256::writeRegister(uint8_t registerAddress, uint8_t registerValueToWrit
|
|||||||
|
|
||||||
CS_HIGH();
|
CS_HIGH();
|
||||||
_spi->endTransaction();
|
_spi->endTransaction();
|
||||||
delay(100);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long ADS1256::readRegister(uint8_t registerAddress) //Reading a register
|
long ADS1256::readRegister(uint8_t registerAddress) //Reading a register
|
||||||
@@ -524,7 +522,7 @@ long ADS1256::readRegister(uint8_t registerAddress) //Reading a register
|
|||||||
|
|
||||||
CS_HIGH();
|
CS_HIGH();
|
||||||
_spi->endTransaction();
|
_spi->endTransaction();
|
||||||
delay(100);
|
|
||||||
return regValue;
|
return regValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// Library defines
|
||||||
|
#define ADS1256_SPI_ALREADY_STARTED
|
||||||
|
|
||||||
// Device Libraries
|
// Device Libraries
|
||||||
#include <ADS1256.h>
|
#include <ADS1256.h>
|
||||||
#include <AD5292.h>
|
#include <AD5292.h>
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ struct ignitionBoxStatus
|
|||||||
// voltage from generator
|
// voltage from generator
|
||||||
float volts_gen = 0.0;
|
float volts_gen = 0.0;
|
||||||
uint32_t n_queue_errors = 0;
|
uint32_t n_queue_errors = 0;
|
||||||
|
uint32_t adc_read_time = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct isrParams
|
struct isrParams
|
||||||
|
|||||||
@@ -19,7 +19,13 @@
|
|||||||
// #define CH_B_ENABLE
|
// #define CH_B_ENABLE
|
||||||
#define TEST
|
#define TEST
|
||||||
|
|
||||||
void printTaskStats() {
|
float freqToRPM(float freq)
|
||||||
|
{
|
||||||
|
return freq * 60.0f; // 1 pulse per revolution
|
||||||
|
}
|
||||||
|
|
||||||
|
void printTaskStats()
|
||||||
|
{
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
vTaskGetRunTimeStats(buffer);
|
vTaskGetRunTimeStats(buffer);
|
||||||
Serial.println(buffer);
|
Serial.println(buffer);
|
||||||
@@ -102,14 +108,15 @@ void loop()
|
|||||||
bool spiA_ok = true;
|
bool spiA_ok = true;
|
||||||
bool spiB_ok = true;
|
bool spiB_ok = true;
|
||||||
|
|
||||||
#ifndef TEST
|
|
||||||
// Init 2 SPI interfaces
|
// Init 2 SPI interfaces
|
||||||
SPIClass SPI_A(FSPI);
|
SPIClass SPI_A(FSPI);
|
||||||
spiA_ok = SPI_A.begin(SPI_A_SCK, SPI_A_MISO, SPI_A_MOSI);
|
spiA_ok = SPI_A.begin(SPI_A_SCK, SPI_A_MISO, SPI_A_MOSI);
|
||||||
|
SPI_A.setDataMode(SPI_MODE1); // ADS1256 requires SPI mode 1
|
||||||
|
#ifndef TEST
|
||||||
SPIClass SPI_B(HSPI);
|
SPIClass SPI_B(HSPI);
|
||||||
spiB_ok = SPI_B.begin(SPI_B_SCK, SPI_B_MISO, SPI_B_MOSI);
|
spiB_ok = SPI_B.begin(SPI_B_SCK, SPI_B_MISO, SPI_B_MOSI);
|
||||||
#endif
|
SPI_B.setDataMode(SPI_MODE1); // ADS1256 requires SPI mode 1
|
||||||
|
#endif
|
||||||
if (!spiA_ok || !spiB_ok)
|
if (!spiA_ok || !spiB_ok)
|
||||||
{
|
{
|
||||||
LOG_ERROR("Unable to Initialize SPI Busses");
|
LOG_ERROR("Unable to Initialize SPI Busses");
|
||||||
@@ -119,13 +126,13 @@ void loop()
|
|||||||
}
|
}
|
||||||
LOG_INFO("Init SPI OK");
|
LOG_INFO("Init SPI OK");
|
||||||
|
|
||||||
#ifndef TEST
|
|
||||||
// Init ADC_A
|
// Init ADC_A
|
||||||
dev.adc_a = new ADS1256(ADC_A_DRDY, ADC_A_RST, ADC_A_SYNC, ADC_A_CS, 2.5, &SPI_A);
|
dev.adc_a = new ADS1256(ADC_A_DRDY, ADS1256::PIN_UNUSED, ADC_A_SYNC, ADC_A_CS, 2.5, &SPI_A);
|
||||||
dev.adc_a->InitializeADC();
|
dev.adc_a->InitializeADC();
|
||||||
dev.adc_a->setPGA(PGA_1);
|
dev.adc_a->setPGA(PGA_1);
|
||||||
dev.adc_a->setDRATE(DRATE_1000SPS);
|
dev.adc_a->setDRATE(DRATE_7500SPS);
|
||||||
|
|
||||||
|
#ifndef TEST
|
||||||
// Init ADC_B
|
// Init ADC_B
|
||||||
dev.adc_a = new ADS1256(ADC_B_DRDY, ADC_B_RST, ADC_B_SYNC, ADC_B_CS, 2.5, &SPI_B);
|
dev.adc_a = new ADS1256(ADC_B_DRDY, ADC_B_RST, ADC_B_SYNC, ADC_B_CS, 2.5, &SPI_B);
|
||||||
dev.adc_a->InitializeADC();
|
dev.adc_a->InitializeADC();
|
||||||
@@ -182,45 +189,50 @@ void loop()
|
|||||||
{
|
{
|
||||||
if (xQueueReceive(rt_taskA_queue, &ignA, pdMS_TO_TICKS(1000)) == pdTRUE)
|
if (xQueueReceive(rt_taskA_queue, &ignA, pdMS_TO_TICKS(1000)) == pdTRUE)
|
||||||
{
|
{
|
||||||
if (ignA.coils12.spark_status == sparkStatus::SPARK_NEG_FAIL || ignA.coils12.spark_status == sparkStatus::SPARK_POS_FAIL)
|
float freq = (esp_timer_get_time() - last) / 1000000.0f; // in seconds
|
||||||
|
freq = freq > 0 ? 1.0f / freq : 0; // Calculate frequency (Hz)
|
||||||
|
last = esp_timer_get_time();
|
||||||
|
|
||||||
|
if (ignA.coils12.spark_status == sparkStatus::SPARK_POS_FAIL || ignA.coils12.spark_status == sparkStatus::SPARK_NEG_FAIL)
|
||||||
missed_firings12++;
|
missed_firings12++;
|
||||||
if (ignA.coils34.spark_status == sparkStatus::SPARK_POS_FAIL || ignA.coils34.spark_status == sparkStatus::SPARK_NEG_FAIL)
|
if (ignA.coils34.spark_status == sparkStatus::SPARK_POS_FAIL || ignA.coils34.spark_status == sparkStatus::SPARK_NEG_FAIL)
|
||||||
missed_firings34++;
|
missed_firings34++;
|
||||||
|
|
||||||
clearScreen();
|
clearScreen();
|
||||||
setCursor(0, 0);
|
setCursor(0, 0);
|
||||||
printField("++ Timestamp", (uint32_t)ignA.timestamp, 0, 0);
|
printField("++ Timestamp", (uint32_t)ignA.timestamp);
|
||||||
Serial.println("========== Coils 12 =============");
|
Serial.println("========== Coils 12 =============");
|
||||||
printField("Events", (uint32_t)ignA.coils12.n_events, 0, 1);
|
printField("Events", (uint32_t)ignA.coils12.n_events);
|
||||||
printField("Missed Firing", missed_firings12, 0, 2);
|
printField("Missed Firing", missed_firings12);
|
||||||
printField("Spark Dly", (uint32_t)ignA.coils12.spark_delay, 0, 3);
|
printField("Spark Dly", (uint32_t)ignA.coils12.spark_delay);
|
||||||
printField("Spark Sts", sparkStatusNames.at(ignA.coils12.spark_status), 0, 4);
|
printField("Spark Sts", sparkStatusNames.at(ignA.coils12.spark_status));
|
||||||
// printField("Peak P_IN", ignA.coils12.peak_p_in, 0, 5);
|
printField("Peak P_IN", ignA.coils12.peak_p_in);
|
||||||
// printField("Peak P_OUT", ignA.coils12.peak_p_out, 0, 6);
|
printField("Peak N_IN", ignA.coils12.peak_n_in);
|
||||||
// printField("Peak N_IN", ignA.coils12.peak_n_in, 0, 7);
|
printField("Peak P_OUT", ignA.coils12.peak_p_out);
|
||||||
// printField("Peak N_OUT", ignA.coils12.peak_n_out, 0, 8);
|
printField("Peak N_OUT", ignA.coils12.peak_n_out);
|
||||||
printField("Soft Start ", softStartStatusNames.at(ignA.coils12.sstart_status), 0, 9);
|
printField("Soft Start ", softStartStatusNames.at(ignA.coils12.sstart_status));
|
||||||
|
|
||||||
Serial.println("========== Coils 34 =============");
|
Serial.println("========== Coils 34 =============");
|
||||||
printField("Events", (uint32_t)ignA.coils34.n_events, 0, 11);
|
printField("Events", (uint32_t)ignA.coils34.n_events);
|
||||||
printField("Missed Firing", missed_firings34, 0, 12);
|
printField("Missed Firing", missed_firings34);
|
||||||
printField("Spark Dly", (uint32_t)ignA.coils34.spark_delay, 0, 13);
|
printField("Spark Dly", (uint32_t)ignA.coils34.spark_delay);
|
||||||
printField("Spark Sts", sparkStatusNames.at(ignA.coils34.spark_status), 0, 14);
|
printField("Spark Sts", sparkStatusNames.at(ignA.coils34.spark_status));
|
||||||
// printField("Peak P_IN", ignA.coils34.peak_p_in, 0, 15);
|
printField("Peak P_IN", ignA.coils34.peak_p_in);
|
||||||
// printField("Peak P_OUT", ignA.coils34.peak_p_out, 0, 16);
|
printField("Peak N_IN", ignA.coils34.peak_n_in);
|
||||||
// printField("Peak N_IN", ignA.coils34.peak_n_in, 0, 17);
|
printField("Peak P_OUT", ignA.coils34.peak_p_out);
|
||||||
// printField("Peak N_OUT", ignA.coils34.peak_n_out, 0, 18);
|
printField("Peak N_OUT", ignA.coils34.peak_n_out);
|
||||||
printField("Soft Start ", softStartStatusNames.at(ignA.coils34.sstart_status), 0, 19);
|
printField("Soft Start ", softStartStatusNames.at(ignA.coils34.sstart_status));
|
||||||
|
|
||||||
Serial.println("========== END =============");
|
Serial.println("========== END =============");
|
||||||
Serial.println();
|
Serial.println();
|
||||||
auto delta = (esp_timer_get_time() - last) / 1000000.0f; //in seconds
|
printField("Engine RPM", freqToRPM(freq));
|
||||||
delta = delta > 0 ? 1.0f / delta : 0; // Calculate frequency (Hz)
|
printField("ADC Read Time", (uint32_t)ignA.adc_read_time);
|
||||||
printField("Frequency (Hz)", delta, 0, 21);
|
printField("Queue Errors", (uint32_t)ignA.n_queue_errors);
|
||||||
printField("Queue Errors", (uint32_t)ignA.n_queue_errors, 0, 22);
|
}
|
||||||
last = esp_timer_get_time();
|
else
|
||||||
} else
|
|
||||||
{
|
{
|
||||||
Serial.println("Waiting for data... ");;
|
Serial.println("Waiting for data... ");
|
||||||
|
delay(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,19 +48,17 @@
|
|||||||
// =====================
|
// =====================
|
||||||
#define ADC_A_CS 4
|
#define ADC_A_CS 4
|
||||||
#define ADC_A_DRDY 5
|
#define ADC_A_DRDY 5
|
||||||
#define ADC_A_RST 6
|
#define ADC_A_SYNC 6
|
||||||
#define ADC_A_SYNC 7
|
|
||||||
|
|
||||||
#define ADC_B_CS 14
|
#define ADC_B_CS 14
|
||||||
#define ADC_B_DRDY 15
|
#define ADC_B_DRDY 15
|
||||||
#define ADC_B_RST 16
|
#define ADC_B_SYNC 16
|
||||||
#define ADC_B_SYNC 17
|
|
||||||
|
|
||||||
// =====================
|
// =====================
|
||||||
// DIGITAL POT
|
// DIGITAL POT
|
||||||
// =====================
|
// =====================
|
||||||
//#define POT_A_CS 1
|
#define POT_A_CS 7
|
||||||
//#define POT_B_CS 2
|
#define POT_B_CS 17
|
||||||
|
|
||||||
// =====================
|
// =====================
|
||||||
// TRIGGER INPUT INTERRUPTS
|
// TRIGGER INPUT INTERRUPTS
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Select coil status reference based on pickup_flag
|
||||||
coilsStatus *coils;
|
coilsStatus *coils;
|
||||||
switch (pickup_flag)
|
switch (pickup_flag)
|
||||||
{
|
{
|
||||||
@@ -176,6 +177,7 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Select logic based on pickup and spark flags
|
||||||
switch (pickup_flag)
|
switch (pickup_flag)
|
||||||
{
|
{
|
||||||
case TRIG_FLAG_12P:
|
case TRIG_FLAG_12P:
|
||||||
@@ -249,10 +251,10 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
{
|
{
|
||||||
cycle12 = false;
|
cycle12 = false;
|
||||||
cycle34 = false;
|
cycle34 = false;
|
||||||
// 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
|
||||||
{
|
{
|
||||||
|
uint32_t start_adc_read = esp_timer_get_time();
|
||||||
// from peak detector circuits
|
// from peak detector circuits
|
||||||
ign_box_sts.coils12.peak_p_in = adcReadChannel(adc, ADC_CH_PEAK_12P_IN);
|
ign_box_sts.coils12.peak_p_in = adcReadChannel(adc, ADC_CH_PEAK_12P_IN);
|
||||||
ign_box_sts.coils12.peak_n_in = adcReadChannel(adc, ADC_CH_PEAK_12N_IN);
|
ign_box_sts.coils12.peak_n_in = adcReadChannel(adc, ADC_CH_PEAK_12N_IN);
|
||||||
@@ -262,6 +264,7 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
ign_box_sts.coils12.peak_n_out = adcReadChannel(adc, ADC_CH_PEAK_12N_OUT);
|
ign_box_sts.coils12.peak_n_out = adcReadChannel(adc, ADC_CH_PEAK_12N_OUT);
|
||||||
ign_box_sts.coils34.peak_p_out = adcReadChannel(adc, ADC_CH_PEAK_34P_OUT);
|
ign_box_sts.coils34.peak_p_out = adcReadChannel(adc, ADC_CH_PEAK_34P_OUT);
|
||||||
ign_box_sts.coils34.peak_n_out = adcReadChannel(adc, ADC_CH_PEAK_34N_OUT);
|
ign_box_sts.coils34.peak_n_out = adcReadChannel(adc, ADC_CH_PEAK_34N_OUT);
|
||||||
|
ign_box_sts.adc_read_time = (uint32_t)(esp_timer_get_time() - start_adc_read);
|
||||||
}
|
}
|
||||||
else // simulate adc read timig
|
else // simulate adc read timig
|
||||||
vTaskDelay(pdMS_TO_TICKS(1));
|
vTaskDelay(pdMS_TO_TICKS(1));
|
||||||
@@ -283,7 +286,9 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
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, 0) != pdPASS)
|
if (xQueueSendToBack(rt_queue, (void *)&ign_box_sts, 0) != pdPASS)
|
||||||
{
|
{
|
||||||
ign_box_sts.n_queue_errors++;
|
static uint32_t n_errors = 0;
|
||||||
|
n_errors++;
|
||||||
|
ign_box_sts.n_queue_errors = n_errors;
|
||||||
LOG_ERROR("Failed to send to rt_queue");
|
LOG_ERROR("Failed to send to rt_queue");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,58 +2,35 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
static bool firstRun = true;
|
void clearScreen()
|
||||||
|
{
|
||||||
void clearScreen(){
|
|
||||||
Serial.print("\033[2J"); // clear screen
|
Serial.print("\033[2J"); // clear screen
|
||||||
Serial.print("\033[H"); // cursor home
|
Serial.print("\033[H"); // cursor home
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCursor(const uint8_t x, const uint8_t y) {
|
void setCursor(const uint8_t x, const uint8_t y)
|
||||||
Serial.printf("\033[%d;%d", y, x+1);
|
{
|
||||||
|
Serial.printf("\033[%d;%d", y, x + 1);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void printField(const char name[], const uint32_t val, const uint8_t x, const uint8_t y) {
|
void printField(const char name[], const uint32_t val)
|
||||||
if (firstRun) {
|
{
|
||||||
setCursor(x,y);
|
|
||||||
Serial.printf("%15s: %06d\n", name, val);
|
Serial.printf("%15s: %06d\n", name, val);
|
||||||
return;
|
|
||||||
}
|
|
||||||
setCursor(x+16, y);
|
|
||||||
Serial.print(val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void printField(const char name[], const int64_t val, const uint8_t x, const uint8_t y) {
|
void printField(const char name[], const int64_t val)
|
||||||
if (firstRun) {
|
{
|
||||||
setCursor(x,y);
|
|
||||||
Serial.printf("%15s: %06u\n", name, (uint64_t)val);
|
Serial.printf("%15s: %06u\n", name, (uint64_t)val);
|
||||||
return;
|
|
||||||
}
|
|
||||||
setCursor(x+16, y);
|
|
||||||
Serial.print((uint64_t)val);
|
|
||||||
Serial.flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void printField(const char name[], const float val, const uint8_t x, const uint8_t y) {
|
void printField(const char name[], const float val)
|
||||||
if (firstRun) {
|
{
|
||||||
setCursor(x,y);
|
|
||||||
Serial.printf("%15s: %4.2f\n", name, val);
|
Serial.printf("%15s: %4.2f\n", name, val);
|
||||||
return;
|
|
||||||
}
|
|
||||||
setCursor(x+16, y);
|
|
||||||
Serial.print(val);
|
|
||||||
Serial.flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void printField(const char name[], const char *val, const uint8_t x, const uint8_t y) {
|
void printField(const char name[], const char *val)
|
||||||
if (firstRun) {
|
{
|
||||||
setCursor(x,y);
|
|
||||||
Serial.printf("%15s: %s\n", name, val);
|
Serial.printf("%15s: %s\n", name, val);
|
||||||
return;
|
|
||||||
}
|
|
||||||
setCursor(x+16, y);
|
|
||||||
Serial.print(val);
|
|
||||||
Serial.flush();
|
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@ lib_deps =
|
|||||||
hideakitai/DebugLog@^0.8.4
|
hideakitai/DebugLog@^0.8.4
|
||||||
board_build.flash_size = 4MB
|
board_build.flash_size = 4MB
|
||||||
board_build.partitions = default.csv
|
board_build.partitions = default.csv
|
||||||
monitor_speed = 115200
|
monitor_speed = 921600
|
||||||
build_type = release
|
build_type = release
|
||||||
|
|
||||||
[env:esp32-devtest-debug]
|
[env:esp32-devtest-debug]
|
||||||
@@ -27,7 +27,7 @@ lib_deps =
|
|||||||
hideakitai/DebugLog@^0.8.4
|
hideakitai/DebugLog@^0.8.4
|
||||||
board_build.flash_size = 4MB
|
board_build.flash_size = 4MB
|
||||||
board_build.partitions = default.csv
|
board_build.partitions = default.csv
|
||||||
monitor_speed = 115200
|
monitor_speed = 921600
|
||||||
build_type = debug
|
build_type = debug
|
||||||
build_flags =
|
build_flags =
|
||||||
-O0
|
-O0
|
||||||
|
|||||||
@@ -18,13 +18,16 @@ static uint32_t count = 0;
|
|||||||
#define PAUSE_LONG_MIN 5000
|
#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_MAX 5500
|
||||||
|
|
||||||
void clearScreen(){
|
void clearScreen(){
|
||||||
Serial.print("\033[2J"); // clear screen
|
Serial.print("\033[2J"); // clear screen
|
||||||
Serial.print("\033[H"); // cursor home
|
Serial.print("\033[H"); // cursor home
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
static double filtered = 0;
|
static double filtered_rpm = 0;
|
||||||
|
|
||||||
static const std::map<const uint32_t, const char *> pin2Name = {
|
static const std::map<const uint32_t, const char *> pin2Name = {
|
||||||
{PIN_TRIG_A12P, "HIGH_PIN_TRIG_A12P"},
|
{PIN_TRIG_A12P, "HIGH_PIN_TRIG_A12P"},
|
||||||
@@ -54,7 +57,7 @@ static timerStatus stsA = {
|
|||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(921600);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
LOG_ATTACH_SERIAL(Serial);
|
LOG_ATTACH_SERIAL(Serial);
|
||||||
|
|
||||||
@@ -94,11 +97,11 @@ void loop()
|
|||||||
stsA.soft_start = false;
|
stsA.soft_start = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
double new_val = (float)(map(analogRead(FREQ_POT), 0, 4096, PAUSE_LONG_MIN, PAUSE_LONG_MAX));
|
double new_rpm = (double)(map(analogRead(FREQ_POT), 0, 4096, RPM_MIN, RPM_MAX));
|
||||||
filtered = filtered + 0.1 * (new_val - filtered);
|
filtered_rpm = filtered_rpm + 0.1 * (new_rpm - filtered_rpm);
|
||||||
stsA.pause_long_us = (uint32_t)filtered;
|
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("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("Coil Pulse: ", stsA.coil_pulse_us, "us");
|
||||||
LOG_INFO("Spark Pulse: ", stsA.spark_pulse_us, "us");
|
LOG_INFO("Spark Pulse: ", stsA.spark_pulse_us, "us");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user