Embedded - 278: Bricks’ Batteries Last Forever (Repeat)
Episode Date: February 11, 2022Matthew Liberty shared good advice for lowering power. We talk about different ways to measure current (Matt has a nice write-up) and things software can do to decrease power consumption. Sleeping is... critical, of course, as is choosing your clock speed and setting the GPIOs to good states. Everything is fine until you start getting into the microamps, then your multimeter measurements may start to fail you. (EEvblog explains why in his uCurrent intro.) Eventually, you may want to measure nanoamp sleep states along with amp-consuming wake states. Matt’s Joulescope is a tool to do just that (Kickstarter goes live Feb 19, 2019!), automatically moving between 9 orders of magnitude of dynamic range and graphing the results on your computer. Matthew’s consulting company is JetPerch. We mentioned Colin O’Flynn’s ChipWhisperer which uses differential power analysis for security attacks. We also talked about Jacob Beningo’s post on protecting your tools. Find Matt on Twitter as @mliberty1. Elecia is giving away a chapter of her O’Reilly book, Making Embedded Systems. It is Chapter 10: Reducing Power Consumption. Hit the contact link if you want a copy.
Transcript
Discussion (0)
Welcome to Embedded.
I am Amicia White.
I'm here with Christopher White.
And this week, we are playing Power Limbo, as in, how low can you go?
Our guest is Matt Liberty.
Hi, Matt.
Thanks for joining us today.
Hello.
Thank you for inviting me.
I'm happy to be here.
Could you tell us a bit about yourself?
Sure. I'm a hardware and software engineer.
I'm currently running my consulting company, JetPerch.
And over the last eight years, I've helped my clients, mostly small companies and startups,
to develop products and to solve problems.
I started on the engineering path when I was little
and still remember that moment when we got an IBM PC, turned it on without any disks in it,
had two floppy drives, and it booted up. And there was this little flashing BASIC cursor.
And I thought, wow, ever since then, I've really been into computers. And as I've aged,
I try to keep that same sense of wonder and curiosity. I studied electrical engineering and then went on to work for a few startups.
And over my career, I've managed a team, designed circuit boards, designed FPGAs, written software, developed signal processing algorithms.
And a lot of those were for motion sensing, something that you've done as well.
Yeah.
Cool. Well, you didn't mention one of the reasons you're here,
which is your new Kickstarter. Definitely. Yeah. So over the last couple years,
I've been working on a new product called Jewel Scope that is going to be on Kickstarter coming
up on February 19th. Okay, well, we'll talk more about that and what it is.
But we need to do lightning round.
We need to do lightning round.
All right, you ready for this?
No.
Good.
That's right.
Anemometer or ammeter or anemone meter?
I say ammeter.
I'm not even sure what that question was.
I don't know either.
Well, one measures wind, one measures current, and one measures anemones.
I see.
Watts or amps?
Depends on what you're measuring.
Watt hour or coulomb volt?
Watt hour.
Would you rather have a penny or $10 million?
What?
That's an easy question.
These are supposed to be easy questions.
$10 million.
Which is greater, the mass of a billion moons or the mass of the sun?
The mass of the sun.
Nope.
What?
Would you rather have a cup of coffee or 60 Olympic swimming pools?
60 Olympic swimming pools.
Have you figured out what these are about?
Not entirely.
What's your favorite animal?
Dolphin.
Do you have a tip everyone should know?
Remember to derate your ceramic capacitors based upon their working voltage.
God, I always do that.
Yeah.
It's the first thing I do.
Every morning I get up and I say, don't forget to derate.
It's important every day.
Yeah.
Okay.
That's derate, not berate, right?
You don't just yell at them.
Whichever one works for you, I guess.
Stupid capacitor. Let's talk about low power. When people come to you and say,
I want a low power device, what does that mean? It really depends upon what you're doing. So
there's low power devices that consume tons of power, but they're low compared to what they replace. You think about HVAC system. We really strive for efficiency in HVAC, but that's not really what I'm talking about. that are battery powered. And you want that battery to last as long as possible, because
no one likes changing batteries. So that low power translates directly into a good thing about the
product, which is longer battery life. And there's products with all different size batteries,
right? We have AAAs, AAs, coin cells, big 12 volt batteries. So it really depends. The other thing
is devices that are always plugged in. If they're always on, they're always sucking a little bit of energy. And that affects the efficiency of everything across the globe.
Do people usually come to you with like, I have a requirement for five days of battery life? Or do they come to you with, well, I've already got this form factor, and it's got a coin cell and how long can it last? That varies a lot based upon customers and the customer
requirements. A lot of times if you're designing something that is meant to be low power,
you know going in that you have to have a battery that lasts for a long time.
So I worked at one point on a remote control and the key rule of thumb that they wanted was
it had to be long enough so that people forgot they replaced their batteries.
And that happens to be about three months that people say, I'm not quite sure when I last replaced it.
So that was the requirement.
And that happens in a lot of different products as product managers are making their decision.
They say, we need something that lasts this long.
And oh, by the way, it can only be this much and fit into this size.
Yeah, it's often the size constraint and the power constraint together,
especially with rechargeables like wearables, that you don't want somebody to have to charge it
every day, but you also want it to be small. And so that's a huge trade off.
It definitely is. And that makes it challenging because, like everything in engineering, you have to trade off that cost, the size, the power, and the engineering implications of all those.
Because there are a lot of engineering implications, including software implications.
This isn't purely a hardware problem.
This isn't just you wave your magic hardware wand and you get low power stuff and it's all good.
Hardly.
Yeah.
So what kinds of things do you suggest to achieve lower power?
Well, it really depends upon the product.
The first thing you want to figure out is where's your power going?
Where's that energy budget? So if you have a Wi-Fi radio, for example,
on your product and you leave it on all the time, it's going to suck up a huge amount of your
available energy. So when you're trying to think about how to optimize your energy consumption,
you first want to know where it's going. If you spend a lot of time optimizing something that's
only 2% of your total energy consumption, you're only going
to get 98% of what you had before, even though you optimize that one part 100%. So it's really
important to figure out where the most energy is going and really start there. And a lot of times,
there's some hardware components. So you can remove things like pull-up resistors for sleep
mode, and we can talk more
about that. And then on the software side, it's turning off things you're not using and only
usually getting on and turning into a full power mode when you really need to, and then going
immediately back to sleep. So that's what you can do tactically when the board is designed. And I
want to come back to that because there are some more strategies there. But even before the board is designed, you look for the parts and you find the low power
parts. And then as you are making your block diagram or you're making your design, you need
to know what the theoretical best you could do would be. You need to make a model. And it can
be Excel or whatever, but you can't
just say, I want the power to be as low as possible and it should last for five days and
not know if it was theoretically possible. Right. Yeah. So if you're talking about the
upfront design phase, then you can certainly pick out the components that you're interested in,
take a look across, and they'll have all different types of active currents
for different modes that they're in, as well as sleep currents.
And in a lot of modern designs and products that I've worked on,
you spend a lot of time in that sleep mode.
And it's not usually the first thing that people look at if they haven't done this before,
but you really want to compute your lowest power possible
when you turn everything off and
are really not operating. You still have battery power so you can turn back on, but you need to
figure out what that lowest thing is. And that amount of current varies dramatically between
different parts that are on the market. You also need to create a plan for how the device will be used.
Looking at the sleep current for all of your parts, and then looking at the partially awake, maybe doing the minimal thing of whatever it's supposed to do,
and then looking at the power for when it's active and squawking and interacting with the user. Those are all different power levels,
and knowing how much time is going to be spent in each level
tells you where you have to optimize the most.
Exactly, yeah.
And it's actually really difficult up front in a lot of design for software things
because you don't have a real good sense until you actually try
of how much time you're going to spend in a full active mode
unless you prototype
up front, which is what I recommend. So as soon as possible, start figuring out those unknowns
so that you can design your budget for the power side and figure out which modes you're in when.
Yeah. And what do you use for that? I do tend to use Excel, but do you have better tools?
I don't know. I tend to use Excel and Python. So when Excel becomes not enough,
or I want to do a little bit more sophisticated things, I really like Python.
Fair enough. It's been hard with clients sometimes getting them to understand
why I want to know, okay, 24 hours, how long is the person going to be using it in this 24 hours and how long is it just going to be sitting there?
And that level of design seems obvious, but to them, they just had a thing that they wanted to work whenever it needed to work.
Sometimes you can't, it's very difficult to figure that out, depending on the product.
Well, yeah, my Fitbit doesn't need to do very much at all at any point.
But an active user of a Fitbit might be looking at their screen
a hundred times a day.
And so sometimes you need to actually just have logging in the field.
And when you're beta testing and you've got a critical mass of users,
then you can say, okay, most users have you know 20 seconds of active
time every hour or something like that but again it depends on the product a user the consumer
product that somebody's interacting with is a lot different from like a thermostat where you can say
well thermostat's not necessarily low power but something that you know okay people tend to look
at this twice a day or it wakes up twice a day to take some reading. And what I've done as well with some
of my clients is walk them through. So you say this type of user and you kind of categorize it,
we'll do this per day. And we have this other user that's like this and this other one that's
like this. And you kind of build up your story of how your product's going to be used. And from
there, you can kind of better estimate your power budget. Exactly.
Okay, so we've estimated our power budget and we've used Excel again,
even though last time we promised ourselves we wouldn't.
We have chosen parts to optimize what we need to do.
And we've come up with some number
that is the ideal current use in multiple states. What do we do next? I mean, build it, but
yeah. Build it and make sure that it works. So the first part before all this is you have a product
that has to do some function too. And power is just one of those aspects. It's an important one,
but it is just one of them. So you have to worry about everything coming together.
And you do your best with all the design up front, especially when you're talking about
hardware.
You want to at least be close on your first iteration if possible.
But the cost of hardware has definitely gone down.
So iterating is much more possible than it ever used to be.
But then you go and design the whole product and implement everything.
And as you go through, one of the things that you're working towards is that power budget.
And you continue to engineer until you get to where you need to be.
Yeah.
And not to pick too much on Fitbit, but if it doesn't count steps.
Please stop.
On nameless pedometer.
If it doesn't count steps, it's of pretty much no use.
It doesn't matter how long its battery lasts.
Yeah.
Bricks batteries last forever.
Okay, so I get my board.
I get it working.
And then I want to do sleeping, and so I read the sleeping chapter.
And maybe I lower my clocks and I optimize my code so I can spend as much time sleeping or as much time in a low power state as I can.
And you mentioned GPIO state.
Could you talk more about that?
That's a really important thing
that a lot of people don't get until they've done power a few times. Yeah, so there's a lot of
things you can do in the software side to make it low power. The first is, like you're saying,
turning off clocks, turning off peripherals, shutting everything down. The other, though,
is more at the hardware level. And a lot of times you'll have signals on
your board that are going between components. Some may have pull-ups, which are resistors connected
to VCC, your positive supply, or to ground. And if you're not careful and put the signals into the
right state, you could leave a resistor essentially powered. So there'll be current flowing through
that even in your low current state.
And it's amazing how fast you can burn up tens or even hundreds of microamps with just a resistor.
You know, 10K or 100K resistor at 3.3 volts
is a lot of times your entire power budget for sleep modes.
So for example, if you have an I2C bus
and those have pull-ups so that they function correctly, they're external to the chip usually, then if you put your GPIO, as you power off, you just say, go low to all GPIOs, then you have a high to low connection there through that resistor, and it's just burning power doing nothing. Yeah. And that's usually like a 4.7K resistor for I squared C. So that's,
if you're a 3.3 volt system, you're almost drawing a milliamp. So that's a killer.
Yeah. But you don't know that until you measure it.
Yep. And that's the challenge. So you can look at your schematic ahead of time
and kind of pick out all those resistors that are going one direction or another so So you can look at your schematic ahead of time and kind of pick out all those
resistors that are going one direction or another so that you can design what you think should be
the low power mode, but you really don't know until you build it. You inevitably, you know,
at least I do, I inevitably miss some. It's one of those things that when I have a fantastic double E. They make a sheet of GPIOs and describe what each one is supposed to do.
And often will tell me, you know, like active high, active low is always a nice thing too.
But we'll say, you know, in sleep mode, I think it should go into input state so that it's high Z,
so that it doesn't, high impedance, so it doesn't draw anything.
Or I think it should be high because that's where the resistor is pulling anyway, so you're just not going to fight anything.
Yeah, it's great if your double E is helping out that way.
A lot of times it doesn't work quite that and you have to figure it out.
Yeah.
And the other thing that I've found, some microcontrollers actually have different
preferred low power states. Some you want to drive out at a specific, you know, whatever level it
needs to be. There are other ones that prefer to have them just set as inputs and leave them
somewhat floating and they have logic inside. That's not what it used to be. You usually want
to drive them all low, but I encountered one chip recently that it consumed more power that way, which is weird.
And sometimes you just try it, which usually leads me back again to Excel or some spreadsheet where I start on day one with my, okay, it's all working.
Now it's time to optimize power or do first passive power optimization.
And so I measure everything and then I make some changes and then I measure everything and then I make some changes and kind of like a drunkard's walk, try to get to the lowest
possible state through a bit of trial and error.
And things do depend on each other.
So you have to be aware of that.
And when I hear about people just changing
everything, it worries me a bit because like, oh, are you sure? How do you do it?
Matt's like, I just change everything.
I just change everything and it gets better. No, measuring as you go along is really important. If
you don't know what you're doing, you are just stumbling blind, like you're saying. And it's,
it is historically, that's been kind of the best that I've been able to do. And that's why I've,
that's been numerous times in my career. And that's why I set out to create a better way to do it.
And we're still not to the better way to do it. It's so sad. It's like,
we're going to talk about all these other things first.
That's awesome.
Okay, so how do you measure power?
Well, the way in electricity, you measure power is by measuring two other quantities,
typically. So you measure voltage, and then current, and then you multiply them together.
So current times voltage is your power. And then that power is just the instantaneous value.
The thing that really matters is how much power you end up using over time.
And the integration of power over time is energy.
And that's joules.
That's the unit, SI unit of measurement for that is joules. And that's joules. The SI unit of measurement for that is joules.
And that's watt-hours?
Watt-seconds.
Watt-seconds, okay.
Yes.
So I want to go back and unpack a lot of that.
So there's voltage and current.
And sometimes when we're doing low-power systems, we don't talk about power.
We just talk about current.
But that's because our voltage is usually the same going in.
So current is nanoamps or amps or microamps or whatever, milliamps, whatever.
It's the amps thing.
And the volts is on our power supply.
And the power, before we got to joules, we had power, and that's watts.
Yes.
So that's all sort of defined.
The easiest way for me to measure power is to look at my power supply.
And I have a desktop power supply, and I set it to 5 volts, and then it says 0.03 or whatever I'm drawing out and that's
current and I can make power by multiplying those two numbers. But that is the easy way to measure
power and it really requires having a desktop power supply. It only gives you the instantaneous
value and it isn't necessarily very exact. So the next method would be a multimeter.
I always get confused on how to set that up.
So Matt, how would you do a multimeter?
Well, there's two parts with the multimeter.
If you want to measure voltage, you always measure across your target device.
So that is the voltage that is across the target and doesn't tell you anything
about current. If you want to measure both voltage and current at the same time, you need a second
multimeter typically, and that one's connected in series. So between the positive, for example,
on your power supply, the positive terminal on your device, you put the multimeter in the middle
and the multimeter is then able to measure
the current flowing through it and through your target device. And of course, the multimeter has
to be in a special mode to do this. And it's kind of confusing because you put your red probe into
the power supply's red terminal, and then you put your black probe onto your device under
test's red terminal. And that step always feels super wrong. Connecting the black and the red
together just is wrong, wrong, wrong. Don't mix those colors.
Yeah. And you mentioned doing it on the high side. You can also do low side. It doesn't matter,
does it? It doesn't, but it does matter if you end up having grounding issues in your system.
So there's a lot of times that people are more concerned about connecting to other equipment.
So if your device has peripherals that are not isolated, electrically isolated, such as SPI or I2C or USB going off to other devices that are powered separately, it's more important to keep those
grounds all at the same level. And by introducing something in that path on the way back on your
device, you can introduce other problems, grounding issues. Oh, that's neat. So I could theoretically
put my multimeter in serial on the negative terminals, of course, then I have to connect my
red to a black the other way. But you're saying that if I do that, and I have a debug port over
to my computer or a programmer over to my computer, that's going to mess up the ground.
So it's really, if you're on your desktop, it's safer to put it on the high side, not the low side. Potentially, yeah. But it also depends upon your power supply. If
your power supply is a bench supply and it's isolated, you're not connecting it up to earth,
ground, or at all, then it really doesn't matter in that case. It's only if different parts of
your system are at different ground levels. And that ends up causing ground loops and ground
noise and things to be injected into your system. And that ends up causing ground loops and ground noise
and things to be injected into your system.
And if you're dealing with analog, this is all really bad stuff.
It makes noise and things don't work.
Ground loops.
I remember for a long time, anytime anything went wrong,
it was either cosmic rays or ground loops.
Easy to blame those.
Okay.
Now, if you don't have a resistor, an ammeter in your multimeter, possibly because you hooked it up in such a way that it blew a fuse, which is when you're measuring current, it can happen.
You can also just use a resistor because that's all this really is.
You use a resistor in serial.
I don't want to monologue, so I'm going to ask Matt to explain that.
Cool.
So this is Ohm's Law.
What happens when you have a current flowing through a resistor, it generates a voltage.
And that voltage is relatively easy to measure.
It's much easier than current.
Counting electrons, there's a lot of them. It just doesn't happen very easily, especially in electronic circuits. So we tend to measure the
side effects of current. The voltage that's generated by the current flowing through
resistor is the one that's most common. And that resistor in that configuration is typically called
a shunt resistor because the current is flowing through as a shunt between it and the actual target.
That V equals IR is one of the fundamental things that is Ohm's law and really is what a lot of the
different ammeters are based on. Another way of measuring current accurately is through the
electric field, or sorry, the magnetic field that is generated by the current flowing through the wire or the conductor. And that is current clamps and other ways of measuring current based upon
that. Okay. Yes. I'm going to stick with the resistor because I understand that one more.
When I put the resistor between my device under test and my power supply, I can then use multimeter to measure the voltage drop over the resistor.
And because of Kirchhoff's laws or whatever, the current has to be the same going through my resistor as it is through the whole system.
Kirchhoff means that the electrons don't disappear.
So as they flow through, they're guaranteed to have the same ones, right? So they're not
vanishing and reappearing, at least at the scale we care about, as they flow through your circuit.
And so I do this with like a 100-ohm resistor, which is a pretty low resistor because I want to be able to measure on my
multimeter. And I calculate, okay, if my voltage is this and my expected current is that, what
resistance will I need to, or I take a resistor and I say, if my expected current is 40 milliwatts
and my resistance is 100 ohms.
What voltage range am I expecting?
And so that gives me an idea of what resistor to use.
But then things start to go wrong.
At what point do you think things start to go wrong with measuring current using this resistor way?
It starts going wrong as soon as the current changes. And in modern devices like
microcontroller-based designs, where we have large variations between the active currents and the
sleep currents, they change a lot. And the problem that you now have is that your voltage is equal
to the current times the resistance. As your current goes from, let's say, 100 milliamps down to 1 microamp,
that's a huge change in the voltage that you're trying to measure.
And the problem ends up being that you can either measure it on the high current side
and do that well without having too much of a voltage drop,
and I'll talk about that just in a moment.
But you lose the resolution, the ability to measure it on the low side.
The one thing that is happening with this whole setup
is we are introducing an intentional voltage change
between your power supply and your device.
If that gets too big, your device gets a voltage
that's a lot lower than you're expecting, and it starts misbehaving,
typically called brownout in microcontrollers.
And so we have a dynamic range problem.
We have a too low voltage.
And there's one other problem, burden voltage, burden current, burden something.
What is the burden that we all share?
Well, in this case, it's actually based upon the resistor's value
and the current through it. The burden voltage is the amount of voltage that is being consumed
by your multimeter or whatever that piece of test equipment is. It's also called, in the RF world,
insertion loss means the exact same thing, or voltage drop. And so that resistor or the multimeter that is in serial
is actually not, it's causing things to happen. Yeah, your test equipment is not ideal. Although
the manufacturers try very, I know, seriously. But it's really easy to forget that. I mean,
you plug your stuff in, you're measuring, you're all happy, and it doesn't do what you're thinking it's doing. It is actually introducing air through the observation, right? So as you hook it up, it's not perfect. some of our test equipment is perfect, but our multimeters have a 1 megaohm or 10 megaohm input
resistance. Oscilloscopes are in the same range, depending upon what type of oscilloscope you have.
So when you're talking about low current stuff, low power, that can be a lot. You can be injecting
measurement air just by measuring voltage on your board.
Heisenberg's never going to let you go. Yeah, and it's not just
the electrical measurement equipment.
You could screw it up
by having your in-circuit programmer
still attached or your debugger.
That could possibly
throw things off as well, right?
Even just having a serial port active
or doing something.
Yeah, that's definitely an issue.
So when you're ever making power measurements
and trying to debug at the same time using your debugger,
you're not measuring the actual power.
That debugger is typically consuming
some of the energy from your board.
And they're not designed necessarily for low power
unless you get one that is specially designed.
That's a good point.
When we talked about the things you need to do,
you have to disconnect your board from anything that is outside of it. It needs to be as
self-contained as possible. And sometimes running off of a power supply instead of batteries
is another change in the system that doesn't work that well.
It really depends upon your system.
There's some systems that are not as dependent upon that,
but if you have some type of switching regulator,
a lot of times those will be more affected by the,
especially the impedance difference between a battery and a power supply.
Okay. So, and then there's also, you're talking, if you're using a resistor, resistors, you know, we don't usually, I don i'm using a 4.4 k ohm i don't care um but when you're measuring things it matters it does yes um so oh that tolerance is what
is the error of your measurement in addition to all of these other possible measurement errors.
Yeah, it's a huge amount of difference. Five percent, if you're talking about your power
budget, could be enough that the change you just made is only a few percent. So you want to be able
to capture that. And if your equipment is varying over time, if you're changing in and out resistors,
then it can change as well. Now, if you're just using the same resistor, as long as they don't have too much of a temperature coefficient, you're okay.
Yeah, as long as you're just trying to go down, it doesn't really matter what the number is,
then you can use the same resistor and it's no big deal. Okay, so we've talked about dynamic
range, which is actually what I was trying to get to in lightning round.
All of the things that we asked you about were 10 billion things apart.
The difference between...
10 billion?
No, a billion things apart.
So nine orders of magnitude, the difference between an amp and a nanoamp?
The one we didn't get to ask about was one second to 30 years.
That's the difference between a nanoamp and an amp is the same as one second to 30, I think it's 32, 31 years, but about 30 years.
Or the difference between a cup of coffee and 60 Olympic swimming pools.
So this dynamic range thing is more interesting than most people think.
How do you, and this is something we're looking at for, we want this to happen.
We want to switch between these states we want to go from
super sleepy nano amps to maybe running a robot in amps how do you i can't change the resistors
i can't uh on my power supply i get rough estimate, but it's just rough. My multimeter says I have to choose between milliamps and amps, and I can't change the dial.
That's how I blew my fuse the first time.
This seems like an impossible problem.
Does anybody solve this?
Ah, yes.
There's a new product coming out.
Would you like a softer ball?
So there's a product that I've been developing over the last two years called JouleScope,
and that's its entire purpose. So it has been very frustrating to do exactly what you're saying,
trying to measure these dynamic ranges of currents. And typically you'd have to either put it
in the high power mode and measure it there
and then specifically set it up.
So it would go into the low power mode and then measure it there separately.
With Dual Scope, the product that I'm doing has a variable shunt resistor, essentially.
And it switches so fast that it can go from that really bigger shunt resistor for low currents down to a much smaller
shunt resistor for high currents without affecting the device that you're measuring.
Why can't you just measure all of them in parallel all the time?
Well, if you do that, your resistance is going to be one of those values to your target device. So if you did it in parallel,
there's no way of making that resistance
be all those different values at the same time.
Why don't you just round-robin between them at 100 megahertz?
That's close enough, no.
I mean, what you're doing is you're introducing,
at least for some period of time, a high impedance.
Let's say you're drawing an amp and you switch to a one kilohm resistor.
Well, it's not going to be drawing an amp anymore, right?
Right.
So, yeah, you have to kind of pick what's appropriate for the current that you're measuring.
And one challenge is also keeping that burden voltage low.
Because as that burden voltage gets too high, bad things happen on your target device.
We tend to, as engineers, say, our power supply. And all of the supply chain in
your product has some type of dynamic response. And if you look closely enough at the data sheets
for like drop linear regulators, switching regulators, they all say something about how
they perform when the load changes from some step of a small step typically and a larger step. But the thing about
your test equipment is it has to be able to do the same thing. It has to be able to respond to
those changes in current. And that's exactly what Julescope is designed to do. And I should just
like leap onto there and talk about that. But there is another tool out there that I think many people have heard of,
and that's the EEV blog's microcurrent,
EEV blog of the NME podcast.
Have you tried one of those?
I have not personally tried it.
I know exactly what it is, and they're great.
So the idea is that you are able to measure
more accurately a specific current,
but it's still, it is not an auto ranging. The shunt resistor is selected by you with a switch,
but it is designed to be a very precise measurement. And unlike your multimeter,
which has, or oscilloscope, either one, which has a one megaohm to 10 megaohm input impedance, the microcurrent
has a much higher input impedance. So you can actually measure small currents accurately.
Yes, but you do have to switch between the different modes. So if I want to measure
in milliamps or amps, I have to do what you said before, I have to set up my system so that it's ready for
that. And then if I want to measure the sleep state, I have to measure the sleep state and
set up my system so that it will do that automatically through usually a power cycle,
but it doesn't range automatically. It was really interesting when it came out because
it talked a lot about burden voltage and what that does for you, which I'll link in the show notes.
But your Joule scope is the auto-ranging is what's important, right?
That's a huge part of it, yeah.
So it's able to dynamically switch its shunt resistance so that it is always at the right
range.
So that burden voltage that is in between
your power supply and your device under test is always held to a very low value. And JouleScope
is designed to be 20 millivolts across that shunt resistor max from zero amps all the way up to 20
or two amps. So that enables it to not really affect your target device.
Whereas if you're using a multimeter or even microcurrent, you have to do that auto-ranging manually, and it's just not really practical to do that.
How fast do you switch?
It switches in about one microsecond, sometimes a little less, sometimes just a touch more, but definitely within two
microseconds. So that's one millionth of a second. Okay. And how does it work? I mean,
is it like the multimeter? I just put it in serial and then what?
Well, Julescope is actually a combination of both a voltmeter and an ammeter. So it has
both of those things at the same time. So you run from the power supply through Joule scope
into your device under test, and that measures current on that side, and then back out. And
usually it goes through Joule scope. It actually doesn't have to, it just needs one side. But that
other side is how it's referencing the voltage. So it measures voltage across your target device as well.
So by connecting it up to both plus and minus to your power supply,
plus and minus to your device under test,
it makes it simpler to think about,
and it's able to measure both voltage and current.
And then it seemed like it was sort of like salient,
that it didn't have a display and it didn't connect to my oscilloscope.
It actually, you made a computer interface for it.
Yeah, computer interface. I'm going to go with that.
Yes, it connects up over USB. So just like the Salier Logic family, it has all on-screen software.
So it's a Python program, actually. It's open source. You just launch it and you can view your multimeter style view if you just start caring about the current value.
Or you can go into more of an oscilloscope view,s and allows you to see all that with great detail so that you can make changes and see in more or less real time how those changes are affecting your power or energy consumption.
I remember not that long ago, probably five years.
Wow.
When did that become not long ago. There was this idea that you can break encryption with power,
differential power analysis. Are you familiar with that?
I am. So I know Colin O'Flynn has done a lot of the research on this. And I met,
I had the opportunity to meet him on a couple of occasions. And he has a specific product that he sells that actually
looks directly at the chip's power supply and has some software as well that's part of that that
looks at the decryption cycle over time and does power analysis to figure out exactly
what the key is, given enough information and enough luck in how you're capturing it. That was the scariest thing I saw in a long time. It really opened my eyes to
how it's all impossible. But can I use the Joule scope to do that?
Perhaps somewhat. It's probably not fast enough to do that same type of analysis that he's doing.
So the point of Joule scope is really to measure more changes over larger periods of time
and typically more at the board scale.
So in order to get that type of power information,
I think he's connecting typically right to the power pins of the microcontroller
or the chip that he's investigating.
And that allows you to have a much higher bandwidth signal.
The problem with most boards, well, not problem, but the constraint with most boards is that they have decoupling
capacitance. And that allows them to function. Without that, microcontrollers don't do what
they're supposed to because you have these voltage variations. The thing about looking at a target
device is that it has that capacitance on it, which tends to hold the voltage steadier to these changes.
So JouleScope is designed more for that type of bandwidth than super high, fast, just looking right at the chip's pin where the power is actually going in.
Well, that makes sense.
Colin also didn't have to worry too much about this dynamic range problem. If he was going
straight into the processor, he didn't have to switch current levels like you do.
Exactly. Yeah. So he doesn't care about sleep mode current and trying to decipher what the
private key is. You just are more or less at an active current all the time. Your dynamic range
is not as interesting as your sensitivity.
And that's really what he was looking at.
With Joule scope and measuring your board supply,
you really care about every single mode that it's going to be in.
And that can be a huge variation of that current.
Looking at the display, it looks like a lot of work.
I mean, that is one of the things that Salier and Digilent and all the people with the USB-based
scopes, it seems like that's the secret sauce and you're making
it open source and it looks like a lot of work.
Explain yourself.
Well, I have a view that you should be able to use your test equipment however you'd like.
You shouldn't be locked into just what is provided for you.
So I like scripting up a lot of my test equipment and want to make sure that people have that opportunity with Julescope.
So part of what I've done is I have two separate projects.
One of them is the driver. It's not really an operating system driver, but it's the software that connects and communicates with Julescope over USB. And you can use that, and there are some examples of how you can just use that to collect data to a file, if you so want. And then the oscilloscope side or the user interface side is a separate project.
And yeah, it is a lot of work. But if I'm successful, which I certainly hope that it is,
then I will be selling hardware. So it's a hardware-based model. And the software, yeah,
will be a continuing ongoing part of the project, but people have the opportunity to modify, tweak
it, add features if they so want. Or if they want to use it for something else, that's great too.
But I feel that's part of giving back to the community and being part of a community.
I really do like open source and I've benefited a lot from it through both my career professionally
and in developing Jewel Scope. So it's part of being part
of that community. I like the idea of being able to modify it for what I want, because sometimes
I want different things, and I don't necessarily trust other people to know what I want.
One of the examples that was brought up in the Slack channel was sometimes you want instantaneous
measurements in multiple states, and sometimes you want instantaneous measurements in multiple states,
and sometimes you want a summation of the states so you know what your overall power draw is.
And you probably have implemented both of those because those are the obvious features, but I can just imagine there'd be other features. Do you know what I want? What do you want? I want it to integrate with an IDE. And so like a profiler, it will show me blocks of code and a heat map.
I think Atmel was trying to do something sort of similar on one of their dev kits,
the D21, SAMD21 or something.
But yeah, it would be neat to have it integrate all the way
and show me where
where my sucky code is yeah that would be really cool i want you're not the first people to mention
that either um having the the trace output from uh cortex m for example m3 and m4 you could
certainly correlate that to the energy consumption yeah uh but right now you
know i'm hoping to just get dual scope out there and we're thinking assuming i know assuming
everyone picks it up and is using it as their daily tool of choice uh we'll we'll go from there
yeah and and making it open source there are people who will be like, oh yeah, that'll be a fun project. So yeah, cool. Have that. Um,
so, uh, I was going to say, when do I get mine? But I realized I already got mine. So,
um, when do other people get theirs? Well, the Kickstarter starts on February 19th and it's
going to run for 30 days. And after that, I'm going to be doing everything you need to do in
order to build and ship a product, uh, already have the beta units, but there's a lot to do to build up a number of units on the manufacturing side.
And those should all ship by the end of June.
And this isn't your first...
The beta units, they're not...
They look nice. They look like products. They don't, you didn't just send me a raw board and like a crown instructions.
Does that happen a lot to you?
No, but I'm waiting for the day.
You seem pretty far along for a Kickstarter.
It's not like you haven't ever made this before give
us the money and we'll figure out three years later i'm getting around to it no i've i've
really spent all the work up front to make sure that it is a product so what you what you've
gotten already and what uh people can see if they go to the kickstarter page uh or the the website
is is very close um if not almost exactly to
what you'll get in the Kickstarter campaign. And that took a long time to get there. So I've been
working on this for two years and have built over that time 17 different prototypes of various
purposes and learning and iterations. So what you're looking at is not just the first shot out of the gate.
It's actually a refined design that I've worked hard to get there.
Where do you think it will go after Kickstarter?
Are you planning on making a business?
Are you going to make more tools?
What's the plan?
I think it really depends upon how your audience
and our audience here is going to respond.
So if everyone loves it and buys it, then that allows me to have the time to really continue to develop it.
And that's really what I would like to do.
I'd like to see this as a product and a business that helps really engineers and makers and developers all over the world to improve their products and reduce energy consumption.
How much is it going to be?
On Kickstarter, it's $3.99 starting for the super early bird and then $7.99 retail.
So Kickstarter is a great deal.
Yeah.
$3.99 super early bird, $4.50 for early bird, $500 for the suckers who wait too long.
Okay, so that's February 19th, which isn't too long after this show airs.
And people should sign up for your newsletter in order to be reminded.
Is that right?
Yes, you can definitely sign up for the newsletter at the Jewel Scope website.
You can also go to the Kickstarter link, which I think you're going to provide,
and click Remind Me There. So it's a preview page for the Kickstarter,
but you're allowed to have it remind you from there as well.
Cool. You said you have 17 prototypes. What went wrong?
Some of them, in the early ones, I was trying to experiment with how it would work.
So it's just a resistor and a voltmeter.
But in order to get the dynamic range and the switching side, there's a lot of things that have to go in supporting that.
So in some ways, it seems a lot of work to get to where I am now, looking back at it.
But there are a lot of things that I learned along the way.
So there's some of the upfront components that I had to select that were very difficult to find in a way that responded correctly.
So there's MOSFETs to actually switch between the resistors,
and those have to be very low leakage.
So the amount of current that flows through them when they're off has to be very low.
If it's not, then it's affecting your measurement in the low current mode.
So all the MOSFETs, even the big ones that are working on the amp range,
have to behave
properly. Then the way of quickly switching uses a different signal path. It uses a couple
comparators that are chosen specifically to be fast enough. And then there's an algorithm in an
FPGA that is controlling the selected resistor. So all of that I had to iterate with to get right.
And then there's more of the mundane side, you know, just getting it to communicate correctly
to a PC. Powering it is actually a challenge. So the design is what's called electrically
isolated, meaning you have as a transformer between the USB side and the sensor side.
And all that just took time and was a little more out of my comfort zone.
So I was an electrical engineer by training, but I haven't really done a lot of analog design for
quite a while. So some of that was me trying to learn and figure out how to do it both cost
effectively and accurately. And the USB, the power, that's because your system has to be powered by the USB
5 volts. You can't sip off of the device under test power because it could be a battery that
can't power you or it could be anything, but anything you take from it will affect your
measurements. So getting power from the USB makes it so that your measurements
are cleaner, right? Exactly. Yeah. So I can't take any power from there because I'm advertising,
you know, nanoamp level accuracy that you can't power very much on a nanoamp. So yeah, it's all
coming from the USB side. And I've designed the sensor side to be very low leakage or also called high impedance so that it does not affect that device under test.
And I want to go back to volts and current.
We talked about we're minimizing current is what we usually think of.
But the other thing people can do is minimize voltage. Do very many
people take that route? Well, every modern IC is getting lower and lower voltage. So certainly,
we used to have chips at five volts, you know, the Arduinos are still there.
But pretty much everything else has moved on to 3.3 volts, 2.7, 2.5, 1.8.
I have a bunch of 1.8.
Yeah, 0.9 now.
I mean, for some things, it's pretty crazy.
But the problem is you get lower and lower voltage is that your tolerance shrinks.
So if you're drawing an amp at 1.8 volts and you have normal resistance,
which happens everywhere. So unless you have a superconductor, your board has resistance, the wires have resistance. It's affecting the actual
voltage that is arriving at your chip. So as you get lower and lower voltage, we have to think as
engineers more and more about keeping that supply within range, which is part of the challenge and also
one of the things that I had to design into Julescope. And that's why that burden voltage
being so low is very important. Is there anything you wish you could tell
the Matt Liberty who started this project?
Projects always take longer than you think, even when you are very pessimistic.
And Julescope has certainly taken a long time over the last two years. And another one is
knowing what I know now about how to do the electrical isolation. So that's something that
took me a long time. I initially started out with an off-the-shelf little power brick. And it's great. It does what it does. And it includes
a transformer and the IC to drive the transformer and then the regulation on the far side.
And it was working okay, but I always had more noise than I thought. And tracing down sources
of noise and analog designs
is really hard when you have lots of noise sources. So it took me a long time to figure out
where my noise sources were. And a huge one that didn't look like it really, because it was at
some different frequencies than I would have expected, was from that switching regulator.
And I ended up going to a discrete solution, my own transformer,
this great driver from TI that another engineer pointed me to. And that solved a huge amount of
my issues with noise and also what's called common mode noise, which probably more than
we want to go into. No, no, I want to know more.
Okay. Common mode noise. So what when you have a any type of device
you have a signal reference to something and typically that's a ground uh and as the signal
wiggles uh it should be wiggling separately from that ground plane and should be that's called
should be that's called differential and sometimes you have differential noise. But what happens if both
the ground and the signal wiggle together? The signal, if it's, let's say it's out at 3.3 volts,
just to pick a number, it's always staying 3.3 volts above the ground. But relative to a separate
measurement, like your device that you're communicating with, or earth ground, they may both be wiggling. And
that's called common mode noise. And that's for something like Joulescope, which is isolated and
trying not to interfere with the devices on either side, either power supply or your device under
test. Common mode noise is a big issue. And transformers can actually couple and cause
common mode noise. And it took me a long time, longer than it should
have, to figure out that issue. But there are a lot of other issues of noise that I was tracking
down at the same time. Did anything in your development go unexpectedly right?
That doesn't normally happen. I would say I was overly pessimistic about USB communication. So I've done a number of USB projects in my career.
And getting data over USB fast enough is actually more challenging than you would think.
So I was pretty pessimistic about being able to keep my, what I'm calling the software driver,
even though it's all in Python, still in Python. I was thinking I'd have to move it to some
type of compiled code rather than Python. But I have DualScope working on Windows, Linux, and Mac,
all without any additional driver software, still all in Python. On Windows, it's using WinUSB,
which is built into Windows 8.1 and later. And then on Linux and Mac, it's using LibUSB.
But the rest of the communication is all at Python.
So that was a good surprise.
And that work actually took a while.
It's now all open source, so people can benefit from that.
Is your hardware open source too?
The hardware is not.
Neither is the FPGA code, at least for the time being. I made a choice to
open source what I thought people would be most interested in modifying. But I have spent a lot
of time on this and haven't quite figured out how to make that open source and still be successful.
Yeah, and that's really hard. And on one hand, you want to open source everything because it's nice when people use it and change it and get excited about it.
But on the other hand, you need kibble.
Yeah, so you sell things and it's important to have something to sell.
And if you give everything away, you don't have anything to sell.
That is the challenge.
And there are some companies that have done remarkably well about that open source model.
But I'm here competing against test equipment manufacturers where nothing is open source.
So I think from that perspective, it's a step in the right direction for this type of market.
It seems like a lot of people are interested in doing FPGA development or getting
into it. Do you have any advice for those wanting to try it? Definitely. It's gotten so cheap to
get involved and actually try it out. So for the price of a few coffees, you can go out and buy one
of the inexpensive development boards. I'd recommend the Lattice Ice family simply because there's so much out there
on the open source community.
The Ice Storm tools that have been developed,
they're really easy to pick up and use.
The main thing to think of
when you're developing FPGAs though
is that it is fundamentally different
from writing software.
So if you're used to writing sequential software,
in hardware, everything runs together by default. So it's a different way of thinking about attacking
a problem. And that's the biggest hurdle, I think, for people getting into FPGAs is to just wrap your
head around how hardware works and why it's different from writing code for a microcontroller.
And there's a lot of examples out there, again,
all around the Ice Storm tools that can help you get started.
It's more like if you have a queue, a line of children waiting for lunch,
and that's sort of how software development works.
The kids come in one at a time.
Versus in an FPGA, you have a room of children all doing things.
Screaming.
Screaming.
All running in different directions at the same time.
Yeah, so it is.
You have every little piece of hardware.
And we think about this in our daily lives.
You have a desk, for example, and all these little things are sitting on your desk and they're doing whatever they do independently without knowing what else is on the desk.
You could have your phone that's sitting there doing its thing. You could have speakers. You
could have a little desk toy. And it doesn't matter if you remove one, the others keep working.
And that's more of the analogy with hardware. You have flip-flops and gates that will continue working on their own, regardless of what the other flip-flops and gates are doing inside the FPGA. They're all in parallel. And the challenge is, in some ways, opposite of software. It's trying to get them to do things together is the design challenge. Normally, they are all kind of separate. They don't wait for each other unless you make them.
And it's really hard to remember to make them wait for each other
because it's so exciting that they're all doing things.
Are there any other features of the Julescope I didn't ask about?
I'm excited to use it.
I have to admit I haven't yet, but I will soon.
But what else should I know or what else is really cool?
So one thing we talked about was the ability to switch really quickly between the resistors.
The other is it's very high impedance or low leakage current.
So it's not really drawing any extra power or current from any of your devices. So it keeps everything working exactly like you would think
without having JouleScope be a big change to your system. The other is it's electrically isolated.
And this is actually more important than you'd think. Jacob Beningo just wrote a great article
on electrical isolation and test equipment for more or less debug stuff. But every time you
add one more thing to your design, so if you're connecting up an oscilloscope or you're connecting
up your debug port, that's one more path for signals. And a lot of devices these days have
sensors and those are analog. So by having these different things connected in, you're usually
injecting noise into your system. By having an electrically isolated system that's done right, you actually remove that noise in a
stronger way than you would have otherwise. It also means that you can run your device
at a different voltage from your USB port on your computer. So it's not tied to your USB ground. That's really important. I mean,
so seldom am I actually running devices at USB levels. Yeah, I have a nasty habit of touching
my oscilloscope probe to things that aren't ground when I'm connected up to my dev boards.
Well, I think I'm out of questions, although I am going to do a slightly uncharacteristic plug for my own book because Chapter 8 is all about optimizing.
And optimizing is what you need to do.
Hey, wait, Chapter 10 is about reducing power consumption.
One of these chapters will be available for people who want to see it. Chapter 10. If you email me, hit the contact link on embedded.fm, I'll send you
the chapter 10 of my book. And you can see if you like it. It's the last chapter. So you can
read the ending first, find out what happens. Matt, do you have any thoughts you'd like to
leave us with? Yes, I do. I'd like to talk a little just
about perseverance. So if you work on a project of any size, and you'll run into issues, and
eventually, they will be difficult to overcome. But it doesn't matter whether it's your first
project or your professional, you run into these issues. And you don't know what it's going to be
up front. You know, you can say I'm going to run into an issue. It could be like your microcontroller driver ends up being too slow.
It could be your software library you select ends up not being a good fit. You break your
only prototype that you've built. I've done all of those in the development of Jules Scope.
So it's a frustrating period going through these roadblocks, these hurdles when you're developing any type of product.
But when it happens, for me, I just take a break until the frustration passes, step back, and really start solving the problem.
Exercise curiosity and ask questions and keep going ahead.
So a lot of people, especially junior engineers I've worked with, get frustrated when this happens and have a hard time refocusing.
It happens to anyone who's developing new stuff.
And having a good sounding board, whether they're people in your community or your coworkers, being able to talk to them or even just your rubber duck at your desk helps as you go about solving the problem.
But persist and keep going and develop great things.
Thank you.
I like that.
Our guest has been Matt Liberty, proprietor of JetPerch and creator of the Jewel Scope.
Its Kickstarter launches February 19th, 2019.
Check out the Kickstarter link in our show notes or head on over to Julescope.com. That's
J-O-U-L-E-S-C-O-P-E.com to sign up for the newsletter to be reminded. Matt, thanks for
being with us. Thank you very much for having me on the show. Thanks, Matt.
Thank you to Christopher for producing and co-hosting, and thank you for listening.
You can always contact us at showatembedded.fm or hit the contact link on embedded.fm.
And now a quote to leave you with.
Anything that's human is mentionable, and anything that is mentionable can be made more manageable.
When we talk about our feelings, they become less overwhelming, less upsetting, and less scary.
The people we trust with the important talk can help us know that we are not alone.
That's from Fred Rogers, Mr. Rogers. I just thought it was related to measuring things.
Embedded is an independently produced radio show that focuses on the many aspects of engineering.
It is a production of Logical
Elegance, an embedded software consulting company in California. If there are advertisements in the
show, we did not put them there and do not receive money from them. At this time, our sponsors are
Logical Elegance and listeners like you.