View previous topic :: View next topic |
Author |
Message |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
Example for RTCC with PIC24FJ |
Posted: Thu Feb 14, 2013 12:52 pm |
|
|
Hi, everyone! I have a few PIC24FJ64GA306 and I saw in the datasheet they have hardware RTCC. So can you tell me which CCS function I can use to work with this RTCC??
Thanks! |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Thu Feb 14, 2013 12:59 pm |
|
|
Make sure to read the PCD Compiler Manual...
Also check the .H file for your device (it's a dead giveaway)
(hint: search for RTCC)
After doing those two things, if you still need help, I'll be happy to advise.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Fri Feb 15, 2013 1:55 am |
|
|
Thanks! I want to ask one more thing. The datasheet of 24FJ64GA306 (RTCC part) says :
Quote: |
• Runs from any one of the following:
- External Real-Time Clock (RTC) of 32.768 kHz
- Internal 31.25 kHz LPRC clock
- 50 Hz or 60 Hz external input |
So as far as I understood this I don`t have to connect external oscillator, but I can use the internal clock. Is this a good idea? Or have misunderstood the datasheet?
I`m using 24FJ controller for first time and it`s little bit different then 18F series.
Where should I connect this extra oscillator? Between PIN 42 and GRD?
I`m not sure for the connection of the controller. I have electrolite cap between pin 56(Vcap) and GRD. Pins 10, 19, 26, 38 are connected to Vcc. Pins 9, 20, 25, 41 to GRD. The main oscillator is on 39 and 40. I have resistor on pin 7 (MCLR). PIN4 of the ICSP connector is connected to PIN 16 PGED1, pin 5 to PIN 15 PGEC1. Is this correct??? |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Fri Feb 15, 2013 8:22 am |
|
|
If you download the PIC24F Family Reference manual (Chapter/Section 29 - RTCC),
You will find on the first page is says, "Requirements: External 32.768KHz Clock Crystal"
The block diagram on the same page verifies this.
The LPRC is for running others things (namely the watchdog)
Additionally, in Chapter 6 - Oscillator (page 2, Figure 6-1), the block diagram specifically shows the LPRC oscillator does not hook up to the RTCC.
So that should answer it for ya.
Cheers,
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Fri Feb 15, 2013 8:31 am |
|
|
stoyanoff wrote: |
Where should I connect this extra oscillator? Between PIN 42 and GRD?
|
MAYBE.
If you have a 32.768 KHz OSCILLATOR, then you can hook up your oscillator output to the SOSC input (but only one).
if you want to use a 32.768KHz CRYSTAL, then it needs to be hooked to BOTH SOSC inputs with addtitional capacitors as the crystal requires.
Microchip has App Notes about this. You should find them and read them.
Quote: |
I`m not sure for the connection of the controller. I have electrolite cap between pin 56(Vcap) and GRD. Pins 10, 19, 26, 38 are connected to Vcc. Pins 9, 20, 25, 41 to GRD. The main oscillator is on 39 and 40. I have resistor on pin 7 (MCLR). PIN4 of the ICSP connector is connected to PIN 16 PGED1, pin 5 to PIN 15 PGEC1. Is this correct??? |
I believe the word you want is "electrolytic" -- and your Vcap connection is correct. What value is the capacitor. Typical recommended is 10uF. You can use Ceramic cap's here as well. (I usually do)
Next - yes. ALL VCC pins should be connected to Vcc (not just some. ALL) and every Vcc pin should have a 0.1uF or so capacitor to GND (ceramic type is fine).
There is an ICSP appnote that tells you how to hook up the PIC programmer (pretty much any of them) in terms of signal. You should review that doc as I can tell you you're missing something. (but your homework is to figure out what since I've pointed it out.)
Cheers,
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1354
|
|
Posted: Fri Feb 15, 2013 3:36 pm |
|
|
bkamen wrote: | If you download the PIC24F Family Reference manual (Chapter/Section 29 - RTCC),
You will find on the first page is says, "Requirements: External 32.768KHz Clock Crystal"
The block diagram on the same page verifies this.
The LPRC is for running others things (namely the watchdog)
Additionally, in Chapter 6 - Oscillator (page 2, Figure 6-1), the block diagram specifically shows the LPRC oscillator does not hook up to the RTCC.
So that should answer it for ya.
Cheers,
-Ben |
The data sheet for this specific family has the following though:
Quote: |
22.1 RTCC Source Clock
The user can select between the SOSC crystal
oscillator, LPRC internal oscillator or an external
50 Hz/60 Hz power line input as the clock reference for
the RTCC module. This gives the user an option to
trade off system cost, accuracy and power
consumption, based on the overall system needs.
|
Additionally, the diagram in section 22-1 of the data sheet references the LPRC as a possible source.
I cannot speak for this chip, but on the PIC24F32KA304, it has a similar option and the LPRC is fine without an external SOSC of 32kHz (again, different chip, but uses the same family reference manual). Is it possible the Family Reference manual is either inspecific or in error, or is the data sheet incorrect? |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Fri Feb 15, 2013 3:56 pm |
|
|
I'm going to say that my datasheet for the RTCC is old. Is the B version. I'll have to check if they've updated.
Just keep in mind the LPRC oscillator is just that, RC (Resistor-Capacitor) and it's accuracy may be less than stellar.
Otherwise, according to the device specific datasheet (which I just downloaded) looks like the LPRC is a valid RTCC Source.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1354
|
|
Posted: Fri Feb 15, 2013 6:11 pm |
|
|
Yeah, the accuracy on the internal is pretty bad...I want to say +-15% tolerance if I remember right? I only use it for coming out of deep sleep on an interval that doesn't require accuracy (like if I just need to wake up once a second or so and it's not critical that it is exactly a second).
To the opening poster:
take a look at the function setup_rtc in both the compiler manual/help index and in the .h file for your chip. It'll highlight the RTC functions and their options |
|
|
Lykos1986
Joined: 26 Nov 2005 Posts: 68
|
|
Posted: Mon Jun 24, 2013 5:59 am |
|
|
Hi! This an old post but I've just resurrected because I am having the same problem.
I am using an 24F32KA304 and I can use the LPRC (page 185 of the datasheet) as a clock source for the internal RTC. As far as I am understanding this will be totally independent of the my primary 12MHz crystal clock and I can still use this 16MHz clock for all the other operations of my program.
How I can use this LPRC for my RTC? I know that the LPRC is not an acurate source for timing but I don't care so much for the RTC accuracy |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Jun 24, 2013 6:18 am |
|
|
#fuses RTCOSC_LPRC// RTCC uses LPRC as reference clock |
|
|
Lykos1986
Joined: 26 Nov 2005 Posts: 68
|
|
Posted: Mon Jun 24, 2013 6:49 am |
|
|
It produces an error (Unknown keyword on MpLab) when I am using this fuse.
Also I was trying to find this fuse using the CCS IDE at the "Valid Fuses" section and there is not there as well.
I am using version 4.14 of CCS. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Mon Jun 24, 2013 8:27 am |
|
|
Are you using 4.014 or 4.140? _________________ Google and Forum Search are some of your best tools!!!! |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Jun 24, 2013 8:41 am |
|
|
Yes, you are right, I was referring to a different 24F chip. With 24F32KA304, the RTCC clock
source is selected in RTCPWC register. Refer to datasheet chapter 19. Don't know if it's supported
by setup_rtc(). In case of doubt, set the SFR directly. |
|
|
Lykos1986
Joined: 26 Nov 2005 Posts: 68
|
|
Posted: Mon Jun 24, 2013 9:22 am |
|
|
I am using the 4.140.
I will try to set the SFR directly. In case you have any news in the mean time please let me know. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Jun 24, 2013 12:46 pm |
|
|
setup_rtc() seems no prepared to write RTCPWC register. When writing directly to SFR, you also have to reset the write lock.
There's another issue with setup_rtc() that is setting OSCCON.SOSCEN which is not suitable for LPRC operation.
All in all, it's probably better to do the complete RTCC setup manually. |
|
|
|