Prototype to Production : RTC clock problem

21 Sep 2010

Hi !

I received my own design board based on the LPC1768 and Mbed eagle drawing.

After solder compoments, one by one with long verification process, my own board is alive ! FlashMagic give me the Device serial number and my first "hello wold" program is working. Great !

I try all parts of my hardware with basic program to test input/output, SdCard, serial (thru Ftdi232) all was perfect and finally i write a little program to test the RTC, my program set the RTC and give me the unix time in a do loop.

I could set the RTC clock, but my RTC don't run :-( very bad news for a datalogger !

I try to change the capacitor around my resonator (18pf -> 22pf) -> nothing

I change my resonator -> nothing

And i read again and again the PC1768 datasheet, perhaps i made issues.

I only find 32.768 Khz resonator (i already use it on I2C realtime chip), the datasheet speack only of 32khz ? a first issue ?

On the datasheet i could not understand if the Vbat need to be set to float if no external 3v battery is use or if Vbat pin (19) NEED to be connected to 3.3v ?

The datasheet say :

The VBAT pin supplies power only to the RTC domain. The RTC requires a minimum of
power to operate, which can be supplied by an external battery. The device core power
(VDD(REG)(3V3)) is used to operate the RTC whenever VDD(REG)(3V3) is present. Therefore,
there is no power drain from the RTC battery when VDD(REG)(3V3) is available.

Picture of the RTC circuit from the datasheet :

We could see Vbat and VDD go into the RTC Power Selector, but VDD seem to be internally wire ? i need to connect Vdd to Vbat pin or not ?

If need to connect VDD and 3v from battery to VBAT, i imagine i need to use diodes ?

If you have information about wiring the vbat pin of an LPC1768, your help will be greatly appreciated !

Thank you.

Regards,

Chris.

22 Sep 2010

Hi,

My RTC clock still not run ;-)

Change the resonator, try other capacitors values, verify and verify again my pcb, try to mount the resonator and caps very close to the pin RTCX1/X2 (i sold the resonator on them !).. nothing my RTC don't want to "count"...

Chris (Chris styles) give me lot of very interesting informations, thank you Chis !

How to be sure RTC clock run from 32kHz resonator source (RTCX1 / X2) after reset ?

I could read in the LPC datasheet, that a pin could be the "reflect" of the RTC clock to fine tuning it if need, this pin is PINSEL3_P1_27_CLKOUT (pin 43 on TQFP LPC1768), how to configure a register with meb to activate this pin in this mode with mbed ?

Thank you for your help...

Chris.

23 Sep 2010

Hi Chris,

If I were facing this problem, the next two things I would do are :

1. Write some software for the mbed that switches the RTC clock source from the external crystal to a (subdivided) internal clock, and then verify that you're programming the RTC, and it is advancing as you'd expect. Then load that app into your own LPC1768 design, and verify that you are seeing the same thing. this will prove the RTC is behaving as you would expect on your own design without the RTC crystal being a potential issue.

2. Write a test program that uses the external crystal, and verify that it is running on your mbed. Have a look at the signals on an oscilloscope, and get familar with what they should look like.

3. Load the second test program into your LPC design, and compare on the scope what you see.

The last thing is to check the schematics of how you have it wired up, and the PCB layout. Screen captures from the board file would work fine, or print the schematic page (and board view) to a PDF and post it here.

Also, feel free to publish the test programs you are writing, so that other can verify correct behaviour.

I remember once someone telling me that crystals can be a bit fragile. It was an anecdote about a consignment of crystals that hand been handled roughly in distribution, and there were a lot of failing parts. Try fitting a crystal form a different batch/source, just in case.

Hope that helps...


Cheers,

Chris

23 Sep 2010


Hi Chris,

Thank you for your help.

1. Write some software for the mbed that switches the RTC clock source from the external crystal to a (subdivided) internal clock, and then verify that you're programming the RTC, and it is advancing as you'd expect. Then load that app into your own LPC1768 design, and verify that you are seeing the same thing. this will prove the RTC is behaving as you would expect on your own design without the RTC crystal being a potential issue.

Good idea, but how to program something like this with the mbed compiler ? i imagine i need to modify the "clock source" register for the RTC, but i don't know how to do this... does mbed have a complete documentation somewhere with function to access of the internal LPC register ?

2. Write a test program that uses the external crystal, and verify that it is running on your mbed. Have a look at the signals on an oscilloscope, and get familar with what they should look like.

Point "2" -> all was perfect on my mbed ! my datalogger program and/or my RTC test program work fine.

I was try to see a signal on the 32.768 khz mbed crystal with my scope, but it is possible ? datasheet of LPC1768 indicate that the RTC system use a very low consumption power system, to see the RTC clock, the way seem to be use PINSEL3_P1_27_CLKOUT, but again, how to activate this pin with mbed compiler ? i'm very new with LPC and mbed... sorry.

3. Load the second test program into your LPC design, and compare on the scope what you see.

The last thing is to check the schematics of how you have it wired up, and the PCB layout. Screen captures from the board file would work fine, or print the schematic page (and board view) to a PDF and post it here.

Also, feel free to publish the test programs you are writing, so that other can verify correct behaviour.

Ok, i will do that asap.

I remember once someone telling me that crystals can be a bit fragile. It was an anecdote about a consignment of crystals that hand been handled roughly in distribution, and there were a lot of failing parts. Try fitting a crystal form a different batch/source, just in case.

I was try yesterday 4 new crystal from my local vendor... no change.

Hope that helps...

Yes ! thank you for your very useful help, I feel less alone with this issue.

thank you again.

Chris (the frog).

 


Cheers,

Chris

23 Sep 2010

Here extract of schematic and PCB  :

Thank you.

Chris the frog.

23 Sep 2010 . Edited: 23 Sep 2010

In the Datasheet there is a note number 12 for the VBAT-Pin, which says: "When the RTC is not used, connect VBAT to VDD(REG)(3V3) and leave RTCX1 floating". So for me this sounds like the VBAT-Pin should always be connected either to a Battery or to VDD, no matter if the RTC is actually used or not. So maybe the RTC can't function with VBAT not connected.

Best regards
Neni

23 Sep 2010

Hi Nenad,

Thank you for your answer.

On my board, i add a wire between my cell coin to the Vbat Pin, my Vbat pin have always 3v on it.

I also tried to connect VDD to Vbat without success...

Chris give me interesting information in a private message :

For the LPC1768, you can hook up your 3v cell directly to the VBAT pin - the power muxing is done inside. Note that this is not the case with the LPC2368, which is sort of (but not quite) pin compatible. The diode arrangement on the mbed board was because it was originally needed the VBAT pin to be powered, even if the other Vdd pins were powered

An i could see on the figure on the datasheet (see my first post) that VDD is internally connected to the "RTC POWER DOMAIN" circuitry.

I think Vbat power source is longer an issue on my board, but my RTC still not run :-(

Thank you.

Chris

23 Sep 2010

Hi Chris,

ok then, what's the load capacitance (CL) of your 32 kHz crystal? This info should be available in the datasheet of the used crystal. The external load capacitors (C3 an C4 in your case) should be chosen according to that value. So for example if CL of the crystal is 10pF, the two external capacitors by theory should be ca. 20pF (CL = Cx1 * Cx2 / (Cx1 + Cx2)). So the external capacitors should be 20pF minus the parasitic capacitances of the PCB, Pins etc. So the actual values for Cx1 and Cx2 have often to be a lot lower than the theoretic values. So in this example for a CL of 10pF one should choose Cx1 and Cx2 to be ca. 12pF or even lower.
Too large load capacitors can prevent the oscillator from starting up properly.

Best regards
Neni

23 Sep 2010

Hi Nenad,

First tests was made with a 32.768Khz crystal (tube type), i have no datasheet on it.

For my last test i was buy new crystal (tube type) from my local vendor, with the datasheet : CL of this crystal is 12pf.

I was try 10pf, 12pf, 18pf, 22pf (all pf capacity i was in stock ! ;-) -> nothing.

I would like to be sure external clock with 32.768khz crystal for RTC is enabled in the software, but for the moment i did not find this information on mbed forum, i continue to seach...

Thanks !

Chris.

23 Sep 2010

Hi,

I take datasheet, cofee and...

I wil try this program when i go home :

 

 

#include "mbed.h"
//Why my RTC did not run ?
int main()
{
    //Black side of the force...
    LPC_SC->PCONP |= 1<<9; // turn on RTC (Page 63, Table 46, bit 9 -> PCRTC : The RTC power/clock control bit)
    
    //Configure CLKOUT (Page 66, paragraphe 4.10 
    // 3:0 CLKOUTSEL Selects the clock source for the CLKOUT function.
            // 0100 Selects the RTC oscillator as the CLKOUT source.
            LPC_SC->CLKOUTCFG != 1 << 2; 
        // 7:4 CLKOUTDIV Integer value to divide the output clock by, minus one.
            //0000 Clock is divided by 1.
            //Nothing to do here 
        
        // 8 CLKOUT_EN CLKOUT enable control, allows switching the CLKOUT
            // set to 1 ton ENABLE
        LPC_SC->CLKOUTCFG = 1 << 8;
    
    //Configure Pin
    //(Page 109 8.5.4 Pin Function Select Register 3 (PINSEL3 - 0x4002 C00C))
    // 23:22 P1.27[1]
    // function when 00 -> GPIO 
    // function when 01 -> CLKOUT
    // function when 10 -> USB_OVRCR
    // function when 11 -> CAP0.1
    LPC_PINCON->PINSEL3 != 0 << 23;
    LPC_PINCON->PINSEL3 != 1 << 22;
              
    set_time(1256729737);
    
    while(1)
    {
        time_t seconds = time(NULL);    
        printf("Seconds = %d\n",seconds);      
        wait (1); 
    } 
}

I hope not to have made too many errors, it is the first time i manipulate LPC register and have a little more luck tonight.

Chris the frog.

03 Oct 2010

Hi !!

After more 1 week, i was solve one issue of this crazy "RTC mystery machine" ;-)

Issue 1 : my RTC did not count -> quartz did not start, i try many 32.768kHz "tube" crystal and many capacitor value without success.
I could solve the issue with a 32.768kHz SMT crystal and 12pf capacitors -> the RTC count now !
I will need to modify my board to add this crystal close as possible of the RTCX1 RTCX2 pins too.

Issue 2 : when i cut the main power, the RTC backup did not work, i try the 3v cell coin directly on the vbat pin (LPC1768 pin 19), try 2 diodes circuitry to automatically apply regulated 3.3v to pin19 or 3V cell coin : -> RTC backup always fail.

If you have experience with the LPC1768 RTC backup circuitry... you help is welcome !

Thanks.

Chris (the Frog).

18 Oct 2010

Hi !

News from my prototype 2 production "RTC issues".

All issues was solved !

The last one (no RTC backup with cell coin) -> issue was due to an bad LPC1768 set, after reorder another batch of LPC, all works fine !

To resume : try to route the RTC crystal and capacitors as close as possible to the LPC. Use the capacitor value that match with the crystal (be sure have the good crystal datasheet), if after many weeks of checking a issue could not be solved... try another µC ! ;-)

Chris (the frog).

15 Jun 2012

Can you point me to the datasheet of this smd oscilator you used? I was going to try these tubular ones, but so far no one confirmed me that they work with the lpc1768 and I'd rather not waste too much time on this. thanks!

15 Jun 2012

Hi Alexandre,

The part we use is a EPSON TOYOCOM, FC-135 32.768KHZ ±20PPM, 12.5PF

Here is a link to it on Farnell :

http://uk.farnell.com/epson-toyocom/fc-135-32-768khz-20ppm-12-5pf/crystal-sm-watch/dp/1278036

Hope this helps!

Thanks, Chris