Hardware interrupts for Analog pin to detect sound wave

28 views
Skip to first unread message

Eric Ouyang

unread,
Feb 17, 2012, 6:07:10 PM2/17/12
to HomeBrew Robotics Club
Hi,

I am using Arduino Uno's Analog pin to detect a sound wave.
For each Analog reading, it takes ~ 110 us for Uno board to read.
If I change the sampling rate (for example, chapter 18 at "Arduino
CookBook" by Michael),
then each Analog reading can be shorten to 17 us.

However, for my application, I just want to know the exact time the
event occur.
Such as, an impulse sound wave will come in within every 2 second,
and I like to know the exact time it comes in.

If I use a loop to keep reading the analoge for the sound wave, such
as reading the Analog pin every 20 us
(20 us is small enough, for 2 second, it has 20000000/20 = 1 million
segments)
then it becomes a big trouble, because I do not know when will sound
come in, the sound may come in
any time within 2 second, so if I like to capture it, I will have to
do
1st reading at t=0, and analog reading takes 110 us (or 17us)
2nd reading will be at t=0+110us (or 17us) and analogue reading
takes 110us (or 17us)
3rd reading will be at t=0+110+110 ....
.......
..... (basically the problem is that analog reading takes too much
time)


My question!
Is there a way to use "hardware interrup" to read the Analog?
I am hoping there is a way that I can detect an analog signal and
know its exact timing using minimum
microcontroller CPU resources, and with simplest programming
approach.

Thanks alot





Preston Monroe

unread,
Feb 17, 2012, 6:28:10 PM2/17/12
to hbrob...@googlegroups.com, HomeBrew Robotics Club
I've seen people use our Ardino for high-speed photography. Maybe do a search for something like that. They use a sound like the popping of a balloon to trigger the camera to take the picture in mid pop.

Sent from my iPhone

> --
> You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
> To post to this group, send email to hbrob...@googlegroups.com.
> To unsubscribe from this group, send email to hbrobotics+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/hbrobotics?hl=en.
>

Alex Sy

unread,
Feb 18, 2012, 2:42:20 AM2/18/12
to hbrob...@googlegroups.com
If you do not actually care about the level, you can get a much higher
resolution using the comparator input. The Atmega CPU has two pins that are
the comparator, you feed the analog signal on one and feed a threshold
voltage on the other pin. Then when the signal exceed the threshold, you
can trigger an interrupt or even an ICP (input capture) interrupt on timer
1. This gives you resolutions in the 100 nanosecond range.
Great for doing sound distance/localization measurements. The exact pin is
CPU dependent.


Hi,

Thanks alot

--

Reply all
Reply to author
Forward
0 new messages