0

Trying to understand the code...
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Trying to understand the code...

by Thunder3000 on Wed Nov 07, 2007 2:25 am

Okay, so I read the code for fun, but it left me with questions...

The ceramic oscillator functions as the clock for the uC, right? So if the clock is 8Mhz and you want to wait one microsecond, 8 nop's should do the trick, right? And 10 microseconds should be 80 nops. But here's how it looks in the code:

Code: Select all | TOGGLE FULL SIZE
// This function delays the specified number of 10 microseconds
#define DELAY_CNT 11
void delay_ten_us(uint16_t us) {
  uint8_t timer;
  while (us != 0) {
    for (timer=0; timer <= DELAY_CNT; timer++) {
      NOP;
      NOP;
    }
    NOP;
    us--;
  }
}


I think that probably actually compiles into pretty close to 80 operations per 10 microsecond delay, was that the goal? There's still function call overhead, and it's probably not exactly 80 operations per 10 us delay (84?), does it just not matter that much to delay precisely 10 microseconds?
User avatar
Thunder3000
 
Posts: 2
Joined: Wed Nov 07, 2007 1:06 am
Location: Boise, ID

by adafruit on Wed Nov 07, 2007 2:43 am

i tweaked it using my oscilloscope. came out to be pretty much 10uS
but very unscientific :)

adafruit
 
Posts: 12149
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

by maltman23 on Thu Nov 08, 2007 3:39 am

It is important to get kinda close to the correct timing for IR remote control codes. But my extensive field testing has shown that the IR remote control receivers on TVs are very forgiving, so the timing can be + or - quite a bit, and still work. That is a really good thing, since it means that turning off TVs is very easy. Yay!

Mitch.

maltman23
 
Posts: 134
Joined: Fri Jul 13, 2007 4:54 pm
Location: San Francisco

Please be positive and constructive with your questions and comments.