Pages: [1]   Go Down
Author Topic: Can pulseIn() function be applied to HW INT pin  (Read 486 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello all,
I was wondering if it is possible to use the pulseIn() function to measure the time delay between received interrupts.

I  can use the function in my main loop if I route the interrupt to an ordinary input as well (which means I have a workaround) but not when routing to the interrupt only.  

Many thanks in advance.

Michael
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 94
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Usually to do this you can read the counter direct, to get a measurement of the time between pulses. You read the counter value, store it, and then read it again on the next interrupt, and you can then work out the interval, before resetting the counter or storing the counter value. You need to make sure you check the overflow flag to see if the counter has overflowed (and consequently started from the beginning again) during  the period whilst waiting for the interrupt. Also make sure you have a sensible prescaler value, that matches the period of the interval that you want to measure.

Have a look through the ATMega datasheet, and it explains the counter registers and how they operate. It's not the easiest thing to get your head around, but very powerful when you do.
« Last Edit: March 09, 2010, 11:55:58 am by programmer » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the feedback. I have found a few examples online but I need to spend the time to understand more about the inner workings.

I will post again with example code once I make progress (I am new to this so it may be a few days!)
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi again,

Just a quick call out for clarification.

If I understand correctly, using the Timer/Counter1 register (TCNT1) to calculate the delay between pulses (interrupts) requires the external interrupt to be routed to the Input Capture Pin (ICP1) - the normal Arduino interrupts (INT0, INT1) cannot be used for this purpose.

I like the idea of using the Arduino interrupts and the workaround using pulseIn() with the interrupt routed to a free IO pin - it's a simple workaround requiring an extra jumper wire.

Am I taking the easy way out here or should I be challenging myself more???


Logged

Pages: [1]   Go Up
Jump to: