19
19
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
20
Boston, MA 02111-1307 USA
21
21
22
- $Id: wiring.c 808 2009-12-18 17:44:08Z dmellis $
22
+ $Id$
23
23
*/
24
24
25
25
#include "wiring_private.h"
@@ -96,13 +96,18 @@ unsigned long micros() {
96
96
}
97
97
98
98
// DuinOS overrides this function with a macro (DuinOS.h)
99
- /*void delay(unsigned long ms)
99
+ /* void delay(unsigned long ms)
100
100
{
101
- unsigned long start = millis();
102
-
103
- while (millis() - start <= ms)
104
- ;
105
- }*/
101
+ uint16_t start = (uint16_t)micros();
102
+
103
+ while (ms > 0) {
104
+ if (((uint16_t)micros() - start) >= 1000) {
105
+ ms--;
106
+ start += 1000;
107
+ }
108
+ }
109
+ }
110
+ */
106
111
107
112
/* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */
108
113
void delayMicroseconds (unsigned int us )
@@ -182,20 +187,22 @@ void init()
182
187
sbi (TIMSK0 , TOIE0 );
183
188
#endif
184
189
185
- // DuinOS: This commented code is the only difference with the standard init() function
186
- // (DuinOS uses the timer 1 for the preemptive kernel):
187
- /*
188
190
// timers 1 and 2 are used for phase-correct hardware pwm
189
191
// this is better for motors as it ensures an even waveform
190
192
// note, however, that fast pwm mode can achieve a frequency of up
191
193
// 8 MHz (with a 16 MHz clock) at 50% duty cycle
194
+
195
+ // DuinOS: This commented code is the only difference with the standard init() function
196
+ // (DuinOS uses the timer 1 for the preemptive kernel):
197
+ /* TCCR1B = 0;
192
198
193
199
// set timer 1 prescale factor to 64
194
200
sbi(TCCR1B, CS11);
195
201
sbi(TCCR1B, CS10);
196
202
// put timer 1 in 8-bit phase correct pwm mode
197
- sbi(TCCR1A, WGM10);
198
- */
203
+ sbi(TCCR1A, WGM10); */
204
+
205
+
199
206
// set timer 2 prescale factor to 64
200
207
#if defined(__AVR_ATmega8__ )
201
208
sbi (TCCR2 , CS22 );
@@ -209,7 +216,7 @@ void init()
209
216
sbi (TCCR2A , WGM20 );
210
217
#endif
211
218
212
- #if defined(__AVR_ATmega1280__ )
219
+ #if defined(__AVR_ATmega1280__ ) || defined( __AVR_ATmega2560__ )
213
220
// set timer 3, 4, 5 prescale factor to 64
214
221
sbi (TCCR3B , CS31 ); sbi (TCCR3B , CS30 );
215
222
sbi (TCCR4B , CS41 ); sbi (TCCR4B , CS40 );
0 commit comments