Hi Rui & Sara,
I am working on a project to read DC voltage, and I am using ADS1115 external ADC by Adafruit. The voltage source is coming from a rectifier unit and we would switch ON for 3 seconds and OFF for 1 second for a predetermined time frame. I do not have any problem getting the readings. Serial plotter is giving me nice square wave. My next task is to detect the falling edge, the instant where by the rectifier switches from ON to OFF. I need to timestamp that instant and retrieve the voltage value, 300ms apart from the instant OFF.
i have studied your interrupt timers etc but could not relate. I hope you guys can help me on this with some ideas.
You need to use interrupts in the falling edge.
When it detects the interrupt it calls a callback function as mentioned in the tutorial.
attachInterrupt(digitalPinToInterrupt(GPIO), function, mode);
If you use the millis() function in the callback function you can timestamp that event—it will return the number of milliseconds that have passed since the program started.
If you really want the exact time, like hour, minute, seconds, millisecond, you need to get the time. You can use an RTC module or get the time from an NTP server.
Let me know if this helps.
Thanks for your reply.
I am not using the interrupt since my analog data is fed by the ADS1115 external ADC over I2C. Feeding the raw input to the esp32 GPIO directly gives me horrible fluctuation that almost every 100ms, there will be a falling edge.
Nevertheless, I managed to work around the falling edge by simply maintaining 2 variables. previous & current, and checking the difference if they differ by 100mV.