8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
nicholastyc
Wed May 07 2008, 10:43PM
 User Offline
Registered Member #7707
Joined: Wed May 07 2008, 07:13PM

Posts: 38
Thanked 1 time in 1 posts
Hi,
I think of it ...but could not figure out a right way, please help.
I need a shaft encoder code on direction.

Need help...

thanks

Hi,
i found a code bbut i don really understand about the last 2 line,
--------------------------------------------------------------------------------------------------
extern signed short angle; /* rotation since reset */
static unsigned char ab = 0; /* the old value of the sensor ports */
const signed short table[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
/* increment of angle for the 16 possible bit codes */
ab = ab << 2; /* move the old data left two places */
ab |= (port & 0x3); /* OR in the two new bits */
angle += table[(ab & 0xf)]; /* get the change from the 16 entry table */

-------------------------------------------------------------------------------------------------
http://www.mkesc.co.uk/ise.pdf

details on the document...

Thanks...
what i want to know is ... wat is the port stated here and why 0&3 ?
then... angle += table[(ab & 0xf)]; then wat is this means?




[ Edited Thu May 08 2008, 12:48AM ]
Back to top


Ajay
Thu May 08 2008, 04:53PM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3304
Thanked 611 times in 578 posts
There can be three cases:
first shaft rotated clockwise: +1
shaft rotated anti-clockwise: -1
shaft did not rotate: 0

as per the datasheet of encoder, there are four cases for +1 and four for -1 rest all are 0.
CODE:
//By default or at starting ab is 0
//means your shaft did not move or still
ab = ab << 2;
// Now you shifted the already read value of ab by 2 bits
// so that you can accommodate new two bits from encoder
// there new two bits give the current movement of shaft
ab |= (port & 0x3);
// now you read the two bits from port and appended it with old bits
// and you have a 4bit number now
// see table on page 2 of datasheet, every number tells you whether your shaft moved clockwise or anti-clockwise.
// these values are stored in array and read with current value of ab
 



www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems