fixed the off by 1 pixel bug, fix counter next

need to stop counter when ivalid is low