Measuring Pulse Width

Thanks Robtillaart

I just want to ask that the values which you showed are the ones which you got after applying the pulse to arduino and the changing its width from 10 15 microseconds? is it so? actually I can't check this at this moment because I don't have arduino at this time but I am realy anxious to know this

Thanks again

I just want to ask that the values which you showed are the ones which you got after applying the pulse to arduino and the changing its width from 10 15 microseconds? is it so? actually I can't check this at this moment because I don't have arduino at this time but I am realy anxious to know this

The table was made by a spreadsheet the first column is the value of the counter and the second one is the number of microseconds the pulse was. As the units are in 6/16 of a micros this is an indication for the precision achievable this way (approx 1/3 micros)

So you said you need to measure pulse of 10-15 micros. How precise do you want to measure? Is a whole value OK, [10,11,12,13,14,15] or do you need a decimal digit?

ahaa that's very nice and yes the whole value is absolutely fine, means that if the input pulse width is 10.35 or so then even the value 10 would be perfect.

@Robtillaart

one more thing I want to ask is can i get serial print messages directly in an excel file simultaneously while the time of printing?

one more thing I want to ask is can i get serial print messages directly in an excel file simultaneously while the time of printing?

Yes, google for gobetwino

@Robtillaart

Thanks and today I have checked the code output by applying different pulses from 10 microseconds to 15 microseconds so for 10 microsecond input pulse the output comes to be 7.13 or 7.50 and for 12 microsecond input pulse the output comes to be either 9.00 or 8.13 and so on. I don't know whether we could improve it or not so what do you think?

Thanks again

what do you think?

The ratio seems to be correct!

7.5 : 9 == 10 : 12
7.13 : 8.13 ~~ 10 : 12

Which version of the code do you use? - the one with the unsigned int?
Can you post the actual output of the script?
How did you connect the signal? Have you connected the GND's?
Did you try a pull down/up resistor?
Do you apply one pulse or a constant stream?

There might be a problem with the synchronization at the start.

So there is a lot to think about,

I don't know whether we could improve

Hi,
Sorry for the persistence, but why doesn't anyone ever use timer1 input capture for this type of thing ?

I have not tried it yet myself and so if there is some fundamental reason why it wont work I would appreciate if someone could point me to it ?

Thanks

Duane B

rcarduino.blogspot.com

@Robtillaart yes I have used the code with unsigned int the output of the code is given below, I have applied constant pulse stream at 1Hz frequency and changed the input from 10 to 13 and then 15 microsecond. I have connected the ground as well but did not use pulldown/up resistor.

DuaneB:
Sorry for the persistence, but why doesn't anyone ever use timer1 input capture for this type of thing ?

My suggestion a few posts back was exactly that!

Sorry for the persistence, but why doesn't anyone ever use timer1 input capture for this type of thing ?

just to give some reasons:

  1. in software you can use (almost) any pin
  2. there are far more SW examples how to do the counting (good bad and ugly)
  3. not everyone understand in detail how to program the timers as counter ( few examples)
  4. not everyone oversees the consequences of using timers
  • timer0 - 8 bit, used for clock
  • timer1 - 16 bit, free (servo lib?)
  • timer2 - 8 bit, free?

maybe you can post a reusable example how to do use Timer1 as counter?

Best I found sofar is : - Arduino Playground - HomePage -

Hi,

maybe you can post a reusable example how to do use Timer1 as counter?

Thats not out of the question, in the meantime I have been busy with having a look at this -

Duane B

rcarduino.blogspot.com

Well written DuaneB, bookmarked!

@Robtillaart and others

How can I improve the resolution? as I have to accurately measure the width and the counter should do more fast counting, can I use external clock of more than 16 MHz by doing prescaling? or if you can suggest some other method may be using a fast counter?

Thanks

switch to a faster processor like the MBED of NCP its around 100Mhz so it shoulc be able to do more counts per microsecond.

Or use Timers as proposed before in this thread, I can't help you on that as I have never really dived into that matter.

@Robtillaart

I have never used MBED of NCP so can it also provide the flexibility of using the serial monitor to see the results and also what about the syntax is it similar to arduino? since arduino is very user friendly

Thanks

scorp84:
How can I improve the resolution? as I have to accurately measure the width and the counter should do more fast counting, can I use external clock of more than 16 MHz by doing prescaling? or if you can suggest some other method may be using a fast counter?

The counter1 method can run at 16 MHz. This should give you 0.0625 microsecond resolution (but not accuracy -- that is determined by the interrupt latency.) If you need better accuracy than that, then you will have to use some pretty fancy custom circuitry -- something like a gate for a clock signal that is controlled by the pulse, and an interrupt on the falling pulse edge to read the value and reset the counter. And if you need better resolution, it has to be run with a counter that can run faster than 16 Mhz, which is a pretty specialized part that you would have to hook up externally from the Arduino.

I honestly don't think the MBED or LPCExpresso can do any better resolution than the Arduino. Their CPUs are faster, but they also have higher overhead in taking interrupts.

At this point, it sounds like what you're asking for is something that you'd pay thousands of dollars for in terms of scientific instrumentation to get a reliable system for doing. Or, alternatively, something that you'd pay several hundreds of dollars for to get a high-bandwidth (100 MHz) digital storage oscilloscope and calculate pulse width from rise/fall edges, if it's only for diagnosis, and not an online system.

@jwatte

Yes you picked it absolutely right and that's what even I was told earlier that may be I should use a fast external counter which can then work with arduino but unfortunately I am not finding any such fast counter, is there any external fast counter you can suggest me which I can use to get higher resolution?

Thanks again

Try a 4040 or similar, perhaps? 12 bits, and some implementations can run at 200 Mhz. You can daisy-chain two to get a 24 bit counter, although interfacing to the Arduino then may need multiplexing.

However, you'd need to generate that 200 MHz pulse train yourself, probably using a crystal and an amplifier/inverter circuit.
Also, you'd need to wire up the right circuit to gate the counter clock while the pulse is on, and then interrupt the Arduino once the pulse completes, so you can read the value and reset the counter. Probably want to use flip/flops to lock out multiple additional triggers until the count has been reset.
Finally, at 200 Mhz, the circuit board design starts mattering. You may run into signal quality issues if you're not careful. You probably want to use surface mount manufacture, and you quite likely can't build this very well on breadboard type surfaces at all.

@ jwatte

Can I use the external counter given by the link below

https://www1.elfa.se/data1/wwwroot/assets/datasheets/ag647877.pdf