PING connected to a PIC16F876
Hi, I'm interfacing a PING))) device directly to a PIC 16F876, using the HI-TECH PICC Lite compiler. I'm running into a funky issue..
In my code, I'm trying to trigger the burst and listen back for the results. Here's some psuedocode of what I'm doing, and the issue I'm seeing. The PING Signal is connected to my RB7 pin.
Set RB7 = Output
Set RB7 = High
Wait 10uS
Set RB7 = Low
Set RB7 = Input
....read in results..
However, once I set the RB7 as an input, the signal on the PING goes high and stays high. I cannot detect any kind of pulse back from the device. Has anyone else run into this? Why would my PIC pin go high when I switch the I/O direction to Input?
Does anyone have any sample code in PICC for interfacing with the PING?
Thanks
EDIT: I should also note, that once I set the RB7 pin High, the ACT LED comes on and stays lit.
Post Edited (nullvalue) : 4/8/2009 3:15:12 PM GMT
In my code, I'm trying to trigger the burst and listen back for the results. Here's some psuedocode of what I'm doing, and the issue I'm seeing. The PING Signal is connected to my RB7 pin.
Set RB7 = Output
Set RB7 = High
Wait 10uS
Set RB7 = Low
Set RB7 = Input
....read in results..
However, once I set the RB7 as an input, the signal on the PING goes high and stays high. I cannot detect any kind of pulse back from the device. Has anyone else run into this? Why would my PIC pin go high when I switch the I/O direction to Input?
Does anyone have any sample code in PICC for interfacing with the PING?
Thanks
EDIT: I should also note, that once I set the RB7 pin High, the ACT LED comes on and stays lit.
Post Edited (nullvalue) : 4/8/2009 3:15:12 PM GMT
Comments
RB7=1; //Set signal high
__delay_us(10); //wait 10uS
RB7=0; //Set signal low
TRISB7=1; //Swtich to Input
while(!RB7) {} //Wait for rising edge from input
j=0; //reset counter
while(RB7) { //loop w/ 1 uS delay, waiting for
__delay_us(1); //signal to go low
j++;
}
LFT_PWM=j/145; //divide max 18500uS / 145 for max 127
TRISB7=0; //Switch to Output
For now I'm using the results to drive a motor through PWM.
With the code as is, it hangs inside the while(RB7) { __delay_us(1); j++; } loop. Apparently after seeing the rising edge of the echo return pulse, the pin is never set low. (If i jump the signal pin to GND the code continues)..... Not sure what's going on... any help is appreciated.
Check your wiring. The ACT LED should only come on briefly when RB7 is pulsed. If you have
access to an oscilloscope or logic analyzer, it would be helpful to look at your signal to see what's
actually present.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
Would a pull-down resistor help? I'm kind of at a loss.
I am going to try putting this on a breadboard to see if the problem remains or if its just my circuit. Maybe my PIC's bad?