Pregunta

How do I create a state transition table/array in actual code/pseudo-code?

I haven't experienced the "ah-ha" moment yet with the state machine to coding (and I really want to). I've looked at several code sample and read blog posts, but it's not clicking yet.

I'm looking for a pragmatic explanation of how the state transition table works and how it's created in an array format. If possible, is there a "step-by-step" method to get to the solution?


The particular case/excercise I'm working on is this: I'm writing a gray-code rotary encoder driver for A micro-controller based on the .netMF framework. It's not real-time and therefore changes the rules a little. Interrupts are captured and queued and then run in a high priority thread. There is a delay so it makes capturing the state of the both encoder pins at the actual time of interrupt in-accurate. In-accurate enough to cause some errors. That being said, when the interrupt is queued, it's state IS captured at that time. When the ISR is finally executed, the pin's state state is passed into it as an argument. Therefore, I can only get ONE pin's state at a time. I think that's sufficient to get this working.

Encoder States For Pin A and B:
A B
0 1
0 0
1 0
1 1 - base state(neutral position of the encoder) (move up for one direction and down for opposite direction)
0 1
0 0
1 0

The mechanical bounce in the encoders will be captured and queued as well, but from what I understand, the state machine can handle these "errors" and continue to produce a good result if the device makes it through a cycle.

I hope this question is clear. I can add additional information as needed.

No hay solución correcta

Licenciado bajo: CC-BY-SA con atribución
No afiliado a cs.stackexchange
scroll top