In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Matthias09 wrote: Guys, thanks a lot! I appreciate your support! PJMonty: looks up-in-the-sky and I tried and got it working! However: I monitored the variable CurrentPosition and it only has values between 0 and 1. What's wrong? My clue: I am not sure, if I can assign negative values to variables in SX/B. The compiler says ok, but I think I read somewhere that is not possible. Also your notation didn't work, so I adjusted, which was no problem but made me ask, if this code run on a SX28 before? PJ Allen: it is an optical encoder, US Digital. Thanks for the hint with the SCHMITT command. SX 28 can use ST_B instead. However in the help file nothing is docummented about that. Any idea where I can find some information about that command? [code] INTERRUPT NOPRESERVE 6000 '360*4 = 1440ppr. Max assumed speed: 2 rev/sec. max frequency = 2 rev/sec * 1440pulses/rev = 2880 pulses/sec. Nyquist: Scanning frequency '2x = 5760Hz == 6kHz ISR_Start: '' WKPND_B = int_storage '----- VERSION 5 ----- 'Create a lookup table EncoderTable(0) = 0 EncoderTable(1) = 1 EncoderTable(2) = -1 EncoderTable(3) = 0 EncoderTable(4) = -1 EncoderTable(5) = 0 EncoderTable(6) = 0 EncoderTable(7) = 1 EncoderTable(8) = 1 EncoderTable(9) = 0 EncoderTable(10) = 0 EncoderTable(11) = -1 EncoderTable(12) = 0 EncoderTable(13) = -1 EncoderTable(14) = 1 EncoderTable(15) = 0 ' Get the current encoder values and mask un-used bits CurrentEncoderInput = RC AND %00000011 ' Create entry into lookup table. NOTE: Multiplying times 4 is the same as left ' shifting two places. Depending on the compiler, the leftshift may be faster PrevEncoderInput = PrevEncoderInput * 4 TableIndex = CurrentEncoderInput OR PrevEncoderInput ' Update current position of encoder CurrentPosition = CurrentPosition + EncoderTable(TableIndex) ' Store current encoder inputs for next time PrevEncoderInput = CurrentEncoderInput [/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=375331#m376211 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)