DS 3231 AND L293DNE Timing issues


I hope this is posted in the correct location

While running the attached sketch the DS3231 does not operate as expected, also attached is a print out from the serial monitor of the odd phenomenon I am experiencing…my question is why is this occurring? When I comment out the motor control section of the code the RTC functions as expected.

I am in need of controlling these motors forward and reverse at exactly one minute intervals without an RTC the drift in timing is noticeable in about 20 minuets.

JasonSketch.ino (3.53 KB)

DS3231 TIME DISPLAY.txt (488 Bytes)

If you need it to run every minute, why do you have 63 seconds of delays in each invocation of loop?

void loop() {
    // motors forward for 2 seconds
    // motors reverse for 2 seconds
     displayTime(); // display the real-time clock data on the Serial Monitor,
  delay(1000); // every second

delay() blocks all execution until the delay is finished. If that's a problem for your applications (which it usually is), you need to recode it without using delay. Take a look at blinkwithoutdelay example, or any of the threads here on "doing more than one thing at a time".

DrAzzy thanks for the reply. I will take a look and see if I can't code this another way. with it coded this way the motors perform as I need them to however I cannot get the time accuracy that is required.

Just occurred to me - DS3231 supports alarms, yes? Do you have a free input that you can use to receive an alarm signal, change the motor direction, and then reset the alarm to the next time the motor needs to change direction, and then wait for the next alarm? Can display the time normally while waiting for that alarm to occur.

Crossroads yes two alarms are available and I have plenty of inputs available but I have no idea how to implement that concept

Looks like you need some data in registers 0x07, 0x08, 0x09, 0x0A use functions like you have now. See page 12.

The data sheet will tell you all you need to know about alarms http://datasheets.maximintegrated.com/en/ds/DS3231.pdf

But, using alarms will not help really help you unless you eliminate the delays in your program.

Use the millis() timer approach as demonstrated in the "blink without delay" example in the digital examples in the IDE. Also, study the "Demonstration Code for Doing Several Things at the Same Time" which is the sticky top posting in the Project Guidance section of the forum.

Once you redesign your program to not use delay() I'm not sure that using the RTC alarms will be any different than using several millis() timers for your motor changes and periodic display.

HA HA I think I have it right now. new coding and RTC time display is attached should work like a charm now… I hope…nope still not right but I now know what the issue is…thanks for the assistance everyone