Thursday, February 16, 2012

Day Twenty-Three

Today I tinkered with the code that does a better increment without using assembly. Tinkered cuz it STILL doesn't work properly. But in this case, while it can keep up with the speed of the arm, both directions doesn't count in their own direction. Like Channel A is ++ and Channel B is --, but it only counts ++ or -- depending on the code setup.

The current code for counting is as follows:
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5000000
  Ao = 20
  Bo = 21

VAR
  long counter

PUB Main | newBits, oldBits, direction
  dira[Bo..Ao]~
  dira[1..16]~~
  oldBits := ina[Bo..Ao]
  counter := 0
  repeat
    outa[1..16] := counter/1000
    newBits := ina[Bo..Ao]
    if newBits <> oldBits
      direction := (newBits & %1) * (oldBits >> 1)
      case direction
        0 : counter++ 'one direction works perfectly but the
        1 : counter-- 'other doesn't when the first does work.
      oldBits := newBits

No comments:

Post a Comment