• AVR Freaks

AnsweredHot!How do I set real world clock (UTC or GMT) in MCU?

Author
WeHongKongers
Super Member
  • Total Posts : 227
  • Reward points : 0
  • Status: offline
2020/05/27 02:31:05 (permalink)
0

How do I set real world clock (UTC or GMT) in MCU?

Hello Friends,
I need to set my 16 bit PIC MCU to synchronise with real world clock (GMT or UTC).
 
Please show me some tips.  Thanks.
#1
ric
Super Member
  • Total Posts : 27629
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How do I set real world clock (UTC or GMT) in MCU? 2020/05/27 03:12:19 (permalink) ☄ Helpfulby Tim Cruise 2020/05/27 03:20:05
+3 (3)
Way too many details left out.
Do you want to add some RTC hardware to your board, or just try to read it from somewhere else?
If somewhere else, do you have an Internet connection (ethernet? wifi?)
Otherwise, can you connect to a GPS receiver?
Do you then need to maintain the time?
You would need to implement some sort of regular interrupt yourself to do it.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#2
WeHongKongers
Super Member
  • Total Posts : 227
  • Reward points : 0
  • Status: offline
Re: How do I set real world clock (UTC or GMT) in MCU? 2020/05/27 03:28:09 (permalink)
0
ric
Way too many details left out.
Do you want to add some RTC hardware to your board, or just try to read it from somewhere else?
If somewhere else, do you have an Internet connection (ethernet? wifi?)
Otherwise, can you connect to a GPS receiver?
Do you then need to maintain the time?
You would need to implement some sort of regular interrupt yourself to do it.



Hello RIC,
My device does not have any GPS etc, to avoid privacy infringement.  It also does not need internet.
 
My idea is that - I synchronise my MCU with a local real time clock when I burn its firmware and then it works by its own clock.  Then, it will work according to a programmed calendar in its own firmware.  Just like a usual alarm clock.  A few minutes shift per year is acceptable.
 
Is it possible? Do I need some external hardware or peripheral?
#3
ric
Super Member
  • Total Posts : 27629
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How do I set real world clock (UTC or GMT) in MCU? 2020/05/27 03:31:50 (permalink) ☼ Best Answerby Tim Cruise 2020/05/27 03:46:08
+2 (2)
You haven't revealed which PIC you are talking about.
If you don't have RTC hardware in your PIC or on your board, you're not going to be able to maintain time whenever your PIC is powered down.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#4
WeHongKongers
Super Member
  • Total Posts : 227
  • Reward points : 0
  • Status: offline
Re: How do I set real world clock (UTC or GMT) in MCU? 2020/05/27 03:45:52 (permalink)
0
Thank you very much RIC!
I have checked my target MCU from within its MCC template which shows a Calendar icon on its peripheral list.
 
Then, I just add an external battery to power it and it will work as a calendar.  Smile: Smile
#5
ric
Super Member
  • Total Posts : 27629
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How do I set real world clock (UTC or GMT) in MCU? 2020/05/27 03:48:12 (permalink)
+1 (1)
You still haven't revealed what device it is.
It probably needs a watch crystal, and correct load capacitors for the crystal, and careful design.
Many people have given up and used an external RTC chip.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#6
WeHongKongers
Super Member
  • Total Posts : 227
  • Reward points : 0
  • Status: offline
Re: How do I set real world clock (UTC or GMT) in MCU? 2020/05/27 03:49:38 (permalink)
0
Mine is PIC24FJ128GA204
Smile
 
post edited by Tim Cruise - 2020/05/27 03:53:44

Attached Image(s)

#7
WeHongKongers
Super Member
  • Total Posts : 227
  • Reward points : 0
  • Status: offline
Re: How do I set real world clock (UTC or GMT) in MCU? 2020/05/27 03:56:12 (permalink)
0
I just find its MCC template with its RTC calendar tab.  So COOL!!!
#8
ric
Super Member
  • Total Posts : 27629
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How do I set real world clock (UTC or GMT) in MCU? 2020/05/27 03:57:41 (permalink)
+1 (1)
Yes, that device does contain a  full RTCC peripheral, you just have to connect up a 32kHz crystal (and caps) to the Secondary Oscillator, and get it oscillating correctly.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#9
katela
Super Member
  • Total Posts : 1809
  • Reward points : 0
  • Joined: 2013/06/11 05:25:18
  • Location: South Africa
  • Status: online
Re: How do I set real world clock (UTC or GMT) in MCU? 2020/05/27 06:17:04 (permalink) ☄ Helpfulby Tim Cruise 2020/05/27 11:16:36
+2 (2)
Connect to internet and get time from an NTP Server, preferably choose a server that is physically close to your exit point (internet provider end point).
The packages received could contain multiple information like UNIX timestamp, accuracy, delay or timezone. There are plenty of info on the internet to help you  extract the data in an easy format

Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
#10
WeHongKongers
Super Member
  • Total Posts : 227
  • Reward points : 0
  • Status: offline
Re: How do I set real world clock (UTC or GMT) in MCU? 2020/05/30 01:47:01 (permalink)
0
ric
You haven't revealed which PIC you are talking about.
If you don't have RTC hardware in your PIC or on your board, you're not going to be able to maintain time whenever your PIC is powered down.
 



Hello RIC,
Will the MCU's RTC Calendar reset or stop when
  1. the MCU is shutdown but the power supply is still connected to it?
  2. the power supply has been unplugged from the target MCU?
Looking forward to hearing your opinions.  grin: grin
#11
ric
Super Member
  • Total Posts : 27629
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How do I set real world clock (UTC or GMT) in MCU? 2020/05/30 02:25:51 (permalink)
+2 (2)
I would have to read the datasheet to answer your questions.
Why not skip the middleman and do it directly yourself?
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#12
WeHongKongers
Super Member
  • Total Posts : 227
  • Reward points : 0
  • Status: offline
Re: How do I set real world clock (UTC or GMT) in MCU? 2020/05/30 03:12:40 (permalink)
+1 (1)
I have found it!
RTCC: 400 nA @ 32 kHz, 3.3V typical
- Deep Sleep current: 40 nA, 3.3V typical
 
Li Cell is good enough for this.
#13
RISC
Super Member
  • Total Posts : 5742
  • Reward points : 0
  • Status: offline
Re: How do I set real world clock (UTC or GMT) in MCU? 2020/06/10 17:14:31 (permalink) ☄ Helpfulby WeHongKongers 2020/06/11 01:49:51
+2 (2)
Hi,
In order to achieve high precision, make sure to select a 32 kHz XTAL with a small deviation (some offer to 5 or 10 ppm).
If your application operates over a wide range of temperature, you may need also to correct the deviation according to the temperature. PIC24 RTCC can adjust 32kHz frequency to compensate for the temperature using an external temperature sensor.
Regards
#14
Jump to:
© 2020 APG vNext Commercial Version 4.5