Go Down

Topic: delay inconsistent between ver 0018 and 0019 (Read 1 time) previous topic - next topic

Garry

Sep 15, 2010, 11:36 am Last Edit: Sep 15, 2010, 11:40 am by garry572 Reason: 1
I have a simple loop using analogwrite function to vary the brightness of a LED, followed by a delay
analogWrite(ledPin, 0);  
   delay(1000);  
   analogWrite(ledPin, 15);  
   delay(1000);
   analogWrite(ledPin, 30);  
   delay(1000);  
   analogWrite(ledPin, 60);  
   delay(1000);
   analogWrite(ledPin, 80);  
   delay(1000);  
   analogWrite(ledPin, 100);  
   delay(1000);
   analogWrite(ledPin, 128);  
   delay(1000);  
   analogWrite(ledPin, 255);  
   delay(1000);
If I compile with version 0018 of the IDE, the time between steps seems much less than 1 sec and seem to vary significantly
Compiling with 0019 , no code change, the steps are consistent and close to ! sec

mowcius

Quote
Compiling with 0019 , no code change, the steps are consistent and close to ! sec

Oh good. Maybe 0019 is an improvement then.

Mowcius

Jeff K

IIRC there were updates in 0019 to the delay functions to address the issues in 0018.  So this behavior is expected between the 2 versions.
Jeff K - JKDevices.com - home of the MegaMini

Jeff K

A quick look at the release notes for 0019 and you have your answer...
Quote
* More accurate delay() function from BenF.
 http://code.google.com/p/arduino/issues/detail?id=237

Jeff K - JKDevices.com - home of the MegaMini

westfw

The new delay should be accurate near the microseconds scale.  The old delay() ought to be been accurate to within a millisecond or so, which should have been imperceptible in a 1000ms delay on a blinking LED, but was somewhat problematic when delay(1) was almost always 2ms long...

Something else may be going on here...
(which pin are you using for the LED?  I wonder if there were unexpected interactions between the timer used for that pin's AnalogWrite and the timer used for milis())

Garry

I  suspect that might be the problem, I thought I checked but..
I'm using a 328, pin D9 for the LED.

I assumed the timing error would be within a few counts, but it seems to var from 100mSec up  to 1 sec.

I will try another pin to see if I can reproduce the error

westfw

I could not duplicate the problem here (on a 168, using the pin13 LED between each set of analogWrites...)

Garry

I think I might a a strange hardware issue with the board I tried it on, I used another 328 and it was fine

mowcius

Quote
I think I might a a strange hardware issue with the board I tried it on, I used another 328 and it was fine

Hmm, strange...

Go Up