View Single Post
  #13   Spotlight this post!  
Unread 04-02-2008, 17:46
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Ultrasonic sensors on digital ports 3-6 problems

Quote:
Originally Posted by wt200999 View Post
I wrote a program to run this sensor (Parallax PING))) ) for ports 1&2, and it worked fine, but I decided I would rather have them on ports 3-6 and have 1&2 for my encoders, so I re-wrote my code, and now it doesn't work properly. I end up getting one high number when I first turn on the robot, then a steady number of 35 for the distance and 25 for the time. Here is my code:

http://www.easternfront.org/ultrasonic_port_3_6.zip

I had several printf's spread around in it to see if I was getting to all of the places in my code, thats what that phasetest is. My implementation of it in the default routine is:

Code:
if(x==1)
{
    Ping(3);
}
 
if(x==20)
{
     printf("Distance:%d Time%d\r",Get_Distance(3),Ultrasonic_3_Time);
     x=0;
}
x++;
Any help would be greatly appreciated, thank you.
I had a quick look at your code and found what I think are a few errors. Have a look at the attached file for my comments (search on "RKW").

-Kevin

Edit: It looks like you're driving the sensor with a digital I/O pin and then using a separate interrupt pin to time the pulse. I had assumed you were doing both from one pin, so you can ignore my comment about the TRISB register.
Attached Files
File Type: c Ultrasonic - RKW Edit.c (8.8 KB, 109 views)
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org

Last edited by Kevin Watson : 04-02-2008 at 18:36.