resolution of pulse width measurement

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi All,

I would like to use an xmega to measure pulse widths/frequencies. I would need a resolution of about 100 ns, but it doesn't have to be absolute in the sense that if all values are shifted 300 ns, I can deal with that. My question is whether the input capture function of the xmega would be suitable for this. As far as I see, one has to set up the event source, and then the capture interrupt. That seems to be a costly procedure, though, and I wonder whether it is meant to measure with a precision of 100 ns. If this doesn't work, I can set up an external PLL and counter, and drive it from the clock of the xmega, and whenever something happens, just read out the counter value.
I would appreciate any comments on this.
Cheers,
Zoltán

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
As far as I see, one has to set up the event source, and then the capture interrupt. That seems to be a costly procedure
But you only have to do that procedure once. Once it is set up, you only need to read the captured value.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Koshchi wrote:
Quote:
As far as I see, one has to set up the event source, and then the capture interrupt. That seems to be a costly procedure
But you only have to do that procedure once. Once it is set up, you only need to read the captured value.

What I meant by that is not that it is expensive to set up, but that since it calls an interrupt, it will probably take longer, than a couple of clock cycles. Is that correct?
Zoltán

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, but this will not affect the value from the input capture, only the minimum amount of time it will be between readings.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use the capture function. There is no latency between the pulse edge and the capture. Sure, you might use an interrupt to read it, but you will read what happened some clocks earlier, and it will be accurate. This WILL, however. limit the minimum time between successive edges that can be handled. But it will NOT limit the resolution.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
This WILL, however. limit the minimum time between successive edges that can be handled.

I think I won't have this problem: I will fire a laser, and the response will come at least a microsecond later. Once I read out the timer, I will wait for some 50-100 microseconds before firing the laser again. That is, the repetition rate of the signal will be 20 kHz at most. But given this scenario, what would result in shorter latency: an interrupt, or continuous interrogation of the timer counter? (I think the timer can be set up in a way that stops the counter, if the pin state changes, in which case I could just keep reading the counter value, and stop, once it does not change anymore. Then the question is if there is some rule of thumb that would tell me how many clock cycles it takes to handle an interrupt.

Quote:

But it will NOT limit the resolution.

So, can I take that if I use the system clock without division, then my resolution should be somewhere around 30 ns?
Zoltán

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, provided you use the Input Capture, NOT any sort of polling or interrupt for the actual timing.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just a suggestion but see Torby's thread about an Xmega based scope/logic analyser in Off Topic ("this is just too cute"). It's made by user ganzziani - it's a fair bet he's pushing the signal capture facilities to the absolute limit in that and will be able to tell you the reality of what's possible.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

XMEGA timers have frequency capture and pulse width capture features. In frequency captue mode, the positive edge restarts the timer and the second positive edge captures the timer. In pulse width capture mode, the positive edge restarts the timer and the negative edge captures the timer. You should use frequency capture mode and there is a need for interrupt after capturing the timer. If you have enough time between 2 captures ( as you stated this would be 50-100us), there is a 31.25ns resolution for 32MHz clock and 20ns for 50MHz overclock.

Ozhan KD
Knowledge is POWER

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Just a suggestion but see Torby's thread about an Xmega based scope/logic analyser in Off Topic ("this is just too cute").

Thanks for the tip-off, Cliff!
Zoltán