# How i make delay .5 microseconds?

Hello i want make delay .5 microseconds(500 nanoseconds).I must use NOP() from assembly?I have ATmega328 16MHZ....nop for me is 62.5ns...ok i want 8 nop but i could use assebly code into my sketch?I must use library first?How i doing this?A small example please...

Why do you want to do this?

I want make IR pulse with accuracy 95KHz...i think i must use asm("nop\n\t"); .....

1/95000 is 10.5 uS.

Anyway, you want PWM not NOPs.

How i use PWM for doing this?

This question reminded me I've been curious about how to change the Arduino PWM frequency, but never bothered to look hard enough... here's what I found:

http://www.arduino.cc/playground/Code/PwmFrequency

This sketch will output 95.23 kHz on pin D9. The period is actually 5.25 uS (ie. for each toggle, being 84 * 62.5) which is 10.5 uS between each leading edge. The inverse of that is 95.238 kHz.

``````const byte LED = 9;

void setup() {
pinMode (LED, OUTPUT);

// set up Timer 1
TCCR1A = _BV (COM1A0);  // toggle OC1A on Compare Match
TCCR1B = _BV(WGM12) | _BV(CS10);   // CTC, no prescaler
OCR1A =  83;       // compare A register value to 84 (zero relative)
}  // end of setup

void loop() { }
``````

You can't get any closer than that, the system clock needs to pulse twice per square wave (once up, once down) and thus the resolution is 125 nS.

http://www.gammon.com.au/forum/?id=11488

If you are going to control a commercial device like a TV, then it's a little more complicated then PWM driving a LED. You may want to check out the TV-B-Gone code to get some ideas if this is what you're trying to do.

I want control my air condition United…i have another A/C Toyotomi i decode ok work to 38KHz i make a library…but the United i think no have the standard frequency 38KHz i decode the pulses but no work and i must test it with little different frequency 32,33,34…40,56 KHz…i have not osciloscope…

I want make IR pulse with accuracy 95KHz...

...

antkan: I want control my air condition United...i have another A/C Toyotomi i decode ok work to 38KHz...

Well which is it? 38 KHz or 95 KHz?

Finaly 95 KHz is wrong i think i want a bandwidth 30-56KHz ....possible frequencies....

``````void pulseIR(long microsecs) {
// we'll count down from the number of microseconds we are told to wait

cli();  // this turns off any background interrupts

while (microsecs > 0) {
// 38 kHz is about 13 microseconds high and 13 microseconds low
digitalWrite(IR_PIN4, HIGH);  // this takes about 3 microseconds to happen
delayMicroseconds(10);         // hang out for 10 microseconds
digitalWrite(IR_PIN4, LOW);   // this also takes about 3 microseconds
delayMicroseconds(10);         // hang out for 10 microseconds

// so 26 microseconds altogether
microsecs -= 26;
}

sei();  // this turns them back on
}

void SendACCodeOn() {
// This is the code for my particular Toyotomi on button

pulseIR(9000);
delayMicroseconds(4340);
pulseIR(840);
delayMicroseconds(320);
pulseIR(740);
delayMicroseconds(400);
pulseIR(700);
delayMicroseconds(1440);
pulseIR(740);
........

}
``````