Problem with the timecalculation of Arduino mega 1280

Hello. I have 2 board and 1 board arduino mega 2560. All are clone board…

I have two board arduino mega 1280 and a board Arduino Arduino Mega 2560. All are clones. Unfortunately Arduino Mega 1280 cards do not seem to calculated time well . To be more precise: I loaded the program below on all three board and the arduino mega 1280 boards have a 0,5 seconds delay on every 60 second. The delay its relative to real time.

I want to know if it’s a configuration problem (given that the two plates have the same size for error, that is 0.5 seconds / minute), or a physical problem (strange though that error to be the same size).
Mention that this problem occurs even for many other codes
Thanks in advance and sorry for my English …
Here is my code:

const int buttonPin = 12;     

int buttonState = 0;         // variabila pentru status buton
long unsigned int intarziere;// intarzierea intre capse pentru placa 2 prima capsa trebuie sa aiba o intarziere de 0, 2sec in plus
long unsigned int timer[] = {10000, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 250, 
500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 250, 
500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 250, 
500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500,5000};           // valori pentru intarziere, stocate in array- atenta la legarea intre sferturi se dau jumatatea din valoarea reala.
int ledPins[] = {38, 40, 42, 44, 46, 48, 50, 52, 39, 41, 43, 45, 47, 49, 51, 53, 37, 35, 33, 31, 29, 27, 25, 23, 36, 34, 32, 30, 28, 26, 24, 22, 19, 18, 17, 16, 15, 14, 2, 3, 4 , 5, 6, 7, 8, 9, 10, 11, 13};       // ordinea pentru capse
int pinCount1 = 12;           // primul sfert de capse (vor fi 12) dupa care incepe stingerea lor pentru economie de curent
int pinCount2 = 24;           //al doilea sfert de capse (vor fi 12) dupa care incepe stingerea lor pentru economie de curent
int pinCount3 = 36;           // al treilea sfert de capse (vor fi 12) dupa care incepe stingerea lor pentru economie de curent
int pinCount4 = 49;           // ultimul sfert de capse (vor fi 12) dupa care incepe stingerea lor pentru economie de curent
void setup() {
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  int thisPin;
   int thisTimer;
  for (int thisPin = 0; thisPin < 53; thisPin++)     // initializare pini pentru output (primul element din array este 0 iar ultimul este numarul total de pini minus 1)
  {
    pinMode(ledPins[thisPin], OUTPUT);      
  }
  pinMode(12, INPUT); //setare buton pe pinul 12
   
  }
   

void loop() {
  
  buttonState = digitalRead(buttonPin); //atribuie variabilei buttonState valoarea citita din pinul buttonpin

  if (buttonState == HIGH) 
 {   //daca butonul este apasat se executa urmatorul for

    
     for (int thisTimer = 0; thisTimer < pinCount1; thisTimer++)  //incepand cu prima valoare din array si pana la primul sfert...
     {
       intarziere = timer[thisTimer];      //atribuie variabilei intarziere valori, pe rand, din array-ul timer
        
       delay(intarziere);  
       digitalWrite(ledPins[thisTimer], HIGH);   
      }

          for (int thisPin = 0; thisPin < pinCount1; thisPin++) 
          { 
            digitalWrite(ledPins[thisPin], LOW);   
          }
  

       for (int thisTimer = 11; thisTimer < pinCount2; thisTimer++)  // se reia iteratia cu o valoare in urma pentru a putea sa ramana HIGH si ultimul pin din sfertul anterior
       { 
         intarziere = timer[thisTimer];      
         delay(intarziere);  
         digitalWrite(ledPins[thisTimer], HIGH);   
        }

            for (int thisPin = 11; thisPin < pinCount2; thisPin++) // se reia iteratia cu o valoarea in urma pentru a putea sa ramana HIGH si ultimul pin din sfertul anterior
            { 
              digitalWrite(ledPins[thisPin], LOW);   
            }



       for (int thisTimer = 23; thisTimer < pinCount3; thisTimer++)  // se reia iteratia cu o valoarea in urma pentru a putea sa ramana HIGH si ultimul pin din sfertul anterior
       { 
         intarziere = timer[thisTimer];      
         delay(intarziere);  
         digitalWrite(ledPins[thisTimer], HIGH);   
        }

            for (int thisPin = 23; thisPin < pinCount3; thisPin++) // se reia iteratia cu o valoarea in urma pentru a putea sa ramana HIGH si ultimul pin din sfertul anterior
            { 
              digitalWrite(ledPins[thisPin], LOW);   
            }



       for (int thisTimer = 35; thisTimer < pinCount4; thisTimer++)  // se reia iteratia cu o valoarea in urma pentru a putea sa ramana HIGH si ultimul pin din sfertul anterior
       { 
         intarziere = timer[thisTimer];      
         delay(intarziere);  
         digitalWrite(ledPins[thisTimer], HIGH);   
        }

            for (int thisPin = 35; thisPin < pinCount4; thisPin++) // se reia iteratia cu o valoarea in urma pentru a putea sa ramana HIGH si ultimul pin din sfertul anterior
            { 
              digitalWrite(ledPins[thisPin], LOW);   
            }




   }
  
  
  else {
        digitalWrite(13, HIGH);
        delay(50);
        digitalWrite(13, LOW);  
        delay(50);             
        }
  
 }

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

You don't tell us what exact type of clone you're using (a link might help too). Is it possible that your 2560 has a crystal as the clock source where the 1280s have a resonator? Where the crystal is only drifting a few ticks per million I learned for the resonator this range is about +/- one percent. Your half a second per minute falls right within this range.

Crystals are usually +/- 50ppm, resonators +/- 0.5% or so. 1 second a minute is way beyond this , I suggest your code isn't accounting for every tick properly.

Often boards have pads for both a crystal (2 pads plus pads for 2 capacitors) or a resonator (3 pins) - so it may be possible to replace the resonator with a crystal.

Due to an (IMO) extremely poor decision by the Arduino team they moved from crystal to resonator with the Uno design, so I've had to resolder my Uno so it can keep time accurately enough.

Anyway your code is using delay() rather than millis() which accounts for the discrepancy - you are not accounting for the time between calls to delay() - look at the blinkWithoutDelay() example for inspiration.

Thanks for your prompt response. This is the board: http://www.ebay.com/itm/Interactive-Media-MEGA1280-Development-Board-for-JY-MCU-Arduino-New-/110852122710?pt=LH_DefaultDomain_0&hash=item19cf4d2856#ht_1896wt_1026 I tried to use a program that has only one delay of 24 minutes and then starts a light, and the result was a delay of 12 seconds to start the led of Arduino Mega 1280. Mention that the error is always the same (every minute is a delay of 0.5 seconds) and the error does not occur on Arduino Mega 2560 board (which works well). I would like to know if: - i can somehow change the behavior of the internal clock of the card; - i should calculate the error and enter in the sketch modified values; - or i should buy an original arduino mega (the original boards have this problem?????!!!!).

Mention that this problem occurs even for many other codes

What is the simplest code you have written that exhibits this problem?

The simple code that I tried and gave a delay of 12 seconds until led on pin 10 light after 24 minutes, is:

int ledPin = 10; // LED connected to digital pin 10

void setup() { pinMode(ledPin, OUTPUT); // sets the digital pin as output }

void loop() { delay(1440000); // waits for 24 minutes digitalWrite(ledPin, HIGH); // sets the LED on delay(1000); // waits for a second digitalWrite(ledPin, LOW); // sets the LED off delay(1000); // waits for a second }

delay(1440000);

It would be nice to think so. C doesn't see it that way.

delay(1440000UL);

or better, and more obvious

delay(24UL * 60UL * 1000UL);