Best Answer gismo, 24 March 2014 - 01:38 AM
Thanks for that! It's still odd behavior, but I ditched those Read call. I was actually thinking about it, but then was wondering how to capture both pin states at the time of interrupt...Because I saw used that method used in some examples.
Here's what I came up with in my driver:
void RotationInterrupt(uint data1, uint data2, DateTime time)//Data1 Is Pin Data 2 Is Pin.Read() { if (data1 == (uint)PinA.Id && data2 == 0)//Pin A Goes LOW { State[StateCount] = 1; } else if (data1 == (uint)PinA.Id && data2 == 1) //Pin A Goes HIGH { State[StateCount] = 2; } else if (data1 == (uint)PinB.Id && data2 == 0) //Pin B Goes LOW { State[StateCount] = 3; } else if (data1 == (uint)PinB.Id && data2 == 1) //Pin B Goes HIGH { State[StateCount] = 4; } StateCount++; if (StateCount == 2)//we've collected two states. Let's compare them and return a rotation direction { StateCount = 0; //reset the state count //COUNTERCLOCKWISE if (!SkipFirstInterrupt) { if ((State[0] == 1 && State[1] == 3) || (State[0] == 2 && State[1] == 4)) { //do counterclockwise RotationEventHandler(COUNTERCLOCKWISE, 0, DateTime.Now); } else if ((State[0] == 3 && State[1] == 1) || (State[0] == 4 && State[1] == 2)) { //do clockwise RotationEventHandler(CLOCKWISE, 0, DateTime.Now); } } SkipFirstInterrupt = !SkipFirstInterrupt; } }
Seems to be working pretty well!
Go to the full post