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

Sleeping does not decrease current draw #137

Open
Electric131 opened this issue May 5, 2024 · 1 comment
Open

Sleeping does not decrease current draw #137

Electric131 opened this issue May 5, 2024 · 1 comment

Comments

@Electric131
Copy link

I'm trying to get my Arduino Nano Every to go into a low-power / deep sleep mode. Even while sleeping, the board still draws ~20mA. I'm trying to get the consumption to (hopefully) <5mA if not less.

I've tried using the Adafruit_SleepyDog library, but MegaAVR seems to be incompatible with that library.
Here's the code I've tried, which does sleep but actually increases the mA draw and still stays at >20mA:
(I found most of this code from a forum post, and added a CPU prescaler in an attempt to decrease power draw)

#include <avr/sleep.h>
uint8_t loopCount = 0 ;


void RTC_init(void)
{
  while (RTC.STATUS > 0) ;    /* Wait for all register to be synchronized */
 
  RTC.CLKSEL = RTC_CLKSEL_INT1K_gc;        // Run low power oscillator (OSCULP32K) at 1024Hz for long term sleep
  RTC.PITINTCTRL = RTC_PI_bm;              // PIT Interrupt: enabled */

  RTC.PITCTRLA = RTC_PERIOD_CYC8192_gc | RTC_PITEN_bm;     // Set period 8 seconds (see data sheet) and enable PIC                      
}

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

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
    CPU_CCP = CCP_IOREG_gc;							// write access for four CPU instructions
    CLKCTRL_MCLKCTRLB = CLKCTRL_PDIV_16X_gc | CLKCTRL_PEN_bm;	// prescaler 16, enable prescaler
  RTC_init();   
  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() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(200 / 16);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(200 / 16);                       // wait for a second

  if( ++ loopCount == 5 ) {
    loopCount = 0 ;
    sleep_cpu();                     // Sleep the device and wait for an interrupt to continue
  }
}
@Electric131
Copy link
Author

Quick note that I am trying to run it at ~4V where it draws ~21mA while sleeping. And, because I was curious, at ~8V it still draws ~18mA. Also I am powering it through the VIN pin.

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

1 participant