UNO/MEGA Less than 1 MICROSECOND Pulse width measurement.

HI, Friends
I want to measure Less than 1 Microseconds Pulse Width.

I refer to this : Gammon Forum : Electronics : Microprocessors : Timers and counters

in that they said they measure 100 nano Second pulse width. i tried it but not able to measure Pulse width less than 10 Microseconds.

Kindly help me.

No, Nick Gammon does not say that.
It says that the measured pulse width by the Arduino is 100ns accurate.
Testing shows that the displayed pulse width is within 100 ns of the actual width (two clock cycles basically) which isn’t too bad.

How accurate do you want to measure that pulse width ?
How often does that pulse occur ?
I think you need extra hardware.

EJLED:
HI, Friends
I want to measure Less than 1 Microseconds Pulse Width.

I refer to this : Gammon Forum : Electronics : Microprocessors : Timers and counters

in that they said they measure 100 nano Second pulse width. i tried it but not able to measure Pulse width less than 10 Microseconds.

Kindly help me.

The only way I see you being able to measure sub microseconds pulses is to:

  • Build some hardware
    Create a high frequency clock source.
    Create a logic circuit that counts those clock pulses while your observational window is open
    Then read the stored count.
  • repurpose one of the Timer/Counter modules

Using the internal hardware of the UNO, the max you can measure is timer_clock (CLKi/o) / 2.5.
So, with a 16mhz crystal, the minimum pulse period you could supply to T0 (D4) would be 6.4MHz or 0.15625 Microseconds. see AVR205 app note:

Realistically you are going to have to build some hardware to measure sub microsecond signals.

Chuck.

You may do it with some additional hardware:

Ah. Here's that post...

You could use code something like this:

int timePulse()
{
    while (PINB & 1 == 0)
    ;  // wait for a high pulse
    if ((PINB & 1) == 0)  // low again?
    return 125;
    if ((PINB & 1) == 0)  //  NOW is low?
    return 250;
    if ((PINB & 1) == 0)  //   how about now?
    return 375;
    if ((PINB & 1) == 0)  //    other things are waiting!
    return 500;
    if ((PINB & 1) == 0)  //      tap tap tap.
    return 625;
    if ((PINB & 1) == 0)  // I've justa about had it!
    return 750;
    if ((PINB & 1) == 0)  //   I really mean it!
    return 875;
    if ((PINB & 1) == 0)  //      Last chance
    return 1000;
    return -1;  // We are SO done...
}

This compiles (for low-address ports), to a series of SBIS/RJMP pairs that the avr ought to run through at two cycles each, which should give accuracy on the order of 125ns...

It will, of course, require adequate time "between" pulses to to the returns and process the results, you might need to do some tuning of the values returned, and perhaps it could use extending and a lot of testing to make sure it's close...

I think this is about as good as you can do on an AVR; you can't start a timer any more quickly than this will enter its string of instructions...

@aromring, I hope that @EJLED got it sorted in the 2.5 years that this thread is old :wink: