Phase Sequence Detection of 3 Phase Supply

I need help regarding the arduino code for phase sequence detection. I want to generate an interrupt and light an led if the phase sequence is disturbed.
In the circuit diagram, I am using a diode to rectify the 5V AC sine wave into a positive half wave and supplying that to the analog pins of the arduino.
I want to detect if there is an error in the phase sequence. In addition to that i also want to generate an interrupt if there is a lag other than the normal lag between the three phases

What would generate that interrupt? Interrupting what?
What curcuit diagram? Nothing is visible here.
More interrupt... Interrupting what? Why?

Why not involve DMA? It's even more sophisticated then Interrupts....

My first question is the source of you 3 phase supply. If from the mains then that has to be addressed first.

Next is; what do you consider out of sequence phases? A lost phase? or actually reversed position?

How does your Arduino know the phase relationship?

Wouldn't it be easier to use three zero-crossing detector modules?
Leo..

1 Like

Not a complete solution but should illustrate the principle. Probably room, too, for code critique but, still.

reversed position

What if we give the 3 phases at 3 analog inputs and note their rising edges?
The rising edges should come in sequence for example R,Y,B . No?

No! What if you read Y,B,R or B,R,Y. Are you playing with a DELTA wiring or a "Y" wiring system?

The sequence should only be R,Y,B
it should generate an interrupt on any other sequence

Is it mains? If so you should have transformers to isolate the voltage. I've used AC output wall warts for some applications.

I would use transistors on the output of the transformer (with the appropriate series resistor) as kind of a Zero Crossing detector.

I don't see how you could generate an interrupt without external circuitry, however AC is slow (assuming 60 Hz or less).

You can simply code the sequence, perhaps as a binary with the first 3 positions the phases, then test if the binary sequence is incorrect.

For lag you would have to do some time testing between zero crossings. Still should be simple as the Arduino will be so much faster than the AC line.

A stepdown transformer steps it down to 12V AC, then a voltage divider drops it down to 5V AC, and a diode rectifies it to positive half sine wave which is then fed to the arduino

Kindly guide me regarding the code for the last two points that you mentioned

As said, three zero crossing detector modules with opto couplers, to three digital inputs. Then it should be a simple matter of detecting the time that the next pulse occors, from which phase.
Leo..

Since opto isolators have a diode drop (shifting the "ideal" zero crossing). I believe transistors will do the same thing will fewer parts.

I would have to think about it but the approach I would takes is to list in a table (pencil and paper OK) the desired sequence. Then list an example of an error condition.

Consider your input is
R Y B
1 0 1 < variable = Last condition
and the next sequence is
1 1 0 < variable = current condition

Write an if test to see that 101 precedes 110.
Then make 110 your last condition etc

Nice.

It might be more fun (!) if you used three additional inputs, and actually wired the LED outputs of your synthesizer to them, and they were the inputs to your analyser.

I can't try that from where I am just now, I'll try it when I get to the lab.

a7

You find an AC mains zero crossing detector integrated with an arduino here: Zero-Crossing Detectors Circuits and Applications . One circuit uses an interesting optocoupler with back to back leds.

I have done it

const int inputPins[] = {A0, A1, A2}; // Analog input pins
const int numPins = 3; // Number of analog input pins

unsigned long risingEdgeTimes[numPins] = {0}; // Array to store rising edge times

void setup() {
  Serial.begin(9600);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
}

void loop() {
  // Monitor rising edges on each input pin
  for (int i = 0; i < numPins; i++) {
    int previousValue = analogRead(inputPins[i]);
    unsigned long previousTime = micros();
    
    while (true) {
      int currentValue = analogRead(inputPins[i]);
      
      // Check for rising edge
      if (currentValue > 512 && previousValue <= 512) {
        risingEdgeTimes[i] = micros();
        break; // Exit the while loop once the rising edge is detected
      }
      
      // Update previousValue and previousTime
      previousValue = currentValue;
      previousTime = micros();
    }
  }

  // Display rising edge times for each input pin
  Serial.println("Rising Edge Times:");
  for (int i = 0; i < numPins; i++) {
    Serial.print("Pin ");
    Serial.print(i + 1);
    Serial.print(": ");
    Serial.print(risingEdgeTimes[i]);
    Serial.println(" microseconds");
  }
  
  // Check for desired time intervals for A1 and A2
  if (!(risingEdgeTimes[1] - risingEdgeTimes[0] >= 6500 && risingEdgeTimes[1] - risingEdgeTimes[0] <= 7000)) {
    // A1 rising edge did not occur 6.5ms to 7ms after A0 rising edge
    digitalWrite(3, HIGH);
    Serial.println(risingEdgeTimes[1] - risingEdgeTimes[0]);
  }
  if (!(risingEdgeTimes[2] - risingEdgeTimes[1] >= 6500 && risingEdgeTimes[2] - risingEdgeTimes[1] <= 7000)) {
    // A2 rising edge did not occur 6.5ms to 7ms after A1 rising edge
    digitalWrite(4, HIGH);
    Serial.println(risingEdgeTimes[2] - risingEdgeTimes[1]);
  }
  if (!(risingEdgeTimes[2] - risingEdgeTimes[0] >= 13000 && risingEdgeTimes[2] - risingEdgeTimes[0] <= 14000)) {
    // A2 rising edge did not occur 13ms to 14ms after A0 rising edge
    digitalWrite(5, HIGH);
    Serial.println(risingEdgeTimes[2] - risingEdgeTimes[0]);
  }
    
  // Add a delay between measurements if needed
  delay(1000);
}

Don't know why some have to re-invent the wheel.
Phase failure relays have been around since Adam was a boy.
Not only do they detect phase failure, but also under and over voltage and phase reversal or sequence.