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 support@ccsinfo.com

SOSC for RTC not running
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dluu13



Joined: 28 Sep 2018
Posts: 355
Location: Toronto, ON

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

SOSC for RTC not running
PostPosted: Tue Sep 01, 2020 2:38 pm     Reply with quote

Hi,

I am having some issues with my crystal that is connected to SOSC for RTC. It is a 32.768 kHz, 12.5 pF crystal.

What is strange is that this circuit + code has been working for over one year now, but now that I made more of them, they are no longer working. I suspect that my code is fine and it's my electronics, but I will post the main bits of code associated with this.
Code:

#include <24FJ128GA308.h>
#DEVICE ADC=12
#case

#FUSES ICSP1                    // ICD uses PGC1/PGD1 pins
#FUSES NOJTAG                   // JTAG disabled
#FUSES NODEBUG                  // No Debug mode for ICD
#FUSES NOWRT                    // Program memory not write protected
#FUSES NOPROTECT                // Code not protected from reading
#FUSES WPDIS                    // All Flash memory may be erased or written
#FUSES NOWPCFG                  // Configuration Words page is not erase/write-protected
#FUSES NOBROWNOUT               // No brownout reset
#FUSES NODSBOR                  // BOR disabled in Deep Sleep
#FUSES NOVBATBOR                // VBAT BOR Disabled
#FUSES NOLVR                    // Low Voltage Regulator Disabled
#FUSES NOIOL1WAY                // Allows multiple reconfigurations of peripheral pins
#FUSES VREFNORM_CVREFNORM       // VREF and CVREF are mapped to their default pins
#FUSES NOIESO                   // Internal External Switch Over mode disabled
#FUSES NOWDT                    // No Watch Dog Timer
#FUSES FRC_PLL                  // Internal Fast RC oscillator with PLL
#FUSES NOOSCIO                  // OSC2 is clock output
#FUSES SOSC_SEL                 // SOSC circuit selected

#use delay(clock=32MHz)

int main(void)
{
   CLKDIVbits.RCDIV = 0;
    delay_ms(500);

    setup_rtc(RTC_ENABLE | RTC_CLOCK_SOSC);
    setup_rtc_alarm(RTC_ALARM_ENABLE | RTC_CHIME_ENABLE, RTC_ALARM_HALFSECOND, 0);

   enable_interrupts(INT_RTC);
    enable_interrupts(INTR_GLOBAL);
   while (1) {}
   return 0;
}

#INT_RTC

void rtc_isr() // fires twice per second
{
    output_toggle(GP_LED);
}


Normally, the LED will just toggle every half second. However, in the new build, sometimes that LED will blink only a few times, or for a couple of minutes before stopping. Sometimes it will not start at all. One time I was able to get it to start just by touching the SOSCI pin with an oscilloscope probe. Sometimes if it is working intermittently, I will kill it altogether if I probe it.

As I said before, I really don't suspect the code, especially since I am able to get it working again sometimes by replacing the crystal. Even with this build, it worked for a few days before going kaput.

Now for the physical setup:
I have a crystal connected to the SOSC pins with 12 pF capacitors on each pin to GND. In researching this problem, I found that I am not supposed to put 12pF as the load capacitors, but the equivalent capacitance of the two capacitors should be equal to the load capacitance of the crystals, taking into account some stray capacitance as well.

I have tried using 18 pF, 20 pF, and 22 pF capacitors with no luck.

Do you have any tips for troubleshooting this? Should I give up and use a clock module? Will that take me down an even darker path? Should I just add an RTC module instead of using the built-in one, and use the interrupt pulse function from the RTC module?

Meanwhile, time to read some appnotes...
temtronic



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

View user's profile Send private message

PostPosted: Tue Sep 01, 2020 3:42 pm     Reply with quote

I've been using external RTC modules for years now. The major plus is battery backed time so who cares if the PIC lose power ! 1st the DS1307 but for past 5-6 years the DS3231. The Made in China boards even have an EEPROM on them ! I can't add discrete parts to a PCB for that price and the 'footprint' really can't be made smaller. I've used the 'extra 7 bytes of RAM' for battery backed scratchpad area. It's normally used for RTC compare times-do something. I setup the INT output for 1Hz, which triggers main() to do stuff like update LCD, trigger DS19B20s, etc.

Jay
dluu13



Joined: 28 Sep 2018
Posts: 355
Location: Toronto, ON

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

PostPosted: Tue Sep 01, 2020 5:14 pm     Reply with quote

That might be a good idea but I've realized that I still need to provide a crystal. I'm reluctant to go that way without understanding why my crystal suddenly stopped working.
temtronic



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

View user's profile Send private message

PostPosted: Tue Sep 01, 2020 6:02 pm     Reply with quote

RTC has it's own xtal, PIC only needs a primary xtal....unless it has an internal RC you can use.
PCM programmer



Joined: 06 Sep 2003
Posts: 21232

View user's profile Send private message

PostPosted: Tue Sep 01, 2020 6:22 pm     Reply with quote

The Microchip Explorer 16/32 board BOM shows a 12.5pf crystal:
http://ww1.microchip.com/downloads/en/DeviceDoc/Explorer_16_32_BillOfMaterials_R6_3.pdf

The Microchip Explorer 16/32 board schematic shows 15pf caps on the
RTC crystal:
http://ww1.microchip.com/downloads/en/DeviceDoc/Explorer_16_32_Schematics_R6_3.pdf

Ignore the "DNP" resistors. They optionally connect the circuit to an
auxiliary connector. Also, the 0603 resistor is 0 ohms. So other than
the caps, there are no other passive components in the circuit.
dluu13



Joined: 28 Sep 2018
Posts: 355
Location: Toronto, ON

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

PostPosted: Tue Sep 01, 2020 7:24 pm     Reply with quote

Thanks for that. Unfortunately, 15 pF is a value that I don't have on hand. I'll have to get some. I noticed that some crystals have a different ESR. Do you know how much of a difference that makes?
Ttelmah



Joined: 11 Mar 2010
Posts: 16429

View user's profile Send private message

PostPosted: Tue Sep 01, 2020 10:46 pm     Reply with quote

I'd suspect your batch of crystals.
Too suspicious that older circuit worked, and the new ones don't.
dluu13



Joined: 28 Sep 2018
Posts: 355
Location: Toronto, ON

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

PostPosted: Wed Sep 02, 2020 5:01 am     Reply with quote

I suspected the crystals themselves at first too but then I tried replacing them, even with ones from a different brand but similar specs.
Ttelmah



Joined: 11 Mar 2010
Posts: 16429

View user's profile Send private message

PostPosted: Wed Sep 02, 2020 6:31 am     Reply with quote

OK.
First miss then...

Tell us about the boards. All the same?.
Are the parts through hole, or surface mount?.
Triple check the capacitors. Something silly like having been accidentally
supply 15nF, instead of 15pF is a 'classic'.
Check the batch's of the PIC's. Are they the same revision?.

There is an interesting erratum on the B2 revision of the chip where the
RTCC may wake up enabled. It says that you should disable the RTCC on
boot:
Quote:

To ensure that the RTCC is not enabled, make
sure to clear the RTCEN bit after a POR. This is
recommended whether RTCC is used or not


Now it is interesting that it says to do this whether the RTCC is used or not.
Suggests that not doing so, may cause an issue. Possibly the RTCC will
fail to configure if it is pre-enabled at the boot?.
dluu13



Joined: 28 Sep 2018
Posts: 355
Location: Toronto, ON

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

PostPosted: Wed Sep 02, 2020 8:22 am     Reply with quote

Unfortunately, I don't have any x100 probes, I can't exactly see what is going on with the crystal.

One update: I put on 15 pF on one board that was not working before at all. It was 20 pF. It was working for a few minutes steadily. Then it became unsteady, no longer toggling every 0.5s. Finally it stopped altogether. POR does not bring it back, nor does any other reset.

Now to answer the questions:
Boards are NOT the same, strictly speaking. It is the same outline with a whole bunch of components de-featured. Small changes in some motor running circuits such as using mosfets to run a BLDC w/ PWM and direction pins rather than a h-bridge with FWD and REV pins. The layout of caps/voltage references/crystal near the micro have stayed identical.

Parts are surface mount. Crystal is a 2-SMD component. Capacitors are 0603. The 15 pF ones are 0402 that I got in there.

I am quite sure that the values are what they are. I am at a board manufacturing house and I'm taking it off their reels.

How do I check the batch? Unfortunately, I am not in my office so I don't have the compiler handy to try that.
dluu13



Joined: 28 Sep 2018
Posts: 355
Location: Toronto, ON

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

PostPosted: Wed Sep 02, 2020 8:47 am     Reply with quote

Just a thought about that errata:

If it were the case that the RTC would not work properly if it starts up from POR, then shouldn't selecting the low frequency oscillator as the clock source end up with the same result? Instead, it works perfectly (with the exception of the internal oscillator being wildly inaccurate).

Either way, I guess I will set them all up with 15 pF for now just so they are the same. Then I'll try disabling the RTC after the POR and then re-enabling it. I hope that's the magic charm to make it work :p
dluu13



Joined: 28 Sep 2018
Posts: 355
Location: Toronto, ON

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

PostPosted: Wed Sep 02, 2020 9:37 am     Reply with quote

I got this at the SOSCI pin:
https://youtu.be/Uq5bdjffreQ

What do you think it means? Looks like the oscillation is dying and then trying to start back up.

Edit: on another board:
https://youtu.be/SFp0CwNzfgU
Ttelmah



Joined: 11 Mar 2010
Posts: 16429

View user's profile Send private message

PostPosted: Wed Sep 02, 2020 10:07 am     Reply with quote

Yes.
That would tie with too much load somewhere on the SOSC, or a crystal
that has too low gain. You might find that a 1MR resistor across the crystal
makes it run.
General thing. The crystal rated capacitance, is the capacitance it expects to
see across it. Now on a PCB, there is trace capacitance, then the leg
capacitance of the crystal, and the leg capacitance of the PIC, all in parallel
with each other, in parallel with the capacitors you add, then these are
all in series with the ones on the other leg, to give the actual value
seen by the crystal. Now if you have something like a 9pF rated crystal,
the physical capacitances already there on the board may well be enough.
The capacitance required, is:

(rated capacitance * 2) - (track capacitance + pin capacitance).

So if you have a track capacitance of (say) 6pF and pin capacitances of
perhaps 3pF and a rated capacitance of 9pF, you have a required
capacitance of:

(9*2)-(6+3) = 9pF, which just happens to be the same as the rated
value.
dluu13



Joined: 28 Sep 2018
Posts: 355
Location: Toronto, ON

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

PostPosted: Wed Sep 02, 2020 10:36 am     Reply with quote

Ok, I am not really sure what my track and pin capacitance is. But let's say I use the same values as you had there, but my rated capacitance is 12.5 pF:

(12.5 pF * 2) - (6 pF + 3 pF) = 16 pF. Currently using 15 pF (albeit 0402) which is quite close. Will 1 pF make much of a difference?

In any case, my plan now is to order a range of pF 0603 caps, and a few thruhole 1M resistors to put across the pads of C9 and C10 as shown in this layout:
https://sta.sh/08qznl8kqor

I tried to find a place in the datasheet with required crystal specs, but I couldn't find any... I would appreciate if you let me know in case I just totally missed it.

I do have a 3M resistor on hand so I'll try that first...

EDIT: The 3M resistor appears not to help.

FURTHER EDIT:
I'm back at my office now and there are no oscillations at all. It's quite a bit more humid here...
Oscilloscope traces taken from SOSCI: https://sta.sh/0yt0vw3a6y1

The code running is the same as original post, but with setup_rtc(RTC_DISABLE); before the delay_ms(500).

The trace for the boards without a 3MOhm resistor are similar with a little blip every one second or so.

The trace for the one board with the 3MOhm resistor goes high and sort of stays high, and then tries again every several seconds.

I will also order some crystals with 20Kohm ESR instead of 50 KOhm and see what happens.

More edit:
Sometimes if I keep the probe on SOSCO as I power on the board with the 3 MOhm resistor, the oscillator starts.
I put a 3MOhm resistor on another board, and it did not behave the same.
PCM programmer



Joined: 06 Sep 2003
Posts: 21232

View user's profile Send private message

PostPosted: Wed Sep 02, 2020 1:34 pm     Reply with quote

Can you post the manufacturers and part numbers of the crystals that
you are using, and that you are ordering ?


The crystal layout shown in your link below is not very good:
https://sta.sh/08qznl8kqor

- The capacitors are next to traces that can couple noise into the sensitive crystal circuit.
- It would have been way better to put the caps in a North-South
orientation instead of East-West. It would keep them away from other traces.
- Then the grounds for the caps could meet at a common ground via between them.
- You could then implement a guard ring, which you should have.

In Microchip AN1798, it shows that 22pf is the correct cap value for a
12.5pf crystal. I recall that on Microchip development boards, 22pf is
the value that they use for 32.768 KHz crystals. See pages 3 and 4:
http://ww1.microchip.com/downloads/en/Appnotes/00001798a.pdf
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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