How do I put an attiny1604 to sleep?

Hi guys, I would like to make my attiny 1604 to sleep for 10 minutes, I tried to modify the sketch found on: https://github.com/SpenceKonde/megaTinyCore/blob/master/megaavr/extras/PowerSave.md:

#include <avr/sleep.h>

void RTC_init(void)
{
  /* Initialize RTC: */
  while (RTC.STATUS > 0)
  {
    ;                                   /* Wait for all register to be synchronized */
  }
  RTC.CLKSEL = RTC_CLKSEL_INT32K_gc;    /* 32.768kHz Internal Ultra-Low-Power Oscillator (OSCULP32K) */
  
  RTC.PITINTCTRL = RTC_PI_bm;           /* PIT Interrupt: enabled */
  
  RTC.PITCTRLA = RTC_PERIOD_CYC16384_gc /* RTC Clock Cycles 16384, resulting in 32.768kHz/16384 = 2Hz */
  | RTC_PITEN_bm;                       /* Enable PIT counter: enabled */
}

ISR(RTC_PIT_vect)
{
  RTC.PITINTFLAGS = RTC_PI_bm;          /* Clear interrupt flag by writing '1' (required) */
}

void setup() {
  RTC_init();                           /* Initialize the RTC timer */
  pinMode(7, OUTPUT);                   /* Configure pin#7 as an output */
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);  /* Set sleep mode to POWER DOWN mode */
  sleep_enable();                       /* Enable sleep mode, but not going to sleep yet */
}

void loop() {
  sleep_cpu();                          /* Sleep the device and wait for an interrupt to continue */
  digitalWrite(7, CHANGE);              /* Device woke up and toggle LED on pin#7 */
}

by changing RTC_PERIOD_CYC16384 to a bigger number, but I cannot use something bigger than 32768.
I also tried to use cycles for repeating sleep_cpu(); but they don't work.

This should work.

for ( uint16_t i = 0 ; i < TIME_IS_UP ; ++i )
{
  sleep_cpu();
}

tf68:
This should work.

for ( uint16_t i = 0 ; i < TIME_IS_UP ; ++i )

{
  sleep_cpu();
}

I don't get how it works, could you explain it better please?

You want to sleep the mcu for 10 minutes and the timer only allows you to sleep for 1 second at a time. You will need to repeatedly sleep, wake up and go back to sleep 600 times. You can do this by having the for statement loop 600 times.

void loop()
{

  uint16_t SecondsToSleep = 600;

  for ( uint16_t i = 0 ; i < SecondsToSleep ; ++i )
  {
    sleep_cpu(); 
  }

  digitalWrite(7, CHANGE); 

} // loop

You can test the concept by setting SecondsToSleep to a smaller number. So that the change in the interval is easier to observe.

tf68:
You want to sleep the mcu for 10 minutes and the timer only allows you to sleep for 1 second at a time. You will need to repeatedly sleep, wake up and go back to sleep 600 times. You can do this by having the for statement loop 600 times.

void loop()

{

uint16_t SecondsToSleep = 600;

for ( uint16_t i = 0 ; i < SecondsToSleep ; ++i )
  {
    sleep_cpu();
  }

digitalWrite(7, CHANGE);

} // loop




You can test the concept by setting SecondsToSleep to a smaller number. So that the change in the interval is easier to observe.

Thank you very much, I will test it tomorrow.