Also, you might want to make sure your command protocol is robust, such that it checks and detects errors in the data stream and doesn't simply assume anything given to it is a valid command. You might want to have your command parser , whe nit sees an invalid command, have it raise an IO pin and simply spin so that you can see if that it what is going on.
You could have stack corruption. You could have noise on your encoder data lines... the possibilities are rather numerous.
Tricks.
Keep a set of io pins spare that you can attach led's to, or a scope to, and have your code write out to these IO pins constantly so that you can follow where it is in the software. You can also use these to display error conditions such that when you have a section of code processing data that you KNOW should be within a certain range, and find out that it's not, you can raise one of the lines or write a certain value to the data lines. Using one line per error is the best so that you can keep track of multiple errors, using all the lines to encode a value gives you more error codes you can watch for though, however, the rate of error writes to those pins would predicate the need for a logic analyzer or some way to record the changes that go onto them.
Good luck.
Horsedorf |