8000 Current unchanged when trying to turn off QSPI during sleep · Issue #3360 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

Current unchanged when trying to turn off QSPI during sleep #3360

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

Closed
catequalsgood opened this issue Aug 31, 2020 · 8 comments
Closed

Current unchanged when trying to turn off QSPI during sleep #3360

catequalsgood opened this issue Aug 31, 2020 · 8 comments

Comments

@catequalsgood
Copy link

After reading about the ability to turn off QSPI during sleep for the nRF52840 in 6.0.0 alpha 3 I tried emulating what @xiongyihui did in issue #3244 on my itsybitsy BLE (also nRF52840). However after building CircuitPython with the CIRCUITPY_ENABLE_MPY_NATIVE=1 flag to be able to use the @micropython.asm_thumb decorator and adding a few lines to xiongyihui's code to disable the DotStar LED the current drawn from battery (no USB connected) is still identical to what it was when using 6.0.0 alpha 2 (about 2.5 mA). The quiescent current of the DotStar is around 1 mA and I will physically remove it once the project is nearly finished.

I am not sure how I could tell if QSPI is actually off other than looking at the current and since xiongyihui measured far less (on a different board however) I assume I am either doing something wrong or the difference in hardware is to blame (maybe turning off the DotStar in this way doesn't allow QSPI to turn off?).

this is all I added to xiongyihui's code:
import board
import adafruit_dotstar as dotstar
dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
dot[0] = (0, 0, 0)

@xiongyihui
Copy link
xiongyihui commented Aug 31, 2020

Does dotstar.DotStar use SPI bus?

We need turn off other peripherals(USB, SPI, PWM and etc) using high frequency clock (HFCLK), and then go to sleep.

@dhalbert
Copy link
Collaborator
dhalbert commented Aug 31, 2020

Yes, the dotstar library uses SPI if it can. Below is from https://github.com/adafruit/Adafruit_CircuitPython_DotStar/blob/master/adafruit_dotstar.py. The way around this would be to modify the code to force it to use bit-bang method it does when SPI is not avialable on the requested pins. That is, just remove the code in the try block, and always do what's in the except block.

        self._spi = None
        try:
            self._spi = busio.SPI(clock, MOSI=data)
            while not self._spi.try_lock():
                pass
            self._spi.configure(baudrate=baudrate)

        except (NotImplementedError, ValueError):
            self.dpin = digitalio.DigitalInOut(data)
            self.cpin = digitalio.DigitalInOut(clock)
            self.dpin.direction = digitalio.Direction.OUTPUT
            self.cpin.direction = digitalio.Direction.OUTPUT
            self.cpin.value = False

@catequalsgood
Copy link
Author

It didn't even occur to me to test current with the LED still on but I did and got this:
Doing nothing but importing time and going to sleep (LED still on) results in about 1.95 mA. Lower than before even though the LED is now on.
When using the code below setting the brightness for the first time using the DotStar object causes the current to jump from 1.95 to 2.85 mA even though the brightness of the LED doesn't change. I assume that increase is caused by the HFCLK turning on again (and then not turning off). But even with the LED physically removed, current would still be around 1 mA which still seems high in comparison to the measurements from #3244.

import time
import adafruit_dotstar as dotstar
import board
dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)

while True:
    time.sleep(10)
    dot[0] = (0, 9, 0) #current jumps from 1.95 mA to 2.85 mA on first execution
    time.sleep(10)

@dhalbert dhalbert added this to the Long term milestone Aug 31, 2020
@tannewt
Copy link
Member
tannewt commented Aug 31, 2020

@catequalsgood try disabling the Dotstar in the board definition you are using. It will configure SPI if it's marked as a status LED for the board.

@xiongyihui
Copy link

@catequalsgood When LFCLK is off, the current of nRF52840 is a few uA. While, other parts of the board may have higher power consumption. As you see, a LED takes about 0.95 mA.

The hardware I used is the M60 keyboard. It is optimized for low power consumption. Other parts of it still needs around 50 uA.

@catequalsgood
Copy link
Author

Thanks for everyone's explanations and tips!
I removed the DotStar in the board definition (I think) by removing the following lines from mpconfigboard.h

#define MICROPY_HW_APA102_MOSI   (&pin_P0_08)
#define MICROPY_HW_APA102_SCK    (&pin_P1_09)

That dropped the current during sleep to 0.95 mA which is obviously way better than what I got when turning off the LED using adafruit_dotstar.Dotstar. Just out of curiosity I did also try physically removing the LED from one of my itsybitsy boards and the current dropped further to just above 0.5 mA (even with mpconfigboard.h untouched). That is pretty close to power consumption I can live with. For my application I would probably do the sleep part of the code first and then everything that might cause any peripherals to turn on. After that the board could reset itself by triggering the reset pin. But that would obviously not work for every application.

Is 0.5 mA going to be the limit for the itsybitsy simply because it was not designed with low-power applications in mind?

PS: Defining all digital pins as outputs might result in a further reduction of about 30 uA or so but I is hard to tell with my cheap multimeter.

@tannewt
Copy link
Member
tannewt commented Sep 1, 2020

@catequalsgood Yup, that's what I was thinking to disable the dotstar status neopixel. I'm not sure what the lowest possible value is. @xiongyihui's work is the best indication of it. When I added the low power support, it was mainly to get the code base ready for it.

@tannewt
Copy link
Member
tannewt commented Aug 27, 2021

I think this is fixed by the led status rework plus #4236

@tannewt tannewt closed this as completed Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0