'************************************************************* 'ENCODERTASK 'Checks encoder inputs, inc/dec tic count depending upon motor dir 'This is run as a multi-tasking operation to trap encoder tics '************************************************************* sub EncoderTask() 'Init encoder pins and hold variables - i.e. inputs as tristate OldLEncoder = GetPin(LEncoderPin) OldRencoder = GetPin(REncoderPin) Do 'Endless loop of checking encoders LEncoder = GetPin(LEncoderPin) 'get current left encoder pin status If (LEncoder <> OldLEncoder) then 'if not like old value we have a transition OldLEncoder = LEncoder If LMotorDir = 1 then 'if forward then count up, else down LeftTicCount = LeftTicCount + 1 else LeftTicCount = LeftTicCount - 1 end if end if REncoder = GetPin(REncoderPin) 'get current right encoder pin status If (REncoder <> OldREncoder) then 'if not like old value we have a transition OldREncoder = REncoder If RMotorDir = 1 then 'if forward then count up, else down RightTicCount = RightTicCount + 1 else RightTicCount = RightTicCount - 1 end if end if Delay( 0.0 ) 'give up some time for other activity Loop end sub