     if(currentTick[8]>=currentPeriod[8]){
       if(currentPosition[8]>=MAX_POSITION){
         sbi(portb,1);
+        sbi(portbdirection,1);
       }else if(currentPosition[8]<=MIN_POSITION){
         cbi(portb,1);
+        cbi(portbdirection,1);
       }
 
       if(ebi(portb,1)){


      if(ebi(portd,4)){
        cbi(portd,4);
        cbi(portddirection,4);
      }else{
        sbi(portd,4);
        sbi(portddirection,4);
      }
      currentTick[4]=0;
    }

    if(currentTick[16]>=currentPeriod[16]){
      if(currentPosition[16]>=MAX_POSITION){
        sbi(portc,3);
        sbi(portcdirection,3);
      }else if(currentPosition[16]<=MIN_POSITION){
        cbi(portc,3);
        cbi(portcdirection,3);
      }

      if(ebi(portc,3)){
