Hi ,
I am new to arduino / electronics. I would like to know a few things about atmega328p mc.
I have a project which I have coded using arduino ide, and then bootloaded it to a atmega328p chip and uploaded the same to it.
It has to be powered by a battery but the time gets reset when I disconnect or the battery is down. I planned to use an external rtc but it would be better if atmega328p supports an internal RTC without resetting.
is there any way this can be achieved ?
No, the ATmega has no RTC. If you want precise timing over longer time and keep the time when you disconnect the main battery (because he, an RTC will need a battery as well), use an external RTC.
It is possible to create an accurate RTC with Arduino. You choose the 8 MHz internal RC oscillator as the CPU clock source, connect a 32 kHz crystal to the OSC terminals and use Timer2 for the RTC counter.
The Arduino must be powered by at least 3V at all times for the RTC Timer2 to work, but it can be in sleep mode.
jremington:
The Arduino must be powered by at least 3V at all times for the RTC Timer2 to work, but it can be in sleep mode.
It works down to 1.8V AFAIK. Probably even less (maybe even down to POR voltage) if you keep the CPU in sleep during the low voltage period.
It can be done but adding an external RTC with own backup battery (or capacitor) will be much easier.
It works down to 1.8V AFAIK.
Most sensor and other modules don't, which is why I recommend 3V minimum to beginners.
I'm planning to use a 3.7v rechargeable battery to charge the arduino, and I got to maintain the time when the rechargeable battery is out of power. I just need to note 24 hrs, and my project don't need the time for day or month, it's just hours, mins that has to be noted. In order to achieve this with less complications and cost what would be your advice. Kindly help..
If I use the internal oscillator of arduino how to switch over to coin battery supply when the rechargeable battery is out of power? Can you share the code gist as well?
Tia
use the 3.3 V as reference, connect battery voltage to an analog input via 10k+ Ohms
If analogread drops below 950.. (3.1V) recharge
@OP: Get an external RTC module - it costs <$1 on eBay including the backup battery. I will take you a LOT of effort to do better with ATMega alone. For battery switchover you may use two diodes, for internal oscillator you need to change fuses, for code look into the Datasheet. Google is your friend, for specific questions you may ask here.