Synchronous Transfer Switch
Synchronous Transfer Switch

Synchronous Transfer Switch

The Synchronous Transfer Switch in this project is for moving connections from one source to another. In contrast to ordinary switches, this device will switch the connection only when the phase angle of the two sources is the same.

When we move the connection that is done manually then this device will take over the transfer task.
Its job is to detect differences in phase angles. If there are differences, the transfer is delayed. If the phase angles are the same then the transfer is carried out.

I will use this synchronous transfer switch on transfers with regular inverters and grid sources.

Circuit

I use a circuit like the one below:

Zero Crossing Detector Schematic
220 V relay connection

Using Dual Comparator LM393 with clipper diodes, each of which is used to detect zero crosses from two sources. A push-on switch as the transfer command input and a 5V relay to actuate the source switching 220V relay.

The output of the comparator is connected to the Arduino UNO interrupt input (INT0 and INT1).

Code

As usual in setup() I define I/O first including the pins and also the interrupts that I use.

void setup() {
  pinMode(source1in,INPUT_PULLUP);  // AC source 1
  pinMode(source2in,INPUT_PULLUP);  // AC source 2
  pinMode(buttonPin,INPUT_PULLUP);   // transfer command button
  pinMode(relayOut,OUTPUT);         // relay drive 
  pinMode(ledBuiltIn,OUTPUT);       // out of phase indicator
  attachInterrupt(digitalPinToInterrupt(source1in), source1, FALLING); //ISR
  attachInterrupt(digitalPinToInterrupt(source2in), source2, FALLING); //ISR
  switchOverStatus=0;
  Serial.begin(115200);
}

ISR

The first four lines are for I/O initialization and the next two lines are for the interrupt (ISR). The ISR function which I named source1() will be called when at pin 2 (INT0) there is a logic change from high to low. And also for source2().

void  source1(){      //ISR for source1
  micros1 = micros(); //store arduino timestamp when source 1 zeo crossing detected 
}

When there is an interrupt from pin 2 this function reads the micros() value from Arduino and stores it as micro1. The same way happens to the interrupt at pin 3 which is stored in micros2. The micro1 and micros2 values ​​will be used in the calculations in the loop().

Loop

void loop() {
  int buttonStat;
 
  if (switchOverStatus==0){  
    buttonStat=digitalRead(buttonPin);         
    if (buttonStat==0) {
      switchOverStatus=1;
      digitalWrite(ledBuiltIn, switchOverStatus); 
      delay(5);
    }
  } 
  else{
    timeDiff = micros2-micros1;
    if (timeDiff<=switchOverTimeDiff){             
      digitalWrite(relayOut,!digitalRead(relayOut));  
      switchOverStatus=0;                                 
      digitalWrite(ledBuiltIn, switchOverStatus);         
      delay(1000);
    } 
  }
}

I use switchOverStatus register as an indication of the transfer process. If the content is “1” indicates that the transfer is in progress because there is still a difference in phase angle.

When the system is powered up the switchOverStatus register will contain a zero value. In this condition, the switch-over button is ready to accept the transfer order. When pressed the buttonStat will be “Low” and when low then switchOverStatus is now changed to a logic “1”.

Because now the contents of switchOverStatus have changed, on the next iteration the instruction part in “if” will be skipped. And what will be executed is the instruction in the “else” section, which is to calculate the phase angle difference between the two sources.

In this section, if the time difference is smaller than specified (almost in phase), the relay will switch connection positions. Note that the phase angle difference here is in microseconds. At 50Hz the phase angle difference of one degree is equal to 55 microseconds, at two degrees is 110 microseconds and so on.

In addition, when a switchover occurs, the contents of the switchOverStatus register are returned to “0“, which means that the next process is to wait for the switch to be pressed again.

That is all and thank you