Problem with RTC Oscilator

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with RTC Oscilator

1,018 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Albert on Mon Jan 31 06:53:39 MST 2011
Hi!

I have a doubt about the use of RTC oscillator.

I tried to use the RTC oscillator to provide sinal clock to the CPU and USB, but my code din't work.

I tested this code in the LPCXpresso IDE with the LPCXpresso with LPC1768 target.

Somebody can point the problem with my code? Here it is.

LPC_SC->CLKSRCSEL = 2;//RTC -> PLL0
LPC_SC->PLL0CFG   = 5126; // Fcc0 = 480MHz
LPC_SC->PLL0FEED  = 0xAA; //Feed sequence
LPC_SC->PLL0FEED  = 0x55; //Feed sequence
LPC_SC->PLL0CON   = 0x01; //PLL0 Enable
LPC_SC->PLL0FEED  = 0xAA; //Feed sequence
LPC_SC->PLL0FEED  = 0x55; //Feed sequence
while ((LPC_SC->PLL0STAT & (1<<26))==0);  //Wait until stable. PROBLEM IT IS NEVER STABLE.

LPC_SC->PLL0CON   = 0x03;  //PLL0 Enable and Conect
LPC_SC->PLL0FEED  = 0xAA;//Feed sequence
LPC_SC->PLL0FEED  = 0x55;//Feed sequence
while ((LPC_SC->PLL0STAT & ((1<<25) | (1<<24)))==0); //Wait until stable.

Thanks!
0 Kudos
29 Replies

800 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by szak10 on Wed Mar 16 07:39:46 MST 2011

Quote: Zero
Obviously :)



:D ok. Sorry. It seems that the 32.768 oscilator block is not reached by this hardware bug on RTC.
0 Kudos

800 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Mar 16 07:02:12 MST 2011

Quote: szak10
... I dont read the whole post ...



Obviously :)


Quote:

I have already done this test ando work very well. I saw the 32KHz wave form.

[LEFT]// TODO: insert code here
LPC_PINCON->PINSEL3 &=~(3<<22);
LPC_PINCON->PINSEL3 |= (1<<22);[/LEFT]
LPC_SC->CLKOUTCFG = (1<<8)|(1<<2); //clockout:RTC 1:1

This test OK.

0 Kudos

800 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by szak10 on Wed Mar 16 06:53:27 MST 2011
Hello. Im new here. I dont read the whole post but it seems that rtc doesnt work. There is a problem with the rtc block (Errata LPC 1768 from nxp site). "the RTC is not relieable" saids. I dont know if the problem is with the complete block (then the 32.768 Khz clock will not work properly too) or is a problem only with the RTC. Please check this. May be is a hardware problem and not a software problem. Regards Guiye
0 Kudos

800 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Albert on Tue Feb 01 13:51:47 MST 2011
Hi Zero,

The PLL0 work very well with IRC and Main oscillator. I think that RTC oscillator work too, because there are some example value to configure the RTC oscillator on datasheet.

If someone have already used the RTC oscillator with PLL0 and work fine, please help us.
0 Kudos

800 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Feb 01 12:42:17 MST 2011
Results:

1. My own LPC1768 board with different (THT) RTC crystal is doing exact the same :mad:

2. Trying to reduce FCC0 to minimum of 275 MHz doesn't work, too :mad:

3. Changing clock source to 0 (IRC) @ 280 MHz

LPC_SC->CLKSRCSEL = 0;//IRC
[LEFT]LPC_SC->PLL0CFG = 34; // FCC0 = 280 MHz[/LEFT]

[LEFT]shows a correct 4 MHz (IRC) * 35 * 2 / 4 / 10 = 7 MHz clockout without problems :)[/LEFT]

[LEFT]So I think PLL0 isn't working correct with RTC as clock source. Don't know if that's a general problem or if there is something special (delay ? UM: ...wait for a fixed time when the input clock to PLL0 is slow (i.e. 32 kHz)) needed to get a running PLL0, but a workaround could be the usage of IRC. [/LEFT]
0 Kudos

800 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Albert on Tue Feb 01 11:25:18 MST 2011
You have reason, but the correct value is MSEL=5126 for M=5127. :)

If you update the instruction to LPC_SC->PLL0CFG = 5126; , the problem persist.:mad:

I hope that your test work.

Maybe RTC oscillator with C_CLK source doesn't work or there are some detail that we need to do on LPCXpresso IDE, the problem can be the linker script. CodeRedSupport can clear this doubt, please?
0 Kudos

800 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Feb 01 11:13:03 MST 2011
No, you are setting MSEL=5127 so M=5128 :)

After changing CLKOUTDIV to 0 this frequency doesn't change.
So this indicates that this frequency isn't a result of something, it's showing that switching to RTC isn't working :mad:

To avoid hardware issues I'll test one of my own boards with different RTC crystal.
0 Kudos

800 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Albert on Tue Feb 01 10:55:03 MST 2011
Yes, You are reason, but if I set M = 5127, N = 1 and Fin = 32.768KHz -> Fcco = 336MHz then I should see on P1.27 84MHz/10 = 8,4MHz, but I didn't see anything near this. My  signal is wrong and unstable.

The 820 kHz (0,82MHz) clockout that you see is wrong too. Are you in accordance?

Why your code run and mine not, if both are using the same code?

I think that the problem is LPCXpresso IDE configuration.
0 Kudos

800 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Feb 01 10:20:49 MST 2011
That's nonsense:

LPC_SC->CCLKCFG = 3; //C_CLK = 3MHz
//HERE I SEE ON OSCILLOSCOPE CLKOUT = 300KHz OK

LPC_SC->CCLKCFG is PLL0 divider and should be set via SystemInit to 3 (= /4) already. This doesn't set 3MHz.

Just delete it. But I can also see 300kHz clkout (without this line). Don't know exactly why, but I assume we are seeing 1/4 of external crystal (12MHz) here after disconnecting PLL0.

Running your code shows a 820 kHz clockout here :), indicating a 8.2 MHz cpu clock, what's about 1/10 of the desired value :mad:
0 Kudos

800 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Albert on Tue Feb 01 09:52:49 MST 2011
No I can't see a valid clock signal at 1.27 pin, just until 300KHz.

Thanks for the steps, I had already used many times this method to debbug again.:D

I follow the advice on manual see:

The following sequence must be followed step by step in order to have PLL0 initialized
and running:
[COLOR=Red]1. Disconnect PLL0 with one feed sequence if PLL0 is already connected.
2. Disable PLL0 with one feed sequence.[/COLOR]
3. Change the CPU Clock Divider setting to speed up operation without PLL0, if desired.
4. Write to the Clock Source Selection Control register to change the clock source if
needed.
5. Write to the PLL0CFG and make it effective with one feed sequence. The PLL0CFG
can only be updated when PLL0 is disabled.
6. Enable PLL0 with one feed sequence.
7. Change the CPU Clock Divider setting for the operation with PLL0. It is critical to do
this before connecting PLL0.
8. Wait for PLL0 to achieve lock by monitoring the PLOCK0 bit in the PLL0STAT register,
or using the PLOCK0 interrupt, or wait for a fixed time when the input clock to PLL0 is
slow (i.e. 32 kHz). The value of PLOCK0 may not be stable when the PLL reference
frequency (FREF, the frequency of REFCLK, which is equal to the PLL input
frequency divided by the pre-divider value) is less than 100 kHz or greater than
20 MHz. In these cases, the PLL may be assumed to be stable after a start-up time
has passed. This time is 500 &#956;s when FREF is greater than 400 kHz and 200 / FREF
seconds when FREF is less than 400 kHz.
9. Connect PLL0 with one feed sequence.

I don't understend why my code doesn't work, I do something different on the manual?
0 Kudos

801 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Feb 01 09:39:31 MST 2011
And can you see a valid clockout signal at P1.27?

After changing PLL0, you are 'destroying' your debug connection.:eek:

If you are not able to program / debug your board, don't panic.Just use bootloader to get your board in programmable state:

1. Disconnect USB.

2. Set P2[10] low (see LPCXpresso schematic) = next start with bootloader

3. Connect USB. Now bootloader is started. That's a stable configuration to program your board again with LPCXpresso.

4. Release P2[10] again = next start without bootloader

5. Cycle USB and your board is 'alive' again :)
0 Kudos

801 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Albert on Tue Feb 01 09:20:23 MST 2011
Hi Zero and CodeRedSupport,

Unfortunately the code didn't work with the LPCXpresso 3.6.1 too, the problem persist even when freerunning without jtag debugg & LPC-link

I try to change the code accordingly with the manual, but when I try to change to RTC oscillator the LPCXpresso IDE send a message "16: Target Error from status-poll: System rejected access at location 0xE000EDF0 - verify population of memory and peripherals." follow the other message "15: Target error from Register access Cannot complete transaction, even after slowing speed."

Code:
#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif

#include <cr_section_macros.h>
#include <NXP/crp.h>

// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

int main(void) {
   
    //Main oscillator
    //M=100
    //N=6
    //C_CLK = 100MHz
    //CLKOUT = 10MHz
    // TODO: insert code here
    LPC_PINCON->PINSEL3 &=~(3<<22);
    LPC_PINCON->PINSEL3 |= (1<<22);
    LPC_SC->CLKOUTCFG = (1<<8)|(9<<4); //enable and divide by 10
    //HERE I SEE ON OSCILLOSCOPE CLKOUT = 10MHz OK

    LPC_SC->PLL0CON = 0x01; //PLL0 disconnected and enable
    LPC_SC->PLL0FEED = 0xAA; //Feed sequence
    LPC_SC->PLL0FEED = 0x55; //Feed sequence

    LPC_SC->PLL0CON = 0x00; //PLL0 disconnected and disable
    LPC_SC->PLL0FEED = 0xAA; //Feed sequence
    LPC_SC->PLL0FEED = 0x55; //Feed sequence

    LPC_SC->CCLKCFG = 3; //C_CLK = 3MHz
    //HERE I SEE ON OSCILLOSCOPE CLKOUT = 300KHz OK

    LPC_SC->CLKSRCSEL = 2; //RTC -> PLL0 - THE DEBUGGER DON'T BE ABLE TO CHANGE toTHIS SOURCE. "Message 16 and 15"

    LPC_SC->PLL0CFG = 5127; // Fcc0 = 336 MHz
    LPC_SC->PLL0FEED = 0xAA; //Feed sequence
    LPC_SC->PLL0FEED = 0x55; //Feed sequence
   
    LPC_SC->CCLKCFG = 3; //C_CLK = 336/4 = 84MHz

    LPC_SC->PLL0CON = 0x01; //PLL0 Enable
    LPC_SC->PLL0FEED = 0xAA; //Feed sequence
    LPC_SC->PLL0FEED = 0x55; //Feed sequence
    while ((LPC_SC->PLL0STAT & (1<<26))==0); //Wait until stable.

    LPC_SC->PLL0CON = 0x03; //PLL0 Enable and Conect
    LPC_SC->PLL0FEED = 0xAA;//Feed sequence
    LPC_SC->PLL0FEED = 0x55;//Feed sequence
    while ((LPC_SC->PLL0STAT & ((1<<25) | (1<<24)))==0); //Wait until stable.

    // Enter an infinite loop, just incrementing a counter
    volatile static int i = 0 ;
    while(1) {
        i++ ;
    }
    return 0 ;
}
0 Kudos

801 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Tue Feb 01 00:24:32 MST 2011

Quote: Albert

I tried to compile the project, but the program didn't found the two files.

#include <cr_section_macros.h>
#include <NXP/crp.h>



As Zero says, these files are provided as part of LPCXPresso 3.6.x.

For more details, please see:

http://support.code-red-tech.com/CodeRedWiki/EnhancedManagedLinkScripts

Regards,
CodeRedSupport
0 Kudos

801 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Jan 31 21:29:11 MST 2011
This files are included in LPCXpresso 3.6.

See properties->C/C++ General->Paths and Symbols

Change this include directories to your own folder setting, then clean / rebuild project.
0 Kudos

801 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Albert on Mon Jan 31 21:09:38 MST 2011
Hi Zero,

I tried to compile the project, but the program didn't found the two files.

#include <cr_section_macros.h>
#include <NXP/crp.h>

I search on the internet, but I didn't found, can you send me the two files, please.

Thanks.
0 Kudos

801 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Jan 31 14:37:57 MST 2011
Good news and bad news:

Your project isn't running on my LPCXpresso, so try this:

[ATTACH]294[/ATTACH]

I've changed MCU settings from 1769 to 1768 already.
0 Kudos

801 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Albert on Mon Jan 31 14:06:59 MST 2011
Here the CMSIS
0 Kudos

801 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Albert on Mon Jan 31 13:43:35 MST 2011
Sorry, I attached the wrong project. :D
0 Kudos

801 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Jan 31 13:36:43 MST 2011
That are several projects :confused:
Which of this projects are we talking about?

New version can't be downloaded, it's invalid!!
0 Kudos

801 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Albert on Mon Jan 31 13:31:14 MST 2011
Here it is.
0 Kudos