Different low power mode behavior when PE BDM is connected and when it's not

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

Different low power mode behavior when PE BDM is connected and when it's not

972 Views
adelantesey
Contributor IV

I wrote a program to be run on MC9S12XEG128 as below and program/debug it using P&E BDM. I tried to take the MCU to full stop mode and fast wake up the MCU using API after 13sec, then start the oscillator clock and at last turn on the PLL. By Toggling a Pin, there should be three different types of pulses with different Period (400us, then 100us and finally 25us). When I run the program in the debugger mode, it works fine and the result is as perfect as below:

Figure 1 : when we are in debugging mode and the debugging cable is connected.

But the problem arises when I disconnect the BDM cable and run the program on its own. Then I observe the following behavior:

Figure 2: when the MCU runs on its own with the debugger cable disconnected.

It seems that the MCU wakes up on the Oscillator not the internal clock in self clock mode. I know that the BDM takes the MCU into special single chip mode using BKGD pin and the MCU normally runs in the Normal single chip mode but I don't understand these different behaviors. Shouldn't the MCU work as it is programmed and run in the debugging mode and if not so, what should I do to get the expected result (I mean those three different periods) as in figure 1? I really would appreciate your help.

void main(void)

{

                MCU_init();                        // does some initialization           

                 _DISABLE_COP();

                EnableInterrupts;

                GPIO_STOP();   //disable other interrupt that can wakeup the MCU

 

/*Enable API*/

VREGAPICL = 0;

                VREGAPIR = 0xFFFF;                       //13 seconds

                VREGAPICL_APIE = 1;   

                VREGAPICL_APIFE = 1;

               

/*Full Stop Mode*/

PLLCTL = 0x09U;                                //enable fast wakeup   

CLKSEL_PLLSEL = 0;     

PLLCTL_PLLON  = 0;

CLKSEL_PSTP = 0;

asm ANDCC #0x6F;

asm STOP;

 

/*Disable API*/

VREGAPICL = 0;

 

ECT_Init();          

ECT_TC0 = ECT_TCNT + 400;

ECT_TSCR1 = 0x90;

PIN_Toggle = ~PIN_Toggle;

for(;;)

{

_FEED_COP();

}

}

 

/*the ECT-channel0 isr*/

__interrupt void isrVectch0(void)

{

                ECT_TFLG1_C0F = 1;      

                ECT_TC0 = ECT_TCNT + 400;       

                PIN_Toggle = ~PIN_Toggle;

                Count++;            

                if (Count == 5)

                {                             

                                PLLCTL_FSTWKP = 0;                       //start oscillator

                }

                if (Count == 30)

                {

PLLCTL_PLLON = 1;                          //turn on PLL

                                while(!CRGFLG_LOCK);               

                                CLKSEL_PLLSEL = 1;                          //switch to PLL

                }  

}

/*It just does some initialization, then activates the API timer (using internal RC and period of 13 seconds) and enables the fast wake up mode. After that, it takes the MCU to full stop mode and wakes up in self clock mode with internal Frequency of 1MHz. Then, it initiates the ECT timer ch0 with the value of 400. In the ECT_isr, after clearing its flag, the timer is reinitiated for another 400 bus clock. After a couple of times, I enabled the oscillator (which takes a while to be stabilized) and it automatically switches to oscillator clock which is 8MHz (bus clock = 4MHz). Finally, the clock is switched to 32MHz PLL (bus clock = 16MHz).*/

Labels (1)
0 Kudos
Reply
3 Replies

753 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

Could you please test folowing code and measure BUSCLK at PE4 pin?

Entire project is also attached. (CodeWarrior 5.1)

Note; BDM must be disconnected otherwise clock is affected by BDM connection and STOP mode does not work correctly

BR

Ladislav

//==============================================================================

// Note: USB BDM Multilink must be disconnected, otherwise it is not working

//       because BDM affect behavior of the MCU and clock.

// OSCCLK = 16MHz; also setup for 8MHz is presented below

// BUSCLK = 16MHz; set by PLL

// BUSCLK is visible at pin PORTE_PE4

//==============================================================================

#include <hidef.h>      /* common defines and macros */

#include <MC9S12XEP100.h>     /* derivative information */

#pragma LINK_INFO DERIVATIVE "mc9s12xep100"

//==============================================================================

//==============================================================================

void set_pll(unsigned char _synr, unsigned char _refdv, unsigned char _postdiv);

void API_Init(void);

#pragma CODE_SEG NON_BANKED

interrupt 64 void API_ISR(void);    // (0xFE-0x7E)/2 = 0x40 H = 64 d

#pragma CODE_SEG DEFAULT

//==============================================================================

void set_pll(unsigned char _synr, unsigned char _refdv, unsigned char _postdiv)

{

  PLLCTL = 0B00000001; // CME=0,PLLON=0,FM1=0,FM2=0,FSTWKP=0,PRE=0,PCE=0,SCME=1

  CLKSEL = 0B00000011; // PLLSEL=0,PSTP=0,PLLWAI=0,RTIWAI=1,COPWAI=1

  SYNR = _synr;        // Set the multiplier register

  REFDV = _refdv;      // Set the divider register

  POSTDIV = _postdiv;  // Set the post divider register

  PLLCTL_PLLON = 1;    // Enable the Phase Lock Loop

  while(!CRGFLG_LOCK); // Wait till the PLL VCO is within tolerance

  CLKSEL_PLLSEL = 1;   // Select clock source from PLLCLK

 

  ECLKCTL_NECLK=0;     // Enable the BusClk output at ECLK pin (PE4) to see

                       // busclk if necessary; J102.15 (51) at EVB9S12XEP100

                      

  PLLCTL_FSTWKP = 1;   // To enable fast wake up from stop mode

}

//==============================================================================

// API_Init

//==============================================================================

void API_Init(void)

  VREGAPICL_APIFE = 0;  //

  

  VREGAPICL_APICLK = 0; //Autonomous periodical interrupt clock used as source.

  VREGAPIR = 0xFFFF;    //13107.2ms for APICLK=0

 

  VREGAPICL_APIES  = 1; //APICLK visible an connected to PTT_PTT5

  VREGAPICL_APIEA  = 1; //

  VREGAPICL_APIE   = 1; //API interrutp enable

  VREGAPICL_APIFE  = 1; //API enable

}

//==============================================================================

// API_ISR

//==============================================================================

#pragma CODE_SEG NON_BANKED

interrupt 64 void API_ISR(void)    // (0xFE-0x7E)/2 = 0x40 H = 64 d

  VREGAPICL_APIF = 1;   //clear flag

}

#pragma CODE_SEG DEFAULT

//==============================================================================

void main(void)

{

  unsigned int i,j;

// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

  DDRB  = 0x0F;                             // PORT B0,B1,B2,B3 are outputs

  PORTB = 0x00;                             // switch off diodes

// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

  API_Init();

// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

  set_pll(0x00, 0xC0, 0x00);                // BUSCLK=16MHz from OSCCLK=16MHz

//  set_pll(0x01, 0x80, 0x00);                // BUSCLK=16MHz from OSCCLK=8MHz

// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

  asm ANDCC #$7F                            // enable STOP mode

// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

  EnableInterrupts;                         // enable I-bit maskable interrupts

// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

  for(;;)

   {

    asm STOP                                 // STOP the MCU

    for(j=0;j<100;j++)

      {

       for(i=0;i<0xFFFE;i++) asm nop;        // SW delay

       PORTB_PB3 = ~PORTB_PB3;               // blink diode at PB3

//     You can perform after STOP mode:

//     1) either

//       if(j==4)                              // procedure to finish self clock

//        {                                    // mode and enable fbus=fosc/2

//          PLLCTL_FSTWKP = 0;

//          PLLCTL_FSTWKP = 1;

//        }

//     2) and/or

       if(j==32)                             // procedure to finish fbus=fosc/2

        {                                    // mode and set and enable PLL

            set_pll(0x00, 0xC0, 0x00);       // BUSCLK=16MHz from OSCCLK=16MHz

        }

      

      }

   }

// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

}

//==============================================================================

753 Views
adelantesey
Contributor IV

Hi,

Thanks for the code you sent me. I tried it and observed the PE4 PIN and it works fine. I mean I see the three types of bus clock on PE4 (period 1000ns, 250ns and 65ns respectively). Then I went through my code and found out when I change the API period from, for example, 0x000F to 0xFFFF, it also works fine. How can it be the reason for this issue?

By the way, in spite of what you did, I disable my API after its first interrupt.  I attached the code since it has been changed a little bit.

Best Regards,

0 Kudos
Reply

753 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

by my opinion the main issue is hidden in the function MCU_Init which is not visible.

1. The most probable root causeis that some of the bits are write once in the NORMAL modeof the MCU and write anytime in the SPECIAL mode.

Could you please check the function MCU_Init. Probably you write in this function into the PLLCTL register and you set PLLCTL_SCME to 0. In the code below you set it to 1. If you are in NORMAL mode you are not able to switch it on again. This could be a reson why it is not started in the self clock mode.

  2. Note: clearovani flagu -  ECT_TFLG1_C0F = 1;  is incorrect. This aproach will clear all flags because bit function is read modify write instruction with entire byte. Correct approach is ECT_TFLG1 = 0x01;       .// clear C0F only;

                                                              //  for more info read http://www.freescale.com/files/microcontrollers/doc/app_note/AN2554.pdf, Clearing and Disabling Interrupt Flags

Best regards,

Ladislav

0 Kudos
Reply