Help with Sleep using PIT

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am using the PIT to wake up from sleep nut it sesms like the controller will not wake up.  I am using the ATTiny1616.  Any help would be appreciated.  Code is attached.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For all sleep mode app, I always start with using idle sleep mode, once the app works with that, deeper sleep modes can be tried!

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The problem I am having it the the Period Timer Enable is not being set before I go to sleep.  Have not figured out why yet because it is being set by the firmware.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note: in Power Down mode, the oscillator for the RTC is stopped, it's only active in idle and standby modes!

Only the oscillator for the watch dog is active in power down mode.

Making low power apps, is an art, start simple (idle mode) and progress to where you want to be.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jim,

 

According to the datasheet for the ATtiny1616,  the Low Power 32KHz Oscillator works in Powerdown Mode.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Perhaps my DS is different:

This table says there is not RTC clock source in PD mode, so I'll repeat myself once more, start in idle mode and work down!

Or ignore me, I don't care.

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you look at Active Clock Domain,  PIT(RTC) is active in Power Down.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When one asks for help, one must be humble enough to accept the help offered.....

 

But what is the clock source for your RTC?  What does the DS say about that in power down mode?  Look at the oscillators row!

Which clock must you use?  Let me know when you find it in the DS.....

 

Again, start with idle mode, get it working, work your way down to PD mode.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Since this is a battery powered app, you may want to enable the BOD and/or the WDT and that will will keep the clock running on PD mode!

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Good Point.  Looking into this.  Also trying your other suggestions.

 

Thank you.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In the older Mega's/Tiny's, PD mode stopped all clocks, only an external int or wdt would wake them,

these new tiny's try to be smart, if the wdt or bod is not being used, then the clock stops in pd mode, otherwise it runs.   

IOW's, you have to read the fine print!  

Good luck with your project.

 

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Jim,

Did you figure this out?

I have the same issue trying to use the PIT to wake up on 8 sec intervals.

Debugging shows that the ISR is executing but the CPU just won't wake up and start executing the code after the sleep instruction.

Weird.

 

BR

Michel

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
//ATMega4809 Curiosity Nano
#include <stdbool.h>
#include <stdint.h>
#include "Clkctrl.hpp"
#include "Port.hpp"
#include "Slpctrl.hpp"
#include "Cpuint.hpp"
#include "Rtc.hpp"

PF5_OUTL_t led1;

Rtc rtc;

void pitISR(){
    rtc.pit_flagclr();  //clear pit irq flag
    led1.tog(); //toggle led (every 32 seconds)
}

int main() {

    //clock 10MHz
    Clkctrl::clksel20M( 10000000 );

    rtc.clksel( rtc.INT1K );        //internal 32k osc /32
    rtc.pit_period( rtc.CYC32768 ); //32sec, (also sets enable bit)
    Cpuint::set_func( Cpuint::RTC_PIT, pitISR ); //set isr function
    rtc.pit_irq( true );            //enable pit irq
    Cpuint::on( true );             //global irq's on

    for(;;){
        Slpctrl::sleep( Slpctrl::PDOWN ); //(also does sei, just in case)
    }
}

That's a minimal example on a 4809, and works- the led toggles at 32 second intervals.

Select rtc clock, set pit period and enable, get a pit isr in place, enable pit irq, enable global irq, clear pit flag in pit isr.

 

Show a minimal example that does not work. I'm guessing you don't clear the pit flag, which means you are 'stuck' in the isr and never get to the instruction after sleep.

 

 

edit- I may have to backtrack. I'm seeing something strange, depending on where led1.tog() is located. Need more testing.

 

Ok, this is weird. My sleep function sets the sleep ctrla smode+sen, does a sei, then sleep, on wakeup (after isr) sleep is disabled (ctrla=0).

If I put the led1.tog() before the sleep function call instead of in the isr, sleep does not work. I'm not sure what 'does not work' means except the led lights up, no blink. I cannot debug very well in mplabx as I have to add nop's to get a breakpoint to stick, viewing register values may or may not update when single stepping, etc., but if I debug and single step I can get it to work. When I stop the debug session, it no longer works (cpu resets, no blink). If I move the led1.tog() after the sleep function call, then it works. I could show the asm listing, but there is nothing to see (6 instructions in the loop, 3 st, sei, sleep, rjmp).

 

So, I try various things and if I split up writing to ctrla- first writing the smode, then turn on the sen bit, it works fine. Or if I add a nop before writing the smode+sen to ctrla in one write, that works, also (that's what I ended up doing because that is less code). I'm not sure what is going on, but maybe there is a thread somewhere about this.

 

My new sleep function-

https://github.com/cv007/ATmega4809CuriosityNano/blob/master/Slpctrl.hpp

updated test case code (I added a setupPIT function/template so it can be setup in one 'call')-

https://github.com/cv007/ATmega4809CuriosityNano/blob/master/power-down-test.cpp

 

 

So maybe this is something people are running into with sleep, I don't know.

 

Last Edited: Tue. Jun 25, 2019 - 01:43 AM