Skip to content

Commit d377ef1

Browse files
cleaned up examples, added measurements
1 parent e218e87 commit d377ef1

File tree

4 files changed

+137
-6
lines changed

4 files changed

+137
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "Arduino_LowPowerPortentaC33.h"
2+
#include "Arduino_PMIC.h"
3+
#include "Wire.h"
4+
5+
#define SLEEP_PIN 0
6+
#define WAKE_PIN A3
7+
8+
LowPower lowPower;
9+
10+
11+
void goToSleep(){
12+
PMIC.getControl() -> turnLDO1Off(Ldo1Mode::Normal); // LDO1 is used for AVCC (Analog Power)
13+
PMIC.getControl() -> turnLDO2Off(Ldo2Mode::Normal); // LDO2 is used for the analog voltage reference
14+
PMIC.getControl() -> turnLDO3Off(Ldo3Mode::Normal); // LDO3 is a 1.2V regulator used by the Ethernet chip
15+
PMIC.getControl() -> turnSw1Off(Sw1Mode::Normal); // SW1 is a 3.3V regulator used by RGB Led, WIFI Chip, Secure element
16+
PMIC.getControl() -> turnSw2Off(Sw2Mode::Normal); // SW2 is the power regulator used for powering external circuits (Labeled 3V3 on the board)
17+
18+
lowPower.deepSleep();
19+
}
20+
21+
void setup(){
22+
lowPower = LowPower();
23+
attachInterrupt(digitalPinToInterrupt(SLEEP_PIN), goToSleep, RISING);
24+
lowPower.enableWakeupFromPin(WAKE_PIN, RISING);
25+
pinMode(LED_BUILTIN, OUTPUT);
26+
27+
PMIC.begin();
28+
PMIC.getControl() -> turnLDO1On(Ldo1Mode::Normal); // LDO1 is used for AVCC (Analog Power)
29+
PMIC.getControl() -> turnLDO2On(Ldo2Mode::Normal); // LDO2 is used for the analog voltage reference
30+
PMIC.getControl() -> turnLDO3On(Ldo3Mode::Normal); // LDO3 is a 1.2V regulator used by the Ethernet chip
31+
PMIC.getControl() -> turnSw1On(Sw1Mode::Normal); // SW1 is a 3.3V regulator used by RGB Led, WIFI Chip, Secure element
32+
PMIC.getControl() -> turnSw2On(Sw2Mode::Normal); // SW2 is the power regulator used for powering external circuits (Labeled 3V3 on the board)
33+
}
34+
35+
void loop(){
36+
digitalWrite(LED_BUILTIN, HIGH);
37+
delay(100);
38+
digitalWrite(LED_BUILTIN, LOW);
39+
delay(100);
40+
}
41+
42+
43+
44+

examples/SimpleDeepSleep/SimpleDeepSleep.ino renamed to examples/WakeFromGPIO/WakeFromGPIO.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LowPower lowPower;
77

88

99
void goToSleep(){
10-
lowPower.sleep(); // lowPower.deepSleep();
10+
lowPower.deepSleep(); // lowPower.deepSleep();
1111
}
1212

1313
void setup(){

examples/WakeFromRTC/WakeFromRTC.ino

+75-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,82 @@
22

33
#include "RTC.h"
44
#include "Arduino_LowPowerPortentaC33.h"
5+
#include "Arduino_PMIC.h"
6+
7+
58

69
LowPower lowPower;
710
RTCTime initialTime(1, Month::JANUARY, 2000, 12, 10, 00, DayOfWeek::TUESDAY, SaveLight::SAVING_TIME_ACTIVE);
811

912

13+
void turnOffPeripherals(){
14+
//stopETHClock();
15+
// Turn off the external power regulator
16+
PMIC.getControl() -> turnSw2Off(Sw2Mode::Normal);
17+
PMIC.getControl() -> turnSw2Off(Sw2Mode::Sleep);
18+
PMIC.getControl() -> turnSw2Off(Sw2Mode::Standby);
19+
20+
21+
// Turn off the Ethernet PHY, SDRAM, and USB PHY
22+
PMIC.getControl() -> turnSw1Off(Sw1Mode::Normal);
23+
PMIC.getControl() -> turnSw1Off(Sw1Mode::Sleep);
24+
PMIC.getControl() -> turnSw1Off(Sw1Mode::Standby);
25+
26+
27+
28+
29+
PMIC.getControl() -> turnLDO1Off(Ldo1Mode::Normal);
30+
PMIC.getControl() -> turnLDO1Off(Ldo1Mode::Sleep);
31+
PMIC.getControl() -> turnLDO1Off(Ldo1Mode::Standby);
32+
33+
34+
// Turn off misc onboard chips
35+
PMIC.getControl() -> turnLDO2Off(Ldo2Mode::Normal);
36+
PMIC.getControl() -> turnLDO2Off(Ldo2Mode::Sleep);
37+
PMIC.getControl() -> turnLDO2Off(Ldo2Mode::Standby);
38+
39+
40+
// Turn off the 1.2V for Ethernet
41+
PMIC.getControl() -> turnLDO3Off(Ldo3Mode::Normal);
42+
PMIC.getControl() -> turnLDO3Off(Ldo3Mode::Sleep);
43+
PMIC.getControl() -> turnLDO3Off(Ldo3Mode::Standby);
44+
delay(1);
45+
46+
}
47+
48+
void turnOnPeripherals(){
49+
// startETHClock();
50+
PMIC.getControl() -> turnLDO1On(Ldo1Mode::Normal);
51+
PMIC.getControl() -> turnLDO1On(Ldo1Mode::Sleep);
52+
PMIC.getControl() -> turnLDO1On(Ldo1Mode::Standby);
53+
54+
// Turn off misc onboard chips
55+
PMIC.getControl() -> turnLDO2On(Ldo2Mode::Normal);
56+
PMIC.getControl() -> turnLDO2On(Ldo2Mode::Sleep);
57+
PMIC.getControl() -> turnLDO2On(Ldo2Mode::Standby);
58+
59+
// Turn off the 1.2V for Ethernet
60+
PMIC.getControl() -> turnLDO3On(Ldo3Mode::Normal);
61+
PMIC.getControl() -> turnLDO3On(Ldo3Mode::Sleep);
62+
PMIC.getControl() -> turnLDO3On(Ldo3Mode::Standby);
63+
64+
// Turn off the Ethernet PHY, SDRAM, and USB PHY
65+
PMIC.getControl() -> turnSw1On(Sw1Mode::Normal);
66+
PMIC.getControl() -> turnSw1On(Sw1Mode::Sleep);
67+
PMIC.getControl() -> turnSw1On(Sw1Mode::Standby);
68+
69+
// Turn off the external power regulator
70+
PMIC.getControl() -> turnSw2On(Sw2Mode::Normal);
71+
PMIC.getControl() -> turnSw2On(Sw2Mode::Sleep);
72+
PMIC.getControl() -> turnSw2On(Sw2Mode::Standby);
73+
}
74+
1075
void alarmCallback()
1176
{
1277
digitalWrite(LED_BUILTIN, HIGH);
1378
delay(1000);
1479
digitalWrite(LED_BUILTIN, LOW);
80+
turnOffPeripherals();
1581
lowPower.deepSleep();
1682
}
1783

@@ -50,8 +116,12 @@ bool sleepFor(int hours, int minutes, int seconds){
50116

51117

52118
void setup(){
119+
120+
PMIC.begin();
121+
122+
turnOnPeripherals();
53123
Serial.begin(9600);
54-
//while(!Serial);
124+
55125

56126
lowPower = LowPower();
57127
lowPower.enableWakeupFromRTC();
@@ -65,9 +135,11 @@ void setup(){
65135
RTC.setTime(initialTime);
66136
sleepFor(0, 0, 1);
67137
}
68-
138+
139+
turnOffPeripherals();
140+
lowPower.deepSleep();
69141
}
70142

71143
void loop(){
72-
lowPower.deepSleep();
144+
73145
}

src/Arduino_LowPowerPortentaC33.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
#include "Arduino_LowPowerPortentaC33.h"
2+
#include "FspTimer.h"
3+
#include "r_lpm.h"
24

35
LowPower::LowPower(){
6+
7+
//ldoConfig.pll1_ldo = LPM_LDO_STANDBY_OPERATION_DISABLED;
8+
//ldoConfig.pll2_ldo = LPM_LDO_STANDBY_OPERATION_DISABLED;
9+
10+
411
RenesasLowPowerConfig.dtc_state_in_snooze = LPM_SNOOZE_DTC_DISABLE;
5-
RenesasLowPowerConfig.power_supply_state = LPM_POWER_SUPPLY_DEEPCUT0;
12+
RenesasLowPowerConfig.power_supply_state = LPM_POWER_SUPPLY_DEEPCUT3 ;
613
RenesasLowPowerConfig.output_port_enable = LPM_OUTPUT_PORT_ENABLE_HIGH_IMPEDANCE;
714
RenesasLowPowerConfig.io_port_state = LPM_IO_PORT_RESET;
815
RenesasLowPowerConfig.low_power_mode = LPM_MODE_DEEP;
916
RenesasLowPowerConfig.standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_IRQ15;
1017
RenesasLowPowerConfig.deep_standby_cancel_source = LPM_DEEP_STANDBY_CANCEL_SOURCE_IRQ15;
11-
18+
19+
//RenesasLowPowerConfig.ldo_standby_cfg = ldoConfig;
20+
21+
22+
23+
1224
}
1325

1426
void LowPower::sleep(){
@@ -19,6 +31,9 @@ void LowPower::sleep(){
1931

2032
void LowPower::deepSleep(){
2133
RenesasLowPowerConfig.low_power_mode = LPM_MODE_DEEP;
34+
35+
36+
2237
R_LPM_Open(&RenesasLowPowerControlBlock, &RenesasLowPowerConfig);
2338
R_LPM_LowPowerModeEnter(&RenesasLowPowerControlBlock);
2439
}

0 commit comments

Comments
 (0)