Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm going to measure very short times as accurately as possible. The device will get first one pulse and within 150 microseconds six more, each on their own wires. The time between first signal and each of the six other signals must be measured as accurately as possible. The accuracy should be at least 100 nanoseconds but more is better.

Which microcontroller would be best for this? I've found this. They seem to have a timer with period of 4 nanoseconds. It would be accurate enough for me.

Would some other microcontroller be better to do this? Can this be done with AVR?

share|improve this question
I think you're talking about precision, not accuracy. What if you have nanosecond precision, but the underlying clock is off by 10%? Then the measurements aren't accurate. – Kaz Feb 26 '13 at 17:53
How far apart are the six pulses? Do they arrive on a common input or on six separate ones? – starblue Feb 26 '13 at 20:09
They have all their own inputs. Pulses can sometimes come all at the same time but usually they come at different times. – Kestis Feb 27 '13 at 4:52
up vote 7 down vote accepted

The speed of the microcontroller is not always the limiting factor. The MSP430 can be an appropriate solution, not because of the fact it only runs up to 25MHz, but because several MSP430 devices have the Timer D peripheral which enables up to 4ns time period (256MHz). This is faster than almost all microcontrollers out there. Even the STM32 in its latest versions (F4) can only do 180MHz.

Timer D is available on MSP430F51x1 and MSP43051x2 devices such as the MSP430F5131.

However, that only solves being able to capture the time. The big question is what do you do with it because the processing itself will be slower. You could sample the time between two pulses, but you won't be able to do any processing between them, if that's what you mean.

share|improve this answer
My bad, hadn't fully RTFM of the MSP430, mainly because TI's website triggers pavlovian convulsions of hate. – John U Feb 26 '13 at 18:15
@JohnU: Never had that reaction. The truth is the OP didn't specify much information about what he's doing so it's hard to give a proper suggestion. – Gustavo Litovsky Feb 26 '13 at 18:57
Processing isn't problem. There is many seconds to do the calculations once the times have been captured and the algorithms aren't even complex. Can one MSP430 handle all six pulses or should there be more of them? – Kestis Feb 26 '13 at 20:01
@Kestis: The Timer D contains 6 capture compares registers, and some MSP430 have more than just one Timer D module, so it should fit your requirement. – Gustavo Litovsky Feb 26 '13 at 20:13

Timing to a resolution of 100ns requires a timer running at 10MHz. Many microcontrollers should be capable of running a timer that fast.

The problem comes when you are trying to time the arrival of 6 signals. Are these signals all on the same wire, or each on a different wire?

If they're all on the same wire, then is might be possible to do this accurately on any MCU with a single 10MHz timer. Naively, the code to do this would look something like this:

wait for trigger signal
reset timer

wait for first signal
save timer value
reset timer


wait for sixth signal
save timer value
reset timer

The problem is that it takes a finite amount of time to reset the timer. This causes two problems:

  1. The times measured would be wrong by a few 100ns, depending on your implementation. However, they should be consistently wrong. I.E. wrong by exactly the same amount every time. This means you can easily compensate for it by adding a small amount to each measurement.

  2. There would be a minimum time you could measure. If the any pulse arrived 100ns after the the previous one, then you'll probably miss it. I don't know if there's anything you can do about that on in software. You'll have to find a microcontroller which can handle multiple pulses in hardware.

Which microcontroller can handle multiple pulses in hardware? The Cypress PSoC! This is a microcontroller which also contains configurable digital blocks, meaning you can easily have 6 separate timers running, each at 60MHz, giving you a better than 20ns resolution.

6 Timers PSoC Cypress

Here's an example I knocked up quickly to show you the sort of things you could do with it. I've got 6 separate timers, all running off the bus clock, which can go up to 67MHz. There's a trigger pin which starts all of the timers running, and 6 other pins, each of which causes a capture event in the timer. A status register allows your code to monitor which timers have captures a pulse. The code can read the values out of the timers.

share|improve this answer
That PSoC seems very interesting. However I would prefer AVR or MSP430 because they're much more common. – Kestis Feb 26 '13 at 19:52

Revised answer: A fast digital storage oscilloscope or possibly frequency counter device.

Old answer:

In simple terms, "the fastest microcontroller you can find", on the grounds that the faster your clock / sampling, the more accurate you can be. MSP430's are not fast devices.

STM32's are 32-bit and will run faster, plus have similarly cheap dev boards & tools available, but even that is quite slow compared to some of the more powerful stuff available (Raspberry Pi @800MHz - 1GHz(Overclocked)). Generally though, the faster you go the more complicated the processor so there can be a trade-off in the learning curve.

Added: Benji is right, you (may) also need an accurate oscillator for the micro if you want very accurate measurements (you don't really specify error bounds in your question).

share|improve this answer
Fundamentally, there are other types of timers, other than microcontroller sampling the signal in a loop. – Nick Alexeev Feb 26 '13 at 17:43
And it would help if the microcontroller has a very accurate external oscillator/crystal attached. – BenjiWiebe Feb 26 '13 at 17:49
You're both right, I've edited. – John U Feb 26 '13 at 18:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.