ADUC7022 Timer3 Sleep Mode Wakeup

Could you provide some example code for waking the microcontroller form sleep using timer3 interrupt?

Since PLL is not started could this be started safely in the interrupt?

Is this a valid ?

__irq void IRQ_Handler (void) 

{

    if ((IRQSTA & WAKEUP_TIMER_BIT) !=0)             // Timer2 IRQ
    {
       
      
         PLLKEY1 = 0xAA;
       PLLCON = 0x01;  // Generate from PLL based on XTAL
       PLLKEY2 = 0x55;

    
       POWKEY1 = 0x01;
       POWCON = frequency;
       POWKEY2 = 0xF4;

   }

}

  • 0
    •  Analog Employees 
    on Jan 14, 2011 3:20 PM

    I assume you are trying to switch the oscillator source for the PLL from internal to external?

    The source you provide below looks like the recommended code from the datasheet. The problem I have with it is, it should not be placed in the interrupt service.

    The reason we place the part in sleep mode when switching the oscillator/clock source is to ensure no glitches occur when changing the PLL clock source. While the part is in Sleep mode, the oscillator source is changed and the program resumes safely when the wakeup timer triggers.

    T2LD = 5;

    T2CON = 0x480;

    while ((T2VAL == t2val_old) || (T2VAL >

    3)) //ensures timer value loaded

    IRQEN = 0x10;

    //enable T2 interrupt

    PLLKEY1 = 0xAA;

    PLLCON = 0x01; //Select external crystal

    PLLKEY2 = 0x55;

    POWKEY1 = 0x01;

    POWCON = 0x27; //

    Set Core into Nap mode

    POWKEY2 = 0xF4;

  • So the steps for going to sleep and return is the following?

    Is this correct?

    1.Microcontroller is using external crystal.

    2.Set the timer to wake up after a period.(we want the microcontroller to sleep for a period of time to save energy)

    3.Set the POWCON to go in sleep mode.(now pll is disabled )

    4.Microcontroller is firing the timer interrupt.(now is awake)

    5.Exit the interrupt

    6 Set external crystal, Set pll

    7 Set interrupt timer

    8.Set the Microcontroller in nap mode

    9.Interrupt timer is firing

    10 Microcontroller is in active mode