SAMD Controller - Deep Sleep - Page 1
Forum section: electronics / general

author: Dicko
author_rank: Contributor
timestamp: January 09, 2023, 10:50:38 pm
content: Hello folks,I am trying to put my Arduino WAN 1310 into deep sleep, this Arduino uses the SAMD21 processor. I have a circuit that uses multiple sensors but I am starting with one sensor at a time to investigate the deep sleep behaviour.```void setup(){/// Force one SERCOM to be configured as a UARTSerial1.begin(9600);// Disconnect sensor power lines onlyenablePower(A4, false);USBDevice.detach();LowPower.deepSleep(5000);}```The enable pin is code used to turn on a pin of the Arduino, it will eventually apply a signal to a MOSFET to switch on power to the sensor.But no sensor connected just now.The Arduino is powered by a battery and I am measuring the current draw.I was noticing some interesting behaviour when printing statements to the serial port. I am using serial1 and using a USB to 485 converter that has two wires, tx and rx that go to the Arduino.Now even though I am not printing anything to Putty here is what I find.1. With serial1 in the code, and with the tx and rx wires connected to the Arduino, I get a sleep current of 69uA.2. With serial1 in the code but the tx and rx wires disconnected, I get a sleep current of 400uA.3. With serial1 commented out, but with the tx and rx wires connected, I get a sleep current of 200uA.I really want the lowest sleep current possible. I do not know why serial1 is causing a lot of extra sleep current in different configurations. Any help to figure out what is going on here and on how to minimise the sleep current would be greatly appreciated. Thank you in advance. I have videos of the current consumption too if you would like to see them, I also have a thread on discord regarding the matter.https://discord.com/channels/420594746990526466/1061989174841970718

author: ataradov
author_rank: Super Contributor
timestamp: January 10, 2023, 07:27:33 am
content: Wires connected/disconnected is due to floating RX input. Internal pull-up/down resistor does not work if the pin is in the UART mode, so you need external pull-up on the RX pin to keep it at a defined level.The rest depends on what Arduino is doing for clock settings and I have no idea about that.

author: Dicko
author_rank: Contributor
timestamp: January 10, 2023, 09:44:54 am
content: Thank you for your input ataradov, once I am finished with the tx and rx pins I will define them as inputs rather than serial and then try to pull them up/down. I'll report back with my findings. I cannot physically add any components as the arduino circuit board is already manufactured, so fingers crossed this works.

author: Dicko
author_rank: Contributor
timestamp: January 10, 2023, 11:17:25 am
content: On a breadboard I tried both a pull-up and pull-down resitor on rx and it did not reduce the sleep currrent. I tried this wil tx also and then for them both but the sleep current did not reduce.

author: Dicko
author_rank: Contributor
timestamp: January 10, 2023, 12:23:04 pm
content: Also, out of interest. I have two I2C sensors that I have been looking at, one measures temperature, the other light. I was testing them both by themselves with my WAN1310 and noticed that when I put the board to deep sleep connected to the temp sensor, I got a sleep current of 69uA. When I put the board to sleep connected to the light sensor the sleep current is 360uA, I wondered if anyone was familiar with this light sensor, it looks like something could be left on that needs to be turned off, here it is:https://www.dfrobot.com/product-2183.htmlI would like to be able to turn off all the processes , turn off everything to the peripherals so I can get a low sleep current, but I do not know how to code that for SAMD21.https://microchipdeveloper.com/32arm:samd21-pm-overview

author: ataradov
author_rank: Super Contributor
timestamp: January 10, 2023, 06:57:01 pm
content: Generally all power consumption issues are diagnosed one step at a time. The default hardware configuration is the lowest possible power consumption. So simply going to sleep before initializing anything will give you the base line current consumption for your board. Then you can enable the clocks and peripherals one at a time and see where the increase comes from.The issue here is the complexity of the Arduino code. I have no idea how to do this debugging in the Arduino system. You would have to go low level and see how it is all implemented.

author: sslupsky
author_rank: Contributor
timestamp: January 10, 2023, 08:25:29 pm
content: You indicated you are using a battery ... are you using a LiPo battery connected to the battery input?

author: Dicko
author_rank: Contributor
timestamp: January 11, 2023, 09:22:47 am
content: Thank you very much for your reply. Yes I am using a 3.7V LiPo battery connected to the jst input of the Arduino WAN 1310. Or rather, instead of wasting my battery life I have connected a bench PSU set to 3.7V and connected this to the jst battery terminal.Do you know how to turn off the SAMD21 clocks etc? For example, in Arduino I have been told I could use code such as that shown below to shutdown sercom2,Code:void shutdown_sercom2() {uint8_t clockId = GCM_SERCOM2_CORE;IRQn_Type IdNvic = SERCOM2_IRQn;NVIC_DisableIRQ(IdNvic);// disable generic clock 0GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID( clockId ) | // Generic Clock 0 (SERCOMx)GCLK_CLKCTRL_GEN_GCLK0; // Generic Clock Generator 0 is source}

author: ataradov
author_rank: Super Contributor
timestamp: January 11, 2023, 03:29:39 pm
content: This would disable the clock to the specific peripheral (SERCOM2 in this case). But the SERCOM itself would remain initialized and if pins were configured for SERCOM, they will remain configured the same way.To reset the peripheral itself there is usually SWRST bit in the control register of the peripheral. And the pin multiplexing should be disabled in the PORTx peripheral. There may be existing Adruino APIs for this, I don't know.

author: sslupsky
author_rank: Contributor
timestamp: January 11, 2023, 06:32:28 pm
content: As I recall, the combined quiescent current of the BQ24195 PMIC (32uA type) and the AP2112K-3.3 LDO (55uA typ) is about 87uA. Add the other components (MCU and the Murata module) and you won't be able to get the sleep current much below 100uA when using the LiPo battery input. There is a jumper labelled "SJ1" on the pcb (after the LDO) that can be cut to disconnect the PMIC and LDO. If you apply a separate regulated voltage to the +3.3V pin to supply power to the board, you can eliminate the power consumption of the PMIC and LDO and as I recall you can reduce the sleep current to less than 20uA. I made a separate "dock" PCB with its own power supply, ADC, temperature sensor, SD card, NAND and FRAM for this purpose. As I recall, my sleep current is about 30uA when I use my board but I would have to go back and check to be sure. I have another pcb with a GPS module, LED, IMU, barometer, temperature sensor and light sensor that when combined with the MKR WAN and dock pcb brings the sleep current to around 50uA when using the battery input on the dock and about 150uA when using the LiPo battery input on the MKR WAN.Regarding the serial port, the issue you are observing is due to the pin configuration (as mentioned by @ataradov). You are observing leakage due to floating pins and/or pull ups. You need to carefully ensure that the unused pins are disabled. Pay attention to the pull ups. Some pins have external and/or internal pull up resistors and if these pins are left in a state where the resistor is conducting current during sleep that will appear in your current measurements.I used the Arduino IDE for a while with the MKR WAN 1310 and encountered some issues. You may want to consider using Zephyr.