Shop OBEX P1 Docs P2 Docs Learn Events
Can't get Parallax PING))) to work. — Parallax Forums

Can't get Parallax PING))) to work.

GroovyChiliGroovyChili Posts: 1
edited 2011-08-03 01:55 in Accessories
Hi, I'm a beginner in electronics, and I have recently hit a problem.
I bought the PING))) ultrasonic sensor, and I can't get it to work.

I have googled around the web and tried many different things, but nothing works. I'm using a PIC16F628 with the PING))) connected to pin nr. 4, and an LED connected to pin nr. 0.

I'm just trying to get the LED to lit up when it's getting a response from the PING))) and I think I've connected everything the right way, from the hardware's point of view, because when I replace the PING))) I/O pin (nr. 4 in my case) with another power source, the LED at pin nr. 0 lits up.

And the Activity LED on the sensor just lits up one tiny tiny moment, barely noticeable, when I'm powering on the circuit for the first time.

Is there any of you who have any experience with the PING))), and can help me?
Here's my code;
;--------Initialize assembler
LIST P=PIC16F628					;	Telling the assembler what kind of microcontroller we are using
#include "P16f628.inc"				;	Converting words to hex. values
__config 0x3f18						;	Settings, such as watchdog, internal timers, etc. All turned off

;---------Macros
bank0   macro
        bcf     STATUS,RP1
        bcf     STATUS,RP0			;	BANK0 (Data Memory)
        endm
bank1   macro
        bcf     STATUS,RP1
        bsf     STATUS,RP0			;	BANK1 (Data Memory)
        endm
bank2   macro
        bsf     STATUS,RP1
        bcf     STATUS,RP0			;	BANK2 (Data Memory)
        endm
bank3   macro
        bsf     STATUS,RP1
        bsf     STATUS,RP0			;	BANK3 (Data Memory)
        endm

;---------Registers
cblock 0x20
	;	Nothing for now...
endc

;---------Program memory
	org 0x00						;	The beginning of the program
		goto Start 

	org 0x04						;	Interrupt Service Routine
									;	Nothing for now....

;##############
;----------Main
Start								;	Starting by setting all pins as outputs
		bank1
		movlw b'00000000'			;	Pin 5 needs to be an input pin
		movwf TRISA					;	Set the inputs and outputs of port A
		
		movlw b'00000000'			; 	All outputs
		movwf TRISB					;	Set the inputs and outputs of port B
		bank0
		
		goto SendSIG
		
PingOut								;	Make pin nr. 4 an output pin for sending trigger signal
		bank1
		movlw b'00000000'
		movwf TRISA
		bank0
		return
		
PingIn								;	Make pin nr. 4 an input pin for retriving an echo signal
		bank1
		movlw b'00010000'
		movwf TRISA
		bank0
		return

SendSIG
		call PingOut
		bsf PORTA,4					;	Trigger signal, 5uS long
		call Delay5uS
		bcf PORTA,4
		goto ScanningSIG			;	Trigger signal, now sent. Start listning for echo signal

ScanningSIG
		call PingIn

ScanningLoop
		btfsc PORTA,4				;	Check I/O pin
		bsf PORTA,0					;	Light LED
		goto ScanningLoop
		
;-----Delays---------------------------------------
Delay5uS						;	A delay lasting for 5 micro seconds, including the "call"
		goto $+1
		return

;-----End------------------------------------------
Finish
		end						;	End of program

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-08-02 21:37
    We really can't help you with your PIC programming. Do you understand the description of the PING)))'s operation as described in the documentation? It's pretty straightforward. Is there something you don't understand about the PING)))'s operation? You seem to be essentially copying the state of the PING)))'s I/O pin to the LED during the echo period. The maximum time to the high echo response is about 18ms and you're probably not going to see a flash that short. You really need to wait up to about 20ms for the echo high. If it's received during that period, turn on the LED. If not, leave the LED off. Leave the LED on for maybe 1/2 second, then go back to send another trigger pulse.
  • LeonLeon Posts: 7,620
    edited 2011-08-03 01:55
    Use banksel for switching banks, instead of those macros, you are less likely to make a mistake. You just type:

    banksel PORTA

    for instance.

    You are setting PORTA to all outputs with

    movlw b'00000000'
    movwf TRISA

    There are lots of problems with the code, as it's written. You'd be better off with a 16F88 as it has in-circuit debugging.
Sign In or Register to comment.