CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

RTC on PIC 24FJ64GA306 drifting

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
JamesW



Joined: 23 Apr 2007
Posts: 91
Location: Rochester, England

View user's profile Send private message Visit poster's website

RTC on PIC 24FJ64GA306 drifting
PostPosted: Mon Dec 19, 2016 12:38 pm     Reply with quote

Hi folks,

Very quick question - I'm running the internal RTC on a PIC24FJ64GA306 and it's drifting badly. I set the time at 1pm and it is now running 50 minutes slow (@ 7pm)

I'm running it on a bog standard watch crystal (uk.farnell.com part 1652573 )

With a couple of 15pF caps across it - it stops completely, but by removing them it does run - albeit slowly.

Can anyone offer any pointers - the datasheet doesn't give any concrete values to use, and I'm not sure if I'm able to tune/trim it in code.

Thanks in advance.

James
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Dec 19, 2016 1:00 pm     Reply with quote

slow... I'd say too much cap.... also check PCB. It MUST be CLEAN, use qtip and alcohol to clean ANY solder residue.
I'd have thought Microchip would specify xtal/cap specs 'somewhere' in teh 500-600 pages though.....

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 19, 2016 1:15 pm     Reply with quote

Your crystal has an ESR of 35K. Microchip appnote AN1798 says the
it should be 50K.

It also says the recommeded capacitors are 22 pf:
Quote:
For example, a 32 kHz crystal with a 12.5 pF load
capacitance, the recommended values of C1 and C2
are 22 pF ±5%, 50V NP0

Also, the appnote says the board layout is extremely important.

AN1798:
http://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en571918
http://ww1.microchip.com/downloads/en/AppNotes/00001798a.pdf
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Mon Dec 19, 2016 2:27 pm     Reply with quote

Layout and the crystal caps are big issues. The one time I had to implement a RTC I managed to get a clock accuracy of about +/- 3 seconds over a weekend, or about 1 second per day with nearby circuitry active/running. With that circuitry off and the RTC operating from a backup battery I got about +/- 2 seconds per week. ....At room temperature.

It was one of those instances of ehhh, good enough.
JamesW



Joined: 23 Apr 2007
Posts: 91
Location: Rochester, England

View user's profile Send private message Visit poster's website

PostPosted: Tue Dec 20, 2016 6:34 am     Reply with quote

Thanks guys,

The problem appears to be a lot better - albeit I wouldn't say it is solved.

I've fitted a different crystal, and ended up with 33pF rather than 22pF caps. With 22pF the clock still wouldn't run.

It's been on now for 3 hours and has lost about 4 seconds. (Which is a definite improvement over the 30 minutes it would have been previously.

I will order in a crystal with and ESR of 50K, and see if this makes things even better.

James
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Dec 20, 2016 7:03 am     Reply with quote

I went through the same 'exercise',got very frustrated and ended up using a discrete RTC chip/battery combination ( DS1307). While it's a few pennies more than xtal/caps it works very,very well. Also has a bit of backedup RAM and 1HZ interrupt.
Perhaps an option, at least look into the 'specs and space' for it.

Jay
gaugeguy



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PostPosted: Tue Dec 20, 2016 7:55 am     Reply with quote

Are you using the low power or high power mode? High power mode would be preferred for better stability and accuracy.
Are you using the I/O pin adjacent to the SOSC pins? Any switching on this pin can inject noise into the clock.
It can also at times help to add a series resistor into the oscillator circuit.
JamesW



Joined: 23 Apr 2007
Posts: 91
Location: Rochester, England

View user's profile Send private message Visit poster's website

PostPosted: Tue Dec 20, 2016 8:37 am     Reply with quote

That is a very interesting question. How do I know what mode the oscillator is running in?

I currently have
Code:

#FUSES SOSC_SEL
gaugeguy



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PostPosted: Tue Dec 20, 2016 9:53 am     Reply with quote

Section 9.5.2 of DS39996F discussed CW3<9:8> determining operation and power mode.

Section 9.5.2 of DS39996G has the low power section omitted and only defines one bit CW3<8>

It appears I was looking at an older version data sheet...
JamesW



Joined: 23 Apr 2007
Posts: 91
Location: Rochester, England

View user's profile Send private message Visit poster's website

PostPosted: Tue Dec 20, 2016 12:55 pm     Reply with quote

Ordered one of these 2064057 from Farnell.

Allegedly it's 50K ohm - so will try it tomorrow and see what happens.


After 8 hours of settings - its about 30 seconds behind.

Thanks for all the help

James
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group