by David Kott
struct RotaryEncoderStruct {
int unused:4; // RB[0:3]
int A:1; // RB4
int B:1; // RB5
int unused2:2; // RB6-7
};
struct RotaryEncoderStruct RotaryEncoder;
#pragma BYTE PORTB = 0x06
#pragma BYTE RotaryEncoder = 0x06 // Place structure right over PORTB at
location 0x06
USHORT g_usEncoderCount = 0;
#pragma INT_RB
void
PortBInterrupt (void)
{
static BYTE OldPortB;
BYTE byTemp;
static struct RotaryEncoderStruct OldEncoder;
if (OldPortB != (byTemp=(PORTB & 0x30))) {
OldPortB = byTemp;
if (RotaryEncoder.A == OldEncoder.A) {
if (RotaryEncoder.B == RotaryEncoder.A)
--g_usEncoderCount;
else
++g_usEncoderCount;
} else {
OldEncoder.A = RotaryEncoder.A;
if (RotaryEncoder.B == RotaryEncoder.A)
++g_usEncoderCount;
else
--g_usEncoderCount;
}
}
// Handle more PORTB stuff here, like a button, or something.
}
Questions:
How many machine cycles does this take to run (worst case)? This sets the maximum rotational speed of encoder that can be tracked (tempered by the processor clock speed and the encoder resolution in lines/rev, obviously)+
Comments:
See also:
| file: /Techref/microchip/language/c/io/qenc-dk.htm, 2KB, , updated: 2009/4/22 23:22, local time: 2013/5/19 20:44,
54.224.75.101:LOG IN |
| ©2013 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://www.piclist.com/techref/microchip/language/c/io/qenc-dk.htm"> PIC C I/O Routine - Quadrature Encoder ISR</A> |
| Did you find what you needed? |
|
o List host: MIT, Site host massmind.org, Top posters @20130519 RussellMc, IVP, John Gardner, veegee, Bob Blick, alan.b.pearce, Sean Breheny, Josh Koffman, Carl Denk, Isaac Marino Bavaresco, * Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: None at this time. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
Welcome to www.piclist.com! |
.