Go to Post The GDC is becoming sane. - Zuelu562 [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 14-11-2008, 17:15
pogenwurst pogenwurst is offline
Ubuntu User
AKA: Brian
FRC #2007 (Robots of the Round Table)
Team Role: Leadership
 
Join Date: Jan 2008
Rookie Year: 2007
Location: Duluth, GA
Posts: 78
pogenwurst is on a distinguished road
Send a message via AIM to pogenwurst
Troublesome encoder ISR

I'm having trouble with the encoder interupt routine I wrote yielding incorrect results. The tick count increases overall, but along the way the count "rolls back" despite the shaft turning in the same direction.

Would anyone care to make a quick check of it for me? It may just be a silly mistake, but I've gone over it again and again and still can't see where I've gone wrong.

A little background:
-> I'm only using one encoder, and resolution is very important for the task at hand, so I'm using the interrupt on digital inputs 3-6 (channel A is in 3, channel B is in 4) so that I can count the ticks for both channels and on both rising and falling transitions.
-> This is on a Vex controller, so I'm using the IFI code, not Kevin's.
-> The following code is contained within the appropriate conditional branch for interrupts 3-6.
-> "encoderCount" is a global volatile signed long, and oldPORTB is a global unsigned char (I use it nowhere but the ISR, so it needn't be indicated as volatile, correct?).

Code:
	const unsigned char aMask = 0x10;
	const unsigned char bMask = 0x20;

	unsigned char a = (PORTB & aMask) == aMask;
	unsigned char b = (PORTB & bMask) == bMask;

	if((PORTB ^ oldPORTB) == aMask)
	{
		if(a)						// a transitioned high
		{
			if(b)					// b is high
				++encoderCount;
			else					// b is low
				--encoderCount;
		}

		else						// a transitioned low
		{
			if(!b)					// b is low
				++encoderCount;
			else					// b is high
				--encoderCount;
		}
	}

	else if((PORTB ^ oldPORTB) == bMask)
	{
		if(b)						// b transitioned high
		{
			if(!a)					// a is low
				++encoderCount;
			else					// a is high
				--encoderCount;
		}

		else						// b transitioned low
		{
			if(a)					// a is high
				++encoderCount;
			else					// a is low
				--encoderCount;
		}
	}

	oldPORTB = PORTB;

	INTCONbits.RBIF = 0;     /*     and clear the interrupt flag         */
Thanks for any help you can offer
 


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
Encoder help E_Unit Electrical 5 16-02-2007 11:02
Encoder Death rfolea Programming 8 14-02-2007 14:06
Encoder Problems bjimster1 Programming 2 10-02-2007 08:04
Encoder Hookup kutty18 Electrical 4 22-01-2005 12:17
encoder.c Gary Bonner Programming 2 14-01-2005 13:41


All times are GMT -5. The time now is 00:04.

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