This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

initialiazation of arm

Dear All,

I am working my project of led Blinking.The controller used is arm7 LPC2214.Crystal is 11.0592mhz.
Which works fine but only one problem is, to make it working i have to touch one of my Oscilloscope probe to crystal of controller.Then it start working.Also works well in keil debugger(internal) and on proteus.So please help me to solve this problem.
The source code is as follows,


#include <lpc22xx.h>
#include <stdio.h>

#define VREF  3
#define Beep      0x00001000
#define LED1      0x00000800
#define LED2      0x00000400
#define LED3      0x00000200
#define LED4      0x00000100
#define CE                0x00000001
#define OE                0x00000002
#define WE                0x08000000




#define low   IO0CLR = LED1 ;   \ 
              IO0CLR = LED2 ;   \ 
              IO0CLR = Beep ;


#define hig   IO0SET  = LED1 ;   \ 
              IO0SET  = LED2 ;   \ 
              IO0SET  = Beep ;

unsigned int val;


unsigned long Fosc = 11059200;
unsigned long Fcclk = 0;
unsigned long Fcco = 0;
unsigned long Fpclk = 0 ;


        void TargetResetInit(void)
        {
        Fcclk = Fosc * 4;
                Fcco = Fcclk * 4;
                Fpclk = (Fcclk / 4) * 1  ;

                MEMMAP = 0x2;                   //remap
            PLLCON = 3;
                if ((Fpclk / (Fcclk / 4)) == 1)
                VPBDIV = 0x10;
                else if ((Fpclk / (Fcclk / 4))== 2)
                                VPBDIV = 0x11;
                         else if ((Fpclk / (Fcclk / 4)) ==  4)
                                        VPBDIV = 1;
                if ((Fcco / Fcclk) == 2)
                PLLCFG = ((Fcclk / Fosc) - 1) | (0 << 5);
                else if ((Fcco / Fcclk) == 4)
                PLLCFG = ((Fcclk / Fosc) - 1) | (1 << 5);
                else if ((Fcco / Fcclk) == 8)
                PLLCFG = ((Fcclk / Fosc) - 1) | (2 << 5);
                else if ((Fcco / Fcclk) == 16)
                PLLCFG = ((Fcclk / Fosc) - 1) | (3 << 5);
                PLLFEED = 0xaa;
        PLLFEED = 0x55;
        while((PLLSTAT & (1 << 10)) == 0);
        PLLCON = 3;
        PLLFEED = 0xaa;
        PLLFEED = 0x55;

            MAMCR = 0;
                if( Fcclk < 20000000)
                MAMTIM = 1;
                else
                if ( Fcclk < 40000000)
                MAMTIM = 2;
                else
                MAMTIM = 3;
            MAMCR = 2;
                VICIntEnClr = 0xffffffff;
        VICVectAddr = 0;
        VICIntSelect = 0;
}



void Delay (unsigned long a) {
  while (--a!=0);
}

 void ledInit(void)
 {

   IO2DIR = 0xFFFFFFFF;
   IO2SET = 0;

   IO1PIN = 0x00000000;
   IO1DIR |= CE;
   IO1DIR |= OE;
   IODIR1 |= CE;
   IODIR1 |= OE;

   IO1SET |= CE;
   IO1SET |= OE;

   IO3DIR = 0xFFFFFFFF;
   IO3SET = WE;

   IO0DIR = LED1;
   IO0SET |= LED1;
}

static void ledOn(int led){
   IO0CLR = led;
}

static void ledOff(int led){
   IO0SET = led;
}

void delay(int d){
  for(; d; --d);
}




   int main(void)
   {
          ledInit();
          TargetResetInit();
      ledOn(LED2);
          ledInit();

           while(1)
       {
        ledOn(LED1);
        delay(20000*8);
        delay(20000*8);
        delay(20000*8);
        delay(20000*8);
        delay(20000*8);

        ledOff(LED1);
                delay(20000*8);
        delay(20000*8);
        delay(20000*8);
        delay(20000*8);
        delay(20000*8);
      }

}




Thanks & regards,
Girish

Parents
  • hi,
    Thanks again,

    As explained earlier the crystal of 11.0592 Mhz. Capacitor across crystal are of 20PF.
    Resistor between two leads of crystal is of 1 M ohm.Power of 3.3v.
    Port2 pin P2.26,P2.27 (Boot0 & Boot1) tied to Vcc(3.3V),V3 = 3.3 V,
    Port0 Pin14 P0.14 to 3.3V
    With Proper grounding and power traces as this board is of commercial product.

    Is initialization routine is ok? any need to modify,any correction ?
    Please reply ,
    Thanks
    Girish.

Reply
  • hi,
    Thanks again,

    As explained earlier the crystal of 11.0592 Mhz. Capacitor across crystal are of 20PF.
    Resistor between two leads of crystal is of 1 M ohm.Power of 3.3v.
    Port2 pin P2.26,P2.27 (Boot0 & Boot1) tied to Vcc(3.3V),V3 = 3.3 V,
    Port0 Pin14 P0.14 to 3.3V
    With Proper grounding and power traces as this board is of commercial product.

    Is initialization routine is ok? any need to modify,any correction ?
    Please reply ,
    Thanks
    Girish.

Children
  • hi,
    I also modified initialization of PLL of lpc2214 as following way till i got same result.

             void init(void)
             {
                    // Initial PLL & VPB Clock For ET-ARM7 STAMP LPC2119
                    // Start of Initial PLL for Generate Processor Clock
                    // PLL Configuration Setup
                    // X-TAL =      11.0592
                    // M(Multiply) = 3                3
                    // P(Divide) = 2                  2
                    // Processor Clock(cclk) = M x OSC
                    //                       =      3*11.0592
                    //                       =      33.1776
                    // FCCO = cclk x 2 x P
                    //      = 132.7104
                    // VPB Clock(pclk) = 16.5888
                    // Start of Initial PLL for Generate Processor Clock
                    PLLCFG &= 0xE0;    // Reset MSEL0:4
                    PLLCFG |= 0x02;    // MSEL(PLL Multiply) = 3
                    PLLCFG &= 0x9F;    // Reset PSEL0:1
                    PLLCFG |= 0x20;    // PSEL(PLL Devide) = 2
                    PLLCON &= 0xFC;    // Reset PLLC,PLLE
                    PLLCON |= 0x01;    // PLLE = 1 = Enable PLL
    
                    PLLFEED = 0xAA;    // Start Update PLL Config
                    PLLFEED = 0x55;
                    while (!(PLLSTAT & 0x00000400));  // Wait PLL Lock bit
                    PLLCON |= 0x02;    // PLLC = 1 (Connect PLL Clock)
                    PLLFEED = 0xAA;     // Start Update PLL Config
                    PLLFEED = 0x55;
                    VPBDIV &= 0xFC;    // Reset VPBDIV
                    VPBDIV |= 0x01;    // VPB Clock(pclk) = cclk / 1
                    // End of Initial PLL for Generate Processor Clock
    
                    // Start of Initial MAM Function
                    MAMCR = 0x00;     // Disable MAM Function
                    MAMTIM = 0x03;     // MAM Timing = 3 Cycle of cclk
                    MAMCR = 0x02;     // Enable MAM = Full Function
                    // End of Initial MAM Function
                    // Start of Main Function Here
             }
    
    

    Please help,
    Girish

  • I haven't looked into the individual steps you use when setting up the PLL, but the user manual clearly describes the requried steps. And it's important that the PLL constants also are correctly selected.

    But back to the oscillator - note that the frequency is not the only parameter for a crystal.

  • hi,

    As you suggested i tested crystal.The waveform and voltage across crystal are according to specs.
    The PLL setting is done as given in user manual.which is also written in comment in above code.
    so is there is any issue of mode of arm like user,Data Abort,udef,IRq,supervisory etc
    & if so it is how to sort out this issue?
    Thanks
    Girish

  • You tested the crystal? You have equpiment to measure, and characterize, a crystal?

    What results did you get?

    What inductances did you measure?
    What static capacitance?
    What motional capacitance?
    What load capacitance?
    What drive level?
    What equivalent series resistance?
    What operating mode - fundamental or third overtone?
    What cut?
    What temperature range?
    ...

    A crystal really is not just a magic device with a stamped frequency on the case. With wrong type of crystal and/or wrong burden capacitors in relation to processor, you can get into lots of troubles with oscillators that never starts, or starts sometimes, who only start within specific temperature ranges or depending on of voltage and noise levels etc.

    So the startup code should match the recommended code from the processor documentation, but the capacitors, trace layout and crystal should also match the recommendations. And different processors are more or less sensitive to variations. Some processors can handle almost everything, while other processors have very narrow windows where the oscillator will work well - or at all.

  • Dear Sir,

    As early stated i didn't went so deeply for testing crystal.
    I checked voltage across crystal and waveform of crystal.It was OK.
    If Agreed the crystal is faulty then the issue is if i program the hex file of old programmer in same IC it works successfully.
    Only if i program the same ic with hex file of my program then i have to touch the probe of oscilloscope to one of crystal pin then it starts working.
    How i can convinced to my senior on this issue?

    I also grounded body of crystal.
    will you please help for sorting out this,

    Thanks in advance,

    Girish

  • I checked voltage across crystal and waveform of crystal.It was OK.
    yes, you said that already, to have "checked voltage across crystal" you have touched it with a scope probe

    With Proper grounding and power traces as this board is of commercial product.
    that is no guarantee there are many shoddy "commercial products" how long are the traces to xtal and burden caps? how long traces to and what are the Vdd decoupling caps?

    Erik

  • Another thing - does your processor always make use of an external oscillator, or does it boot with an internal RC oscillator like 23xx does? In that case - what code do you have that turns on the external oscillator and waits for it to stabilize before it may be connected for use by the core?

    You post code for the PLL (seems to be different PLL settings for the two codes) but the PLL needs input. Is the oscillator spun up correcly before connected?

  • Just show him/her!

    Get him/her to help you: he/she knows you, knows your project, can see your hardware, can probe it him/herself, can see your software, etc, etc - nobody on a forum has any of those advantages!

  • Do you mean that you are creating this board to be used as a commercial product?

    Or have you bought the board as a ready-made commercial product?

    If you've bought the board as a ready-made commercial product, why are you not seeking support from your supplier?

  • Hi,

    Thanks for your kind Co-operation,
    Yes i posted two codes .First is sample code of led blinking. Other is i made as given in user manual.
    My senior is not embedded professional is Analog Expert. So i can not ask my queries to him.
    Other thing is the board which i am working is old board and is customized from other party.
    So i am only having the circuit diagram and a sample code. Which is based on ucosII and no other details. So i cant get more help from my resources.
    On power up initiate the PLL frequency which is on 11 Mhz. is anything else required ?

    Thanks & Regards

    Girish.

  • "So i can not ask my queries to him"

    Nonsense!

    Even if he's not a microcontroller expert, he should be able to help you with the basic hardware debugging to find why your oscillator's not working; in fact, an Analogue expert would be an excellent choice to help with oscillator problems - as that is, essentially, an analogue problem!

    And, anyhow, the act of explaining to someone else is often a great way to help yourself; see, for example, www.8052.com/.../96775
    and: www.8052.com/.../100837

    Again, someone who is actually there with you, looking at your actual hardware, seeing the actual results of your tests, speaking your language, who knows you, knows your project, etc, etc is at a great advantage over any remote stranger on a forum!
    Even if he isn't an expert in the field.

    "the board which i am working is old board and is customized from other party"

    So you have to consider the possibility that it is broken.

  • Dear Sir,

    As you suggested i discussed with our senior,He took following actions,
    Changed Crystal,
    Change Capacitor across it (used 33pf ,old was 20p) ,
    Resistor of 1 Mega Ohm used across crystal,
    Grounded Body of crystal by wire,

    Comes to result that there is something wrong in initialization of Crystal/PLL in
    Program.
    Because i am getting same result as before,
    I have to touch the Oscilloscope probe to Crystal out Pin.Then it starts working.
    One thing i want to point out is ,My crystal Frequency is 11.0592 Mhz. And the frequency which is out from XCLk Pin is 44Mhz which is calculated from formula.

    Fcclk = Fosc * 4;

    Fcco = Fcclk * 4;

    Fpclk = Fcclk / 4 * 1;

    given user manual.

    So can you suggest any change or give proper initialization code for PLL.

    Please.
    Thanks & regards,
    Girish

  • But have you realized that the startup of the crystal is not the same as the initialization of the PLL.

    If your processor is similar to the LPC23xx chips then:
    - Enable main oscillator.
    - Wait for main oscillator to stabilize.
    - Select the clock source for the PLL.
    - Wait for the PLL to stabilize.
    - Setup clock dividers.
    - Switch to PLL clock.

    Your posted code covers only some of these steps - and getting the oscillator to start is separate from having the PLL produce a core clock frequency.

    Strictly speaking, the processor does not have any "please I want you to spin up exactly as much as this".

    But it isn't unlikely that your processor contains a similar setting as the LPC23xx have, to select which oscillator range to use. The 23xx have a driver optimization setting to know if the oscillator crystal is 1..20MHz or if it is above. An error in this setting would obviously be a good way for the oscillator to have a hard time spinning up.

    However - as already noted in this post and previous posts: You have not posted any code for turning on the oscillator. We just don't know. We have only seen the irrelevant code where you play with the PLL.

  • Dear sir,

    enable main Oscillator

    
    #ifdef __DEBUG
    
                            _WDWORD(0xE01FC080, 0x00000001); // PLLCON
                            _WDWORD(0xE01FC08C, 0x000000AA); // PLLFEED
                            _WDWORD(0xE01FC08C, 0x00000055); // PLLFEED
    
                            // Disable PLL
                            _WDWORD(0xE01FC080, 0x00000000); // PLLCON
                            _WDWORD(0xE01FC08C, 0x000000AA); // PLLFEED
                            _WDWORD(0xE01FC08C, 0x00000055); // PLLFEED
    
    
                            _sleep_ (100); // Wait for PLL disable
                            _WDWORD(0xE01FC10C, 0x00000001); // CLKSRCSEL: main osc
    
                            _WDWORD(0xE01FC1A0, 0x00000020); // SCS: Enable main osc
    
                            _sleep_ (100); // Wait for osc to stabilize
                            //_WDWORD(0xE01FC084, 0x0000000E); // PLLCFG for 12mhz->60mhz
                            _sleep_ (1000); // Wait
            #endif
    .
    
    

    Thanks & regards,
    Girish

  • "Changed Crystal,
    Change Capacitor across it (used 33pf ,old was 20p) ,
    Resistor of 1 Mega Ohm used across crystal,
    Grounded Body of crystal by wire,"

    User manual for LPC2214 does not specify any resistor if a fundamental crystal is used. Do you use a fundamental crystal, or overtone crystal?

    Requirement for a fundamental crystal is also that Cp is <= 7pF - does your crystal fulfill this?

    You mention old capacitors was 20p and now is 30p - but without mentioning crystal load capacitance or series reistance. So are the capacitors correct according to the table in the processor user manual, for the given frequency range and load capacitance?

    It isn't clear from your posts if your reset signal is asserted for at least 10ms after power-on.

    Your posted code contains:

                            _WDWORD(0xE01FC10C, 0x00000001); // CLKSRCSEL: main osc
    
                            _WDWORD(0xE01FC1A0, 0x00000020); // SCS: Enable main osc
    

    1 - Why magic numbers instead of labeling the registers. Is it funny to read code containing 0xE01FC10C?

    2 - You say you have LPC2214 - but it doesn't seem to have any CLKSRCSEL register or any register at address 0xE01FC10C. It is available on LPC23xx (and maybe other families).

    3 - You say you have LPC2214, and sets bit 0x20 in SCS. But that bit doesn't seem to be defined. It is OSCEN on LPC23xx (and maybe other families).

    Are you doing cut-and-paste programming from whatever sources you find all over the net? Or does the following sentence not only mix up milli/Mega for crystal frequency, but also used processor:
    "The controller used is arm7 LPC2214.Crystal is 11.0592mhz."