facing problem in running 3 function in arduino

I am making and Arduino program for 3 phase inverter. I have designed 3 functions for each individual phase.
In 3 phase, the 2nd phase has to start at 120 degree with respect to first phase and similarly for 3rd phase.
I calculated a delay for it and i got about 6.67 ms delay. After 6.67 ms delay, function 2 should be start while function 1 should continue executing and after 13.33 ms delay function 3 should start while function 1 and function 2 are executing.

Is the above logic possible? If possible, then how?

You can't have two functions executing simultaneously.

You can have the appearance of two or more functions executing simultaneously, if you follow simple programming rules described here

The Arduino doesn't have an operating system to do multitasking or multi-threading so your sketch can only be executing one function at a time. Some operations can be done with hardware, such as the timers and counters. Without seeing an example of your functions it will be hard to advise how to re-write them to appear to run simultaneously. I suspect you will be using one or more timers to generate three PWM outputs and timer interrupts to schedule the changes in PWM outputs to emulate a sine wave. If you want variable frequency, the design becomes much more complicated.

no i am not using timer to do this

the code i am using is this

float f=50;
float t=(1/f)*1000000;
float a1=17;
float a2=57;
float a1p1=(a1*t)/360;
float a1p2=(a2*t)/360;
float d=5;

int pin1=1;
int pin2=2;
int pin3=3;
int pin4=4;
int pin5=5;
int pin6=6;
int pin7=7;
int pin8=8;

void setup(){
  Serial.begin(9600);
  pinMode(pin1, OUTPUT);
  pinMode(pin2, OUTPUT);
  pinMode(pin3, OUTPUT);
  pinMode(pin4, OUTPUT);
  pinMode(pin5, OUTPUT);
  pinMode(pin6, OUTPUT);
  pinMode(pin7, OUTPUT);
  pinMode(pin8, OUTPUT);
}

void loop(){
 
  
  digitalWrite(pin1,HIGH);
  digitalWrite(pin2,HIGH);
  digitalWrite(pin5,HIGH);
  digitalWrite(pin6,HIGH);
  delayMicroseconds(a1p1-d);                                                                                                                                                                                                                                   

  digitalWrite(pin2, LOW);
  delayMicroseconds(d);
  digitalWrite(pin4,HIGH);
  delayMicroseconds(a1p2-a1p1-d);

  digitalWrite(pin6,LOW);
  delayMicroseconds(d);
  digitalWrite(pin8,HIGH);
  delayMicroseconds(t/2-(2*a1p2)-d);

  digitalWrite(pin5,LOW);
  delayMicroseconds(d);
  digitalWrite(pin7,HIGH);
  delayMicroseconds(a1p2-a1p1-d);

   digitalWrite(pin1,LOW);
   delayMicroseconds(d);
   digitalWrite(pin3,HIGH);
   delayMicroseconds((2*a1p1)-d);

   digitalWrite(pin4,LOW);
   delayMicroseconds(d);
   digitalWrite(pin2,HIGH);
   delayMicroseconds(a1p2-a1p1-d);

   digitalWrite(pin8,LOW);
   delayMicroseconds(d);
   digitalWrite(pin6,HIGH);
   delayMicroseconds(t/2-(2*a1p2)-d);

   digitalWrite(pin7,LOW);
   delayMicroseconds(d);
   digitalWrite(pin5,HIGH);
   delayMicroseconds(a1p2-a1p1-d);

   digitalWrite(pin3,LOW);
   delayMicroseconds(d);
   digitalWrite(pin1,HIGH);
   delayMicroseconds(a1p1);
}

delayMicroseconds does not accept float arguments, so they will be truncated to integers.

The timeshift between the phases is fixed
delay() does block the whole arduino so as long as a delay is executed no other code can be executed.

If this is about 3-Phase AC-current
You have to aproximate a sinewave. This approximation has a timing granularity.
This means there is a fixed number of values. These vlaues could be stored in an array.

As the time-shift is fixed I would use just one loop where the values for each phase are shifted against each other.
And then count up the index-number based on function millis().
If you use rectangular "phases" it will be enough to have an array of 6 elements.
always 3 elements symbolising HIGH 3 elements symbolising LOW
The start when phase 2 is set is HIGH is shifted two index-numbers to the right

The start when phase 3 is set HIGH i shifted 4 indexnumbers to the right. This means the "seventh" indexnumber would be high. instead on phase C index 0 is already high.

see attached grafik

For an aproximated sinewave the array has to be larger but the vlaues are round-shifted 1/3 and 2/3 inside the array.
I would initialise the array with the duty-cycle-values in setup and then you just count through the index and set the outputs with analogWrite() to the values stored in the array elements. At 50 Hz the RC-element has to have a low timing-constant to react fast enough on the continuos change.

best regards Stefan

problem with 50 Hz is

50 Hz = 20 milliseconds = 20.000 microseconds
1 / 6 of this time is 3333**.333** microseconds

1000000 µSecs/sec / (3333*6) = 50.005 Hz

best regards Stefan

So you are using 8 output pins for one phase? That would mean 24 output pins for three phases. Are you using an Arduio MEGA? You can use some of the ports on the MEGA to write 8 bits at a time so that may simplify things.

So the 8 IO-pins are connected to a R2R-ladder DAC?

tested it for rectangular wave-form

//#include 
void PrintFileNameDateTime()
{
  Serial.println("Code running comes from file ");
  Serial.println(__FILE__);
  Serial.print("  compiled ");
  Serial.print(__DATE__);
  Serial.print(" ");
  Serial.println(__TIME__);  
}


boolean TimePeriodIsOver (unsigned long &expireTime, unsigned long TimePeriod) {
  unsigned long currentMillis  = millis();  
  if ( currentMillis - expireTime >= TimePeriod )
  {
    expireTime = currentMillis; // set new expireTime
    return true;                // more time than TimePeriod) has elapsed since last time if-condition was true
  } 
  else return false;            // not expired
}

unsigned long MyTestTimer = 0;                   // variables MUST be of type unsigned long
const byte    OnBoard_LED = 13;


void BlinkHeartBeatLED(int IO_Pin, int BlinkPeriod) {
  static unsigned long MyBlinkTimer;
  pinMode(IO_Pin, OUTPUT);
  
  if ( TimePeriodIsOver(MyBlinkTimer,BlinkPeriod) ) {
    digitalWrite(IO_Pin,!digitalRead(IO_Pin) ); 
  }
}

const int phaseA_Pin = 1;
const int phaseB_Pin = 2;
const int phaseC_Pin = 3;
const int control_Pin = 4;

//                0     1    2     3     4     5
int phaseA[6] = {HIGH, HIGH,HIGH, LOW , LOW , LOW }; 
int phaseB[6] = {LOW , LOW ,HIGH, HIGH,HIGH , LOW }; 
int phaseC[6] = {HIGH, LOW ,LOW , LOW ,HIGH , HIGH}; 

int Idx;

unsigned long currentMicros = 0;
unsigned long previousMicros = 0;

void setup() {
  pinMode(phaseA_Pin , OUTPUT);
  pinMode(phaseB_Pin , OUTPUT);
  pinMode(phaseC_Pin , OUTPUT);
  pinMode(control_Pin , OUTPUT);
  digitalWrite(control_Pin,LOW);
  
  Serial.begin(115200);
  Serial.println("Setup-Start");
  PrintFileNameDateTime();
  Idx = 0;
}


void loop() {  
  BlinkHeartBeatLED(OnBoard_LED,250);

  currentMicros = micros();

  if (Idx == 0) {
    digitalWrite(control_Pin, HIGH);
  }
  else {
    digitalWrite(control_Pin, LOW);
  }
    
  digitalWrite(phaseA_Pin, phaseA[Idx]); 
  digitalWrite(phaseB_Pin, phaseB[Idx]); 
  digitalWrite(phaseC_Pin, phaseC[Idx]); 

  if (currentMicros - previousMicros >= 3333) {
    previousMicros = currentMicros;

    Idx++;    
    if (Idx == 6) {
      Idx = 0;
    }
  }  
}

best regards Stefan