 
 
 //program variables
-#define MAXCURRENT 1.5 //peak rotational current. Actual max current hit may be slightly higher
+#define MAXCURRENT 0.2 //peak rotational current. Actual max current hit may be slightly higher
 
 
 volatile long encoderTicks = 0;

  
  else //otherwise if same coil being used, check for overcurrent. If over, disable. If under, update pwm
  {
    int coilCurrent = readCurrent(); //read current is very slow because analog read sucks
//    if (coilCurrent > currentThresh) // !!! may need to fully ground coil instead of just cutting and making floating !!!
//      disableMotor();
//    else
//      setPWM(correctedOutput);
  }
  long endtme = micros();
  if (!stateChangeFlag)
    Serial.println(endtme - starttime);
}

void disableMotor()
{
//  PORT->Group[PORTA].OUTCLR.reg = 111011000000010000000; //turns off all mosfets using registers

  PORT->Group[PORTA].OUTCLR.reg = (1<<15);
  PORT->Group[PORTA].OUTCLR.reg = (1<<20);
  PORT->Group[PORTA].OUTCLR.reg = (1<<7);

}

/* MOSFET STATES */
void state0(double pwmfreq) //P2N3
{
  PORT->Group[PORTA].OUTSET.reg = (1<<20);
  PORT->Group[PORTA].OUTSET.reg = (1<<19);
}

void state1(double pwmfreq) //P1N3
{
  PORT->Group[PORTA].OUTSET.reg = (1<<15);
  PORT->Group[PORTA].OUTSET.reg = (1<<19);
}

void state2(double pwmfreq) //P1N2
{
  PORT->Group[PORTA].OUTSET.reg = (1<<15);
  PORT->Group[PORTA].OUTSET.reg = (1<<16);
}

void state3(double pwmfreq) //P3N2
{
  PORT->Group[PORTA].OUTSET.reg = (1<<7);
  PORT->Group[PORTA].OUTSET.reg = (1<<16); 
}

void state4(double pwmfreq) //P3N1
{
  PORT->Group[PORTA].OUTSET.reg = (1<<7);
  PORT->Group[PORTA].OUTSET.reg = (1<<18);
}

void state5(double pwmfreq) //P2N1
{
  PORT->Group[PORTA].OUTSET.reg = (1<<20);
  PORT->Group[PORTA].OUTSET.reg = (1<<18);
}

void stateGND() //N1N2N3
{
  PORT->Group[PORTA].OUTSET.reg = (1<<16);
  PORT->Group[PORTA].OUTSET.reg = (1<<18);
  PORT->Group[PORTA].OUTSET.reg = (1<<19);
}

