# How do we solve Delays 1.5 mS in elapsedMillis.h ?

Hi Guys
Im using Timer (elapsedMillis.h) for countdown from 40 to Zero it will reduce 1 digit per minute.
in each second it will delay 1.5 mS

``````int TaboorT = 40; // (40 minutes)
#include <elapsedMillis.h>
elapsedMillis timer1;
#define interval 60000 /// the interval in mS (one minute)
int b21 = 0;
int c21 = 0;
int d21 = 0;
int e21 = 0;
int z21 = 0;
int x21 = 0;
int f21 = 0;
int g21 = 0;
int h21 = 0;
int r21 = 0;
int clockpin2 = 7; // connect to pin 11 on the '595
int latchpin2 = 6; // connect to pin 12 on the '595
int datapin2 = 5; // connect to pin 14 on the '595
int segdisp = {
3,159,37,13,153,73,65,27,1,9 };
void setup()
{
pinMode(latchpin2, OUTPUT);
pinMode(clockpin2, OUTPUT);
pinMode(datapin2, OUTPUT);
timer1 = 0; // clear the timer at the end of startup
}

void loop()
{
if (timer1 >= (interval))
{
timer1 = 0; //reset the timer
if (TaboorT > 0)
{
TaboorT--;
d21=(TaboorT%100)/10; // find the remainder of dividing z by 10, this will be the right-hand digit
c21=int(d21); // make it an integer, c is the right hand digit
b21=(TaboorT%10)%10; // divide z by 10 - the whole number value will be the left-hand digit
e21 = int(b21); // e is the left hand digit
//---------------------------------------------------------------------------------------
digitalWrite(latchpin2, LOW); // send the digits down to the shift registers!
shiftOut(datapin2, clockpin2, LSBFIRST, segdisp[c21]);
shiftOut(datapin2, clockpin2, LSBFIRST, segdisp[e21]);
digitalWrite(latchpin2, HIGH);

}
}
}
``````

How i can avoid that delay 1.5 mS in each second ?

How i can avoid that delay 1.5 mS in each second ?

First, you need to post a link to the library you are using.
Second, you need to define why you think that the library is causing the 1.5 millisecond delay per second.

``````      d21=(TaboorT%100)/10; // find the remainder of dividing z by 10, this will be the right-hand digit
``````

That is NOT what that code does. If you are going to have useless comments, you MUST keep them accurate.

So, why do you think the library is responsible for the 1.5mS delay? How are you determining that there IS a 1.5mS delay? Between what two events?

I may just be the error in your clock.

The resonator on my Uno (at room temperature) is off by about 0.8 ms/sec.

Can't edit my post for some reason so I'll post again to correct my typo:

It may just be the error in your clock.

The resonator on my Uno (at room temperature) is off by about 0.8 ms/sec.

I think you're probably on the right there is another problem, let me discovered

Im using in this project 56 seven segment through shift register 74595 by Arduino mega 2560 .
and DS3231 RTC.

alhootti:
Im using in this project 56 seven segment through shift register 74595 by Arduino mega 2560 .
and DS3231 RTC.

And?

Mr.PaulS
Kindlly check your Personal Messages

alhootti:
How i can avoid that delay 1.5 mS in each second ?

You can correct for it pretty closely. Use micros() to time and you get 4 usec granularity.

You could use a controller that has a crystal instead of a less accurate resonator, or build one cheaply enough.

You could use an RTC to generate a very accurate interrupt.
Or perhaps use a high speed oscillator and CTC to do the same.

But if you don't need super-accuracy but just better, measure the early or lateness of the clock and add or subtract that amount from your interval to get your time right.

So instead of 1,000,000 micros() per second it will be 1,001,500.

alhootti:
Im using in this project 56 seven segment through shift register 74595 by Arduino mega 2560 .
and DS3231 RTC.

The oscillator on the Mega 2560 looks just like the one on my Uno. These ceramic resonators are typically rated to something like ±0.5% with a temperature variation of ±0.3% across their operating range. So you could be off by 5ms each second. And while you could adjust for this in your code by counting to 10015 instead of 10000 or whatever, you might find yourself off again if it's a hot or cold day.

The real question is, if you already have an RTC in your system why are you using millis() to count seconds?

The real question is, if you already have an RTC in your system why are you using millis() to count seconds?

I think we are close to the solution

can you post small example in RCT?

RTC is Real Time Clock, a piece of calibrated hardware with temperature correction built in.
You can set it up to provide a consistent signal.

How i can set it up to provide a consistent signal ?

Sparkfun sells the DS3234 chip as well as breakout board. It has programmable square output according to the datasheet. How is in the datasheet.

However the square wave outputs are 1 Hz, 1024 Hz, 4096 Hz or 8192 Hz.

If you want more flexibility, there is the temperature compensated CSS555(C) timer.