I am stuck with my problem from quite some time now and could not get the solution yet. Actually I have to measure pulse widths accurately but my code is not giving me good resolution and hence the accuracy since the pulses are very short only 5 to 15 microseconds in duration, my code measures the widths after every 1 microsecond but not the values in between them- Here is my code
So I have to now use some external fast counter which can bring more accuracy and I have found one fast counter given by the link below but I don't know whether and how I could use this to achieve better results so please guide.
You might try using an interrupt to capture the start of he pulse and end the interrupt when the pulse is complete.
You also might consider doing this in assembler. You can reduce the time because you would have total control over what registers are used so you could spend less time saving and restoring registers, which takes a bit of time in the arduino code.
I wrote some code for a step & direction stepper driver (ATtiny2313) that was 1200+ bytes in Arduino and I was able to get it in 88 bytes and all running from registers in Assembler. My final interrupt routine was 12 words long, the C version was much longer...
Okay - a short pulse every second. Interrupt on the pulse, your interrupt routine is a short loop with that increments a variable. When the interrupt input turns off (don't know wheterh you interrupt is a rising or falling) the loop exits and the interrupt returns. You can then let loop send the value via serial.print..
Since you know the characterisics of your signal this would be a valid way to use an interrupt. For faster signals, or unpredictable signals it might not work.
a thought of how to do it - code has not been checked for syntax...
void setup(){
attachInterrupt(0, intHandler, RISING);
pinMode(intPin, INPUT);
interrupt routine - assumed the interrupt was a rising interrupt