How Much Power??? | Raspberry Pi Pico Deep Sleep Tutorial | Rising Signal Wake-Up on the RP2040

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what is up guys welcome back to another low level learning tutorial in today's tutorial we're going to be checking out the deep sleep functionality of the rp2040 and see how low we can get the power consumption of our chip so the first thing we have to do is baseline the rp2040 the way we're going to do that is we're going to run this program here to the board and see how much power it consumes just doing tight loop contents if you didn't know tight loop contents is literally just a no op operation in c so if you look here in the actual implementation of the pico sdk there's no code here at all it doesn't do anything so this is a no op operation happening infinitely so in theory the only instructions that get ran are your jump and your no op and that's it so we got to see how much power does a pi pico use by default and see if we can get that number lower so what we're going to do here is we will export our two paths here we'll make the program we'll copy it over to the device and you'll see here on the right so currently the pi pico is consuming this many volts at this many amps which means that it is consuming this many watts of power so that's our baseline we need to do things now in our code that beat this number so my first thoughts on how we're going to accomplish this is we are going to put the device to sleep and we can literally do that with the sleep ms function the idea being that maybe if i just put it to sleep with the sleep function it'll go into a lower state of execution and use less power so let's build this real quick and we'll copy it over yeah and you'll see here the results are pretty disappointing actually we lose a little bit of current which means that the power has gone down a little bit but we're still pulling in the same amount of power as just no opting in a loop so you gotta ask why does that happen well let's dive into the instructions of the actual sleep code and see how that works so here we are in the picosdk we're actually at the code that executes the sleep ms function sleep ms is just sleep milliseconds and it ends up just calling sleep microseconds with your time times a thousand if you go to the sleep microseconds function that is just a sleep until function if alarm pools are not disabled which they're not by default and then if you actually go into the code after a couple checks get done to see if you've gotten to the point where you should be done sleeping the code is just the wfe micro instruction which is an assembly instruction in c um and wfe is just wait for event which executes as a knob on the target so again our sleep functionality which you would think gives you lower power consumption faster code execution while sleeping no it's just a knob now when i was making this video i was starting to get really disappointed because i felt like there was no code in the pico sdk library that actually implemented the deep sleep functionality of the arm cortex processor but then in looking around i discovered that raspberry pi put out this extra library literally called pico extras and it exports this sleep interface and the sleep interface has some functionality one of them is a sleep go to sleep until where you can specify a real-time counter alarm and a callback to execute once the alarm has gone off and within this api they actually use the deep sleep functionality of the processor and you'll see here in a second the power consumption is significantly lower so basically what this code does here i'll kind of walk y'all through it we turn the processor on it is not awake we put it into real-time clock sleep we basically say that this is the date now and then we say that this is the time we want to wake up which is just this previous date 10 seconds later we initialize the real time clock and then we set the date time to the time we say it is and then we say go to sleep until this alarm goes off and when it goes off execute the sleep call back the sleep callback just says the global variable awake is true and what that does for us is that means that we should never get here because we should be sleeping until we are awake and then we go into tight loop contents so what you're going to see is we have 10 seconds of low power consumption and then after that 10 seconds is up when we come out of sleep the power consumption jumps way up and we'll show you that real quick so let's build this and put it onto the raspberry pi pico okay so once the power supply starts up you can see right here we have extremely low power consumption over cut in half and then after 10 seconds has elapsed boom knocks all the way up and goes into tight loop contents and goes back to where we were before so we can go a little bit better than this this is just sleeping on a timer when the timer goes off it wakes up there's one more piece of code that it actually exports where we are able to go dormant until a rising clock edge hits the raspberry pi pico and i think that's the most useful for people that are waiting on edges like uart spy or i2c and the way that we do that is with this code right here let's walk through it line by line so line 10 and 11 pretty standard uh line 13 we're going to initialize the led pin so that we can see when we've come out of sleep so when the sleep expires the led comes on and then we want to set the direction of the wake pin and the wake pin is the pin that we're waiting for input on gpio in and then the direction of the output pin obviously to be an output pin this line here line number 18 is extremely crucial when you cannot ignore this line so this says sleep run from external oscillator what this line does is it puts the processor into a mode that it can go into what's called dormant mode so to be able to go into dormant mode you basically have to be running from a clock source that you can stop and you have to turn off all external subsystems that depend on a clock by calling this function we bring the power consumption of the processor down by disabling those subsystems then line 20 sleep go to dormant until edge high we bring the processor to an even lower state and wait for a clock edge to rise on the wake pin which in this case is pin 10. once that happens so line 20 the program will freeze once it comes out of sleep meaning we've received a clock edge on pin 10 the light will go on and then we'll go into tight loop contents tight loop contents will actually not be the same power consumption as it was the 0.29 amps because we've disabled so many of the subsystems on the processor but the time before that when we're in dormant sleep we'll be at an extremely low power consumption true deep sleep on the rp-2040 so let's build it and check it out all right so as you can see here we turn on the raspberry pi pico with the power supply it begins with .002 amps or two milliamps and then we hit the clock edge and it goes up to four milliamps so we have the raspberry pi pico down at 6.6 milliwatts so guys look how far we came we started out at nearly a hundred milliwatts operating the raspberry pi pico and an infinite loop that's 1 10 of a watt that is actually a significant amount of power now using deep sleep code we are able to get the raspberry pi pico down to 6.6 milliwatts in deep sleep hopefully this is useful to you guys um if it was and if you learned something do me a favor hit like hit subscribe and leave a comment with your latest rp 2040 project guys thanks for watching i appreciate it bye
Info
Channel: Low Level Learning
Views: 4,718
Rating: undefined out of 5
Keywords: raspberry pi, pico, rpi, microcontroller, arduino, maker, craft, hobby, electronics, wires, temperature, safety, project, board, electric, leds, led, thonny, python, micropython, os, ide, onewire, ds18b20, circuitpython, review, launch, measure, probe, rp2040, specs, specifications, how to, guide, programming, Pico emulation, retro games raspberry pi pico, etaprime, eta prime, raspberry pi pico, arm cortex m0+, low cost
Id: 05o5QOZkpwg
Channel Id: undefined
Length: 7min 13sec (433 seconds)
Published: Sat May 15 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.