Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLEEP_MODE_PWR_DOWN have too much consumption #1142

Open
PM04290 opened this issue Sep 13, 2024 · 2 comments
Open

SLEEP_MODE_PWR_DOWN have too much consumption #1142

PM04290 opened this issue Sep 13, 2024 · 2 comments

Comments

@PM04290
Copy link

PM04290 commented Sep 13, 2024

Hello,
I use new ATtinys since few weeks (ATtiny84 before, without problem) and i need to have a minimum consumption in sleep mode.
After documention reading, i wrotte the little code below for ATTiny3216 and i have 520µA in sleep mode, too far from AVR datasheet (5µA)
I'am on 5Vdc, 1MHz internal, no BOR, no millis()

I found a few rare posts that talk about the problem but none solve my problem; any idea?

// Led ON during 100ms, and power off during 10s
#include "avr/sleep.h"
#define PIN_DEBUG_LED  PIN_PC2
volatile uint16_t sleepCounter = 0;

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

void timerInit()
{
  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_CYC32768_gc /* RTC Clock Cycles 32768, resulting in 32.768kHz/32768 = 1Hz  */
                    | RTC_PITEN_bm;        /* Enable PIT counter: enabled                                 */
}

void setup() {
  for (uint8_t i = 0; i < 8; i++)
  {
    *((uint8_t *)&PORTA + 0x10 + i) |= 1 << PORT_PULLUPEN_bp;
    *((uint8_t *)&PORTB + 0x10 + i) |= 1 << PORT_PULLUPEN_bp;
  }
  pinMode(PIN_DEBUG_LED, OUTPUT);
  timerInit();
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
}

void loop() {
  digitalWrite(PIN_DEBUG_LED, HIGH);
  delay(100);
  digitalWrite(PIN_DEBUG_LED, LOW);
  powerOff();
}

void powerOff()
{
  ADC0.CTRLA &= ~ADC_ENABLE_bm; // Disable ADC
  sleepCounter = 0;
  do {
    sleep_cpu();
  } while (sleepCounter < 10);

  ADC0.CTRLA |= ADC_ENABLE_bm;  // Enable ADC
}

@freemovers
Copy link
Collaborator

A lot of information about the sleep modes can be found here:
https://github.com/SpenceKonde/megaTinyCore/blob/master/megaavr/extras/PowerSave.md
Since you are using an ATtiny3216 you have to make sure that you disable input buffer and enable the internal pull-ups for pins on PORTC as well. If you want to reduce the power consumption even more, then you should replace the delay(100) with another timer (RTC) and have it sleep for that time period.

@PM04290
Copy link
Author

PM04290 commented Sep 17, 2024

@SpenceKonde i read somewhere that you plan to investigate for Sleep power saving. some remarks to help you in this way :
If hardware have floating input, put them in INPUT_PULLUP have no (signifiant) effect, the only way to stop consumption is to desactivate input
PORTA.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc;
Exemple on ATtiny1616 with all pins floating, in power off sleep mode i have 0.1µA
BUT, it's imposible to go back with friendly function, like pinMode, when wakeup.
if you write a dedicated library for power saving, you may create function to manage pins easly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants