Pages: [1]   Go Down
Author Topic: delay inconsistent between ver 0018 and 0019  (Read 1570 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: September 15, 2010, 04:40:06 am by garry572 » Logged

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Compiling with 0019 , no code change, the steps are consistent and close to ! sec
Oh good. Maybe 0019 is an improvement then.

Mowcius
Logged

DeKalb, IL USA
Offline Offline
Full Member
***
Karma: 0
Posts: 243
KB9SXU
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Jeff K - JKDevices.com - home of the MegaMini

DeKalb, IL USA
Offline Offline
Full Member
***
Karma: 0
Posts: 243
KB9SXU
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Jeff K - JKDevices.com - home of the MegaMini

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6636
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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())
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6636
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: