I have random operation of the RTC DS 1302 on a project based on MEGA 2560 PRO.
The assembly is powered by a 240Vac/12Vdc switching power supply and a 5Vdc regulator (7805).
The connections on 2560 are made by ribbon cables.
I control six 12v motors with MOSFET for on/off and PWM and relay for direction reversal.
I have limit switches.
I have temperature probes with OneWire.
I record on SD card and display with LCD 4x20 I2C.
I tried several RTC libraries
I added capacitors.
I swapped the RTC connections.
The other elements work correctly.
If it is possible I would like to stay with this RTC because I have 5 devices in operation.
Can you guide me to protect the RTC from disturbances and have reliable operation.
Probably we can. But not based on the rant you posted. Please read the forum guide and follow it. DS1307 do not behave randomly unless you put them in a random circuit.
Welcome! It appears you have a EMI (Electromagnetic interference problem) which are quite difficult to solve. Post an annotated schematic of your project being sure to show All connections (and there values), power, ground, power source and note any leads over 25cm/10" in length. Be sure to show any additional components such as capacitors etc. Also post links to the technical information on the hardware items. You have to tell us what you have preferable in the language of electronics schematics as we cannot see what you have nor do we know what is in your tool box. Does the RTC (Real Time Clock) work when it is the only thing connected?
This is indeed EMI disturbances.
DS 1302 works alone outside this environment and 4 out of 5 devices have been operating 24 hours a day for 6 months.
The relay modules have flyback diodes and are optocoupled
Are there Threewire libraries that are more robust to disruptions ?
Had similar problems once with an I2C LCD. The solution was the use shielded wires (UTP) as much as possible and reduce the I2C speed to 50 KHz.
Don't know if these options fir within your project.
Do you have flyback diodes across the motor lines? If the motors reverse, you will need 4 diodes or a full wave bridge for each motor.
We really need a drawing.
EDIT: Or a bidirectional TVS diode of the correct voltage.
I put pull up resistors for I2C and OneWire (which pose no problem).
for the motors I first switch the relays and then the control MOSFET with PWM ramp. Currently I have RTC problems even without motors and without limit switches (which have cables 5 to 10 meters long)
following your comments, I am thinking about the distribution and shielding of my 5V wiring because I have wires quite long, 300 cm.
I also have a LED controlled with an R 1K on the 5V which I use to check my cycle time by switching at each cycle. It must disturb
Good evening,
I don't have flyback diodes on the motors, I will probably add them. But my current problem persists even without checking the motors.
I did not use an H-bridge because I used the principle of old installations which worked, perhaps wrongly because at the time they were installations on 12V battery and not powered by switching power supply and as I had no pest problems; I did not take sufficient precautions when wiring the current installations.
I am in the process of redoing the wiring in order to shorten the cables that are too long and separate the signal and power cables: 5V, 12V and 240V.
Thank you in any case and I will keep you informed of the result.
Hello,
I can't believe it, my device has been working for sixteen hours!
The power supply and signals from my RTC had different paths and lengths and did not suffer the same disturbances. After correction it's good.
I should have written to you sooner! Thanks for your advices !
I will close the exchange in a few days after checking how it works.