Skip to content

Commit e919709

Browse files
committed
Add low power example
1 parent 5a92a7c commit e919709

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Artemis Low Power: How low can we go?
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: October 17th, 2019
6+
License: This code is public domain. Based on deepsleep.c from Ambiq SDK v2.2.0.
7+
A big thanks to robin_hodgson for pointing out the HFRC shutdown requirement.
8+
9+
SparkFun labored with love to create this code. Feel like supporting open source hardware?
10+
Buy a board from SparkFun! https://www.sparkfun.com/products/15376
11+
12+
How close can we get to 2.7uA in deep sleep?
13+
This example shows how decrease the Artemis current consumption to less than 3uA in deep sleep.
14+
15+
To monitor the current to the Edge cut the MEAS jumper, solder in headers, and attach
16+
a DMM via IC hooks (https://www.sparkfun.com/products/506).
17+
18+
The USB to serial bridge draws some current:
19+
Serial Basic C - ~1.2uA (https://www.sparkfun.com/products/15096)
20+
FTDI Basic - ~5.5uA (https://www.sparkfun.com/products/9873)
21+
22+
The various components on the Edge2 can be powered on/off as well
23+
PDM microphones (2) - ~50.9uA
24+
Accelerometer (POR mode) - ~79.7uA
25+
Camera regulator enabled (no camera) - ~96.8uA
26+
*/
27+
28+
void setup()
29+
{
30+
Serial.begin(115200);
31+
Serial.println("Low power sleep example");
32+
33+
#if defined(ARDUINO_SFE_EDGE2)
34+
pinMode(ACCEL_VDD, OUTPUT);
35+
digitalWrite(ACCEL_VDD, LOW);
36+
37+
pinMode(MIC_VDD, OUTPUT);
38+
digitalWrite(MIC_VDD, LOW);
39+
40+
pinMode(CAMERA_VDD, OUTPUT);
41+
digitalWrite(CAMERA_VDD, LOW);
42+
#endif
43+
44+
//Turn off ADC
45+
power_adc_disable();
46+
47+
// Initialize for low power in the power control block
48+
am_hal_pwrctrl_low_power_init();
49+
50+
// Stop the XTAL.
51+
am_hal_clkgen_control(AM_HAL_CLKGEN_CONTROL_XTAL_STOP, 0);
52+
53+
// Disable the RTC.
54+
am_hal_rtc_osc_disable();
55+
56+
// The default Arduino environment runs the System Timer (STIMER) off the 48 MHZ HFRC clock source.
57+
// The HFRC appears to take over 60 uA when it is running, so this is a big source of extra
58+
// current consumption in deep sleep.
59+
// For systems that might want to use the STIMER to generate a periodic wakeup, it needs to be left running.
60+
// However, it does not have to run at 48 MHz. If we reconfigure STIMER (system timer) to use the 32768 Hz
61+
// XTAL clock source instead the measured deepsleep power drops by about 64 uA.
62+
am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE);
63+
64+
// This option selects 32768 Hz via crystal osc. This appears to cost about 0.1 uA versus selecting "no clock"
65+
am_hal_stimer_config(AM_HAL_STIMER_XTAL_32KHZ);
66+
67+
// This option would be available to systems that don't care about passing time, but might be set
68+
// to wake up on a GPIO transition interrupt.
69+
// am_hal_stimer_config(AM_HAL_STIMER_NO_CLK);
70+
71+
// Turn OFF Flash1
72+
if (am_hal_pwrctrl_memory_enable(AM_HAL_PWRCTRL_MEM_FLASH_512K))
73+
{
74+
while (1)
75+
;
76+
}
77+
78+
// Power down SRAM
79+
PWRCTRL->MEMPWDINSLEEP_b.SRAMPWDSLP = PWRCTRL_MEMPWDINSLEEP_SRAMPWDSLP_ALLBUTLOWER32K;
80+
81+
Serial.println("Going to sleep...");
82+
delay(100); //Wait for print to complete
83+
84+
Serial.end(); //Disable Serial
85+
86+
am_hal_sysctrl_sleep(AM_HAL_SYSCTRL_SLEEP_DEEP);
87+
88+
//We should never get here.
89+
}
90+
91+
void loop()
92+
{
93+
//Do nothing
94+
}

0 commit comments

Comments
 (0)