Checking Phase sequence in a 3Ph. supply with uC
Figure 1. Wait until phase A is near peak. Then see whether B or C goes positive first.
Pseudo code
aMax = 0;                        // Peak voltage on phase A
t0 = millis();                   // Start time.

while((millis() - t0) &lt; 100){    // Monitor a few cycles.
  if (Ain0 &gt; aMax){
    aMax = Ain0;                 // Peak voltage phase A.
  }
}
while(Ain0 &lt; aMax * 0.8)         // Wait until A is near peak.
}
while(1 = 1){     // Now wait see which phase comes up first.
  if(Ain1 &gt; aMax * 0.8){         // Phase B.
    dir = 1;                     // ABC sequence.
    break;
  }
  if(Ain2 &gt; aMax * 0.8){         // Phase C.
    dir = 0;                     // ACB sequence.
    break;
  }
}