https://www.electrosal.com/product/automatic-phase-selection-using-pic-microcontroller/