Hello Everyone;
I am trying to measure the fall time of an input signal to my Arduino Due. Basically the Due input will see 2.1 volts under normal operation. When the signal is activated, the Due input will drop from 2.1 volts to 0 volts in about 1.2 microseconds. I am trying to measure the time it takes that signal to go from 1.2 volts to .2 volts and determine if the time was less than 5us. I am not even sure this is possible with the Due and that's why I wanted to ask everyone's opinion. My basic code I have so far is:
// INCLUDE LCD
#include <LiquidCrystal.h> //include LCD Library
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);// // initialize the library with the numbers of the LCD RS, E, D4, D5, D6, D7 pins
// DECLARE VARIABLES
unsigned long Interval_1; // set variable to store first time value
unsigned long Interval_2; // set variable to store second time value
unsigned long T_fall; // set variable for fall time of pulse
//********************************************************************************************
void setup(){
analogReadResolution(12);
/ SETUP LCD
lcd.begin(20, 4); // set up the LCD's number of columns and rows
lcd.clear(); // clear the lcd
//********************************************************************************************
void loop(){
// MEASURE WAVEFORM
if (analogRead(A0) <= 1489 ){ //Start measurement routine when voltage is less than or equal to 1.2 volts
Interval_1 = micros(); // Set the current time
while(analogRead(A0) >= 248 ){} // while the reading is greater than or equal to .2v, do nothing
Interval_2 = micros(); // Set the current time
T_fall = (Interval_2 - Interval_1); // calculate the time of the fall
// OUTPUT DATA TO LCD
lcd.clear(); // clear the lcd
lcd.setCursor(4, 0); // Set cursor position
lcd.print("TEST RESULTS"); // Print data to the LCD.
lcd.setCursor(0, 1); // Set cursor position
lcd.print("T_fall = "); // Print data to the LCD.
lcd.print(T_fall); // Print data to the LCD.
}
Thank you in advance for your help