Other replies and chats presented some reasons for the problem you mentioned:
... It worked amazingly well when I connected different batteries, such as 3.7V, 6V and 12V, but when I connected charger to the battery, I soon found that the speed of the wall clock was noticeably faster than normal...
I don't understand why this happens when I connect charger to the battery.
As we don't have the exact details as some other requested, we can mostly speculate.
I believe there is a combination of effects/issues that are superimposed to the results found:
- Minimum Load Current: LM317, like other series regulators, require a minimum load current, which vary from model to model. In case of the LM317, using 120 Ohm as R1 provides the required 10 mA for the worst case condition.
- Transient response of LM317: The LM317 might operate with a lower Load than 10 mA, but transient response and its output voltage may be compromised. This could explain why LM317 works with battery as smoothest power supply, but may not respond well to transients.
- Noisy Charger: Most Battery chargers are electrically "noisy", with rare exceptions.
Simple battery chargers can even feed the battery with pulsed DC, which is not even filtered, using a diode only, without capacitors!
Other "smart chargers" can use switched mode power supplies SMPS, but count on the voltage-smoothing effect of the battery. SMPS can cause a high-frequency "ripple", usually in the 20KHz-100KHz range.
Transient response of LM317 is better for low frequency (rectified line = 60-120Hz) than for poorly filtered voltages from a SMPS in certain chargers (that is why readers asked about the charger model).
- Internal Resistance of Battery: 12V Battery can have a higher internal resistance compared to the pulsed charging current. It could a motorcycle battery (5-10Ah) or an aged car battery. In both cases, internal resistance could be as high as 50 milli-Ohm. Let's say charging pulses are 10A; in this case, the charging ripple would be 500 mV.
If LM317 was properly loaded, its attenuation would be about 60 dB, so output ripple would be negligible.
But your circuit drains just 1.25/1K5 = 0.83mA = 8% or the minimum required (worst case).
- Clock circuitry under Pulsed voltage supply: most digital clocks are battery powered and do not have enough protection against pulsing supply voltage. Such pulses could perturb the quartz timing and divider, by creating extra clocking pulses, making your clock run faster than expected. Minimizing any overvoltage - pulsed or not - should be a priority.
Ways of Investigation:
If you have a cheap portable oscilloscope (as DSO138), it would be a great tool to see the behavior of any voltage transient.
But if you don't have any, don't worry: Try to use a RED LED as here:
I assume the Red LED voltage is 1.7V; other colors have different threshold voltages.
For V_out = 1.8V, LED will light up dimmly with a 10_Ohm resistor. "Memorize" the light intensity using just the 12V battery.
Then connect and power the charger. If the LED changes its light intensity or starts pulsing, that is the evidence the LM317 is not operating correctly. I used your drawing and made a small revision and upgrade.
About the Revised Circuit:
Resistor values: To avoid the improper operation of the LM317, I changed resistor values R1 and R2; R1 = 120R and R2 = 52R (or 56R, if 1.83V is Ok). This is the revised value of R2, with the comment/help from OP.
Two capacitors - electrolytic and polyester/ceramic - would help the transient response too.
RED LED could be omitted but is a visual indication that all continues to work right.
Obviously, the circuit could be designed differently, from the selection of the series regulator to the charger circuitry, but that would be another question. So I believe I have addressed the most likely reasons for the findings identified.
Let us know about the RED LED behavior (investigation) and if the changes proposed worked as intended.
Update and Feedback from OP:
The Original Poster - Asmat Ali - helped me to identify a mistake in R2 calculation - thanks! He also mentioned the problem was solved using (my additions):
After adding a 4.7uF capacitor there (output), the circuit worked perfectly with (R1) 1000 and (R2) 470 ohm resistors.
While the circuit could now work just adding the output capacitor, the load current is still too small and I recommend the minimum load is increased.
A minimalistic suggestion is adding to the original circuit R_Load = 180R, providing the worst-case minimum current of 10 mA (@ 1.8V), while keeping that 4.7uF OP mentioned.