Signal input: Toff = 117500us Ton = 2500us
esp32 reading: Toff 117539us Ton=2462us
Code: Select all
volatile unsigned long TotalON_uS, InstantON_uS, Instant_ciclo_uS; // volatile garante que a variavel é lida sempre, evita ler valor desatualizado
void IRAM_ATTR interrupt_pulso1()
{
static unsigned long _micros1, _micros2, _last_micros1 = 1;
if (gpio_get_level(GPIO_NUM_27) == HIGH)
{
_micros1 = micros();
Instant_ciclo_uS = (_micros1 - _last_micros1);
_last_micros1 = _micros1;
}
else
{
_micros2 = micros();
if (_micros2 > _micros1)
{
InstantON_uS = (_micros2 - _micros1);
TotalON_uS += InstantON_uS;
}
}
}
Code: Select all
void setup(void)
{
attachInterrupt(input1_pin, interrupt_pulso1, CHANGE); //input1 expand into GPIO27
}