Go to Post The part I like best is your method of transfering the torque via the balls. Very elegant. - Joe Johnson [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
  #1   Spotlight this post!  
Unread 17-01-2005, 17:32
pickle's Avatar
pickle pickle is offline
Talking vegtable
AKA: Jeremy
#1296 (Full Metal Jackets)
Team Role: Programmer
 
Join Date: Apr 2004
Rookie Year: 2004
Location: Rockwall,TX
Posts: 42
pickle is on a distinguished road
Send a message via AIM to pickle
Code violation using Hall effect sensor

I need some serious help here, so, I have been using the Hall effect sensors to count gear teeth and get an RPS for the wheels. It works pretty well. I was told to check the sensor every millisecond, so I set an interrupt to fire every millisecond and do a little math.

Code:
	// this function will be called when a timer 2 interrupt occurs

	static unsigned char lastHighL = 0; //The last value seen was a high
	static unsigned char lastLowL = 0; //The last value seen was a low
	static unsigned char lastHighR = 0; //The last value seen was a high
	static unsigned char lastLowR = 0; //The last value seen was a low
 	msClock++; // increment the millisecond clock
	if(msClock > 0 && msClock % 26 ==0)
		return;
	
	//Count the changed between highs and lows	

	if(Get_Analog_Value(rc_ana_in01) > 900 && lastLowL)
	{
		lastHighL=1;
		lastLowL=0;
		leftTicks++;
	}
	else if(Get_Analog_Value(rc_ana_in01) < 100 && lastHighL)
	{
		lastHighL=0;
		lastLowL=1;
	}
	else if(!lastHighL && !lastLowL && Get_Analog_Value(rc_ana_in01) > 900)
	{
		lastHighL=1;
		lastLowL=0;
	}
	else if(!lastHighL && !lastLowL && Get_Analog_Value(rc_ana_in01) < 100)
	{
		lastHighL=0;
		lastLowL=1;
	}



	if(Get_Analog_Value(rc_ana_in02) > 900 && lastLowR)
	{
		lastHighR=1;
		lastLowR=0;
		rightTicks++;
	}
	else if(Get_Analog_Value(rc_ana_in02) < 100 && lastHighR)
	{
		lastHighR=0;
		lastLowR=1;
	}
	else if(!lastHighR && !lastLowR && Get_Analog_Value(rc_ana_in02) > 900)
	{
		lastHighR=1;
		lastLowR=0;
	}
	else if(!lastHighR && !lastLowR && Get_Analog_Value(rc_ana_in02) < 100)
	{
		lastHighR=0;
		lastLowR=1;
	}	

	if(leftTicks == GEAR_TEETH)
	{
		leftTicks=0;
		leftRevo++;
	}
	if(rightTicks == GEAR_TEETH)
	{
		rightTicks=0;
		rightRevo++;
	}

	//Every second, increment secClock
	if(msClock%1000 == 0 && msClock>0)
	{
		secClock++;
	}

	//Calculate RPS every 4 seconds
	if(secClock>0 && secClock % 4 ==0)
	{
		leftRPS=leftRevo/secClock;
		rightRPS=rightRevo/secClock;
	}
This is what I have going right now in that interrupt, most of it is just incrementing variables and such, so it shouldn't be too much, though I am worried that the division is taking too long. Is there anything I can do to optimze this? Or am I overlooking something? I told the interrupt to return immediately after starting if the number of milliseconds is divisible by 26, so every 26ms, return without doing any processing (I'm concerned that all that code may take more than .2 ms, and I think the 1ms check should be more than enough to skip once without too many detrimental effects, though I could be wrong). I then plugged it into the dashboard to try and get more details, as the manual suggests, and it tells me "User violation: Invalid CONTROL or CURRENT_MODE byte". Any clue what that means? I sure have no clue....... Any help would be wonderful, or ideas, or better ideas. :'( :'( :'( :'( I'm going nuts, and I have an angry teacher glaring at me and breathing down my neck...... That would be grand if any of you can help
__________________
2004 Rookie Inspiration Award winner - Midwest Regional
2004 Autodesk Visualization Award winner - Lone Star Regional
2004 Quarterfinalist - Lone Star Regional
2005 Team Spirit Award - Lone Star Regional
 


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
Hall Effect Sensor. Nixterrimus Electrical 77 29-01-2005 10:48
Coding / Style Standards for sharing C code Joe Johnson Programming 33 01-05-2004 15:15
heres the code. y this not working omega Programming 16 31-03-2004 15:18
Strange IR sensor movement with default tracker code wun Programming 5 19-03-2004 10:51
Infrared Beacon and Sensor Diagnostics Code Released Kevin Watson Programming 3 25-02-2004 17:50


All times are GMT -5. The time now is 14:44.

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