Hey guys and gals,

I had my SRF04 Range Finder working after a lot of trouble and now it is not working anymore. I am using the Rapid18iXL board from www.dhmicro.com. I got a wire going from ground on the board to ground on the SRF04, another wire from the 5volt on the board to positive on the SRF04, another wire from RA0 on the board to the Trigger pin, another wire from RA1 on the board to the echo pin, and finally a wire from RB2 to the MAX232 chip for serial communication. I have loocked extensively at http://www.rentron.com/Micro-Bot/Sonar.htm and based by code off http://www.rentron.com/remote_control/SRF04.htm but to work with a 4mhz internal oscilator in the PIC16F628. I don't know why its not working. Here is the code


@ DEVICE pic16F628, INTRC_OSC_NOCLKOUT ' system clock options
@ DEVICE pic16F628, WDT_ON ' watchdog timer
@ DEVICE pic16F628, PWRT_ON ' power-on timer
@ DEVICE pic16F628, MCLR_OFF ' master clear options (internal)
@ DEVICE pic16F628, BOD_ON ' brown-out detect
@ DEVICE pic16F628, LVP_OFF ' low-voltage programming
@ DEVICE pic16F628, CPD_OFF ' data memory code Protect
@ DEVICE pic16F628, PROTECT_OFF ' program code protection

include "modedefs.bas"

CMCON = 7 ' Disable analog comparator
TRISA = %11110110 ' set PORTA to input
TRISB = %00100000 ' set PORTB to output

DEFINE HSER_BAUD 2400 'send serial data at 2400 baud
Trigger VAR PORTA.0 'PORTA.0 to SRF04 trigger pin
Echo VAR PORTA.1 'PORTA.1 to SRF04 echo pin
Width VAR WORD 'pulse width from sensor
Raw VAR WORD 'raw measurement
Distance1 VAR WORD 'converted value
Distance2 VAR WORD
Loops VAR BYTE ' loop counter for measurement
Trigger = 0 ' Pulsout is compliment of pin value

Main:
GOSUB Read_Range ' take sonar reading
HSEROUT ["Raw Value = ", DEC Raw, 10, 13, 13]
Distance2 = Raw ** 1777
Distance1 = Distance2 / 10
HSEROUT ["Distance = ", DEC Distance1,".", DEC1 Distance2," inches", 10, 13]
PAUSE 500 ' delay between readings
GOTO Main

Read_Range:
Raw = 0
FOR Loops = 0 TO 4 ' loop for 5 samples
PULSOUT Trigger, 1 ' >=10uS (~20uS)trigger pulse
PULSIN Echo, 1, Width ' measure distance to target
Raw = Raw + (Width / 5) ' divide samples down
PAUSE 10 ' wait period between pulses
NEXT
RETURN
END


And here is the output from the serial communicator in MicrocodeStudio


Raw Value = 0


Distance = 0.0 inches

Is my SRF04 ultrasonic rangfinder sensor busted up? Did i do something wrong in the code or wiring. I am pulling my hair out :P Any help is of course greatly appreciated!

- Matthew