PWM capabilities

Not sure I follow. Can I do this in software? I need to be able to do this in software because I want to change the duty cycle of the PWM from time to time, as well as to turn it off at specific intervals.

I tried this code in void loop() :

for (int i = 1; i <= 300; i++){
digitalWrite(10, HIGH);
delayMicroseconds(5);
digitalWrite(10, LOW);
delayMicroseconds(5);
}
delay(3);

However, looking at the signal with a scope, I can tell that the command "delayMicroseconds(5);" is not 5us. It is closer to 10us, which I assume is partly due to the overhead in executing the command.

What can I do to get more precision on my timing?