Basic Atom Pro code for Ping)))

I put your modified PING code in and all I get is board resets. It is not working for me. :frowning:

8-Dale

Are you using the atom pro?

Yes.

8-Dale

Hmm, are you sure all your connections are right? It seems to work fine for me. :slight_smile:

I will double check the next time I switch to having the Atom PRO control the PING directly. It is possible I connected it wrong the last time I switched configurations.

I am testing two different setups for the PING, controlling it through the MCP23017, and directly from the Atom PRO. It would be easy to connect something wrong when switching.

8-Dale

I just started to test this, and it’s not working for my Atom Pro. I’m sure I have everything connected right… I’m even using port 15 as in the code sample posted here. Here is what happens in Debug mode:

This line causes the PING LED to flash:

PULSOUT PING, PING_Trigger

Then it immediately jumps to ERROR when this line executes:

RCTIME PING, 1, PING_Echo      ' Wait for the signal to go high 

Any ideas? After reading this thread I was optimistic about getting some good readings from this sensor …

My code works fine.

I still can not debug this as I still don’t own one of these sensors. I assume since you mentioned the LED flashes that you probably do have it hooked up properly, including making sure +5v is going to the right set of pins…

A-Bot - Have you tried the code in non-debug mode? I have had troubles using debug mode when I am doing anything that involves timers or the like. This would be especially true if I was stepping the code or the like.

Just a thought

Kurte, thanks for the tip! I had not tried outside debug mode yet. Thanks for saving me some headache.

I wrote a program to turn a servo for 1 second if the range is less than 10 cm, and it works perfectly. I should probably get an LCD or something.

I must say like the performance of this sensor a lot more than Sharp IR. The only thing I don’t like about the Ping is the angle of the connector, and the way it makes the data cable stick out so far. It makes mounting it rather awkward. I might change it around so the connector is perpendicular to the PCB.

I believe we are both seeing the same problem. I did some serious work with the PING code today and have isolated the reset to the line of code it is happening on. We are both getting resets on an RCTIME command, which is interesting. I have my PING sensor on pin 4, but that should not make any difference. Please post the entire code you are using to read the PING sensor, including constant and variable declarations so we can compare further.

Here is my current PING code for the Atom PRO:

[code]PING con p4 ’ PING Ultrasonic Ranger I/O pin
PING_Trigger con 5 ’ Trigger pulse length in uS
PING_Threshld con 25 ’ PING detection threshold
PING_Error con $FF ’ PING Error value

PING_Detected var bit ’ 1 = Detected, 0 = Nothing detected
PING_Distance var word ’ PING object detection distance
PING_Echo var word ’ PING echo duration
PING_Scale var long ’ Divisor for distance units conversion
Read_PING
’ if makenoise then
’ sound speaker,[dur\note13, dur\note14, dur\note15, dur\note16]
’ endif

low PING

pulsout PING, PING_Trigger

if sendoutput then
	serout S_OUT, I9600, "PING, before rctime 1", 13]
endif

rctime PING, 1, PING_Echo      ' Wait for the signal to go high

if PING_Echo > 65000 then
	goto Error
endif

if sendoutput then
	serout S_OUT, I9600, "PING, before rctime 2", 13]
endif

' Atom PRO resets as soon as it executes the following line
rctime PING, 0, PING_Echo      ' Wait for it to go low again - this is our time

if sendoutput then
	serout S_OUT, I9600, "PING, after rctime 2, before divisor creation", 13]
endif

' Create the divisor for cm distance conversion
PING_Scale.highword = 0
PING_Scale.lowword = 2251         ' 0.03434 * 65535 cm conversion factor

if sendoutput then
	serout S_OUT, I9600, "PING, before distance calculation", 13]
endif

PING_Distance = (PING_Echo */ PING_Scale ) / 2

return PING_Distance

Error:
return PING_Error[/code]

8-Dale

Just a thought, have you tried moving off of pin 4? Why I ask is that on the pro we had to move the PS2 controller off of pins 4-7 because it had some problems… So you might try some other pins out of this range and see if you have better luck

Kurt

I have the PING on what the ABB designates as p8 now and have p8 referenced for the PING pin number. Now the Atom PRO still resets, but when it executes the very first pulsout command. I have the same situation as A-Bot now.

8-Dale

Can you look at the pulses with an occilliscope for us. That will show what it outputs. :stuck_out_tongue:

I don’t have an oscilloscope here.

8-Dale

OK, I guess it is time to bring this topic to the top again. I have switched back to using the Basic Atom (not the PRO) for now. However, the pulsout command still does not work and causes what is apparently a sort of core dump when my program is compiled. I just have a single PULSOUT command in my code where I am trying to read the PING sensor.

The problem seems to be in mbasicpuls.lib and the messages complain about Value of symbol “_pulsoutfinish” differs on second pass. This points to a spot right near the end of the pulsout code at a label called “_pulsoutfinish” where there is not much code.

Could it be real difficult to fix this problem and give us a patch? I would copy and paste the mesasges, but the IDE won’t allow me to do that. :frowning: Perhaps copy could be enabled for a later version of the IDE?

8-Dale

Send me your program and a copy of this post. I assume you are using the 5.3 compiler

[email protected]

Here is my current multi-PING code for the Atom PRO. I have not tested it with more than one PING, but everything else works as it should within the loop and my PING_Max value is correct for a single PING.

[code]PING_Max con 1 ’ Number of PING sensors we have
PING_Base con p8 ’ PING Ultrasonic Ranger I/O pin
PING_Trigger con 10 ’ Trigger pulse length in uS (Must be 10 for Atom PRO)
PING_Threshld con 15 ’ PING detection threshold

PING_Detected var bit(8) ’ 1 = Detected, 0 = Nothing detected
PING_Distance var word(8) ’ PING object detection distance
PING_Threshold var word(8)
PING_Echo var word ’ PING echo duration
PING_Scale var long ’ Divisor for distance units conversion
PING_Status var word ’ Status of PING sensors
PING_Dist_Check var word ’ For distance checking

’ Initialize PING Sensor Arrays
for index = 0 to (PING_Max - 1)
PING_Distance(index) = 0
PING_Detected(index) = 0
PING_Threshold(index) = 0
next

PING_Threshold(0) = 30

’ Create the divisor for PING cm distance conversion
PING_Scale.highword = 0
PING_Scale.lowword = 2251 ’ 0.03434 * 65535 cm conversion factor

’ Check the Ultrasonic Sonar Ranger on the Pan/Tilt Turret
Read_PINGS:
PING_Status = 0
PING_Dist_Check = 999

for index = 0 to PING_Max - 1
	PING_Detected(index) = 0

	' Start the PING detection cycle
	low PING_Base + index

	' Send the PING sensor pulse
	pulsout PING_Base + index, PING_Trigger

	' Read the pulse echo return time
	pulsin PING_Base + index, 0, PING_Echo

	low PING_Base + index

	PING_Distance(index) = (PING_Echo */ PING_Scale) / 2

	if PING_Distance(index) < PING_Dist_Check then
		PING_Dist_Check = PING_Distance(index)
	endif

	if debugoutput then
		serout S_OUT, I9600, "Read_PINGS 1: index = ", DEC index, ", PING_Status = ", DEC PING_Status, ", PING_Dist_Check = ", DEC PING_Dist_Check, ". PING_Distance(index) = ", DEC PING_Distance(index), 13]
	endif

	if PING_Distance(index) <= PING_Threshold(index) then
		PING_Detected(index) = 1

		gosub Power_Of_2									' Calculate bit value for sensor index

		PING_Status = PING_Status + power2					' Add the correct bit value to the IR Status
		
		if debugoutput then
			serout S_OUT, I9600, "Read_PINGS 2: index = ", DEC index, ", PING_Status = ", DEC PING_Status, ", Power2 = ", DEC power2, ", Detected = ", DEC PING_Detected(index), 13]
		endif
	
		if makenoise then
			sound speaker, [dur\note13, dur\note14, dur\note15, dur\note16]
		endif
	endif
next

if PING_Status then
	Behavior_Status = Behavior_Status | Avoid_Bit
endif

return

’ Calculate the correct power of 2 for a bit index
’ Parameter: index. Returns: power2 with the correct power of 2
Power_Of_2:
power2 = 1

if index > 0 then
	for loop = 1 to index
		power2 = power2 * 2
	next
endif

return[/code]

The debugoutput and makenoise variables are defined as BIT and are used to turn on/off debugging output and noises, respectively.

8-Dale