Test working at 100Khz
This commit is contained in:
@@ -7,8 +7,13 @@
|
||||
static hw_timer_t *timerA = NULL;
|
||||
static hw_timer_t *timerB = NULL;
|
||||
TaskHandle_t main_t = NULL;
|
||||
static uint32_t count = 0;
|
||||
|
||||
static const std::map<const uint32_t, const char*> pin2Name = {
|
||||
#define FREQUENCY 100000 // 100 KHz
|
||||
//#define PERIOD_US 1000000 / FREQUENCY
|
||||
#define PERIOD_US 10
|
||||
|
||||
static const std::map<const uint32_t, const char *> pin2Name = {
|
||||
{PIN_TRIG_A12P, "HIGH_PIN_TRIG_A12P"},
|
||||
{~PIN_TRIG_A12P, "LOW_PIN_TRIG_A12P"},
|
||||
{PIN_TRIG_A12N, "HIGH_PIN_TRIG_A12N"},
|
||||
@@ -20,8 +25,18 @@ static const std::map<const uint32_t, const char*> pin2Name = {
|
||||
{SPARK_A12, "HIGH_SPARK_A12"},
|
||||
{~SPARK_A12, "LOW_SPARK_A12"},
|
||||
{SPARK_A34, "HIGH_SPARK_A34"},
|
||||
{~SPARK_A34, "LOW_SPARK_A34"}
|
||||
};
|
||||
{~SPARK_A34, "LOW_SPARK_A34"},
|
||||
{State::S_WAIT_10MS_END, "S_WAIT_10MS_END"},
|
||||
{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 = 500,
|
||||
.spark_pulse_us = 100,
|
||||
.spark_delay_us = 100,
|
||||
.main_task = NULL};
|
||||
|
||||
void setup()
|
||||
{
|
||||
@@ -43,25 +58,22 @@ void setup()
|
||||
pinMode(SPARK_B12, OUTPUT);
|
||||
pinMode(SPARK_B34, OUTPUT);
|
||||
|
||||
main_t = xTaskGetCurrentTaskHandleForCore(1);
|
||||
pinMode(12, ANALOG);
|
||||
stsA.main_task = xTaskGetCurrentTaskHandleForCore(1);
|
||||
|
||||
// Timer: 80MHz / 80 = 1MHz → 1 tick = 1 µs
|
||||
timerA = timerBegin(10000);
|
||||
timerAttachInterruptArg(timerA, &onTimer, (void *)main_t);
|
||||
timerAlarm(timerA, 10000, true, 0);
|
||||
|
||||
// Timer: 80MHz / 80 = 1MHz → 1 tick = 1 µs
|
||||
// timerB = timerBegin(1);
|
||||
// timerAttachInterrupt(timerB, &onTimer);
|
||||
// timerStart(timerB);
|
||||
timerA = timerBegin(FREQUENCY);
|
||||
timerAttachInterruptArg(timerA, &onTimer, (void *)&stsA);
|
||||
timerAlarm(timerA, 1, true, 0);
|
||||
|
||||
LOG_INFO("Setup Complete");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
uint32_t value = 0;
|
||||
if (xTaskNotifyWait(0x00, ULONG_MAX, &value, 0))
|
||||
Serial.println(pin2Name.at(value));
|
||||
delay(10);
|
||||
LOG_INFO("Loop: ", count++);
|
||||
uint32_t spark_delay = (uint32_t)(map(analogRead(12), 0, 4096, 100, 1000) / PERIOD_US);
|
||||
stsA.spark_delay_us = spark_delay * PERIOD_US;
|
||||
LOG_INFO("Spark Delay uS: ", stsA.spark_delay_us);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user