I imagine this has been addressed before but my searches have not been successful.
I have a sensor that sends pulses from approx 0.7 volts to 1.4 volts. The pulse length is 45, 90, or 180 microseconds depending on the sensed condition. I run this signal through a comparator with a reference voltage of 1.0 volts. The output from the comparator produces the 0 to 5 volt pulse necessary for an arduino digital input read. Wondering if there is a way via an analog input to eliminate the need for the comparator.
The standard analogRead() can make ~8000 samples per second max so it takes about 100 micros(), so analogRead() will be to slow.There are fast version of analogRead that uses less bits (e.g. 8) to gain speed.
(disclaimer no EE) Think you can connect the signal to a transistor that will switch 0/5V that can be read with a digitalRead().
you might use the interrupt pin to see the rising and falling edge. - google attachinterrupt arduino -
Wondering if there is a way via an analog input to eliminate the need for the comparator
Yes, the 328p (arduino) does include an Analog comparator..
The Analog Comparator compares the input values on the positive pin AIN0 and negative pin
AIN1. When the voltage on the positive pin AIN0 is higher than the voltage on the negative pin
AIN1, the Analog Comparator output, ACO, is set. The comparator’s output can be set to trigger
the Timer/Counter1 Input Capture function. In addition, the comparator can trigger a separate
interrupt, exclusive to the Analog Comparator. The user can select Interrupt triggering on comparator
output rise, fall or toggle.
Look at the way the level shifters use to go from a 3.3v micro (eg the DUE) to a 5v micros.
Can you use the same type of hardware/idea to get your pulse over the threshold of a digital input?.
For example a low on the 5v Uno is less than 0.6v and a high is greater than 3.0v so if you can shift your 0.7 to over 3.0 then you have a digital 1 and ........
Thanks for the responses. I was able to utilize a simple transistor circuit by adjusting the load resistance on the sensor to get its low output to about .5 V and a high of about 1.2 V. With these values, I am driving a 2N2222 to get the desired output of approximately 0 and 5V to the arduino. This is certainly cheaper and requires less space than my original comparator approach. Space is a big issue and ultimately I will be using a digispark controller. I believe the attiny85 has a comparator on board like the arduino chip so utilizing this is my ultimate goal. For now though , I will go with transistor solution as I need to move to other aspects of the project.