Teensy 4.1 using Snooze library with deepSleep

Patrick_D

New member
I am working on building an eDNA Sampler with https://www.sciencedirect.com/science/article/pii/S2468067221000699 as my template. The whole project is made for a Teensy 3.5 but I only have a Teensy 4.1.
So far I managed to adapt everything except a good power consumption management. Originally the Snooze.hibernate function is used but I can't manage to make it work with the Teensy 4.1 and the Teensy 4.0 config from the Snooze library.
By geeting rid of 4 lines of code in the hal.c function I got the Snooze.deepSleep function to work just fine. The problem is that I need the Teensy to draw less current when in deepSleep. Currently it draws 25.86 mA. I already clocked the Teensy down to 24 MHz.
Here are the altered lines in hal.c (Line 213-240)
Code:
FASTRUN void set_clock_rc_osc( void ) {
    // Switch to RC-OSC
    //XTALOSC24M_LOWPWR_CTRL_SET = XTALOSC24M_LOWPWR_CTRL_SET_OSC_SEL;  //ERROR: Reset
    // Turn off XTAL-OSC
    //CCM_ANALOG_MISC0_SET = CCM_ANALOG_MISC0_XTAL_24M_PWD;             //ERROR: No Wake up
    while ( CCM_CDHIPR != 0 );                                           
    for ( uint32_t i = 0; i < 5 * 50; i++ ) asm volatile( "nop \n" );     
}
//----------------------------------------------------------------------------------
FASTRUN void power_down_subsytem( void ) {
    // Power down
    //CCM_ANALOG_MISC0_SET = CCM_ANALOG_MISC0_XTAL_24M_PWD;             //ERROR
    // Lower OSC current by 37.5%
    CCM_ANALOG_MISC0_SET = 0x6000;//CCM_ANALOG_MISC0_OSC_I( 3 );          
    // Enable FET ODRIVE
    PMU_REG_CORE_SET = PMU_REG_CORE_FET_ODRIVE;                                 
    // Disconnect vdd_high_in and connect vdd_snvs_in
    CCM_ANALOG_MISC0_SET = CCM_ANALOG_MISC0_DISCON_HIGH_SNVS;         
    // Switch bandgap
    // TODO: See about STOP_MODE_CONFIG Bit in PMU_MIS0
    PMU_MISC0_SET = 0x00000004;                                         
    XTALOSC24M_LOWPWR_CTRL_SET = XTALOSC24M_LOWPWR_CTRL_LPBG_SEL; 
    //PMU_MISC0_SET = CCM_ANALOG_MISC0_REFTOP_PWD;                    //ERROR
    while ( CCM_CDHIPR != 0 );                                            
    for ( uint32_t i = 0; i < 5 * 50; i++ ) asm volatile( "nop \n" );   
    CCM_CCR = ( CCM_CCR_COSC_EN | CCM_CCR_OSCNT( 0xAF ) );              
    GPC_CNTR |= GPC_CNTR_PDRAM0_PGE;                                    
}

The lines marked with //ERROR are the ones I refer to. As you can see the first line causes the Teensy to reset and also reconnect when it should go to sleep while the second ERROR causes it to never wake up again. The third and forth do similar things. I just managed to get to these lines via Trial-and-Error.

Now my two questions are:
1. What exactly did I get rid of? I don't really understand what these lines of code do. I only get that it tries to switch to a different oscillator.
and 2. Is there anything else I can add to lower the power consumption while in deepSleep?

Attached is the Code on the ArduinoIDE. The reffered function is in line 763 [who = Snooze.deepSleep( config_teensy40 );]

This is my first post so please let me know if there are any more information needed or differently packaged.

Thanks in advance for any help.

Patrick
 

Attachments

  • SASeV3c_my_Version.ino
    62.8 KB · Views: 121
Back
Top