MC9S08QE128 STOP3 RTC waking up using alternatively ICS 32kHz and LPO 1khz

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

MC9S08QE128 STOP3 RTC waking up using alternatively ICS 32kHz and LPO 1khz

1,897 Views
goiz74
Contributor I
Hello,

I've succeeded in implementing STOP3 mode with LPO 1kHz OR with ICS 32 kHz (separately)
=> MCU enter stop3 mode then is waked up by RTC (or KBI).

But when I tried the following sequence :

Enter stop3 mode with ICS 32kHz => waking up after ~100ms (run mode) => 1s later, enter stop3 with LPO 1khz (RTC timer = 1s) => MCU cannot be waked up by RTI (but it can be waked up by KBI) !!!

Note : The sequence {STOP3 LPO 1kHz => waking up => STOP3 ICS 32 kHz => waking up} works....

according to MC9S08QE128_0M11J.pdf errata sheet
=> I've a delay of 1ms before each stop instruction (I've tried with 10ms, 100ms)
=> STOP instruction is executed out of RAM memory instead of from flash memory .
=> SCGC2_RTC is always clocked (even if LPO 1khz is used)

does anyone see where could be the problem ?

Thanks !


Labels (1)
0 Kudos
Reply
3 Replies

370 Views
tloten
Contributor I

OK I believe I have stumbled onto the solution.

 

 Basically, I was switching the RTC clock source from 32Khz to the 1KHz clocks, and then disabling the 32KHz clock.

 

This was all being done together:

 

    RTCSC_RTCLKS = 0x00;                // Select internal clock source (1Khz).       
    ICSC1_IREFSTEN = 0;                 // Disable 32KHz during stop mode.
    ICSC1_IRCLKEN = 0;                  // Disable 32KHz clock source.

 

 If it is done like this:

    RTCSC_RTCLKS = 0x00;                // Select internal clock source (1Khz).   
    _asm nop;
    _asm nop;
    _asm nop;
.... 32 nops total (1MHz / 32KHz... ensure 1 cycle of the 32khz is allowed).

_asm nop; 
    ICSC1_IREFSTEN = 0;                 // Disable 32KHz during stop mode.
    ICSC1_IRCLKEN = 0;                  // Disable 32KHz clock source.

 

then it works.

It must be that the RTC requires a clock cycle (of its own clock, not the bus clock) to switch clock sources.

 

Quirky, and should definitely be documented.

 

Message Edited by tloten on 2009-12-21 03:25 AM
0 Kudos
Reply

370 Views
goiz74
Contributor I

hello,

 

my following methods seem work without "timers" :smileywink:

 

 

 

/************************************************************************
 * enable 32khz clock before entering stop3 mode
 *
 ************************************************************************/
void RTC_AllowStop3ExitIcs32K(TByte ics32kValueArg)
{
  // Setup RTC peripheral to generate a 100ms period interrupt ; clock source : ICS 32 kHz internal
 
  // CAUTION !! Setup RTC clock BEFORE setup RTC module itself !!
  ICSC1_IRCLKEN = 1;                  // Activates internal 32 kHz clock
  ICSC1_IREFSTEN = 1;                 // Allow internal 32 kHz clock to continue running during stop3 mode
  SCGC2_RTC = 1;                      // Gates IRCLK clock to RTC peripheral
 
 
  RTCMOD = 0x00;

  RTCSC= (0x00 | RTCSC_RTIF_MASK );// Remove a potential spurious interrupt
  //code factorization for RTCLKS MASK (the same for the 2 RTC values)
 
  switch ( ics32kValueArg )
  {
    default:
      DEV_ASSERT(FALSE);
    break;
   
    case E_RTC_4MS:
      RTCSC |= (RTCSC_RTCLKS1_MASK | VALUE_ICS32K_4MS );
    break;

    case E_RTC_64MS:
      RTCSC |= (RTCSC_RTCLKS1_MASK | RTCSC_RTCLKS0_MASK | VALUE_ICS32K_64MS );
    break;
    case E_RTC_16MS:
      RTCSC |= (RTCSC_RTCLKS1_MASK | VALUE_ICS32K_16MS );
    break;
    case E_RTC_8MS:
      RTCSC |= (RTCSC_RTCLKS1_MASK | VALUE_ICS32K_8MS );
    break;
  }
   

  RTCSC_RTIE = 1;                     // Enable RTC interrupt
}



/************************************************************************
 * enable lpo 1khz clock before entering stop3 mode
 *
 ************************************************************************/
void RTC_AllowStop3ExitLpo1K(TByte lpo1kValueArg)
{
 
  // Setup RTC peripheral to generate a 1s period interrupt ; clock source : LPO 1 kHz internal
 
  // This seems to be useles according spec chap 5.8.11 ; but RTC does not generate interrupts if this line is removed
  // Confirmed by Freescale on 20/3/2008 : enable bus clock to RTC peripheral, even if RTC is clocke by LPO
  SCGC2_RTC = 1;

 
  RTCMOD = 2-1; //2s period


  RTCSC= (0x00 | RTCSC_RTIF_MASK);// Remove a potential spurious interrupt

  switch ( lpo1kValueArg )
  {
    default:
      DEV_ASSERT(FALSE);
    break;
   
    case E_LPO_2S:
      RTCSC |= VALUE_LPO1K_1S;
    break;
  }
  RTCSC_RTIE = 1;                     // Enable RTC interrupt
}

 

/************************************************************************
 *Called from ISR

*
 ************************************************************************/
void RTC_SetupDisable(void)
{
  // Disable wake-up on RTC (case : "MCU goes out of STOP3 mode")
  RTCSC = ( 0x00
  //      | RTCSC_RTIF_MASK
  //      | RTCSC_RTCLKS1_MASK
  //      | RTCSC_RTCLKS0_MASK
  //      | RTCSC_RTIE_MASK           // Disable RTC interrupt
  //      | RTCSC_RTCPS3_MASK         // 0000 => RTC off
  //      | RTCSC_RTCPS2_MASK
  //      | RTCSC_RTCPS1_MASK
  //      | RTCSC_RTCPS0_MASK
          );


  //***************************************************************************
  //WARNING BUG !!!!
  //WARNING BUG !!!!
  //DON'T USE THE LINE BELOW

  //ICSC1_IRCLKEN = 0;                  // Deactivates internal 32 kHz clock
  //***************************************************************************


  //ONLY DISABLED IN STOP MODE (FOR NEXT LPO STOP)
  ICSC1_IREFSTEN= 0;


  SCGC2_RTC = 0;                      // Deactivate clock for RTC peripheral
 
  /*
  AN3460 :
  The clock is gated on or off immediately after the register is written. Be careful when using this feature.
=> After a reset all the clocks are gated on. To keep power consumption down, the clocks should be
gated off as soon as possible.
=> Writes to registers associated with a gated off module have no effect (e.g. writing to the Modulo of
the RTC module if the SCGC2_RTC bit is 1 will not cause the register value to change).
=> To avoid errors, disable the module before gating it off and re-initializing the register when the
module is gated back on.
  */
 
 

}

 

 

/************************************************************************
 * ISR !!!
 *
 ************************************************************************/
#pragma CODE_SEG   __NEAR_SEG NON_BANKED
__interrupt void RTC_ISR_Handler(void)
{
  //--------------------------------------------
  // First thing a interrupt must do (in most cases)
  // Here it is needed because it includes calls to K_Event_Signal() & K_OS_Tick_Update()
  //--------------------------------------------
  K_OS_Intrp_Entry();


  // !! This interrupt should be called only to exit STOP3 mode !!

  RTCSC_RTIF = 1;                     // Acknowledge interrupt
  RTCSC_RTIE = 0;                     // Disable RTC interrupt
  RTC_SetupDisable();
 

  //--------------------------------------------
  // Last thing an interrupt must do (if K_OS_Intrp_Entry called)
  //--------------------------------------------
  K_OS_Intrp_Exit();
}

#pragma CODE_SEG DEFAULT_ROM
 

Message Edited by goiz74 on 2009-12-21 08:32 AM
0 Kudos
Reply

370 Views
tloten
Contributor I

I have just come across the same issue, except I am using a MC9S08QB4.

Seperately, using the LPO (1KHz) to wake from stop3 OR using the ICS 32KHz to wake from stop3 works

However, if using the LPO to wake after have previously used the ICS 32Khz, it will never wake up (as the RTC interrupt never occurs.

 

OP, did you find a fix for the problem?

0 Kudos
Reply