View previous topic :: View next topic |
Author |
Message |
evan
Joined: 02 Apr 2012 Posts: 22
|
Built in RTC / SOSC on PIC24 - What's the secret? |
Posted: Thu Aug 23, 2018 4:12 pm |
|
|
Hi all,
A new challenge, I am using PIC24FJ128GA310 which has the built in RTCC, and I have placed a 32.768kHz secondary oscillator and backup battery to run it.
I am running ex.rtcc with just the chip type changed, but my seconds don't count up, and I can see no waveform on the oscillator pins.
There is no entry in the help file for setup_rtc so I am a bit in the dark about whether it's configured correctly. Does this look like a configuration problem or a hardware problem, does anyone have this module working correctly?
I am using compiler Version 5.078, xxxxx
Thanks in advance as always!
Last edited by evan on Thu Aug 23, 2018 4:51 pm; edited 1 time in total |
|
|
evan
Joined: 02 Apr 2012 Posts: 22
|
|
Posted: Thu Aug 23, 2018 4:35 pm |
|
|
Update:
I changed the setup_rtc line to add RTC_CLOCK_INT, and now the clock is actually running! Albeit a bit fast.
OK, may I change my question to: please help me debug the secondary oscillator? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Thu Aug 23, 2018 7:21 pm |
|
|
If 'debug' you mean it's running fast, you can 'trim' the caps and xtal to get a more accurate speed, beware though that temp and humidty will affect the value a tad. Ideally have the SOSC buffered as the load of a scope probe can affect the speed as well....
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Fri Aug 24, 2018 12:31 am |
|
|
What is the specified Cl of your crystal?.
What loading capacitors have you got on your board?.
Running too fast suggests you do not have enough load capacitance on the crystal. |
|
|
evan
Joined: 02 Apr 2012 Posts: 22
|
|
Posted: Fri Aug 24, 2018 3:21 am |
|
|
To clarify: the RTCC is working with the internal oscillator, which I tried as a test. I don't want to use the internal oscillator, so I don't care that it's fast.
I can't get the secondary oscillator (the crystal) to work at all. I have checked the layout and it looks fine, in line with the datasheet guidelines, appropriate capacitors etc. Is there some trick to enabling it? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Fri Aug 24, 2018 4:54 am |
|
|
While I don't use that PIC..
the 'trick' would be to select the correct FUSE and to enable the SOSC to use an external xtal/cap on the pins.
perhaps use the search button (top of the page) and look for 'SOSC' as a keyword. probably a few dozen hits. since you're not the 1st to ask, it's probably here or in the code library.
Jay |
|
|
evan
Joined: 02 Apr 2012 Posts: 22
|
|
Posted: Fri Aug 24, 2018 5:03 am |
|
|
temtronic wrote: | While I don't use that PIC..
the 'trick' would be to select the correct FUSE and to enable the SOSC to use an external xtal/cap on the pins.
perhaps use the search button (top of the page) and look for 'SOSC' as a keyword. probably a few dozen hits. since you're not the 1st to ask, it's probably here or in the code library.
Jay |
Thanks Jay. I'm posting because I did search, and tried various assembler code solutions about unlocking registers and so on (does anyone know if the compiler handles that, in recent versions?). But anyway, no success, and I am stuck.
There is no mention of Fuses in the data sheet, and the example doesn't use fuses either...?
If I can be sure that the configuration is correct, then it must be the crystal hardware or a problem with the PIC itself. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Fri Aug 24, 2018 5:30 am |
|
|
There has to be a CCS 'command' to instruct whatever 'timer' used to select what 'clock' signal to be the input. Scan the datasheet for the 'flow' diagram, it has to be there. Typically the 'timer' can get it's input signal from a xtal/caps on the SOSC pins, an external signal (say from a canned xtal osc) or an internal osc. So there has to be a 'configuration' SFR to do that.
As I said I don't use any 24PICs, don't have the datasheet but all PICs do share a lot of 'internal' stuff so I'm thinking I'm right. |
|
|
evan
Joined: 02 Apr 2012 Posts: 22
|
|
Posted: Fri Aug 24, 2018 5:45 am |
|
|
You are right - the RTCC can definitely get its clock source from the SOSC - the diagram is in the datasheet page 276: http://ww1.microchip.com/downloads/en/DeviceDoc/30009996g.pdf
And I have guessed that the way to select it for the RTCC is:
setup_rtc(RTC_ENABLE|RTC_CLOCK_SOSC|RTC_OUTPUT_CLOCK,0x00); //enables internal RTCC
(it is always a guess)
But regardless of that, the SOSC is not running, and I can't find whether something else is required to get it running or enable its pins or what have you. |
|
|
evan
Joined: 02 Apr 2012 Posts: 22
|
|
Posted: Fri Aug 24, 2018 6:27 am |
|
|
After more guessing, it turns out that the trick is to put "SOSC_SEL" in the #fuses line. Not SOSC.
Thanks Jay for the hint, but apart from that it was trial and error. I thought I was looking for SOSCEN, from the datasheet.
The assembler unlock sequence mentioned in other threads is *not* needed, at least for this processor version and chip.
Maybe this will help the next person...
Last edited by evan on Fri Aug 24, 2018 6:47 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Fri Aug 24, 2018 6:40 am |
|
|
yeah, what CCS calls a register or pin or bit is not necessarily the exact same as what Microchip does. That's why you need to start with the Microchip datasheet, find the 'thing' you need to control THEN look at the device header file that CCS supplies for your PIC, to see what they call it.
I've seen in the past where CCS call the same bit different names between different PICs, sigh...so now I CONFIRM by scanning the device header file though I've settled on about 3 PICs,saves me a lot of headaches...well, some.....
Jay |
|
|
evan
Joined: 02 Apr 2012 Posts: 22
|
|
Posted: Fri Aug 24, 2018 6:49 am |
|
|
Thanks again for the help, I appreciate it. It just can be frustrating, you can see what you want to do from the datasheet but finding out how (or even if) CCS have implemented it is rarely obvious.
Referring to the device .h file is a must. I'm still in the dark on fuses though! |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Fri Aug 24, 2018 7:28 am |
|
|
If you have the CCS IDE, View->Config Bits brings up a list of the fuses for your processor (the one used by your project). If you don't have the IDE, look for "fuses.txt" in the root directory of your compiler installation.
Between that and the processor's data sheet (the fuses are usually near the back somewhere), and you should be good. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Fri Aug 24, 2018 9:03 am |
|
|
If you look at section 9.5.1 in the data sheet, you will see it says:
Quote: |
To use the Secondary Oscillator, the SOSCSEL bit
(CW3<8>) must be set (= 1).
|
CW3<8> is a fuse (in the configuration words).
The SOSCSEL bit is the SOSC_SEL fuse.
Basically it switches the pins to 'oscillator' mode, as opposed to 'IO' mode. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1354
|
|
Posted: Tue Sep 04, 2018 7:02 am |
|
|
evan wrote: | After more guessing, it turns out that the trick is to put "SOSC_SEL" in the #fuses line. Not SOSC.
Thanks Jay for the hint, but apart from that it was trial and error. I thought I was looking for SOSCEN, from the datasheet.
The assembler unlock sequence mentioned in other threads is *not* needed, at least for this processor version and chip.
Maybe this will help the next person... |
As a PIC24 user, I wanted to point out that the SOSC fuse is for a different selection. It tells the chip to use the SOSC as the primary external clock (which is rarely what you want). Someone mentioned the IDE config bits window. I find it very helpful because you can see how all the fuses are grouped. Based on the mask and the bit values it specifies you can see which fuses are options for each other really easily. Looking at that, you can easily see that the SOSC and SOSC_SEL fuses aren't even related. Hopefully that helps for the future. |
|
|
|