Go Down

### Topic: Simple Passive Sonar (Read 5544 times)previous topic - next topic

#### Hunter235711

##### Feb 26, 2011, 07:35 pm
Hello,
I am trying to come up with a very simple passive sonar design that could be used to determine the direction of arrival of an ultrasonic sound pulse. I was planning on having 3 or 4 hydrophones each connected to a comparator circuit so that when the wavefront of the ultrasonic pulse reaches a particular hydrophone the output of that hydrophone's comparator goes high.

I was thinking that I could attach these comparator outputs to the digital pins of an arduino and use the arduino to calculate the time difference between each of the digital pins switching to a high input. I think I could figure out how to calculate the direction of arrival after that point, but I am unsure how to get the exact times at which the input pins go high. Because the speed of sound is very fast in water ~1500 m/s, I believe the timing would need to be accurate to approximately 30 microseconds or so. Does anyone have any ideas on how to measure the time at which digital pins go high very accurately?

#### robtillaart

#1
##### Feb 27, 2011, 10:44 am

discusses the same problem with sound
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#### Hunter235711

#2
##### Feb 27, 2011, 05:50 pm
Thank you for your reply! That article is very similar to what I am trying to do. However, my problem is that I don't know how to write an arduino program to measure the time delay between two or more digital input pins changing state. That specific part didn't seem to be mentioned in the article. I was thinking that perhaps interrupts could be used, but I have never used them and I don't know if even they would give me the required time accuracy. I do not know if this is at all possible, but I was imagining that when any one of the 3 or 4 digital inputs switched to a high state it would start a timer and see how long before the other inputs switched to high.

#### retrolefty

#3
##### Feb 27, 2011, 06:04 pmLast Edit: Feb 27, 2011, 06:14 pm by retrolefty Reason: 1
Quote
do not know if this is at all possible, but I was imagining that when any one of the 3 or 4 digital inputs switched to a high state it would start a timer and see how long before the other inputs switched to high.

It's pretty straight forward. You can utilize the arduino micros() or millis() commands (depending on your time resolution requirements) to take a 'snapshot' of either these two free running timer variables. You save the present count in a variable when a 'start' change is read on a input pin and then when another pin changes you again read the time function and compare it to the saved 'start' variable, the difference in time is how long it took for the event to happen sense it was started. You need to deal with if a pulse never returns, so your code would need to check on a time out value to give up waiting for a input pin that may never change.

PS: "Passive Sonar" is really a much different animal and you are probably misusing the term. Active sonar is where you send a ultrasonic pulse and wait for a return pulse. Passive sonar is more like simply listening with a microphone to see what sounds may be out there. In Navy use, active sonar can give the 'enemy' the knowledge that you are out there by the pulses you are transmitting, where passive sonar does not give your location away.

Lefty

#### robtillaart

#4
##### Feb 27, 2011, 06:30 pm
Quote
my problem is that I don't know how to write an arduino program to measure the time delay between two or more digital input pins changing state

Start spending some time on the tutorial section - http://www.arduino.cc/en/Tutorial/HomePage - , it may costs an extra week or so to go through the samples but you will learn a lot about how to prog an Arduino.

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#### Hunter235711

#5
##### Feb 28, 2011, 10:31 pm
Thank you all. I spent some time looking around on the tutorial section of the arduino website and I found a good example of how to do "state change detection". However, it works by sequentially reading the state of each of the digital input pins in a loop. I was thinking that the time required to loop through reading all of my 4 digital input pins may be comparable to the delay I am trying to measure (10's of microseconds). I may be totally wrong about this, but it seems that if all 4 pins switched to high simultaneously the pins that were polled first would falsely seem to have been triggered first.

#### robtillaart

#6
##### Mar 01, 2011, 06:48 pm
ONe of the tutorials is about interrupts. The Arduino 328 has 2 IRQ lines, The Mega has 5.

- http://arduino.cc/en/Reference/AttachInterrupt

When a specific IRQ occurs you need to copy some timestamp, something like:

Code: [Select]
`volatile int IRQcounter = 0;void setup(){  attachInterrupt(0, time_one, RISING );  attachInterrupt(1, time_two, RISING );  attachInterrupt(2, time_three, RISING );  attachInterrupt(3, time_four, RISING );}void loop(){  if (IRQcounter == 4)  {    IRQCOunter = 0; // for next shot    // do the math    // display result  }}void time_one()  // similar 4 times{  IRQcounter++;  time1 = micros();}`

The 328 can also have an IRQ on other pins - http://www.arduino.cc/playground/Main/PinChangeInt -  however I would advise to start with the normal IRQ's first to understand the mechanisms.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#### Hunter235711

#7
##### Mar 05, 2011, 11:06 pm
I think that this may be perfect for what I am trying to do, thanks!

Go Up