# Pwm frequency of SPWM

Hello, i’m using this code to creat SPWM signal to a full-bridge inverter

``````float carrier, Uref, notref, t;

void setup()
{

pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(3, OUTPUT);
pinMode(11, OUTPUT);

digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(3, LOW);

}

void loop() {

for (t = 0; t < 100; t = t + 0.0002) {

Uref = sin(2 * PI * 50 * t);

notref = -1 * sin(2 * PI * 50 * t);

carrier = ((2 / PI) * asin(sin(2 * PI * 9500 * t)));

if (Uref >= carrier) {

digitalWrite(10, LOW);
delayMicroseconds(100);
digitalWrite(11, HIGH);
} else {

digitalWrite(11, LOW);
delayMicroseconds(100);
digitalWrite(10, HIGH);
}

//********************************************//

if (notref >= carrier) {

digitalWrite(3, LOW);
delayMicroseconds(100);
digitalWrite(9, HIGH);
} else {
digitalWrite(9, LOW);
delayMicroseconds(100);
digitalWrite(3, HIGH);
}
}
}
``````

So I have tried this and I get good results so, I have a doubt because I’m compare a sin wave (Uref) 50hz with a triangular carrier 9500Hz, so my PWM should have 9500Hz of frequency but i’m printing this PWM in pin 3,9,10 and 11 which have 490Hz frequency and this is a problem… How I can change my code to solve this?

Thanks

but i'm printing this PWM in pin 3,9,10 and 11 which have 490Hz frequency

Only if you use analogWrite() to do hardware PWM. Which you aren't, so

and this is a problem

is an erroneous conclusion.

PaulS:
Only if you use analogWrite() to do hardware PWM. Which you aren't, sois an erroneous conclusion.

I don't understand sorry, what you suggest me?