Shop OBEX P1 Docs P2 Docs Learn Events
PING))) Ultrasonic Sensor and PIR Sensor MPASM help — Parallax Forums

PING))) Ultrasonic Sensor and PIR Sensor MPASM help

Tony YuTony Yu Posts: 1
edited 2008-04-29 15:34 in General Discussion
I was wondering if anyone had success in using the PING))) Ultrasonic Sensor and the PIR sensor with a PICDEM4 Demo board that has a PIC18F1320 microcontroller?

The following was coded in MPLAB IDE and compile with MPASM v5.14.

For the PING))) Ultrasonic Sensor

bcf TRISA,0 ; Clear RA0 for output
bcf PORTA,0 ; Clear RA0
movlw d'1' ; 1*3=3 clock delay
movwf count
call delay ; delay next reading
bsf PORTA,0 ; set RA0 to send trigger
movlw d'1' ; 1*3=3 clock delay
movwf count
call delay ; delay command
bcf PORTA,0 ; clear RA0 to end command
bsf TRISA,0 ; set RA0 to input
again1
btfss PORTA,0 ; wait for high logic
goto again1
again2
btfsc PORTA,0 ; wait for low logic
goto again2


delay
movf count,w ; delay loop
movwf temp
del
decfsz temp ; 3 clock cycles per delay loop
goto del
return
I'm using RA0 as my I/O pin. The issue I'm having is that I'm not sure if I'm configuring this correctly. My understanding is that I need to send a trigger pulse out the SIG pin to the sensor, then I need to reconfigure that output pin as input and read the rising and falling edges, and "time" how long it takes for it to reach the falling edge.· From this all I get is a blink on the LED(on the sensor), and the program stays in the "again1" loop. So there doesn't seem to be a high logic flowing back from the sensor.· The only response I get(and tells me the sensor is alive), if I send out a high signal to the sensor, the sensor LED comes on, and when I send a low signal to the sensor, the sensor LED shuts off.

Secondly for the PIR Sensor

clrf PORTA ; Clear PORTA data
bcf TRISA,0 ; Set RA0 as output
bsf TRISA,1 ; Set RA1 as input
again
btfss PORTA,1 ; If RA1 is set skip
bcf PORTA,0 ; Clear RA0
btfsc PORTA,1 ; If RA1 is clear skip
bsf PORTA,0 ; Set RA0
goto again

I'm using RA0 as the output LED on my board, and having RA1 as input for the signal. I think all I need to do is read the input signal and see if its high or low. I don't seem to get a response with this code. The pin is set to "retrigger".

Any help would be greatly appreciated!
Tony
·

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-04-29 15:34
    This thread is being moved from the SX Forum to the Sandbox Forum, since it is off topic in the original forum, which is for SX support only.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.