Go Down

Topic: How i make delay .5 microseconds? (Read 1 time) previous topic - next topic

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...
Web / sms / bluetooth / arduino / android remote control. Home Automation projects.
http://www.power7.net

Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

I want make IR pulse with accuracy 95KHz...i think i must use __asm__("nop\n\t"); .....
Web / sms / bluetooth / arduino / android remote control. Home Automation projects.
http://www.power7.net

Nick Gammon

1/95000 is 10.5 uS.

Anyway, you want PWM not NOPs.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Web / sms / bluetooth / arduino / android remote control. Home Automation projects.
http://www.power7.net

mromani

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

Nick Gammon

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.

Code: [Select]
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.

More stuff about timers here:

http://www.gammon.com.au/forum/?id=11488
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

mkwired

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.

http://www.ladyada.net/media/tvbgone/firmwarev12.zip

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....
Web / sms / bluetooth / arduino / android remote control. Home Automation projects.
http://www.power7.net

Nick Gammon

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


...


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?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Finaly 95 KHz is wrong i think i want a bandwidth 30-56KHz ....possible frequencies....
Web / sms / bluetooth / arduino / android remote control. Home Automation projects.
http://www.power7.net

Code: [Select]

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);
  ........

}
Web / sms / bluetooth / arduino / android remote control. Home Automation projects.
http://www.power7.net

Go Up