In SX Microcontrollers, SX/B Compiler and SX-Key Tool, PJMonty wrote: Matthias, I have used this algorithm on different processors before, but in C. Since I don't normally use SX/B, I'm just not familiar enough with its syntax, which is why I wrote it out in pseudo-code. Have you verified that both outputs on your encoder are producing a signal? A oscilloscope is the easiest way to check, but you could also do it with a voltmeter if you turn the encoder very slowly to catch the signal going high and low. If one of your outputs is dead (or not hooked up right), then that would explain why you only get one direction. You can swap the A and B output leads from the encoder to the SX and see if you only get -1 and 0. If so, then you know something is up with one of the channels. I have used US Digital optical encoders before. They are well made and won't need any debouncing. BTW, you should move the table creation out of the interrupt loop. Build it once at the beginning of your code and then use the table from within the interrupt handler. Also, if you want, you can change the line: PrevEncoderInput = PrevEncoderInput * 4 to read: PrevEncoderInput = PrevEncoderInput SHL 2 This will explicitly tell the compiler to left shift the value two places rather than hoping the compiler optimizes it correctly. Also, you can test if negative values are allowed in SX/B tables by writing a simple bit of code like this: CurrentPosition = 100; CurrentPosition = CurrentPosition + EncoderTable(2) Here you are setting an initial value of 100 in the variable, and then adding a table entry to it that has a negative value. If "CurrentPosition" = 99 after that line is run, then you know SX/B allows negative values in tables. Thanks, PeterM ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=375331#m376221 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)