adc ok
This commit is contained in:
@@ -51,7 +51,7 @@ inline float adcReadChannel(ADS1256 *adc, const uint8_t ch)
|
||||
{
|
||||
adc->setMUX(ch);
|
||||
// scarta 3 conversioni
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
adc->readSingle();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include <led.h>
|
||||
|
||||
// Defines to enable channel B
|
||||
#define CH_B_ENABLE
|
||||
// #define CH_B_ENABLE
|
||||
|
||||
// Debug Defines
|
||||
#define WIFI_SSID "AstroRotaxMonitor"
|
||||
@@ -32,7 +32,7 @@ void setup()
|
||||
|
||||
// Setup Logger
|
||||
LOG_ATTACH_SERIAL(Serial);
|
||||
LOG_SET_LEVEL(DebugLogLevel::LVL_DEBUG);
|
||||
LOG_SET_LEVEL(DebugLogLevel::LVL_INFO);
|
||||
|
||||
// Print Processor Info
|
||||
LOG_DEBUG("ESP32 Chip:", ESP.getChipModel());
|
||||
@@ -108,37 +108,33 @@ void loop()
|
||||
{
|
||||
LOG_ERROR("Unable to Initialize SPI Busses");
|
||||
LOG_ERROR("5 seconds to restart...");
|
||||
//vTaskDelay(pdMS_TO_TICKS(5000));
|
||||
//esp_restart();
|
||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||
esp_restart();
|
||||
}
|
||||
//dev->m_spi_a = std::make_unique<SPIClass*>(&SPI_A);
|
||||
dev->m_spi_a.reset(&SPI_A);
|
||||
#ifdef CH_B_ENABLE
|
||||
//dev->m_spi_b = std::make_unique<SPIClass*>(&SPI_B);
|
||||
dev->m_spi_b.reset(&SPI_B);
|
||||
#endif
|
||||
// Init ADCs
|
||||
dev->m_adc_a = std::make_unique<ADS1256>(ADC_A_DRDY, ADS1256::PIN_UNUSED, ADS1256::PIN_UNUSED, ADC_A_CS, 2.5, &SPI_A);
|
||||
LOG_DEBUG("Init ADC A pointer ok");
|
||||
#ifdef CH_B_ENABLE
|
||||
dev->m_adc_b = std::make_unique<ADS1256>(ADC_B_DRDY, ADS1256::PIN_UNUSED, ADS1256::PIN_UNUSED, ADC_B_CS, 2.5, &SPI_B);
|
||||
LOG_DEBUG("Init ADC B pointer ok");
|
||||
#endif
|
||||
// Configure ADCs
|
||||
dev->m_adc_a->InitializeADC();
|
||||
dev->m_adc_a->setPGA(PGA_1);
|
||||
dev->m_adc_a->setDRATE(DRATE_7500SPS);
|
||||
LOG_DEBUG("Init ADC A params ok");
|
||||
#ifdef CH_B_ENABLE
|
||||
dev->m_adc_b->InitializeADC();
|
||||
dev->m_adc_b->setPGA(PGA_1);
|
||||
dev->m_adc_b->setDRATE(DRATE_7500SPS);
|
||||
LOG_DEBUG("Init ADC B params ok");
|
||||
#endif
|
||||
LOG_DEBUG("Init SPI OK");
|
||||
|
||||
//////// INIT I2C INTERFACES ////////
|
||||
LOG_DEBUG("Init I2C Interfaces");
|
||||
bool i2c_ok = true;
|
||||
i2c_ok = Wire.begin();
|
||||
i2c_ok = Wire.begin(SDA, SCL, 100000);
|
||||
if (!i2c_ok)
|
||||
{
|
||||
LOG_ERROR("Unable to Initialize I2C Bus");
|
||||
@@ -148,7 +144,7 @@ void loop()
|
||||
}
|
||||
|
||||
// Init IO Expanders
|
||||
dev->m_ext_io = std::make_unique<ExternalIO>(Wire, dev->m_i2c_mutex, EXPANDER_ALL_INTERRUPT);
|
||||
// dev->m_ext_io = std::make_unique<ExternalIO>(Wire, dev->m_i2c_mutex, EXPANDER_ALL_INTERRUPT);
|
||||
|
||||
//////// INIT REALTIME TASKS PARAMETERS ////////
|
||||
const rtIgnitionTask::rtTaskParams taskA_params{
|
||||
|
||||
@@ -53,12 +53,6 @@
|
||||
#define ADC_B_CS 21
|
||||
#define ADC_B_DRDY 47
|
||||
|
||||
// =====================
|
||||
// DIGITAL POT
|
||||
// =====================
|
||||
#define POT_A_CS 18
|
||||
#define POT_B_CS 35
|
||||
|
||||
// =====================
|
||||
// TRIGGER INPUT INTERRUPTS
|
||||
// =====================
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "tasks.h"
|
||||
#include <esp_timer.h>
|
||||
#include <datasave.h>
|
||||
#include <mutex>
|
||||
|
||||
//// GLOBAL STATIC FUNCTIONS
|
||||
|
||||
@@ -38,7 +39,8 @@ void rtIgnitionTask::rtIgnitionTask_realtime(void *pvParameters)
|
||||
const rtTaskIOParams rt_rst = params->rt_io; // copy to avoid external override
|
||||
QueueHandle_t rt_queue = params->rt_queue;
|
||||
Devices *dev = params->dev.get();
|
||||
ADS1256 *adc = dev->m_adc_a.get();
|
||||
ADS1256 *adc = params->name == "rtIgnTask_A" ? dev->m_adc_a.get() : dev->m_adc_b.get();
|
||||
std::mutex& spi_mutex = params->name == "rtIgnTask_A" ? dev->m_spi_a_mutex : dev->m_spi_b_mutex;
|
||||
ExternalIO* io = dev->m_ext_io.get();
|
||||
|
||||
TaskStatus_t rt_task_info;
|
||||
@@ -234,6 +236,7 @@ void rtIgnitionTask::rtIgnitionTask_realtime(void *pvParameters)
|
||||
// read adc channels: pickup12, out12 [ pos + neg ]
|
||||
if (adc) // read only if adc initialized
|
||||
{
|
||||
std::lock_guard<std::mutex> lock (spi_mutex);
|
||||
uint32_t start_adc_read = esp_timer_get_time();
|
||||
// from peak detector circuits
|
||||
ign_box_sts.coils12.peak_p_in = adcReadChannel(adc, ADC_CH_PEAK_12P_IN);
|
||||
@@ -256,7 +259,7 @@ void rtIgnitionTask::rtIgnitionTask_realtime(void *pvParameters)
|
||||
// [TODO] code to reset sample and hold and arm trigger level detectors
|
||||
}
|
||||
else
|
||||
vTaskDelay(pdMS_TO_TICKS(1));
|
||||
vTaskDelay(pdMS_TO_TICKS(2));
|
||||
|
||||
// send essage to main loop with ignition info, by copy so local static variable is ok
|
||||
if (rt_queue)
|
||||
|
||||
Reference in New Issue
Block a user