In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Johnson Rod wrote: hail the project: in a continous rotation drive one encoder returns command (where do i want the drive to point), another returns feedback (where the drive is pointing). the controller compares the 2 encoders w/ a simple algorithm and turns the drive so that the feedback matches the control. the algorithm: if command = feedback then dont move if command - feedback < feedback - command then turn clockwise if command - feedback > feedback - command then turn counterclockwise the trouble: the encoders have 512 bits of resolution, to simplify the project i ignored the lsb and voila. the algorithm applies directly to the sx because the byte sized variable wraps around itself. that is 1 - 255 = 1 255 - 1 = 254 so go clockwise. but i think i can do better! i can do this with 9 bits.... ok i cant because i'm stuck on this snippet ; btw testcw = cmd mov w, feedback0 ; testcw = cmd - fbk sub testcw0, w mov w, feedback1 sc movsz w, ++feedback1 sub testcw1, w the result is true 16bit and wraps around 65535, but i need it to wrap around 511. my previous sub wrapping script would dec the variable in a loop and detect for overflow. but thats way to slow. does anyone have any experiance with this? any help would be well received. a attached 2 files, apec256 is the working 8b program and is well commented apec512 is the partial program in question and is poorly commented future thanks for your generous reply nickB ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=89622 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2005 (http://www.dotNetBB.com)