Maker Pro
Maker Pro

Ping))) Ultrasonic Sensor

fyah17

Apr 12, 2014
8
Joined
Apr 12, 2014
Messages
8
I have to interface the sensor to work with a PIC18F4680 without using the basic stamp code procedure. I have to use assembly language and write code to transmit and detect the signal to and from the PING sensor. I know how it works, I'm just not sure about the code needed to get it done. Any guidance would help. I have a general idea that the timer module should be used but I'm not sure exactly how it will be used in this case.
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
So this is for ultrasonic distance measurement? And you need to generate a burst of ultrasonic signal? You're making a parking distance measuring device, are you?

One way to do this is to use an output compare module to toggle an output pin when a timer reaches a certain value. You clock the timer from a known frequency source and have it incrementing steadily all the time. When you want to generate a burst of ultrasound, you read the timer, add a bit, and program that value into the output compare register, and set the output compare logic to drive your pin high. When the timer reaches that value, the pin goes high. You detect the output compare match, and program the output compare block to drive the pin low when the right time arrives for the falling edge of the cycle. Then repeat for the next rising edge, and so on.

I assume you have circuitry to toggle a pin when the reflection is detected? That can trigger an input capture from the same timer, so you can calculate the time from when the burst was transmitted to when the reflection was received.

The best way to structure the software for this depends on what else the micro will be doing. What interrupt sources are active, how often do they fire, and how long do the interrupt handlers take? What's your ultrasonic frequency? What's your clock frequency for the PIC?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Can you give us a link to this ping sensor so we know more about it than its name?
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
Ah, that device does most of the work. You just generate a pulse to trigger it (set the PIC's I/O pin low, then turn it to output mode, then back to input mode) and read a counter, then wait for the device to generate a pulse in response, read the counter again, and calculate the elapsed time.

If you want more specific advice, tell us about how your software is structured and what timers it uses.
 
Top