Pages: [1]   Go Down
Author Topic: How i make delay .5 microseconds?  (Read 789 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 2
Posts: 175
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why do you want to do this?
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 175
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1/95000 is 10.5 uS.

Anyway, you want PWM not NOPs.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 175
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How i use PWM for doing this?
Logged

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

0
Offline Offline
God Member
*****
Karma: 1
Posts: 596
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

USA
Offline Offline
Full Member
***
Karma: 0
Posts: 235
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 175
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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....
Logged

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 175
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Offline Offline
Full Member
***
Karma: 2
Posts: 175
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

}
Logged

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

Pages: [1]   Go Up
Jump to: