PIC Microcontroller RTC Views

Thread Starter

dhruv1128

Joined Jun 28, 2014
6
Hello Everyone,

I want to manufacture a Datalogger using PIC microcontroller. I am logging the data every minute and storing in a SD card along with the timestamp. The temperature of the surrounding environment would be around 50 *C. So, what would be better for generating timestamp :

1. To generate the timestamp using the timers of the pic controller internally through coding.

2. To use RTC modules like DS1307, DS3231 externally connected to the circuit.

Any other options are welcomed.

Hope for a reply

Thank you
 

JohnInTX

Joined Jun 26, 2012
4,787
Its easy enough to generate an interrupt driven system tick using TMR2/PR2 of most PICs. You'll need an accurate oscillator (crystal controlled). Usually the period is on the order of 1-10ms. Just count interrupts to seconds and count minutes and hours from there.

You also can use TMR1's internal oscillator with an external 32KHz watch crystal to generate (slower) tiks. This setup can be configured to keep time using battery backup (the PIC sleeps while the timer keeps running) during periods of power off.

Using the PIC internal timers will require some additional programming but that's offset by not having to buy and program the interface for an external RTC.

There are many threads here on just that subject. Poke around.

Have fun.
 

takao21203

Joined Apr 28, 2012
3,702
Some PICs have integrated RTCC now such as PIC32.

Of course they must kept powered on all the time. Using a module with battery can be easier.

If power supply is secure, then of course using the PIC for RTCC is better.

Or both things, loading from RTCC module, then using the 512 Hz test signal to update the clockkeeping.
 

ErnieM

Joined Apr 24, 2011
8,377
While some PICs come with an internal RTC they are not the easiest thing to use, not if you wish to hold the time date during power outages.

My choice when doing this was to use an external RTC to keep the time.

The reasons are multiple in choosing the PCF2129A to do this:
- very accurate time
- it has it's own battery backup, so set time today and use it for a long long time.
- has internal crystal, one less part to install, plus defined strays for increased accuracy.
- at about $3USD in single quantities is less then half the cost of alternatives.
 

NorthGuy

Joined Jun 28, 2014
611
The internal PIC's RTCC combined with a sleep mode consumes very little current and doesn't require any external parts except for the watch crystal. You only need to design your battery backup in such a way that PIC always has power.

The added benefit is that you can easily wake up at any time if you need to. For example, you can wake up when a button is pressed and turn on the main power. You can also turn off the main power without losing memory state.
 

Potato Pudding

Joined Jun 11, 2010
688
The internal PIC's RTCC combined with a sleep mode consumes very little current and doesn't require any external parts except for the watch crystal. You only need to design your battery backup in such a way that PIC always has power.

The added benefit is that you can easily wake up at any time if you need to. For example, you can wake up when a button is pressed and turn on the main power. You can also turn off the main power without losing memory state.
I also doubt that adding a coin cell battery backup to your PIC w/RTCC peripheral will be more complicated than adding an external RTCC device.

The simplest form of staggered supply isolation is a pair of low Vf diodes dropping power to the PIC's decoupling Capacitors. One for main power and another for the backup batter(y/ies). The Main power must be higher voltage than the backup to make this work. You need to have an onboard comparator in the PIC, connected and coded to drop it into sleep mode whenever the main power drops below the backup coin cell voltage.
 

sirch2

Joined Jan 21, 2013
1,037
The advantage of an external RTC is that you can happily power down or reset the MCU (power failure, watchdog or whatever) without loosing the actual time if you use the RTC battery backup.
 

NorthGuy

Joined Jun 28, 2014
611
The advantage of an external RTC is that you can happily power down or reset the MCU (power failure, watchdog or whatever) without loosing the actual time if you use the RTC battery backup.
PIC's RTCC module will function through the reset without any problems, at least on the MCUs that I looked at.

As to the total lost of all power (including backup), it'll kill time with any RTC, be it external or internal one.
 

embpic

Joined May 29, 2013
189
USE RTC then it can be external or internal. but don't use interrupt driven. bcoz u want time stamp then when u cut off power then this time will lost so better way use RTC with Battery.
 

THE_RB

Joined Feb 11, 2008
5,438
...
I want to manufacture a Datalogger using PIC microcontroller. I am logging the data every minute and storing in a SD card along with the timestamp. The temperature of the surrounding environment would be around 50 *C. So, what would be better for generating timestamp :
...
I think there will already be a lot of coding for operating the SD card and FAT file system, power down code, and obviosuly the sensor logging code etc so the tiny bit of added code to make minutes, and count hours:mins is pretty trivial. So personally I would do it in the PIC.

Regarding the months:days, I would just use linear days ie;
days:hours:mins
where days is a number from 0 to 65536 (assuming you use a 16bit var for "days"). That saves a lot of issues with months:days and gives you easy and reliable code.
 

Thread Starter

dhruv1128

Joined Jun 28, 2014
6
Hello,

Thank You for your reply.

Is PCF2129A accurate when working environment is around 55*C. Orr else can you suggest me some good RTC modules ?
 

ErnieM

Joined Apr 24, 2011
8,377
The accuracy is spec'ed in section 13.2 of the data sheet at ±5 ppm up to 60°C. A conventional tuning fork crystal is off 30-30 ppm at the same temperature.

I could suggest modules with similar performance (made by Maxim) but at a much higher price ($9.06 USD single quantity), or modules that don't perform as well (every module with an external crystal), but I wouldn't.

If you want to look for yourself, here's a list of 2,184 devices. With full knowledge of your needs you may find a device that better suits your custom needs.

I did this using Microchip's file system library code. I'm not sure where this is in their current app library, but the old one is there and it is very simple to work with. I would base my app on the sample "Device - Mass Storage - SD Card reader" project which can read/write the SC card from a PC, add in the file system libraries. The app could read/write the card, and you have the options of either removing the card or just using s USB cable to read out the data.
 
Last edited:
Top