Reboot in timer
Posted: Tue Aug 11, 2020 7:35 am
Hello everyone,
I need some help regarding the timer in ESP32.
When I activated the timer3 and read a value from a digital sensor, the ESP32 reboot by itself everytime.
Below is the part of the code.
Thank you !
I need some help regarding the timer in ESP32.
When I activated the timer3 and read a value from a digital sensor, the ESP32 reboot by itself everytime.
Below is the part of the code.
Code: Select all
#include <setjmp.h>
#include <actuatorsESP32.h>
#include <PISO.h>
#define divPin 17
PISO p;
jmp_buf env;
actuatorsESP32 a(env);
hw_timer_t * timer3 = NULL;
portMUX_TYPE timerMux3 = portMUX_INITIALIZER_UNLOCKED;
volatile int count1_Sec; // Seconds counter of timer 1
volatile int count1_Min; // minutes counter of timer 1
volatile int count3_Sec; // Seconds counter of timer
volatile boolean stateDiverterValve;
int counter_start;
int timeDiverter;
/*timer 3 did not worked. ESP32 reboots by itself everytime after try to read value of "a.diverterDirPin"*/
void IRAM_ATTR onTimer3()
{
portENTER_CRITICAL_ISR(&timerMux3);
volatile bool actualDir, pastDir;
bool door, cancel;
if (count3_Sec != timeDiverter) { // verifies if the amout of time set was achieved
count3_Sec++;
}
else {
count3_Sec = 0;
pastDir = LOW;//digitalRead(a.diverterDirPin);
Serial.print("First direction -> ");
Serial.println(pastDir);
a.diverterMotor_on();
do {
actualDir = LOW;//digitalRead(a.diverterDirPin);
Serial.print("Actual direction -> ");
Serial.println(actualDir);
} while (pastDir == actualDir);
a.diverterMotor_off();
}
portEXIT_CRITICAL_ISR(&timerMux3);
}
void diverterValve_on(void) {
Serial.println("The diverter interruption was set");
timerAlarmEnable(timer3);
stateDiverterValve = HIGH;
}
void diverterValve_off() {
timerAlarmDisable(timer3);
Serial.println("The diverter interruption was disabled");
stateDiverterValve = LOW;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("SETUP --> START");
pinMode(divPin, INPUT);
timer3 = timerBegin(2, 80, true); // timer 2, MWDT clock period = 12.5 ns * TIMGn_Tx_WDT_CLK_PRESCALE -> 12.5 ns * 80 -> 1000 ns = 1 us, countUp
timerAttachInterrupt(timer3, &onTimer3, true); // edge (not level) triggered
timerAlarmWrite(timer3, 1000000, true); // 1000000 * 1 us = 1s, autoreload true
void loop() {
a.relayOn_on();
delay(100);
a.cyclage_on();
delay(500);
timeDiverter = 10;
diverterValve_on();
delay(20000);
diverterValve_off();
vTaskDelay(portMAX_DELAY);
}