pwm 5Khz uno r3

Hello to all.
How can I create a 5Khz PWM by uno r3. I want to change its width.
Very thank you.

timer counter interrupt setting RA/RC values.

im not sure about on a 328 but on a due you can change any pwm setting on the fly without disturbing the pulse.

in my opinion using a timer counter gives more control than using a pwm interrupt, depending on what you are trying to do

I just need to a pwm about 5 kHz.

What's your idea about this code?
void loop()

digitalWrite(2,HIGH) ;

digitalWrite(2,LOW) ;

The parameter in delay() has to be an integer so delay(0.1) would work the same as delay(0).

Maybe you'd get somewhere with delayMicroseconds(100).

Alternatively, here's how you change the frequency you get from analogWrite(). You can't have 5kHz that way but you can get 3.9 or 7.8 kHz.