@@ -92,7 +92,6 @@ unsigned long micros() {
92
92
#error TIMER 0 not defined
93
93
#endif
94
94
95
-
96
95
#ifdef TIFR0
97
96
if ((TIFR0 & _BV (TOV0 )) && (t < 255 ))
98
97
m ++ ;
@@ -122,16 +121,16 @@ void delay(unsigned long ms)
122
121
/* Delay for the given number of microseconds. Assumes a 1, 8, 12, 16, 20 or 24 MHz clock. */
123
122
void delayMicroseconds (unsigned int us )
124
123
{
125
- // call = 4 cycles + 2 to 4 cycles to init us(2 for constant delay, 4 for variable)
126
-
124
+ // call = 4 cycles + 2 to 4 cycles to init us(2 for constant delay, 4 for variable)
125
+
127
126
// calling avrlib's delay_us() function with low values (e.g. 1 or
128
127
// 2 microseconds) gives delays longer than desired.
129
128
//delay_us(us);
130
129
#if F_CPU >= 24000000L
131
130
// for the 24 MHz clock for the aventurous ones, trying to overclock
132
131
133
132
// zero delay fix
134
- if (!us ) return ; // = 3 cycles, (4 when true)
133
+ if (!us ) return ; // = 3 cycles, (4 when true)
135
134
136
135
// the following loop takes a 1/6 of a microsecond (4 cycles)
137
136
// per iteration, so execute it six times for each microsecond of
@@ -140,7 +139,7 @@ void delayMicroseconds(unsigned int us)
140
139
141
140
// account for the time taken in the preceeding commands.
142
141
// we just burned 22 (24) cycles above, remove 5, (5*4=20)
143
- // us is at least 6 so we can substract 5
142
+ // us is at least 6 so we can substract 5
144
143
us -= 5 ; //=2 cycles
145
144
146
145
#elif F_CPU >= 20000000L
@@ -153,7 +152,7 @@ void delayMicroseconds(unsigned int us)
153
152
"nop" "\n\t"
154
153
"nop" "\n\t"
155
154
"nop" ); //just waiting 4 cycles
156
- if (us <= 1 ) return ; // = 3 cycles, (4 when true)
155
+ if (us <= 1 ) return ; // = 3 cycles, (4 when true)
157
156
158
157
// the following loop takes a 1/5 of a microsecond (4 cycles)
159
158
// per iteration, so execute it five times for each microsecond of
@@ -162,7 +161,7 @@ void delayMicroseconds(unsigned int us)
162
161
163
162
// account for the time taken in the preceeding commands.
164
163
// we just burned 26 (28) cycles above, remove 7, (7*4=28)
165
- // us is at least 10 so we can substract 7
164
+ // us is at least 10 so we can substract 7
166
165
us -= 7 ; // 2 cycles
167
166
168
167
#elif F_CPU >= 16000000L
@@ -179,8 +178,8 @@ void delayMicroseconds(unsigned int us)
179
178
180
179
// account for the time taken in the preceeding commands.
181
180
// we just burned 19 (21) cycles above, remove 5, (5*4=20)
182
- // us is at least 8 so we can substract 5
183
- us -= 5 ; // = 2 cycles,
181
+ // us is at least 8 so we can substract 5
182
+ us -= 5 ; // = 2 cycles,
184
183
185
184
#elif F_CPU >= 12000000L
186
185
// for the 12 MHz clock if somebody is working with USB
@@ -196,7 +195,7 @@ void delayMicroseconds(unsigned int us)
196
195
197
196
// account for the time taken in the preceeding commands.
198
197
// we just burned 20 (22) cycles above, remove 5, (5*4=20)
199
- // us is at least 6 so we can substract 5
198
+ // us is at least 6 so we can substract 5
200
199
us -= 5 ; //2 cycles
201
200
202
201
#elif F_CPU >= 8000000L
@@ -213,7 +212,7 @@ void delayMicroseconds(unsigned int us)
213
212
214
213
// account for the time taken in the preceeding commands.
215
214
// we just burned 17 (19) cycles above, remove 4, (4*4=16)
216
- // us is at least 6 so we can substract 4
215
+ // us is at least 6 so we can substract 4
217
216
us -= 4 ; // = 2 cycles
218
217
219
218
#else
@@ -227,7 +226,7 @@ void delayMicroseconds(unsigned int us)
227
226
us -= 22 ; // = 2 cycles
228
227
// the following loop takes 4 microseconds (4 cycles)
229
228
// per iteration, so execute it us/4 times
230
- // us is at least 4, divided by 4 gives us 1 (no zero delay bug)
229
+ // us is at least 4, divided by 4 gives us 1 (no zero delay bug)
231
230
us >>= 2 ; // us div 4, = 4 cycles
232
231
233
232
@@ -253,7 +252,7 @@ void init()
253
252
#if defined(TCCR0A ) && defined(WGM01 )
254
253
sbi (TCCR0A , WGM01 );
255
254
sbi (TCCR0A , WGM00 );
256
- #endif
255
+ #endif
257
256
258
257
// set timer 0 prescale factor to 64
259
258
#if defined(__AVR_ATmega128__ )
@@ -357,31 +356,31 @@ void init()
357
356
358
357
#if defined(ADCSRA )
359
358
// set a2d prescaler so we are inside the desired 50-200 KHz range.
360
- #if F_CPU >= 16000000 // 16 MHz / 128 = 125 KHz
361
- sbi (ADCSRA , ADPS2 );
362
- sbi (ADCSRA , ADPS1 );
363
- sbi (ADCSRA , ADPS0 );
364
- #elif F_CPU >= 8000000 // 8 MHz / 64 = 125 KHz
365
- sbi (ADCSRA , ADPS2 );
366
- sbi (ADCSRA , ADPS1 );
367
- cbi (ADCSRA , ADPS0 );
368
- #elif F_CPU >= 4000000 // 4 MHz / 32 = 125 KHz
369
- sbi (ADCSRA , ADPS2 );
370
- cbi (ADCSRA , ADPS1 );
371
- sbi (ADCSRA , ADPS0 );
372
- #elif F_CPU >= 2000000 // 2 MHz / 16 = 125 KHz
373
- sbi (ADCSRA , ADPS2 );
374
- cbi (ADCSRA , ADPS1 );
375
- cbi (ADCSRA , ADPS0 );
376
- #elif F_CPU >= 1000000 // 1 MHz / 8 = 125 KHz
377
- cbi (ADCSRA , ADPS2 );
378
- sbi (ADCSRA , ADPS1 );
379
- sbi (ADCSRA , ADPS0 );
380
- #else // 128 kHz / 2 = 64 KHz -> This is the closest you can get, the prescaler is 2
381
- cbi (ADCSRA , ADPS2 );
382
- cbi (ADCSRA , ADPS1 );
383
- sbi (ADCSRA , ADPS0 );
384
- #endif
359
+ #if F_CPU >= 16000000 // 16 MHz / 128 = 125 KHz
360
+ sbi (ADCSRA , ADPS2 );
361
+ sbi (ADCSRA , ADPS1 );
362
+ sbi (ADCSRA , ADPS0 );
363
+ #elif F_CPU >= 8000000 // 8 MHz / 64 = 125 KHz
364
+ sbi (ADCSRA , ADPS2 );
365
+ sbi (ADCSRA , ADPS1 );
366
+ cbi (ADCSRA , ADPS0 );
367
+ #elif F_CPU >= 4000000 // 4 MHz / 32 = 125 KHz
368
+ sbi (ADCSRA , ADPS2 );
369
+ cbi (ADCSRA , ADPS1 );
370
+ sbi (ADCSRA , ADPS0 );
371
+ #elif F_CPU >= 2000000 // 2 MHz / 16 = 125 KHz
372
+ sbi (ADCSRA , ADPS2 );
373
+ cbi (ADCSRA , ADPS1 );
374
+ cbi (ADCSRA , ADPS0 );
375
+ #elif F_CPU >= 1000000 // 1 MHz / 8 = 125 KHz
376
+ cbi (ADCSRA , ADPS2 );
377
+ sbi (ADCSRA , ADPS1 );
378
+ sbi (ADCSRA , ADPS0 );
379
+ #else // 128 kHz / 2 = 64 KHz -> This is the closest you can get, the prescaler is 2
380
+ cbi (ADCSRA , ADPS2 );
381
+ cbi (ADCSRA , ADPS1 );
382
+ sbi (ADCSRA , ADPS0 );
383
+ #endif
385
384
// enable a2d conversions
386
385
sbi (ADCSRA , ADEN );
387
386
#endif
0 commit comments