Hello y'all , I'm in a bit of a pickle. I want to measure the pulse width of my smartphone flashlight pulses. The circuit has a photodiode, which is connected to an op-amp and from the op-amp, i connected its output to arduino analog pin A0. The pulse width is around 750 us. I used a simple software snippet to measure pulse width, but it is missing pulses below 1 ms width. Basically my pulse is high when it has a voltage of above 19.52 mV , else it is a Low pulse. I want to measure the pulse width of the high pulses. Requesting help from the pros here. Let me Share my Sketch
Sketch:
Sketch:
C-like:
#define cellpin A0
const float mvc=4.88;
float counts=0;
float mv=0;
int ctr=0;
long int t1,t2;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); }
void loop() {
// put your main code here, to run repeatedly:
counts=analogRead(cellpin);
mv=counts*mvc; // this is the output voltage
if(mv>19.52 && ctr==0){
t1 = micros();
ctr=1; // ctr is used for detecting edges
}
if(mv<19.52 && ctr==1){
t2=micros();
Serial.print("The on-pulse duration in microsecond is "); /* if the output voltage(mv) is higher than 19.52 mV, consider it a high, else consider it a Low pulse.*/
Serial.println(t2-t1); // the pulse width in us
ctr=0;
t1=0;
t2=0;
}
}