Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Arduino Mega Irrigation System

dvalero484

Junior Member level 1
Junior Member level 1
Joined
Oct 20, 2024
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
145
Hello everyone.

I'm working on an automatic irrigation system using Arduino Mega 2560, TFT screen ILI9488, RTC module DS3231 and a KY-023 joystick module in a physical assembly. The problem is that the RTC doesn't keep the correct time. When the system is turned on, it starts to lag by seconds after a few minutes. The longer it is on, the more it is delayed.

I have already posted about this (https://www.edaboard.com/threads/rt...and-doesnt-keep-the-correct-time-pace.413832/) and I was recommended to run the RTC with interrupts. I haven't worked with interrupts in Arduino before, so I followed a video:

Anyways, I tried interrupts, but as I said, it's my first time working with interrupts in Arduino, so I probably didn't do it right.

I'm attaching the code. I'd be grateful if you could tell me what's wrong with it and give me some tips on how to fix it. Thanks in advance.

Note: I'll also attach the code example I used for interrupts.
 

Attachments

  • Irrigation System.txt
    50.5 KB · Views: 39
  • ds3231_Example.txt
    5.5 KB · Views: 35
Hi,

it seems the RTC module is not very accurate in timing .. since all your time informations comes form the RTC module:
* 1Hz clock --> Interrupt
* absolute time read out from the RTC module

Thus:
you need to investigate the problem there:
* download the module datasheet
* download the RTC IC datasheet
--> read all about RTC accuracy and the recommendations to keep the error low.

Also:
Use your current software and calculate the lagging error. Use a fixed time span - maybe 10 minutes.
Now modify your code in a way that it does NOT communicae with the RTC every 1s. Maybe disable the time readout for 9 minutes. then find out the error - again over a span of 10 minutes.

* if the error changes: It´s a communication problem
* if the error stays constant, then most probably it´s an RTC IC / module problem.

***
I personally don´t like the idea to read out the time every 1s. It´s not a mistake to do so. But I´d relax the RTC communication. ... and btw it´s way less processing time consuming if you run a software_RTC in your microcontroller. I usually read out the absolute time only once a day.

****
Btw: what is your reference time source? Is it reliable?
You could use the microcontroller clock as reference .. maybe by using "micros()" function.

You may also try to disable the RTC.adjust function to be performed ... just to find out if this is the culprit.

Klaus
 
Hi,

it seems the RTC module is not very accurate in timing .. since all your time informations comes form the RTC module:
* 1Hz clock --> Interrupt
* absolute time read out from the RTC module

Thus:
you need to investigate the problem there:
* download the module datasheet
* download the RTC IC datasheet
--> read all about RTC accuracy and the recommendations to keep the error low.

Also:
Use your current software and calculate the lagging error. Use a fixed time span - maybe 10 minutes.
Now modify your code in a way that it does NOT communicae with the RTC every 1s. Maybe disable the time readout for 9 minutes. then find out the error - again over a span of 10 minutes.

* if the error changes: It´s a communication problem
* if the error stays constant, then most probably it´s an RTC IC / module problem.

***
I personally don´t like the idea to read out the time every 1s. It´s not a mistake to do so. But I´d relax the RTC communication. ... and btw it´s way less processing time consuming if you run a software_RTC in your microcontroller. I usually read out the absolute time only once a day.

****
Btw: what is your reference time source? Is it reliable?
You could use the microcontroller clock as reference .. maybe by using "micros()" function.

You may also try to disable the RTC.adjust function to be performed ... just to find out if this is the culprit.

Klaus


I'll try everything you say and come back to tell you how it went. Thanks for the help!
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top