• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Detecting falling or rising edge

Q&A Forum › Category: ESP32 › Detecting falling or rising edge
0 Vote Up Vote Down
NUR AZLIN AIRUL AZLIN MOHAMED ZOHDI asked 4 years ago

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.
 
thanks
https://imgur.com/m5Kb9jj

Question Tags: falling edge
3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
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.

  • https://randomnerdtutorials.com/esp32-date-time-ntp-client-server-arduino/

Let me know if this helps.
Regards,
Sara
 
 
 

0 Vote Up Vote Down
NUR AZLIN AIRUL AZLIN MOHAMED ZOHDI answered 4 years ago

Hi Sara,
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.
   Thanks.

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Great!
I’m glad you found a workaround.
I’ll mark this issue as resolved.
If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.