question about RTC and cycling of switches

Hi All

I would like to have an Arduino control 4 switches / relays, that will have to switch on and off for set amount of times (Sw1 for n seconds, Sw2 for m seconds,...).

The switches will have to cycle for a set number of times after stopping the program, something like Sw1, Sw2, Sw3, Sw4, pause, Sw1, Sw2, Sw3, Sw4, pause... Sw4, stop.

I'd like to use an RTC since the switching times have to be very precise AND accurate (milliseconds of accuracy and precision) and I've read that variation in temperature can cause the Arduino internal clock to lose accuracy.

I have been after this for a while but I can't seem to get to an answer on my own, so here's the question: how would I interface the RTC to the code I need? I've read that I shouldn't use "delay ()", but that's the only command I can think of.

Any help is appreciated :slight_smile:

Thanks!

Most real time clock modules will not give you a milli second output . You could use it however to regulate the Arduino clock .
Also note that if you use relays there will be some scatter in the time they take to operate , so you need solid state switching .

It would help to know in a bit more detail what you are trying to do

Sync the Arduino operations to the 1 Hz and 32 KHz hardware outputs of a DS3231.

Alternatively use the 1Hz output of the DS3231 to figure out the true value of the Arduino clock and compensate accordingly.

Hi all

thanks for the quick replies...

  1. how can I sync the Arduino internal clock to the RTC? Let's say every 10 cycles? I've got a scientific instrument that is made of superfast switching valves (down to 5 ms relay action).

2)... not even sure where to start with that... ? :slight_smile:

Total ignorant here...

Thanks :slight_smile:

superfast switching valves (down to 5 ms relay action).

!!!!!!

Mark

Paolopizzol:

  1. how can I sync the Arduino internal clock to the RTC? Let's say every 10 cycles? I've got a scientific instrument that is made of superfast switching valves (down to 5 ms relay action).

To measure time simply count the pulses from the DS3231. If 32k is too fast to count, then use a hardware divider chip to give a 1k pulse rate, or whatever is needed for the resolution you desire. You might want to use interrupts instead of polling.

Paolopizzol:
2)... not even sure where to start with that... ? :slight_smile:

Use the Arduino to measure the length of the 1 second pulse from the DS3231. The Arduino will tell you that it's slightly longer or shorter than 1 second. With this information you can calculate a correction factor that you need to apply to your measurements to give the true time.