Assistance on program for 3 phase inverter PWM control

Good day, i recently bought an UNO so i can learn some arduino programming. Ive decided to start a project of my own, which consists for a 3 phase inverter and a BLDC motor which i want to control with the inverter. My goal is 0-400 Hz controlable frequency, adjustable with a potentiometer. For the inverter ill be using 3 PMOS and 3 NMOS transistors. I have made a simulation with LTspice of the desired outcome.
Ive attatched pics of the simulation and the frequency diagram. Since im new to arduino, i am trying to avoid difficult register commands(atleast difficult for a beginner), which are necessary for adjusting the pwm outputs. Here is my code, if anyone has any idea if this code can work, please answer:

int D9 = 9;
void setup() {
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(A0, INPUT);
// put your setup code here, to run once:

}

void loop() {
int pot = analogRead(A0);
pot = map(pot, 0, 1023, 0, 400); // 0-400 Hz frequency control from pot
digitalWrite(9, HIGH);
delay(((1/pot)1000)/2); // delay = to 1/Frequency, which is = to the period * 1000 so the values can be in mS, then divided by 2 so the HIGH state can be 1/2 the period for 50% duty cycle
digitalWrite(9, LOW);
delay(((1/pot)1000)/2); // samme as above this time for the LOW state
if (D9=HIGH) // digital output 10 only generates a pulse when digital output 9 is in HIGH state
{ delay(((1/pot)10002.0943951023931954923084289221863)/2); // same as above but this time the values are multiplied by 2
pi/3, so that the second phase can be 120 degree dephased from the first one
digitalWrite(10, HIGH);
delay(((1/pot)1000)/2); // same as before
digitalWrite(10, LOW);
else digitalWrite(10, LOW); // if digital output 9 is LOW d10 is also LOW
}
if(D9=HIGH) // same
{ delay(((1/pot)10004.1887902047863909846168578443727)/2); // this time the values are multipled by 4
pi/3, so that the third phase can be 120 degree dephased from the other 2 phases
digitalWrite(11, HIGH);
delay(((1/pot)*1000)/2); // same
digitalWrite(11, LOW);
else digitalWrite(11, LOW); // same
}
// put your main code here, to run repeatedly:

}


I do not comment on the UNO, as I use the smaller nano 328.

400 Hz adjustable is only going to be possible with "difficult register commands" which are not that bad at all; you just need to read a lot to find the number referred to by the thingy referred to by the .... well sending one byte to the correct register is often simpler than sending someone's arbitrary choice of representation to the thingy to do whoknowswhat.

In this text,

digitalWrite(10, LOW)

is an example of a thingy.

Do check that you have enough registers on your choice of hardware. I have some vague recollection of some of the smaller arduino types having two pairs of pwm's, capable of two frequencies not three ... that might not matter for what you are doing but be careful and do read the datasheet.

More crucial, I suspect, would be finding the relative phase between the pwm's. I have not looked into that but suggest that you want a four channel oscilloscope handy.

Thanks for the reply, I bought the UNO, because i have a really small experience with it. I hope it does the trick. As for the "difficult register commands" i guess i`ll learn them when i get more advanced in the arduino world, for now i am trying to stick to what i know and understand :D

If you use blink without delay and start a phase change every 416uS, that will yield 3 phase 400 Hz. Something like this I would think:

byte phase1pin = 2;
byte phase2pin = 3;
byte phase3pin = 4;
byte phaseState = 1; // of 6: 001, 011, 111, 110, 100, 000
unsigned long currentMicros;
unsigned long previousMicros;
unsigned long elapsedMicros;
unsigned long phaseTime = 416; // 416 microseconds x 6 = 2496 us, 1/.002496 = 400.64 Hz
void setup(){
pinMode (phase1pin, OUTPUT);
pinMode (phase2pin, OUTPUT);
pinMode (phase3pin, OUTPUT);
digitalWrite (phase1pin, HIGH);
digitalWrite (phase2pin, LOW);
digitalWrite (phase3pin, LOW);
currentMicros = micros();
previousMicros = currentMicros;
}
void loop(){
currentMicros = micros();
elapsedMicros = currentMicros - previousMicros;
if (elapsedMicros >= phaseTime){
phaseState = phaseState +1;
if (phaseState == 7){ phaseState =1 ;}
switch (phaseState){ // start with 001: 011,111,110, 100, 000, then back to 001
case 1:
PIND = PIND | 0b00001000; // toggle phase2pin by writing to input register
break;
case 2;
PIND = PIND | 0b00010000; // toggle phase3pin
break;
case 3:
PIND = PIND | 0b00000100; // toggle phase1pin
break;
case 4:
PIND = PIND | 0b00001000; // toggle phase2pin
break;
case 5;
PIND = PIND | 0b00010000; // toggle phase3pin
break;
case 6:
PIND = PIND | 0b00000100; // toggle phase1pin
break;
} // end switch
} // end time check
} // end loop

CrossRoads: If you use blink without delay and start a phase change every 416uS, that will yield 3 phase 400 Hz. Something like this I would think:

byte phase1pin = 2;
byte phase2pin = 3;
byte phase3pin = 4;
byte phaseState = 1; // of 6: 001, 011, 111, 110, 100, 000
unsigned long currentMicros;
unsigned long previousMicros;
unsigned long elapsedMicros;
unsigned long phaseTime = 416; // 416 microseconds x 6 = 2496 us, 1/.002496 = 400.64 Hz
void setup(){
pinMode (phase1pin, OUTPUT);
pinMode (phase2pin, OUTPUT);
pinMode (phase3pin, OUTPUT);
digitalWrite (phase1pin, HIGH);
digitalWrite (phase2pin, LOW);
digitalWrite (phase3pin, LOW);
currentMicros = micros();
previousMicros = currentMicros;
}
void loop(){
currentMicros = micros();
elapsedMicros = currentMicros - previousMicros;
if (elapsedMicros >= phaseTime){
phaseState = phaseState +1;
if (phaseState == 7){ phaseState =1 ;}
switch (phaseState){ // start with 001: 011,111,110, 100, 000, then back to 001
case 1:
PIND = PIND | 0b00001000; // toggle phase2pin by writing to input register
break;
case 2;
PIND = PIND | 0b00010000; // toggle phase3pin
break;
case 3:
PIND = PIND | 0b00000100; // toggle phase1pin
break;
case 4:
PIND = PIND | 0b00001000; // toggle phase2pin
break;
case 5;
PIND = PIND | 0b00010000; // toggle phase3pin
break;
case 6:
PIND = PIND | 0b00000100; // toggle phase1pin
break;
} // end switch
} // end time check
} // end loop

I really appriciate your reply. I will go trough your code. I dont have an oscilloscope to check if the code i wrote is working so my only option is to wait for the transistor delivery to arrive and try to move the BLDC with it. If it doesn't work and i do not fry up the transistors, i will most definitely try your suggestion and then think of a way to make it adjustable.