Go to Post Off-topic: THIS IS THE REASON WHY I LOVE FIRST! - FlyingD662 [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Spotlight this post!  
Unread 21-03-2006, 22:36
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: Ultrasonic will not work with another Ultrasonic plz help

Here is a code fragment for managing 3 ultrasonic sensors:

Code:
int Service_Ultrasonic_Sensors (void)
{

  ultra_counter++;
  switch (ultra_counter)		// Process Ultrasonic Transducer
	{
	case 1:
	  for (pulsecount = 0 ; pulsecount < PULSE_WIDTH ; pulsecount++)
		{
		rc_dig_out10 = 1;		//	Make another pulse
		};
	  rc_dig_out10 = 0;			//	The pulse is over
	  break;
	case 2:
	  for (pulsecount = 0 ; pulsecount < PULSE_WIDTH ; pulsecount++)
		{
		rc_dig_out11 = 1;		//	Make another pulse
		};
	  rc_dig_out11 = 0;			//	The pulse is over
	  break;
	case 3:
	  for (pulsecount = 0 ; pulsecount < PULSE_WIDTH ; pulsecount++)
		{
		rc_dig_out12 = 1;		//	Make another pulse
		};
	  rc_dig_out12 = 0;			//	The pulse is over
	  break;
	case 4:
	  if (ultra_left_flag == TRUE)
		{
		INTCONbits.GIEL = 0;		//	Disable Low Priority Interrupts
		ultra_left_time = ultra_left_stop - ultra_left_start;
		INTCONbits.GIEL = 1;		//	Enable Low Priority Interrupts
		ultra_good_count++;
		}
	  else
		{
		ultra_left_time = -1;
		ultra_bad_count++;
		};
	  if (ultra_front_flag == TRUE)
		{
		INTCONbits.GIEL = 0;		//	Disable Low Priority Interrupts
		ultra_front_time = ultra_front_stop - ultra_front_start;
		INTCONbits.GIEL = 1;		//	Enable Low Priority Interrupts
		ultra_good_count++;
		}
	  else
		{
		ultra_front_time = -1;
		ultra_bad_count++;
		};
	  if (ultra_right_flag == TRUE)
		{
		INTCONbits.GIEL = 0;		//	Disable Low Priority Interrupts
		ultra_right_time = ultra_right_stop - ultra_right_start;
		INTCONbits.GIEL = 1;		//	Enable Low Priority Interrupts
		ultra_good_count++;
		}
	  else
		{
		ultra_right_time = -1;
		ultra_bad_count++;
		};
	  ultra_left_flag = FALSE;
	  ultra_front_flag = FALSE;
	  ultra_right_flag = FALSE;
	  ultra_counter = 0;
	  break;
	default:							// for any unexpected result
	  ultra_left_flag = FALSE;
	  ultra_front_flag = FALSE;
	  ultra_right_flag = FALSE;
	  ultra_counter = 0;
	  break;
	};
   
}
The code above can be called once per communications loop or via a timer interrupt, et cetera...

the variables ultra_bad_count and ultra_good_count were used during development and can be deleted.

An example interrupt routine is:

Code:
void Service_DIO4_Interrupt(unsigned char state)
{
	if (state == 1)						 // rising-edge interrupt
	{
	ultra_front_start = Read_Timer_3 ();	 // Read Start Time.
	}
	else									// falling-edge interrupt
	{
	ultra_front_flag = TRUE;
	ultra_front_stop = Read_Timer_3 ();	  // Read Stop Time
	}
}
The user routine has only to test for the time to be greater than zero to know that it is valid data.

Hopefully, this helps.


Mike
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
3D Studio Max won't work David the bomb 3D Animation and Competition 3 03-03-2004 17:12
Problems of the mind... effecting work Gadget470 Chit-Chat 20 18-11-2003 11:56
Edit doesn't work on original title posts??? Elgin Clock CD Forum Support 6 12-03-2003 17:30
Who knows how the motors [I]really[/I] work? Wetzel Chit-Chat 5 13-02-2002 21:50
Does anyone on this board work at home depot? mnkysp6353 General Forum 2 30-12-2001 13:27


All times are GMT -5. The time now is 03:31.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi