IC Catu daya terkecil dan simpel

Produsen IC Maxim Integrated menawarkan produk baru mereka untuk solusi catu daya dengan mengeluarkan produk MAX1722/MAX1723/MAX1724 yang mereka namai dengan Small Low-Power Boost Converter.
Beberapa keunggulannya antara lain adalah kemampuan untuk mengubah tegangag catu daya daro 0.8 volt menjadi 3,3 Volt (cukup untuk tegangan IC TTL) dengan hanya menambahkan komponen induktor dan kapasitor agar IC tersebut dapat bekerja. IC hanya membutuhkan catu daya 1,5 mikro Ampere, sehingga disinyalir mampu menghemat daya baterai, terutama untuk diterapkan di perangkat mobile. Sayangnya, hasil dari catu daya IC dengan bentuk paket TSOT ini masih sebatas 150 mili Ampere saja.

Sumber:

  • http://monitor.espec.ws/section27/printview200427.html
  • http://monitor.espec.ws/section27/printview200427.html

Hardware and Firmware Issues in Using Ultra-Low Power MCUs

By Jack Ganssle

December 2014

Rev 1: March 2015 – Added new info about improved Freescale datasheets.

Rev 2: May 2015 – Added link to Low Power Design article.

Rev 3: May 2015 – Added update in section 11 about electron pooling.

Rev 4: March 2016 – Added section 12 about watchdog timers.

Today many of us are building ultra-low power embedded systems that must run for years off a battery. The idea is that these systems are nearly always in a deep sleep mode, waking from time to time to do something before going back to sleep. Many vendors of microcontrollers (MCUs) claim their products can run like this for decades from a coin cell.

These claims are mostly bogus.

This report describes the hardware and firmware issues one must consider when designing very low-power coin-cell products. There are a lot of nuances; even decoupling capacitor selection can hugely influence battery life. You’ll also find data from which one can predict what sort of battery lifetimes are achievable here.

Because the report is very long and covers a number of related subjects, not everyone may need to read the entire thing. Here’s a roadmap so you can get to the sections important for your design efforts:

  1. Background — Do read this. It gives a bit of information about coin cells, and then shows how the basic assumptions made by MCU vendors are completely off-base. They talk about how long a system can sleep; we care about how much work can be done when it is awake. Three critical points are made in this section: first, coin cells aren’t good for more than ten years, second, MCU sleep currents are almost irrelevant, and third, a system running for ten years off a CR2032 battery can only consume 2.5 uA on average.
  2. On Typical Specifications — Many MCU vendors make glorious claims about low current consumption and quote astonishing numbers. Dig into the datasheets and it’s not uncommon to find these as “typical” specifications. I investigated what “typical” means. The result: never, ever, use a “typical” specification as design guidance.
  3. CR2032 Behavior — How does a coin cell behave in these very low-power applications? No one seems to know, so I took a ton of data. The results are surprising and bode ill for long-lived systems. You may find that less than half the battery’s advertised capacity is actually available in a real system.
  4. Leaks and Drains — The MCU is not the only power consumer on a board. Even the capacitors leak — a lot. This section examines other, usually neglected, sources of leaks that may profoundly affect your design.
  5. Decoupling, and Using a Capacitor to Boost Vdd — Pick the wrong decoupling capacitor and your system will discharge the battery in a short time. And, given that an ultra-low power system sleeps most of the time and wakes for only milliseconds, can we use a capacitor’s time constant to keep Vdd high enough to power the system during the brief time it is awake? Hint: the answer is no.
  6. Running Fast to Save Power — The vendors recommend running the MCU as fast as possible to get back to sleep quickly, as the total power consumption will be less than running at a slow clock rate. While that is true, it is naïve. There are other factors to watch out for. This section is important for firmware designers.
  7. Dropping Vdd to Cut Current and Increase Battery Life — You might get some benefits by reducing Vdd to the MCU, but there are some caveats.
  8. Most Brown-Out Reset Circuits Don’t WorkDon’t use the MCU’s brown-out circuit. It will not perform as you would expect in most cases. An alternative is presented. Firmware people take note.
  9. Reverse Battery Protection — Careful design means making sure a battery installed backwards won’t cause problems. Alas, the usual fixes create more problems than they solve.
  10. UL Coin Cell Requirements — UL is very strict about using coin cells. Here are the rules, and their implications.
  11. Battery Droop Over Time — With a load on a coin cell the voltage decays for a while… and then, oddly, stops. Figure on another 10% loss of capacity due to droop.
  12. Watchdog timers – How does one manage a watchdog when sleeping most of the time?
  13. Summary
  14. Reviews of tools to profile low-power systems. This isn’t really in this report; this is a link to my web site’s reviews.

Another
great resource on these issues is Low Power Design by CMicrotek.
It covers other important issues about these applications, and is highly recommended.

1 – Background

There’s a sleep current war raging between MCU vendors. Marketing glitz and web pages are the guns; white papers are the ammo, which is being broadsided with increasing frequency. Much of what is claimed is probably true, but more than a little of it is misleading and/or irrelevant.

It’s truly remarkable just how little current is needed to keep a processor alive today. In the deepest sleep modes even some ARM parts claim just 20 nA (nanoamp) of consumption. That’s a mere 0.02 microamp, a number that boggles the mind. In the desktop world CPUs suck over 100 amps while active, so I salute the MCU community for achieving such astonishingly-low figures.

First, some context. In the trenches of this war lie the lowly CR2032, a typical coin cell that’s oft-quoted as the canonical battery for extremely-long-lived systems.

Coin cell

A CR2032 primary cell

A CR2032 has about 225 mAh of capacity (quoted capacities vary a little depending on the vendor), which means it can source one mA for 225 hours. (Note there is some dependency on capacity vs. how fast one discharges the battery). Its nominal voltage is 3.0, perfect for these 1.8 to 2V min MCUs, and the discharge curve has a sharp knee. They are considered “dead” at 2.0 V, which is confirmed by my experiments. Here’s data for a number of batteries, all from one batch from the same vendor, discharged at a 0.5 mA rate:

Discharge curve
Batteries discharging at a 0.5 mA rate
.

Some of the vendors claim their MCUs can run for 20-30 years from a single CR2032. That’s may be true in theory, but not in practice. The first question one must ask is: are the batteries rated for those kinds of lifetimes?

I contacted a number of battery vendors. None guarantee shelf lives over ten years. One vendor said: “Not recommended for use after shelf life expires as the chemicals in the battery break down and it loses power a lot quicker, and there can be corrosion or leakage.”

It’s poor engineering practice to use a component beyond its rated specifications. For this discussion I’ll assume that the maximum achievable lifetime of a system powered by a CR2032 is 10 years, because that’s the life guaranteed by the battery vendors.

Though the war is all about battery lifetime of a mostly-sleeping system, that’s irrelevant for design engineers. The right question – which no one seems to be asking – is: how much useful work can the system do while awake?

“Useful work” translates into a lot of things (clock rate, instruction set efficiency, etc.), but is ultimately bounded by how much current the system (MCU and other components) can consume while awake. It’s is the budget a design engineer has to work with, and cannot be exceeded (on average).

Doing the math, I came up with the following curve, which assumes a ten year battery life for a cell with 225 mAh capacity. It shows the number of mA available while awake, as a function of time spent sleeping and amount of current consumed while sleeping. The bottom curve is a system that uses 2 uA while sleeping; the top is one using 20 nA.

Useful work 1
mA available as a function of sleep time and sleep current.

For systems that sleep the vast majority of the time, the following chart blows up the data at the right side of the graph above:

Useful work 2

Here’s the key takeaway: Sleep currents are almost irrelevant. Take two MCUs, one that needs 20 nA while sleeping and another that consumes 200 nA. The available awake current is just about the same in both cases. Even one that sucks a microamp while sleeping gives results not much different from an MCU needing an order of magnitude less.

If the system (MCU plus everything else) draws a microamp or less when sleeping we find:

  • If your system sleeps 99% of the time you only have a 0.24 mA budget while awake. This means the system is awake 36 seconds per hour over ten years before the battery is depleted. And while it’s awake, you cannot, on average, draw more than 0.24 mA.
  • If the system sleeps 99.7% of the time you have 0.8 mA available and are awake 11 seconds per hour. And while it’s awake, you cannot, on average, draw more than 0.8 mA.
  • At a 99.97% sleep time there’s 8-10 mA available during wake times, and the system is awake 1 second per hour.
    And while it’s awake, you cannot, on average, draw more than 8-10 mA.

It’s useful to think about a total system current budget. For a CR2032 with 220 mAh of capacity running for ten years the calculation is simple:

Equation

x-amps is the average current consumed by the system over a decade, and works out to 2.5 uA. Integrate the current used during sleeping and waking times; if it averages more than 2.5 uA the battery won’t last ten years. Another way of looking at this, as we’ll see later, is that, since the system sleeps most of the time, the parasitic drains (sleep current plus other circuit drains) cannot exceed 2.5 uA.

 

2 – On Typical Specifications

Check out the electrical specs of an ultra-low power MCU. Clearly we’re really concerned with the current used in various modes. Surprise! Many only give “typical” (i.e., no worst-case) specifications.

It wasn’t always this way. Here’s an example from TI’s 1976 TTL Databook for the 7447A BCD to seven segment decoder/driver:

. TI data book

Note that all of the specs have a max or min number, and the data shows what conditions those numbers apply to (e.g., Vol is with Vcc-MIN, Vih=2, Vil=0.8, Ioh=-200 uA).

Admittedly, in the olden days just a few pages were enough to fully document a part. Today a thousand page datasheet isn’t uncommon. Properly characterizing a component isn’t easy.

Here’s another datasheet — it’s from a box of Entenmann’s donuts:

Donut datasheet

These are worst-case specs. They are guarantees. Contractual terms between Entenmann’s and the buyer. You know what you’re getting.

Here’s some sleep current consumption data from an MCU datasheet:

Typical (+25C): 0.01 uA
Typical (+60C): 0.04 uA
Maximum (+85C): 2 uA
Maximum (+125C): 10 uA

What does that mean? The range covers three orders of magnitude.

Decades ago one of my mentors taught me to never use a “typical” spec; always design for worst case. That has been good advice which I’ve only violated in circumstances where some other data was available or a wide distribution of values was acceptable.

TI agrees. Their datasheet for the LPV521 op amp states: “Typical values represent the most likely parametric norm at the time of characterization. Actual typical values may vary over time and will also depend on the application and configuration. The typical values are not tested and are not guaranteed on shipped production material.” (Emphasis added).

So how does one interpret the current consumption data listed earlier? My first reaction is to use the max (+85C) number as that is, presumably, guaranteed. But that’s 200X the room-temperature “typical” value.

While there’s really not enough data to use for curve fits, an exponential trend line fits pretty darn well, which is hardly surprising given that much of the current is consumed by reverse-biased P-N junctions (think of the Shockley diode equation). But that’s mixing typ and max values, a proverbial conflation of apples and oranges.

I have always assumed “typical” represents an average, or the most-likely value in some probability distribution function. But does it?

I contacted tech support of several semiconductor vendors and asked what “typical” means. The responses were hardly enlightening.

Energy Micro (now owned by Silicon Labs) was the first to reply. They said: “A typical for Energy Micro’s specs is the mean value of the devices measured. So [it’s] not really dependent on the standard deviation. Most CMOS characteristics have a normal distribution, so mean and median are pretty much the same thing.”

That mirrors my expectation, but since bigger standard deviations implies a wider range of values the mean doesn’t tell us much about what to expect. Yet the datasheets for Energy Micro’s ultra-low power MCUs offer (as of this writing) only “typical” current consumption values.

TI weighed in soon after. “‘Typical’ values in datasheets are not taken from probability functions. These are taken from multi-lot characterization testing with the mode being considered the ‘typical’ for a give[n] set of characterization parameters (temperature, Vcc, etc).”

That’s interesting but not terribly helpful. The mode alone tells us nothing about what kind of values one can expect. And TI, like most vendors, only lists the typ value (no min or max) for some parameters on at least some of their MCUs so we don’t get even a sense of the distribution that can be expected.

Microchip responded: “Typical’ is the average of our characterization data.” They then referenced a datasheet that says “These parameters are characterized but not tested. Data in ‘Typ’ column is at 3.0V, 25C unless otherwise stated. These parameters are for design guidance only and are not tested.”

Freescale replied with a link to a Kinetis data sheet. Section 3.8 reads:

A typical value is a specified value for a technical characteristic that:
* Lies within the range of values specified by the operating behavior
* Given the typical manufacturing process, is representative of that characteristic during operation when you meet the typical-value conditions or other specified conditions

Given that typical is “representative of that characteristic” one might assume this means one can expect the part to behave much like the specified typ data. But the example shown on that datasheet just a few lines later rates a current with a min of 10, typ of 70, and max of 130 uA. The standard deviation is enormous. The typ value teaches nothing about the range of values to expect (though, in that example, the min and max tell us everything we need to know; wise engineers will create a design that works properly over that entire range).

March 2015 Update:

Freescale’s latest datasheet for their KL02 Cortex M0+ MCUs now states:

“The maximum values stated in the following table represent characterized results equivalent to the mean plus three times the standard deviation (mean + 3 sigma)”

The listed power consumption numbers are given as max values. That’s useful engineering data! Kudos to Freescale.

NXP told me: “We have not seen a universal definition of ‘typical’, though it has been one of the most commonly used terms in the industry and product. One interpretation would be that ‘typical’ represents ‘material that comes from our production process under standard SPC (statistical process control.)'”

Again, this is interesting and useless, at least for practicing design engineers.

In 2013 an FAE from a large semiconductor vendor told me some of their typical numbers are really marketing tools. Does that mean they can change with the competitive landscape? “Our competitor just dropped their typ specs; we better do the same!”

The bottom line is that the meaning of a “typical” spec is devoid of engineering value. If a spec isn’t guaranteed, it’s not a spec, it’s an aspiration.

Min/max specs are guarantees. “Typical” is not. It’s time for us to rise up and demand better data! Power to the processors! (Well, I guess we want to minimize power to the processors in these applications).

 

3 – CR2032 Behavior

Some vendors take their MCU’s sleep currents and divide those into a CR2032’s capacity to get huge and improbable lifetimes. But how do coin cells really behave in these low-power applications? No one knows! Even the battery vendors provide only the slimmest amounts of data for systems that go from a deep sleep to needing power for a handful of ms.

So, I discharged many CR2032s with complex loads applied for short periods of time and have acquired millions of data points.

battery tester

Nine-cell battery profiler using an ARM controller board. Transistors switch different loads on each battery to run various current and time profiles. Loads are low tempco, 1% resistors. An A/D reads battery voltages and Vce of the transistors. A precision reference and software calibrates the entire analog path.

The following results are for 42 batteries from Duracell, Energizer and Panasonic (including other experiments detailed later, I discharged roughly 100 coin cells). For each vendor I ran two groups of cells, each group purchased months apart from distributors located in distant States, in hopes that these represent different batches. (The devices are not marked with any sort of serial or batch numbers).

First, the weird part. Our local grocery store sells these cells for up to $5 each. Yet Digi-Key only wants $0.28 for a Panasonic and $0.40 for an Energizer — in singles. Duracells are harder to find from commercial distributors, but I paid about a buck each from on-line sources (e.g., Amazon).

I found little battery-to-battery variability (other than one obviously bad Panasonic and one bad Duracell), little vendor-to-vendor difference, and likewise different batches gave about the same results.

What parameters matter? Chiefly, capacity (how many milliamp-hours one can really get from a cell), and internal resistance, which varies with capacity used.

All of the vendors say “dead” is at 2.0 volts.

The following graph shows the average voltage for the batteries from each vendor, as well as the worst-case voltage from each vendor, as they discharge at a 0.5 mA rate. The curve ascending from left to right is the cumulative capacity used. By the time 2.0 volts is reached the capacity variation is in the noise. I found it averaged 233 mAh with a standard deviation between all results of 5 mAh. Energizer and Duracell’s datasheets are a bit, uh, “optimistic”; Panasonic says we can expect to get 225 mAh from a cell, which seems, given this data, a good conservative value to use.

Discharge curve

But in practice you won’t get anything near that 225 mAh.

It’s useful to model a battery as a perfect voltage source with an internal series resistance, as follows:

Battery model

As cells discharge their internal resistance (IR) goes up. Actually, this is not quite correct, despite the claims of all of the published literature I have found. Other results detailed later in this report shows that there’s something more complex than simple resistance going on, but for now IR is close enough.

The next chart shows average IR for each vendor’s products, plus the IR’s standard deviation.

Internal Resistance

Internal resistance and its standard deviation.

So what does this all mean to a cautious engineer? The IR grows so quickly that much of the battery’s capacity can’t be used!

First, the average IR is not useful. Conservative design means using worst case figures, which we can estimate using the measured standard deviation. By using three sigma our odds of being right are 99.7%.

The following graph combines the IR plus three sigma IR. Depending on the load, the drop across the battery’s internal resistor will reduce the voltage delivered to the system, as shown:

IR
Voltage delivered from battery depending on load.

If a system, when awake, draws just 10 mA 88% of the battery’s capacity is available before the voltage delivered to the load drops to 2.0. It’s pretty hard to build a useful system that only needs 10 mA. Some ultra-low power processors are rated at 200 uA/MHz with a 48 MHz max clock frequency — almost 10 mA just for the CPU.

With higher loads, like any sort of communications, things get much worse. Bluetooth could take 80 mA, and even Bluetooth LE can suck nearly 30 mA. At 30 mA only 39% of the battery’s rated capacity can be used. An optimist might use two sigma and suffer from 5% of his system’s not working to spec, but that only increases the useful capacity to 44%. The battery will not be able to power the system long before it is really “dead,” and long before the system’s design lifetime.

And long before the time MCU vendors cite in their white papers.

(Some MCUs will run to 1.8 volts, so vendors might say my cutoff at 2.0 is unfair. Since battery vendors say that 2.0 is “dead” I disagree. And, even if one were to run to 1.8V there’s less than a 5% gain in useful capacity.)

 

4 – Leaks and Drains

The microcontroller doesn’t live in a vacuum; it’s part of the system. Other components draw power, and it’s the design engineer’s job to evaluate those drains. Some may be surprising.

I have a lot of evaluation boards here; many are designed to show off the long-battery-life aspects of a particular processor. It’s interesting to examine the designs. I put one of the boards under a microscope and looked at some of the ancillary parts. There’s a 22 uF decoupling capacitor. No real surprise there. It appears to be one of those nice Kemet polymer tantalums designed for high-density SMT applications.

The datasheet pegs the cap’s internal leakage at 22 uA. That means the capacitor draws a thousand times more power than the “typical” value cited for the dozing CPU. In fact, the cap alone will drain the battery in under a year!

Engineers may argue that 22 uF is a really high value. But that’s what the silicon vendors suggest. Silicon Labs application note AN0002 Rev 1.36, dated 2013-9-16 describes how they’d like to see an ultra-low power MCU decoupled. Over 20 uF is required.

A capacitor has parasitics, and in simplified form looks like this:

Capacitor circuit

Usually the ESR (equivalent series resistance) is pretty low; for caps that are not wound ESL, too, is low. One would hope that Rleak would be infinity. Alas, that’s far from true. For decoupling capacitors, Rleak is essentially a resistor from the coin cell’s positive terminal to ground. For all of the years the MCU is sleeping, Rleak is discharging the battery.

Section 5 of this report gives more information about selecting decoupling capacitors; a poor selection is guaranteed to drain the battery in a short period of time. Tantalums leak far too much to use as decoupling capacitors. Most MLCCs won’t work, either. Use the advice in that section to specify the right decoupling parts.

There is good news for designers: if the batteries start failing at the five or seven year mark, probably no one will remember who is at fault.

What about other sources of leaks? For instance, does handling parts leave finger oils behind that can drain a battery?

A lot of on-line pundits bloviate that the leakage problem is a big factor; experience shows that the more an Internet poster asserts that X is an indisputable fact, the more likely it’s not. (A century and a half ago, Charles Darwin noted that “ignorance more frequently begets confidence than does knowledge.”) This is engineering, not speculation, so I decided to run some experiments to see how significant these leaks are in a digital circuit. But how to do so? Clearly, to get meaningful data one must measure these drains to a resolution much better than the 20 nA (nanoamps) or less some of the MCUs use while sleeping.

One could use a DMM to measure leakage in ohms. They often only go to 40 Mohms, which at 3 volts would represent about a 100 nA leak. That’s too crude. The uCurrent tool can resolve to a single nA, which is probably adequate, but at 1 nA it generates only a single mV, which is pushing the resolution of most DMMs pretty hard.

So I built a sample and hold circuit (S&H). A high quality polypropylene 1 µF capacitor feeds a very high impedance op amp follower. Put a component whose properties you want to measure around the cap, charge it up, and watch the discharge curves by reading the op amp.

Femtoameter
Sample & Hold circuit to test for very low leakages

I used an LM662 op amp, which has a 2 femtoamp (typical – no max is listed) input bias current. One fA is a miniscule 10-15 amps, a millionth of a billionth of an amp, or about 6000 electrons/second, so its effect on the capacitor is minimal. The amplifier’s inputs and the cap’s connection are all made in the air. A Cortex M3 controller with a 12 bit A/D reads the amplifier periodically, as well as temperature and humidity sensors, and shoots the results to a PC via USB for logging.

Measuring the time constant with a 10 Mohm resistor across the capacitor proved the circuit worked as expected. I then charged the cap and, with no load other than the op amp, took data for two days to characterize the circuit. The results are summarized in the following graph.

Temperature response of femtoammeter

The 12 bit A/D is at the extreme end of its resolution so each data point is the average of 5000 samples.

Clearly the voltage is highly dependent on temperature. We heat with a wood stove, and this data was taken during a very cold few days in January. The dips bottomed out in the morning as the house cooled all night; they veered up when I restarted the fire.

My goal was to measure the resolution of the circuit, but the results are very hard to interpret as it’s tough to separate out the temperature effect. Has it discharged at all?

Plotting voltage against temperature:

Voltage vs temperature

The voltage across a capacitor that is discharging over time is:

Time constant equation

Where V0 is the initial voltage on the cap and t is the elapsed time. Taking the natural log and rearranging we get:

. Antilog of time constant

R is the effective resistance that bleeds charge from the capacitor. Some of that “resistance” is due to the bias current going into the op amp; some is in the cap body itself, and some is from leakage into air.

Ohm’s Law converts R to amps. If the voltage decayed by 1 mV this gives 6.6 fA of leakage from all sources. Alternatively, by plugging 10 fA into the equation the voltage would have decayed to 3.228, which would have been very easy to see. So the S&H can resolve better than 10 fA. That’s many orders of magnitude lower than any leakage that would concern us in designing a low-power system.

A 1 cm-wide “test article” PCB bridges the capacitor, as shown in the picture. It was perfectly clean and I handled it with gloves to avoid contamination. There’s a 0.5mm grove whittled across the board. How much does FR-4 material leak in 30% relative humidity? I have no idea. But the S&H confirmed that it’s less than 10 fA.

Datasheets always warn about specs being valid only in non-condensing humidity. How important is that? I boiled some water and collected the condensate to emulate the sort of moisture that likely makes up water vapor in the air, and bridged the test article’s insulating gap with a 2 mm diameter drop. Just over 1 µA flowed, similar to figures available on-line. Conductivity is measured in units of ohm-meters, so there could be a lot of µA flowing in a real PCB with more surface area under water.

Despite extensive searches I couldn’t find any useful data about how the conductivity of a PCB is affected by humidity. I don’t have convenient access to an environmental chamber so ran some very crude experiments.

I covered the test article and humidity sensor with a plastic coffee can with a hose protruding from the bottom. Taking data in real time (with humidity and voltage readings displayed on the PC) I huffed and puffed into the hose. At 70% relative humidity the test article’s leakage went from under 10 fA to 13 pA, a jump of three orders of magnitude. At 80% (the highest I was able to achieve) that went to 20 pA. Now, this is over a 1 cm long gap, so a better metric is 20 pA/cm. A board with 50 cm of track would experience about 1 uA of leakage, enough to eat almost half of a CR2032 battery’s 10 year power budget of 2.5 uA.

There are two mechanisms for leakage due to humidity. The first is through the moist air that separates two tracks or terminals. The second is via adsorption of water molecules on the surface of the PCB. Other contaminates like dirt that might have a very low conductivity can adsorb water molecules and reduce the board’s resistance. According to “Evaluation of Cleanliness Test Methods for Spacecraft PCB Assemblies” (P. E. Tegehall and B. D. Dunn, ESA STM-275, October 2006) a water film just 20 molecules thick will have a conductivity that is only an order of magnitude lower than that of bulk water.

What about contamination? Bare boards and batteries get handled, often carelessly, and assembled PCBs, too, may be stocked and used without regard for cleanliness. A common concern is leakage due to finger oils. Lots of on-line pedants complain that this is a very significant problem. But hard data is scarce.

I grabbed a bottle of my wife’s Jergens Dry Skin Moisturizer, Original Scent, and spread the thinnest layer I could on the test article insuring the entire 1 cm long gap between copper foils was bridged. The leakage was too much to measure with the S&H. But 24 hours later, after the volatiles evaporated, it was down to 180 pA. After another day the leakage hadn’t changed. That’s 0.18 nA, not much, but is over a short 1 cm length, and could add up with lots of contaminated PCB tracks.

After cleaning the board with isopropyl alcohol the leakage was 2 pA, the better part of three orders of magnitude worse than when I tested the fresh, uncontaminated board. More cleaning didn’t help. The Moisturizer had effected some change to the PCB. Happily, 2 pA is a very small value, though it could be disastrous to some analog circuits.

Next came the finger oil test using both lovely soft female fingers which an hour earlier had been gooped up with the Jergens, as well as nasty crackled Jergens-free male fingers. We touched the test article gently, rubbed some, then smeared furiously. In no case did the leakage exceed 8 pA. Now, that’s enough to cause the S&H’s output to droop by more than 50 mV in 20 seconds, devastating in a sensitive analog sample and hold circuit. But it’s not enough to have any measurable effect on battery life.

Since containments can increase the adsorption of water molecules I exposed the finger-oily test article to 80% relative humidity. The numbers rocketed to 65 pA, three times the humidity result with a clean board. Again, 65 pA is nothing, but multiply your track lengths by the 1 cm long test article used in this experiment.

Could leakage come from salts left behind from perspiration? I mixed up a solution of warm water and salt, supersaturating the solution to the point where the water could hold no more salt, and completely coated the 1 cm gap in the test article. Wet, the leakage was unsurprisingly too huge to measure with this circuit. But after the water dried, it dropped to under 50 fA at 30% ambient relative humidity.

That’s with dry salt. Subjecting the test article to 50% relative humidity caused the leakage to jump to 2 µA.

This is a very contrived test. It’s hard to believe that handling a board would leave so much salt behind (as confirmed by my finger-oil experiments).

Using a fresh test article, I tested several kinds of rosin, first soldering while taking care to insure the rosin smeared across the gap in the copper foil, and later just gooping bulk rosin across it. The worst leakage was 2 pA. Adding 80% humidity simply boosted the number to 20 pA, the same result for a clean test article.

Interestingly, careful cleaning with isopropyl alcohol boosted the drain to 32 pA over the 1 cm gap length. Recleaning even more carefully got that down to 4 pA. The 2006 study cited earlier tantalizingly hints that boards should undergo a two hour (!) bath in an ultrasonic cleaner.

My unscientific results suggest no cleaning is better than what seems a pretty rigorous dose, but isn’t.

What about solder mask? I reran the salt water experiment on a PCB whose traces were covered by a solder mask. Even sopping wet, the leakage was under 10 fA. The finger oil experiments, too, gave leakages too low to measure. Ditto for smearing Jergens on the board. The solder mask seems to be a nearly-perfect insulator, though of course there will be no mask around solder joints.

Here are the results:

Leaks and drains

To summarize, assuming no sensitive analog circuits, the experiments showed:

  • Finger oils are not a big deal.
  • Humidity matters if there’s a lot of exposed track and the humidity is very high for a long time.
  • Condensing water is bad.
  • Cleaning is hard, and may cause even worse problems.
  • Solder mask solves essentially all of the leakage problems.

The takeaway is that the usual practice of putting a layer of solder mask on a PCB eliminates leakage problems related to battery-powered MCUs. Don’t worry about assemblers mishandling the board or the battery. There will be leakage around exposed pads, but outside of extreme environments that should have no noticeable effect on battery life.

 

5 – Decoupling, and Using a Capacitor to Boost Vdd

Capacitors leak. Some a lot. What type of decoupling capacitor should we use? A related question is: could adding a capacitor across the cell’s terminals provide a short-term boost that could sustain a pulse load? It’s not hard to show mathematically that the answer is “yes.”

But the math is irrelevant. In engineering we’re always faced by conflicting needs and what appears a simple solution sometimes isn’t.

As shown earlier, it’s useful to think of the battery as a zero impedance source with an internal resistor between it and the terminal. That resistor’s value increases as the battery capacity is drained. If it were 50 ohms and the system needed 10 mA the terminal voltage is down by half a volt, often enough to cause the MCU to crash. Add a big capacitor, as in the following diagram, and a short pulse load can draw on the charge stored in the cap.

Capacitor to boost Vdd

In a TI white paper (“Coin Cells and Peak Current Draw“) the authors conclude that this is a viable solution. They show a case where a capacitor must sustain a 30 mA load for 1 ms. An 87 uF capacitor will do the trick, though they recommend 100 uF since no one makes 87 uF devices.

There are a couple of problems with this conclusion.

First, the capacitor leaks. It’s always across the battery terminals, so is sucking juice, depleting the battery, even during long sleep intervals. How much leakage? It depends on a number of factors, including dielectric material. Let’s consider tantalums, which offer great capacitance versus cost figures. The following table shows the numbers for a 100 uF part. (For tantalums it’s usual to rate leakage in CV, where V is the rated, not the applied, value.)

Tantalum capacitors

The last column is the most telling. Given that the average current draw over 10 years cannot exceed 2.5 uA, just the capacitor’s leakage will suck the battery dry in a fraction of a decade.

Who would have thought that a cap could leak more than Edward Snowden?

How about a better part? The best low-leakage capacitors with the C values needed are MLCC. MLCC leaks are specified in ohm-farads:

MLCC leakage

It’s clear Y5V dielectrics can’t be used. Select a more expensive X7R device. And, one must be careful which X7R is selected as some leak as badly as Y5Vs.

Takeaway: be really careful which decoupling capacitors you choose!

The X7Rs exhibit better temperature stability, which has always been the primary reason to use them, but not as a function of leakage! Here’s a typical graph of normalized leakage versus temperature:

MLCC leakage vs temperature

A system that has to run over wide temperature extremes may leak two orders of magnitude more than shown in the previous table; that sweet AVX spec’d at 0.3 uA suddenly looks like a moderately low-value resistor. But even over room temperature, say 20 to 30 degrees, plan on twice the parasitic drain than specified. In the case of the AVX a quarter of the battery is lost to the capacitor.

It gets worse.

MLCC devices derate themselves. As the applied voltage increases, the effective capacitance decreases. Murata has a tool that helps model this, and here’s the result for 22 uF parts:

Derating MLCC

If space is precious you have few options. Apply 3 volts to a nice small 6 V 3216 device and only half the capacitance is available. The TI paper specifies a 100 uF part, but in this package you’d have to use 200 uF. Alternatively, one could use a higher-voltage (bigger and more expensive) device, or use a larger package as shown in the graph.

Capacitors have tolerances, and though X7Rs are generally +/- 20%, one still has to figure that in:

Derating with tolerance

Figure on an even bigger capacitor to deal with tolerance.

Perusing various sites it’s rather astonishing how few capacitor vendors specify leakage. A lot of them claim “low leakage” but don’t give numbers. That’s about as useless as a campaign pledge.

Kemet’s excellent “Application Notes for Tantalum Capacitors” does show how derating the voltage can help. Operate at the cap at a third of the rated voltage and the leakage will typically decrease by an order of magnitude. Go to ten percent of the part’s rated level and leakage dives by another factor of five. But in a three volt system that means a 30 volt capacitor — bigger and pricier.

Derating a capacitor

These deratings are “typical” numbers. Use with caution.

So, despite the problems with capacitor deratings and leakages, can use use one to temporarily sustain a Vdd high enough to keep an MCU from crashing during a brief waking period?

The following graph shows the required capacitor, at 20 degrees C, for 10, 20 and 30 ms pulses with various loads, ignoring all of the complicated effects noted above. You’ll have to factor all of those parameters in as well, which, as we’ve seen, can more than double the required uF. The leakage numbers are based on that nice AVX component. Though the TI paper uses a capacitor to boost power for 1 ms, for Bluetooth and other protocols tens of ms are more likely.

Capacitor boosting Vdd

So we’ve done the math, and have figured out what size capacitor to buy. Let’s ignore all of the unpleasantness and assume that a 100 uF part fits the bill, and that we’re using a low-leakage AVX part. They’re $14.50 each! Neither Digi-Key nor Mouser has them in stock, and quote a 25 week lead time as of this writing. Digi-Key does have a 50 V version available today, but that will set you back $36.54.

A complete Raspberry Pi with 700 MHz ARM processor and half a gig of RAM costs less than that capacitor.

Maybe this is a government project where costs don’t matter. Using the graph above we pick off a 400 uF part for a 10 mA 20 ms load (remember, this is before all of the derating that must be done). The leakage will eat about half the battery capacity. And, the capacitor doesn’t exist; the biggest such part on the market is 220 uF. You can’t buy a bunch of smaller parts and parallel them, since the leakage will go up.

What about a supercapacitor? These are astonishing devices that offer farad-levels of capacity. Alas, the lowest-leakage supercap I can find is from Cap-xx, and they quote 2 uA at 23C, doubling at 70C. That’s impractical since even at room temperature it’ll eat just about the entire 2.5 uA current budget.

Summing up, in the use case I’ve described (ten years of system life from a coin cell) it’s impractical to get a short Vdd boost from a capacitor across the battery.

 

6 – Running Fast to Save Power

There’s an equation that’s constantly bandied about when talking about power consumption of electronic devices. If you’re designing battery-operated ultra-low-power devices, it’s critical that you, well, ignore it.

Power vs frequency and voltage

Engineers’ eyes light up by the V-squared term; they immediately start looking for a way to lower Vdd to get more battery life.

As we’ll see there might be some benefit to dropping the power supply voltage. But this equation is irrelevant to ultra-low power systems because it measures power — watts — not current. High-performance systems live and die by power; have you seen the cooling towers on desktop CPUs? Battery operated systems are constrained by battery capacity, which is measured in amp-hours; typically the units are milliamp-hours (mAh). Power is not the issue for figuring battery lifetime.

Think in terms of current.

The following graph shows how one of Microchip’s nice low-power MCUs uses current as a function of clock frequency:

Microchip Vdd vs F

Note that doubling the clock rate from one to two MHz uses much less than a twice the current. The reason is that the CPU is only one of the powered components. Memory and peripherals suck coulombs, too, and not all of these needs vary with clock frequency. There’s a static, constant draw, and one which is a function of frequency. It’s not hard to pick points off the graph at 3.5 volts and solve a couple of simultaneous equations, which gives:

Static current: 0.39 mA
Dynamic current: 0.11 mA/MHz

At one or two MHz most of the current is used by static loads. At higher frequencies the constant draw is still significant. It’s clear that wise designers will run at the max possible clock rate to get back to sleep as quickly as possible. This is the advice given by all of the MCU vendors.

And it’s wrong. Or at least naïve.

Remember how a battery’s internal resistance increases as it is depleted? Here’s the graph again, which shows the voltage delivered by the battery depending on load:

Voltage vs load

If one were to follow the advice to run as fast as possible, coming out of a sleep state means the system will be drawing perhaps a lot of current. Over time, the battery’s internal resistance will increase to a point where it may have a lot of capacity left, but cannot power a speedy current-hungry MCU. Wake up, and Vdd drops below the minimum allowed, so the processor crashes.

At least one series of MCUs advertised for ultra-low power operation consumes 200 uA/MHz, maxing at 48 MHz. That’s about 10 mA just for the MCU. The battery might not be able to sustain a 10 mA load, but at 1 MHz — 200 uA – it can have plenty of life left.

The moral is to wake up at a low clock frequency. Ramp it up while watching Vdd, stopping a bit above the MCU’s cutoff point. Be sure to factor in the needs of I/O you’ll be powering up.

Alternatively one could apply some a priori knowledge (e.g., track consumed mAh and use data such as in the graph above to estimate the operating point) to set the clock frequency.

But if you take the vendors’ advice and wake up at full throttle, the useful battery lifetime may fall far short of your design goal.

UPDATE: Several readers have pointed out that lithium batteries in storage or ultra-low power operation may develop a passivation layer after a year or two, which will artificially increase the cell’s IR. The way to get rid of the passivation layer is to drop a high load on the cell till the battery’s voltage recovers. Some info on-line suggests that only certain kinds of lithium cells suffer from this but information is sparse. This link describes the situation.

So the advice above is good: wake up in a low-power mode as described, but if it’s early in the cell’s life and a high IR (low voltage) is found, drop a heavy load on the cell till it recovers. This could be done by powering up a transmitter or doing a flash write. Be cautioned, though: don’t apply a load so high that the MCU crashes.

 

7 – Dropping Vdd to Cut Current and Increase Battery Life

When trying to maximize the amount of energy one can get from a battery powering an MCU it’s important to remember that we’re interested in current, not power, since battery capacity is measured in mAh. The equation for power has a hugely-seductive V squared term, but when we’re (correctly) thinking about current, voltage’s effects are linear.

So, does it make sense to exploit current’s linear relationship with voltage?

Consider the following graph for one of TI’s nifty MSP430 MCUs:

TI Current

The curves above show a substantial reduction in current as the Vdd decreases. Even at 1 MHz, where the graph isn’t very dramatic-looking, there’s about a 2X improvement by scaling back the MCU’s supply voltage. So this sure looks like a great place to cut coulombs.

It’s tempting to put in a low-dropout regulator to reduce Vdd to 2.0, but I can’t find any linear devices whose idle current during the MCU’s long sleep states won’t deplete the battery. Smarter parts can work, like TI’s $0.80 TPS 62736 buck/boost converter that needs only 400 nA for Iq. It does require an inductor, but those are only about 7 cents in quantity. Touchstone’s TS3310 (now owned by Silicon Labs) has even better specs.

But long-lived systems are almost always asleep. A device that has to run for a decade off a coin cell will be snoozing well over 99% of the time. The graph above is active current; cut that by half, and factor in the 1% or less awake time, and it’s clear that there’s really no real benefit to scaling Vdd.

What about cutting Vdd during the 99% of the time when the processor is sleeping?

Most MCUs offer a number of sleep modes that each have differing energy needs. Some show a very small difference in worst-case consumptions; it’s common to find in a deep sleep only a 20% variation between 3 and 2 volts. 20% may be enough to justify an extra dollar’s worth of buck/boost parts as that could add a couple of years to the operating life of a very-low-power system. But remember that a ten-year life means the system’s average draw from a CR2032 can’t exceed 2.5 uA. The TPS 62736 will eat 400 nA of that budget.

One vendor shows curves for “typical” sleep needs, and there’s about a 2X difference between 3 and 2 volts, which sounds promising. But under 3V the curve is labeled “limited accuracy.” Combine the meaninglessness of “typical” numbers with “limited accuracy” and I, for one, have no idea how to interpret the data. One wonders if the datasheet was created by marketing folks rather than engineers. “Take it from us, in some modes, it’s possible, based on a statistically meaningless set of observations, that the part might, if coupled to the wings of angels, work in your application.”

Unfortunately, most datasheets don’t spec out the difference in sleep current as a function of voltage, so it’s impossible to know what benefits, if any, accrue from voltage scaling.

As always, read the datasheets carefully and do a full analysis of your design goals.

 

8 – Most Brown-Out Reset Circuits Don’t Work

Low-power MCUs usually have a built-in brown-out reset (BOR) circuit. Unfortunately, most are poorly designed and/or lightly documented and should not be used.

One popular ultra-low power MCU, from a vendor who noisily advertises two to three decades of coin cell operation, has a BOR which is off by default. On, it requires somewhere between 8 (typical) and 16 uA (worst case). Remember that, for a decade of life from a CR2032, the system’s average power draw cannot exceed 2.5 uA. Even if one were to foolishly use the typical number, the BOR by itself will deplete the battery in just a couple of years.

Another vendor, pushing extremely-low power ARM parts, rates the BOR at 0.49 to 1.26 uA — typical. There’s no max listed; there’s not the slightest guidance of what statistical distribution one can expect when making thousands of systems. 1.26 uA eats half the 2.5 uA budget.

In another case the datasheet reads about the BOR: “In the deeper sleep modes, this will contribute significantly to the total current consumption.”

As Deming said: “In God we trust, all others bring data.” They didn’t, and it strikes me as risky to rely on divine intervention instead of careful analysis. I’d be wary of using these uncharacterized parts in long-lived applications. As always, read the datasheets pessimistically and carefully.

When does the BOR interrupt occur? In some cases the voltage range is very wide; an example is an MCU where it is listed as 2.05 (min), 2.2 (typ), and 2.35 volts (max). Doing worst-case design you’d have to assume that the BOR may occur at 2.35 volts.

The following graph is one I have used before; it shows the voltage a CR2032 can deliver as it discharges as a function of load.

Brown out reset curve

The 10 mA load line is pretty common for an awake MCU with enabled peripherals; 30 mA is not unexpected if there’s any sort of wireless comm going on. The heavy red line is at 2.35 volts, the max value where we may see a BOR interrupt. Note that in this case the BOR circuit will signal a dead battery, if there’s a 30 mA load, shortly after you ship the product. With a 10 mA load the battery-dead indication happens when there’s still 31% capacity left.

In other words, the BOR circuit is useless.

A much better alternative is to leave the BOR off and use the A/D. Wake up from time to time, apply a load similar to what the system normally needs when awake, and read Vcc. If it’s near 2.0, then signal a battery failure (or take whatever action your system needs in this situation).

If such a reading is taken once every ten hours (surely, more often than needed), and 10 mA were pulled for 1 ms during this reading, over a decade this eats only 0.03 mAh, or 0.01% of a CR2032’s capacity. And, by manually reading the A/D a more nuanced approach to battery management is possible than by relying on a single, poorly-controlled, BOR voltage.

 

9 – Reverse Battery Protection

How should you design the system to protect it from well-meaning users trying to change the battery?

A typical coin cell battery socket looks like this:

Coin cell socket

Inexpensive coin cell holder.

It’s cheap, it’s easy, it mounts well on a PCB, and it’s a disaster. A confused user, poor instructions, perhaps a martini-induced brain fart, and an upside down battery will fry all of the sensitive electronics.

I saw a system not long ago that used a small signal diode to insure the electrons flow in the right direction. But that sort of a design is a catastrophe for these systems. It takes 0.7 volts right off the top; as the battery discharges it’s not long before there’s not enough voltage to keep the MCU going, even though the battery is a very long way from being dead.

Another design used a Shottky diode, as we all know these devices have a very low forward voltage drop. Anecdotally people talk about 0.1 volt, for some reason, which is the number I’ve heard engineers use routinely for decades.

But that’s simply not true. Here’s the forward voltage drop for a typical Shottky diode:

Shottky diode Vf

Shottky diode forward voltage

Sure, you can expect 0.1 V or so… at 0.005 mA! At more realistic currents (10 to 30 mA or so) that jumps to 0.4 V at room temperature.

If the protection diode drops 0.4V, then once the battery drops below 2.4V the system gets 2.0V. It can no longer provide enough voltage to keep the MCU alive. Remember the graph that showed typical voltage from a CR2032 for various loads? This is the same plot with a red line at 2.4V.

Loss due to a Shottky Diode

The useful battery capacity with a diode is above the red line.

Once the battery voltage falls below the red line the MCU will be starved for electrons. In the case of a 30 mA load pretty much the entire capacity of the battery is lost. Even with a 10 mA load over half the battery is unusable.

A much better solution is a one that won’t properly engage the battery if the cell is inserted backwards. The following part from Memory Protection Devices
is a good example:

Better coin cell socket

A better coin cell socket.

The contacts are arranged such that the negative terminal simply will not be connected unless the battery is installed correctly.

It’s $0.25 more than the socket shown before. But if you care about the customer experience, use a socket that will simply leave the system unpowered when the battery is inserted backwards.

 

10 – UL Coin Cell Requirements

Bob Snyder sent me the UL rules for using coin cells in products.

There are a number of requirements that must be met to obtain UL approval in devices with user-replaceable batteries. For instance, the device must be marked “Replace Battery With (Battery Manufacturer’s Name or End-Product Manufacturer’s Name), Part No. ( ) Only. Use of another battery may present a risk of fire or explosion. See owner’s manual for safety instructions.”

I have never seen this on any product that uses coin cells.

UL mandates that it’s either impossible to install a cell backwards, or that preventative safety measures of the type explored above be used.

In many applications coin cells are used just to maintain RAM’s contents when the mains power is down. UL is very concerned that the battery cannot be reverse-biased when the power supply is feeding memory, so requires that either two series diodes, or a diode with a current-limiting resistor, be placed between the battery and the rest of the circuit, as follows:

UL battery wiring

Why two diodes? UL’s ultraconservative approach assumes one may fail. The resistor is to limit current if the diode in that circuit shorts.

In most cases the first circuit won’t work; even two Shottky diodes will drop about 0.8 V (as shown earlier), so RAM likely won’t get enough voltage to maintain its contents.

The second circuit requires a resistor that limits reverse current to a UL spec of 25 mA for most coin cells. But how is one to compute the proper resistance? You need to know the battery’s internal resistance (IR) when reverse-biased, and I cannot find any documentation about that. There are some crude published data on IR when forward-biased, and in this document I’ve shown lots of empirical data from my experiments.

One could assume the battery’s IR is zero, which would certainly give a nice worst-case result, but I decided to explore this a bit more.

I applied a power supply to a CR2032 and measured the current flow when the supply’s voltage was 0.5, 0.75, and 1.0 volts above the battery’s unloaded voltage. The battery was contained in an explosion-proof container. Well, actually, an old coffee can, but it sure would have been fun to hear a boom. Alas, nothing exciting happened.

From that it was easy to compute IR, which is displayed in the lower three lines on the following graph:

Reverse biased coin cell

(I took data every minute for the first 8 minutes, and at 5 minute intervals thereafter. The dotted lines are trendlines.)

Strangely, the internal resistance spikes immediately after the power supply is applied, then quickly tapers off. In a matter of minutes it falls to six to eight ohms. The data is very similar for when the power supply was 0.5, 0.75 or 1 volt above the cell’s unloaded voltage; that’s not unexpected if one assumes this really is resistance and not some complexity arising from the chemistry.

The top three curves are the battery’s temperature. Unsurprisingly, temperature goes up with the voltage difference. Given UL’s dire warnings about catastrophic failure I expected more heat, but the max encountered was only about 50 C, far lower than the 100 C allowed by UL rules.

Now, this data is for a single battery, so be wary, but it does conform to the IR characteristics I measured for forward-biased cells.

Probably the only decent solution, if you don’t want to use a socket as described above, is to use a FET to protect the circuit if the battery is installed backwards. TI has a nice application note about this.

This leads to another question: to get more capacity, can we parallel two or more coin cells? UL is silent on the subject. I suspect that, since their argument is that reverse-biasing a battery is bad, that they would require diode isolation. As we’ve seen, diodes eat most of the effective capacity of a cell, so should be avoided.

From a non-UL, purely electronics standpoint, what would happen?

This is a debate that rages constantly in my community of ocean-sailing friends. The systems on our sailboats run off large, often lead-acid, batteries. On my 32 foot ketch, the fridge sucks 50 Ah/day, the autopilot another 50 Ah, and the radar, well, at 4 amps we don’t have the power to leave it on all of the time. All of this comes from two 220 Ah six volt golf-cart cells wired in series. After a day or so of running the systems we have to fire up the engine to recharge, which everyone hates. Can we wire two banks of golf cart cells in parallel? I have heard all sorts of arguments for and against, but many do wire their systems that way and get good results.

What about coin cells?

My experimental data shows that the maximum difference in unloaded voltage for fresh CR2032s is about 0.25 volt. This is true for a single brand and between brands and lots.

With two paralleled cells of unequal initial voltages, the lower-voltage battery’s small IR will discharge the higher-voltage cell rapidly until both batteries are at the same voltage.

LiMnO2 cells have a very flat discharge curve till they approach end of life. Discharge one by a quarter volt and you have lost around 200 mAh of capacity, or about 90% of the cell’s 220 mAh rating. So the battery with the higher voltage will quickly run down to 10% reserves. Most of its capacity is thrown away.

But it gets worse. Once heavily discharged the battery’s voltage is at a knee on the curve and falls rapidly. The one that seemed better, with a higher voltage when first installed, now acts as a load on the other!

They essentially suck each other dry. So don’t put these in parallel.

 

11 — Battery Droop Over Time

Suppose one applies a fixed load to a coin cell for a short period of time. Does the battery voltage change? That’s a special case of a broader question: everyone uses internal resistance (IR) to characterize these cells. Is IR really an accurate way to model their behavior?

For this experiment I discharged 9 CR2032s. Most of the time there was only a 0.5 mA background load to run the batteries down, but every two hours the test jig applied either a 10 mA or a 30 mA load for one second. That is, at the 2 hour mark the cells saw a 10 mA load; at four hours it was 30 mA. The system read voltages immediately after applying the load, every 10 ms until 100 ms went by, and then at 100 ms intervals.

Here are the results for 30 mA. The horizontal axis is time, but I left it unlabeled as it could be weeks, months or years depending on the discharge profile. The blue line is the battery’s loaded voltage; other lines are the internal resistances during the one second interval:

Coin cell voltage droop

Note that the bottom red line is the mean IR for 9 batteries at 0 ms, immediately after slamming on the load. All of the other data points are pretty tightly grouped. In other words, the IR goes up significantly (about 10%) milliseconds after the load shows up, but there’s little change after that.

In other words, IR is not an accurate model of coin cell behavior. It’s not bad; for an engineering analysis it’s probably close enough. But there is some other effect from the battery chemistry going on.

The results are clearer with less data. Here the red line is the IR at 0 ms; grey is at 10 ms, and yellow at 1 second:

More details about voltage droop of coin cells

Especially nearing the end of life we can see a big increase in IR from 0 to 10 ms, but not much more from 10 ms to 1000 ms. Yes, the effect is different when the battery hasn’t run down too much, but then the voltage is higher and IR is so low the increasing IR isn’t particularly important.

With a 10 mA load the results are about the same:

More droop data

The bottom line is that the voltage the MCU sees when it first wakes up is not that which will be there mere milliseconds later. Figure on another 10% drop, on top of all of the losses detailed earlier.

May, 2015 Update: I’m told this is due to electron migration within a cell. Electrons pool on an electrode; when a load is applied these pooled charges are the first to be drawn off. It’s as if there’s a bit of capacitance involved.

12 – Watchdog Timers

Quite a few people have written asking about using watchdog timers (WDT) in battery-operated systems that achieve years-long life by snoozing 99+ percent of the time. The system may be dead to the world for hours — how does one service a WDT when the code isn’t running?

Why would you want to? How can the software crash when it’s not running?

The answer is that the code can fail while awake and accidently enter a sleep state. Running the WDT during sleep insures the system will recover.

One could wake up once a minute or so and tickle the watchdog. Generally that only requires a handful of instructions. Even when running from a 32 kHz clock (typical for ultra-low power sleep modes) the tickle will only need a ms or so of awake time. If the MCU consumes 50 uA while servicing the WDT that’s just 7.5 uAh per year of operation. Given that a CR2032 coin cell has about 220 mAh of capacity, the energy needed for managing the WDT is insignificant.

But the reality is a bit more complex. We have to work with real parts, not idealized devices.

I looked at a typical microcontroller from Microchip, picked at random from their incredibly diverse selection of “XLP” (extremely low power) devices. The PIC16LF1704/8 is a nice 8 bitter with gobs on on-board I/O, including a watchdog timer. In the low-power sleep mode the WDT consumes 14-17 uA. I started engineering when a microprocessor needed a huge honking power supply, so this is an incredibly small number. But it’s too much for long-lived coin cell operation. That compendium I referenced demonstrates that for 10 years of life from a coin cell the average current consumed can’t exceed 2.5 uA. That watchdog is unusable in this environment.
(I didn’t do an exhaustive search; possibly other MCUs from Microchip have lower-current WDTs. And I commend them for publishing these worst-case numbers; too many other vendors don’t.)

A competing MCU from TI, the MSP430F11x1a, takes only 1 to 3.4 uA in the lowest-power sleep that still has an oscillator running (to support the WDT). Nice, but 3.4 uA is far too much for these applications. The better figures assume Vdd is 2.2 volts and it’s not hot. No incremental current is listed for turning on the watchdog, which suggests that is included in these figures. However, the user’s guide reads “When the watchdog timer is not required, the WDTHOLD bit can be used to hold the WDTCNT, reducing power consumption.” That sounds like there is some, undocumented, hit for using that peripheral. Is it a nanoamp or do you have to run jumper cables to a car battery? Sans data engineers are left adrift.

Other vendors are equally vague.

Since the code can’t crash while sleeping, leave the WDT turned off during those long periods. Enable it while awake. Running, a crash will be mediated by the operating WDT. The upside of this approach is that, since the MCU is awake for such short periods, the current consumed by the WDT is insignificant and won’t drain the battery.

While awake, of course, a crash could vector to the code that disables the watchdog before going to sleep. Instead, structure the code to initialize a variable to a known value, and add offsets to it while running. That could be done in functions that are always called. Before executing the SLEEP instruction check to see if that variable contains a value that indicates the code executed correctly. Take recovery action if the variable is not correct. Or, if basically the same code runs during each awake cycle, use a timer to measure execution time; error if it deviates much from nominal.

There are other failure modes. The firmware could be perfect, but an external event — EMI or a cosmic ray impact — may scramble the MCU’s neurons. Perhaps the program counter gets altered. When the MCU wakes up it will resume operation at a random address without re-enabling the WDT. Or maybe the event flips a bit in the sleep logic so the microcontroller never wakes up.

Essentially, one would need a watchdog that operates during sleep times to counter these threats. Internal WDTs use too much current. Readers have suggested two TI parts: the TPL15111 timer (beware of footnote #4 in that datasheet), and the TPL5010.

13- Summary

This report uses the results of extensive experiments, plus analysis, to prove that most assumptions about designing ultra-low power systems are wrong. Among the most important findings:

  • Sleep current is almost irrelevant
  • What matters is time spent sleeping…
  • … and contributions of other leaks and drains
  • The internal resistance of coin cells increases hugely as the battery is discharged.
  • Don’t wake up at full speed! Check the voltage as you ramp up frequency.
  • Don’t use the on-board brown-out reset circuits.
  • Droop will trim another 10% or so of battery capacity.
  • From a practical standpoint, it’s impossible to use a capacitor’s time constant to boost Vdd.
  • Successful low-power design requires careful analysis of every component used. Even poor decoupling capacitor selection will drain a battery in short order.
  • I doubt anyone will get 10 years from a coin cell even with the most careful design practices.

The bottom line is to apply careful engineering judgment to all design decisions.

And test your design. You know the IR will go up as the cell’s voltage declines. Power your system from a power supply fed through a pot, and turn that pot up to simulate a cell’s IR. Run the system through sleep and wake modes, as well as brown-out-reset, to insure it will still operate correctly even as a battery approaches end of life.

source: http://www.ganssle.com/reports/ultra-low-power-design.html

Bypass Capacitors – Why and How to Use Them?

Bypass Capacitors – Why and How to Use Them?

You may have heard about the phenomenon of bypassing in circuits, however, we may not have sufficient knowledge of how to apply this technique in real circuits. In this tutorial, we will discuss about the bypass capacitors, why we need to use and how to use these capacitors in circuits.

What is a Bypass Capacitor?

A capacitor that filters out the AC signal removing the noise and provides a DC signal is known as a bypass capacitor. The capacitor connected in the figure below is a bypass capacitor bypassing AC noise and allowing pure DC signal to pass through the component.

operation-of-a-bypass-capacitor

Operation of a Bypass Capacitor

Why Use Bypass Capacitors?

In electronics, most of the circuits are digital in nature using direct current (DC). It has been observed that variations in voltage can cause problems to the circuit operation. A circuit may operate incorrectly due to voltage swing. In practical circuits, the voltage fluctuation is usually caused by the AC component that may ride over DC signal causing noise. Therefore, a bypass capacitor is needed to dampen the AC or noise present at all frequencies. Also, it prevents the unwanted communication between devices sharing the same power source.

 

When do you Need Bypass Capacitors?

Firstly, the low frequency circuits may not require bypass capacitors. However, many low frequency active devices comprise of high frequency units. For example, a microcontroller is a low frequency device using a clock making a low frequency system, but the rising and falling glitches can occur due to internal gate transitions without proper filtering of power supply that will traverse the circuit. Therefore, you may need a bypass capacitor with an appropriate value to achieve proper filtering of power supply.

Secondly, you may have this misconception that only digital devices need bypass capacitors. However, bypass capacitors also benefit the analog circuits and devices in a different way. In digital systems, bypass capacitors control the fast timing of rising and falling glitches. Conversely, bypass capacitors help in reducing noise of power supply in analog systems. Generally, analog devices have built in capability of filtering power supply that is effective for reducing low frequency power supply noise, but it is not useful at higher frequencies.

Types of Bypass Capacitor

Bypass capacitors are usually used in high speed environments where the capacitor inductances play a very critical role. The output of a part generates high frequency noise, typically greater than 100 MHz, on the power line at high speed switching. A high lead inductance capacitor will behave as an open circuit due to these harmonics which prevents it from providing the needed current to the power line to maintain a stable level, which results in failure of circuit functionality. Therefore, capacitors with very small inductances are required to bypass the internal noise of the device.

The inductance of a typical surface mount ceramic capacitor is 0.5nH, while the inductance of an electrolytic capacitor is 15nH. By calculating the inductive impedance of these bypass capacitors, we can observe the effect on bypassing:

Electrolytic Capacitor Ceramic Capacitor
Z_L = 2 pi fL
Z_L = 2 x 3.142x 1.5x10^{8}x 15x10^{-9}
Z_L = 14 Omega
Z_L = 2 pi fL
Z_L = 2x 3.142x1.5x10^{8}x 0.5x10^{-9}
Z_L = 0.4 Omega
V_{drop} = IxZ_L
V_{drop} = (0.04 A)x (14 Omega)
V_{drop} = 0.56V
V_{drop} = IxZ_L
V_{drop} = (0.04 A)x (0.4 Omega)
V_{drop} = 0.016V

From this example, we have observed that supply voltage drops below the operating voltage of the device due to more than one channel switching at the same time. Therefore, it is important to use the correct type of bypass capacitor. This is the reason that ceramic capacitors are more favorable than electrolytic capacitors for bypassing. They allow easy flow of charge when needed due to negligible internal inductance.

How to Select Value of Bypass Capacitor?

Now we know why and when we need to use bypass capacitors, but we still need to find out the appropriate value of the capacitor to use for a particular device. The typical values considered for bypass capacitors are 0.1 µF and 1 µF. The higher the frequency, the smaller the value; while the lower the frequency, the large the value.

f = frac{1}{2t_R}

where tR = rise time.

The most important parameter to select an appropriate bypass capacitor is its ability to supply instantaneous current when it is needed. In order to select the capacitor size for a particular device, we have the following methods:

1. Firstly, the bypass capacitor size can be calculated using the following equation:

C = frac{I*N* Delta t}{Delta V}

I = amount of current needed to switch one output from low to high

N = switching number of outputs

∆t = time required to charge the line by the capacitor

∆V = tolerated drop in VCC

The values given in the formula should be known, where ∆t and ∆V can be assumed.

2. Another way to find out the bypass capacitor size is by calculating its maximum current with the specified maximum pulse slew rate. Maximum pulse slew rate is specified by several capacitor manufacturers.

I = Cfrac{dV}{dt}

How to Use Bypass Capacitors?

The bypass capacitor value depends on the noise frequency of the supply that requires filtering. Therefore, a typical bypass capacitor of 0.01 µF or 0.1 µF is connected for high frequency supply noise and low current applications as shown in figure below:

bypass-capacitor-for-low-current-and-high-frequency-application

Bypass capacitor for low current and high frequency application

However, power supply lines may have multiple frequencies in some applications where a single bypass capacitor is not sufficient. Thus, a network of bypass capacitors is used to filter the noise of wider range of frequencies. An example is given in the circuit below where capacitor C2 filters mid range frequencies, C3 filters higher frequencies and C4 filters low frequencies.

bypass-capacitor-network-for-filtering-multiple-frequencies

Bypass capacitor network for filtering multiple frequencies

It is also important to know that the bypass capacitors should be connected closer to the power supply pins because longer traces on printed circuit boards will increase the inductance and lower the frequency of the bypass track.

Example of a Bypass Capacitor Application

It is simple and easy to use a bypass capacitor in a circuit without changing the connections of other circuit components. A bypass capacitor is simply placed between power source (VCC) and ground of each active device, as shown in figure below:

bypass-capacitor-connected-in-a-circuit

Bypass Capacitor connected in a Circuit

In the given circuit, the bypass capacitor is responsible for holding the emitter voltage steady and maintaining voltage gain. For the transistor connected in the above given circuit, iC increases as iB rises, increasing the emitter voltage. This decreases VBE that decreases iC resisting the rise in emitter voltage. Here the bypass capacitor is connected to shunt the signal occurring at the emitter through to the ground.

Library untuk WAU8822 pada Nuvoton LB-140

Berikut contoh library untuk WAU8822 pada Nuvoton LB-140

Penggunaan:

#include "NUC100Series.h"
    void main (void){
    SYS_UnlockReg(); // Unlock protected registers
    CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk | CLK_PWRCON_OSC10K_EN_Msk ); // Enable HXT external 12MHz cyrstal
    CLK_SetCoreClock(50000000);    //  Set HCLK frequency 50MHz
    SYS_LockReg(); // Lock protected registers

    //I2C - I2S WAU8822 codec
    WAU8822_Config();

    GPIO_SetMode(PE, BIT14, GPIO_PMD_OUTPUT);
    PE14=0;  //PHone OUT Enable (NUC-LB-140)

#ifdef POOLING
    //open I2S function
    //st.u32SampleRate     = 16000;
    //st.u8WordWidth       = I2S_DATABIT_16;
    //st.u8AudioFormat     = I2S_STEREO;
    //st.u8DataFormat      = I2S_FORMAT_I2S;
    //st.u8Mode            = I2S_MODE_SLAVE;
    //st.u8TxFIFOThreshold = I2S_FIFO_TX_LEVEL_WORD_0;
    //st.u8RxFIFOThreshold = I2S_FIFO_RX_LEVEL_WORD_8;//SMP_ONE
    I2S_Open(I2S,I2S_MODE_MASTER,32000,I2S_DATABIT_16,I2S_STEREO,I2S_FORMAT_I2S);

    // Set MCLK and enable MCLK
    I2S_EnableMCLK(I2S,6000000);

    while(1)
    {
            if((I2S->STATUS & I2S_STATUS_TXFULL_Msk) == 0)
            {
               //write your code here
            }
    }
#else   //interrupt

    //interrupt
    I2S_Open(I2S,I2S_MODE_SLAVE,32000,I2S_DATABIT_16,I2S_STEREO,I2S_FORMAT_I2S);
    I2S_EnableMCLK(I2S,12000000);

    I2S_EnableInt(I2S,I2S_IE_RXTHIE_Msk );
    NVIC_EnableIRQ(I2S_IRQn);
    
    while(1){}
#endif
}

void I2S_IRQHandler(void)
{
    /* Fill sin samples to I2S until Tx FIFO full */
    while((I2S->STATUS & I2S_STATUS_TXFULL_Msk) == 0)
    {
         //write your interrupt code here
    }
}

wau8822n.h

 #ifndef WAU8822N_H
 #define WAU8822N_H

#include "NUC100Series.h"
 #include "gpio.h"

#define WAU8822_INIT_MASTER 0x1
 #define WAU8822_INIT_SLAVE 0x2
 #define WAU8822_INIT_IN_LINE_L 0x4
 #define WAU8822_INIT_IN_LINE_R 0x8
 #define WAU8822_INIT_IN_MIC_L 0x10
 #define WAU8822_INIT_IN_MIC_R 0x20
 #define WAU8822_INIT_IN_AUX_L 0x40
 #define WAU8822_INIT_IN_AUX_R 0x80
 #define WAU8822_INIT_OUT_HP_L 0x100
 #define WAU8822_INIT_OUT_HP_R 0x200
 #define WAU8822_INIT_OUT_AUX1 0x400
 #define WAU8822_INIT_OUT_AUX2 0x800

#define WAU8822_INIT_SR8000 0x1000
 #define WAU8822_INIT_SR12000 0x2000
 #define WAU8822_INIT_SR16000 0x4000
 #define WAU8822_INIT_SR24000 0x8000
 #define WAU8822_INIT_SR32000 0x10000
 #define WAU8822_INIT_SR48000 0x20000

void I2C_WriteWAU8822(uint8_t regAddr, uint16_t u16data);
 void WAU8822_Init(uint32_t u32Option);
 void WAU8822_Config(void);

#endif

wau8822n.c

#include "wau8822n.h"

void I2C_WriteWAU8822(uint8_t regAddr, uint16_t u16data)
{
    I2C_START(I2C0);                            //Start
    I2C_WAIT_READY(I2C0);                        //Wait action completed

    I2C_SET_DATA(I2C0,  0x34);                    //set WAU8822 I2C address
    I2C_SET_CONTROL_REG(I2C0, I2C_I2CON_SI);     //Set SI (transfer data)
    I2C_WAIT_READY(I2C0);                        //Wait action completed

    I2C_SET_DATA(I2C0, (uint8_t)((regAddr << 1) | (u16data >> 8)));  //set I2Cdata w/  reg address shifted << 1, + data bit 8
    I2C_SET_CONTROL_REG(I2C0, I2C_I2CON_SI | I2C_I2CON_AA);          //Set SI and AA (transfer data with Acknowledge)
    I2C_WAIT_READY(I2C0);                        //Wait action completed

    I2C_SET_DATA(I2C0, (uint8_t)(u16data & 0x00FF) );                //set I2Cdata w/ data bit 7:0
    I2C_SET_CONTROL_REG(I2C0, I2C_I2CON_SI | I2C_I2CON_AA);         //Set SI and AA (transfer data with Acknowledge)
    I2C_WAIT_READY(I2C0);                        //Wait action completed

    I2C_STOP(I2C0);                                //Stop

}


void WAU8822_Init(uint32_t u32Option)
{
    uint32_t u32Reg;

    I2C_WriteWAU8822(0, 0x000);//Reset

    u32Reg = 0x00B;
    if(u32Option & WAU8822_INIT_MASTER)
        u32Reg |= 0x020; // Enable PLL in Master mode
    if(u32Option & WAU8822_INIT_OUT_AUX1)
        u32Reg |= 0x084; // For AUX1 Output
    if(u32Option & WAU8822_INIT_OUT_AUX2)
        u32Reg |= 0x044; // For AUX2 Output
    if(u32Option & (WAU8822_INIT_IN_MIC_L | WAU8822_INIT_IN_MIC_R))
        u32Reg |= 0x010; // For MIC Bias output
    I2C_WriteWAU8822(1, u32Reg);

    u32Reg = 0;
    if(u32Option & WAU8822_INIT_OUT_HP_L)
        u32Reg |= 0x080; // Enable Headphone Left output
    if(u32Option & WAU8822_INIT_OUT_HP_R)
        u32Reg |= 0x100; // Enable Headphone Right output
    if(u32Option & (WAU8822_INIT_IN_LINE_L | WAU8822_INIT_IN_MIC_L | WAU8822_INIT_IN_AUX_L))
        u32Reg |= 0x011; // Enable LADC Mix/Boost & Left ADC
    if(u32Option & (WAU8822_INIT_IN_LINE_R | WAU8822_INIT_IN_MIC_R | WAU8822_INIT_IN_AUX_R))
        u32Reg |= 0x022; // Enable RADC Mix/Boost & Right ADC
    if(u32Option & WAU8822_INIT_IN_MIC_L)
        u32Reg |= 0x004; // Enable Left PGA
    if(u32Option & WAU8822_INIT_IN_MIC_R)
        u32Reg |= 0x008; // Enable Right PGA
    I2C_WriteWAU8822(2, u32Reg);

    u32Reg = 0;
    if(u32Option & WAU8822_INIT_OUT_AUX1)
        u32Reg |= 0x102; // Enable AUX1 & RDAC
    if(u32Option & WAU8822_INIT_OUT_AUX2)
        u32Reg |= 0x081; // Enable AUX2 & LDAC
    if(u32Option & WAU8822_INIT_OUT_HP_L)
        u32Reg |= 0x005; // Eanble LMIX & LDAC
    if(u32Option & WAU8822_INIT_OUT_HP_R)
        u32Reg |= 0x00A; // Eanble RMIX & RDAC
    I2C_WriteWAU8822(3, u32Reg);

    I2C_WriteWAU8822(4,  0x010);// I2S 16-bit format

    I2C_WriteWAU8822(10,  0x000);

    I2C_WriteWAU8822(5,  0x000);//R5 companding ctrl and loop back mode (all disable)

    if(u32Option & WAU8822_INIT_MASTER)
    {
        // Codec works as an Master

        // MCLK = 6MHz
        I2C_WriteWAU8822(36, 0x008);
        I2C_WriteWAU8822(37, 0x00C);
        I2C_WriteWAU8822(38, 0x093);
        I2C_WriteWAU8822(39, 0x0E9);
        if(u32Option & WAU8822_INIT_SR8000)
        {
            I2C_WriteWAU8822(6 , 0x1AD);
            I2C_WriteWAU8822(7 , 0x00A);
        }
        else if(u32Option & WAU8822_INIT_SR12000)
        {
            I2C_WriteWAU8822(6 , 0x18D);
            I2C_WriteWAU8822(7 , 0x008);
        }
        else if(u32Option & WAU8822_INIT_SR16000)
        {
            I2C_WriteWAU8822(6 , 0x16D);
            I2C_WriteWAU8822(7 , 0x006);
        }
        else if(u32Option & WAU8822_INIT_SR24000)
        {
            I2C_WriteWAU8822(6 , 0x14D);
            I2C_WriteWAU8822(7 , 0x004);
        }
        else if(u32Option & WAU8822_INIT_SR32000)
        {
            I2C_WriteWAU8822(6 , 0x12D);
            I2C_WriteWAU8822(7 , 0x002);
        }
        else if(u32Option & WAU8822_INIT_SR48000)
        {
            I2C_WriteWAU8822(6 , 0x10D);
            I2C_WriteWAU8822(7 , 0x000);
        }
    }
    else
    {
        I2C_WriteWAU8822(6 , 0x000);
        if(u32Option & WAU8822_INIT_SR8000)
        {
            I2C_WriteWAU8822(7 , 0x00A);
        }
        else if(u32Option & WAU8822_INIT_SR16000)
        {
            I2C_WriteWAU8822(7 , 0x006);
        }
        else if(u32Option & WAU8822_INIT_SR24000)
        {
            I2C_WriteWAU8822(7 , 0x004);
        }
        else if(u32Option & WAU8822_INIT_SR32000)
        {
            I2C_WriteWAU8822(7 , 0x002);
        }
        else if(u32Option & WAU8822_INIT_SR48000)
        {
            I2C_WriteWAU8822(7 , 0x000);
        }
    }

    I2C_WriteWAU8822(8 , 0x034);

    I2C_WriteWAU8822(59, 0x000);
    I2C_WriteWAU8822(60, 0x020);
    I2C_WriteWAU8822(61, 0x000);

    I2C_WriteWAU8822(10, 0x009);//R10 DAC control (softmute disable, oversample select 128x)
    I2C_WriteWAU8822(43, 0x020);//speaker mute

    u32Reg = 0;
    if(u32Option & WAU8822_INIT_IN_MIC_L)
        u32Reg |= 0x003; // Connect LMICP, LMICN to LPGA
    if(u32Option & WAU8822_INIT_IN_MIC_R)
        u32Reg |= 0x030; // Connect RMICP, RMICN to RPGA
    I2C_WriteWAU8822(44, u32Reg);

//
// MIC input gain control
//
    u32Reg = 0;
    if(u32Option & WAU8822_INIT_IN_MIC_L)
        I2C_WriteWAU8822(45, 0x110); // MIC LPGA Gain 0dB
    else
        I2C_WriteWAU8822(45, 0x140); // MIC LPGA Mute

    u32Reg = 0;
    if(u32Option & WAU8822_INIT_IN_MIC_R)
        I2C_WriteWAU8822(46, 0x110); // MIC RPGA Gain 0dB
    else
        I2C_WriteWAU8822(46, 0x140); // MIC RPGA Mute

//
// Line In gain control
//
    u32Reg = 0;
    if(u32Option & WAU8822_INIT_IN_LINE_L)
        u32Reg |= 0x050; // LINE LPGA Gain 0dB
    if(u32Option & WAU8822_INIT_IN_AUX_L)
        u32Reg |= 0x005; // AUX LPGA Gain 0dB
    I2C_WriteWAU8822(47, u32Reg);

    u32Reg = 0;
    if(u32Option & WAU8822_INIT_IN_LINE_R)
        u32Reg |= 0x050; // LINE RPGA Gain 0dB
    if(u32Option & WAU8822_INIT_IN_AUX_R)
        u32Reg |= 0x005; // AUX RPGA Gain 0dB
    I2C_WriteWAU8822(48, u32Reg);


    I2C_WriteWAU8822(49, 0x01E);

    I2C_WriteWAU8822(50, 0x001);//R50 DACL2LMIX
    I2C_WriteWAU8822(51, 0x001);//R51 DACR2RMIX

//
// For Headphone Output
//

     // Left headphone volume/mute control
    if(u32Option & WAU8822_INIT_OUT_HP_L)
        I2C_WriteWAU8822(52, 0x039);
    else
        I2C_WriteWAU8822(52, 0x079);

     // Right headphone volume/mute control
    if(u32Option & WAU8822_INIT_OUT_HP_R)
        I2C_WriteWAU8822(53, 0x139);
    else
        I2C_WriteWAU8822(53, 0x179);

//
// For AUX output
//
    if(u32Option & WAU8822_INIT_OUT_AUX2)
        I2C_WriteWAU8822(56, 0x001); // LDAC to AUX2
    else
        I2C_WriteWAU8822(56, 0x040); // AUX2 Mute

    if(u32Option & WAU8822_INIT_OUT_AUX1)
        I2C_WriteWAU8822(57, 0x001); // RDAC to AUX1
    else
        I2C_WriteWAU8822(57, 0x040);// AUX1 Mute

    I2C_WriteWAU8822(11, 0x0FF); // LDAC Volume
    I2C_WriteWAU8822(12, 0x1FF); // RDAC Volume

    I2C_WriteWAU8822(54, 0x040);
    I2C_WriteWAU8822(55, 0x140);

    // high pass eanble
    I2C_WriteWAU8822(14, 0x180);

    /* Disable EQ and 3D */
    I2C_WriteWAU8822(41, 0x000); // No 3D
    I2C_WriteWAU8822(18, 0x02C);
    I2C_WriteWAU8822(19, 0x02C);
    I2C_WriteWAU8822(20, 0x02C);
    I2C_WriteWAU8822(21, 0x02C);
    I2C_WriteWAU8822(22, 0x02C);

}


void WAU8822_Config(void)
{
    //Set I2C0 source Clock to default with no Divider
     CLK_SetModuleClock(I2C0_MODULE, 0, 0);
     //Enable I2C0
     CLK_EnableModuleClock(I2C0_MODULE);
    // Set I2C I/O
    SYS->GPA_MFP |= SYS_GPA_MFP_PA8_I2C0_SDA;
    SYS->GPA_MFP |= SYS_GPA_MFP_PA9_I2C0_SCL;
     // Open I2C0, and set clock = 100Kbps
    I2C_Open(I2C0, 100000);
    // Enable I2C0 interrupt and set corresponding NVIC bit
    I2C_EnableInt(I2C0);


    // Setup wau8822 codec - I2C
    //WAU8822_Setup();
    WAU8822_Init(WAU8822_INIT_MASTER | WAU8822_INIT_SR32000
            | WAU8822_INIT_OUT_HP_L | WAU8822_INIT_OUT_HP_R
            //| WAU8822_INIT_IN_MIC_L
            | WAU8822_INIT_IN_AUX_L | WAU8822_INIT_IN_AUX_R
                );

    CLK_SetModuleClock(I2S_MODULE,CLK_CLKSEL2_I2S_S_HXT,0);
    CLK_EnableModuleClock(I2S_MODULE);

    SYS->GPA_MFP = SYS_GPA_MFP_PA15_I2S_MCLK;
    SYS->GPC_MFP = SYS_GPC_MFP_PC0_I2S_LRCLK | SYS_GPC_MFP_PC1_I2S_BCLK | SYS_GPC_MFP_PC2_I2S_DI | SYS_GPC_MFP_PC3_I2S_DO;
    SYS->ALT_MFP = SYS_ALT_MFP_PA15_I2S_MCLK | SYS_ALT_MFP_PC0_I2S_LRCLK | SYS_ALT_MFP_PC1_I2S_BCLK | SYS_ALT_MFP_PC2_I2S_DI | SYS_ALT_MFP_PC3_I2S_DO;

    // Tri-state for FS and BCLK of CODEC
    GPIO_SetMode(PC, BIT0,  GPIO_PMD_OPEN_DRAIN);PC0 = 1;
    GPIO_SetMode(PC, BIT1, GPIO_PMD_OPEN_DRAIN);PC1 = 1;

}

portinit.h

#ifndef _INITIALIZATION_H
#define _INITIALIZATION_H

enum {GPIOPIN,
    ADC0PIN, ADC1PIN, ADC2PIN, ADC3PIN, ADC4PIN, ADC5PIN, ADC6PIN, ADC7PIN,
    SPI0PORT, SPI1PORT, SPI2PORT, SPI3PORT};

extern void Port_Init(uint32_t pinName);
#endif

PortInitNUC140.c

#include <stdio.h>
#include "NUC100Series.h"
#include "portinit.h"

extern void Port_Init(uint32_t pinName){
    switch(pinName){
    case ADC7PIN:
            // Configure the GPA7 ADC analog input pins
            SYS->GPA_MFP &= ~(SYS_GPA_MFP_PA7_Msk);
            SYS->GPA_MFP |= SYS_GPA_MFP_PA7_ADC7;
            // Disable the GPA7 digital input path to avoid the leakage current.
            GPIO_DISABLE_DIGITAL_PATH(PA, SYS_GPA_MFP_PA7_Msk);
            break;
    case SPI1PORT:
        SYS->GPC_MFP &= ~(SYS_GPC_MFP_PC8_Msk | SYS_GPC_MFP_PC9_Msk | SYS_GPC_MFP_PC10_Msk | SYS_GPC_MFP_PC11_Msk);
        SYS->GPC_MFP |=  (SYS_GPC_MFP_PC8_SPI1_SS0 | SYS_GPC_MFP_PC9_SPI1_CLK | SYS_GPC_MFP_PC10_SPI1_MISO0 | SYS_GPC_MFP_PC11_SPI1_MOSI0);
        break;
    case SPI2PORT:
        // Setup SPI3 multi-function pins
        SYS->GPD_MFP = (SYS->GPD_MFP & ~(SYS_GPD_MFP_PD0_Msk | SYS_GPD_MFP_PD1_Msk | SYS_GPD_MFP_PD2_Msk | SYS_GPD_MFP_PD3_Msk)) |
                       (SYS_GPD_MFP_PD0_SPI2_SS0 | SYS_GPD_MFP_PD1_SPI2_CLK | SYS_GPD_MFP_PD2_SPI2_MISO0 | SYS_GPD_MFP_PD3_SPI2_MOSI0);
        break;
    case SPI3PORT:
        // Setup SPI3 multi-function pins
        SYS->GPD_MFP = (SYS->GPD_MFP & ~(SYS_GPD_MFP_PD8_Msk | SYS_GPD_MFP_PD9_Msk | SYS_GPD_MFP_PD10_Msk | SYS_GPD_MFP_PD11_Msk)) |
                       (SYS_GPD_MFP_PD8_SPI3_SS0 | SYS_GPD_MFP_PD9_SPI3_CLK | SYS_GPD_MFP_PD10_SPI3_MISO0 | SYS_GPD_MFP_PD11_SPI3_MOSI0);
        break;


    default:
        break;
    }
}

 

SetUp ESP8266 as AP, WebServer

BAUD RATE 115200
AT

AT+UART_DEF=9600,8,1,0,0 //(CHANGE TO 9600)
AT+CWMODE=2 //AP MODE
AT+CWSAP?    //CEK SSID

AT+CWSAP=”AsepRemote”,””,1,0 //Set SSID
AT+CWDHCP=0,1 //set dhcp

AT+CIPAPMAC=”2c:aa:35:97:d4:7b” //set mac AP

AT+CIPAP? //cek ip
AT+CIPAP=”192.168.4.1″

AT+CIPMUX=1 //Enable multiple connections

AT+CIFSR //cek local ip

AT+CIPSERVER=1,80 //start server

Connection request is here, take a look at id (e.g: +IPD, 0)  –> 0 will be the connection id

AT+CIPSEND=0,40  //0 is the id and 40 is char length

<html><head></head><body>Hello from ESP8266 </body></html>

AT+CIPCLOSE=0  //0 is the ID

 

Arduino Code Example:

 

Another arduino Code Example:

sources: &nbsp
http://allaboutee.com/2015/01/20/esp8266-android-application-for-arduino-pin-control/ &nbsp
https://github.com/espressif/ESP8266_AT/wiki

Routing PCB dengan CNC (YOOCNC 3020ZD)

Buka File Layout

Buka file skema (.sch) dan juga board (.brd) dengan Eagle. Arahkan pada tampilan Board.
disarankan untuk mengubah latar belakang menjadi hitam dengan cara pilih menu

Option --> User Interface --> Pilih pada Layout--> Background --> Black.

Cek posisi dan kesalahan layout dengan DRC

Cek desain dengan DRC, pada menu tool –> DRC lalu isikan parameter jika diperlukan.

Penting: Untuk penggunaan VBit ukuran ujung 0.5 mm maka isikan di bagian clearance 20mil. untuk ujung 0.2 mm maka isikan di bagian clearance 10 mil. Jika sudah memunyai simpanan seting DRC, tinggal di-Load aja. Berikut contohnya: File DRC Yoo CNC

Klik tombol Check dan jika ada Error atau Warning akan muncul di bagian kanan bawah. Benahi  dahulu error! Jika yakin tidak ada masalah, maka dapat di klik tombol Clear All atau langsung ditutup.

Buat kode GCode dengan PCB GCode

Klik tombol dengan tulisan ULP (di bagian atas, di bawah menu library). Pilih file PCB-Gcode-Setup.ulp lalu buka setingan default pada menu tab GCode Style.

Penting: harus memilih software yang digunakan untuk CNC terlebih dahulu sebelum mengisi parameter. Jika memilihnya setelah mengisi parameter, maka isian parameter akan ter-reset!

Pada tab Generation Option: (pilih GCode yang akan dibuat, centang yang dipilih)
——————

cnc-t1

  • Top Side: Layer atas
  • Outline: Guratan
  • Drill: Lubang
  • Bottom Side: Layer Bawah
  • Outline: Guratan
  • Drill: Lubang
  • Mirror: dibalik (gunakan fitur ini untuk YOOCNC, karena koordinat x+ dan x- mesin terbalik)
  • Show preview: tampilkan preview, isikan sesuai ukuran PCB
  • Generate milling: -1.27mm / sesuaikan dengan tebal PCB (pilihan ini untuk membuat GCOde milling/bentuk PCB sesuai layer 46. Tandai centang jika diperlukan)
  • Generate text: -0.127mm (pilihan untuk membuat GCOde guratan text yang ada pada layer 46. Tandai centang jika diperlukan)
  • Spot drill hole: -0.05mm (Tandai lubang pada PCB.  Gunakan jika akan dibor secara manual untuk memudahkan pengeboran. Jika dibor dengan CNC, tidak perlu ditandai, hilangkan tanda centang)
  • Isolation: centang single pass jika ingin sekali guratan saja. (Gunakan fasilitas singgle pass  ini untuk mengecek preview guratan)
  • Minimum: 0.005mm (isikan jarak guratan terdekat dengan jalur PCB)
  • Maximum: 0.5mm (Isikan dengan ukuran ujung bor/bits)
  • Stepsize: 0.127mm (isikan jarak antar guratan pertama dengan guratan selanjutnya)
  • Etching tool size: 0.20 (idealnya adalah ukuran ujung bor/bits, namun biarkan ke angka default)

Machine:
——–

cnc-t2

  • Unit: Milimeter
  • Spin Up Time: 1 detik (Jeda waktu untuk spindle/bor berputar)
  • Feed rates:
    •     X Y: 500 mm/menit (kecepatan pindah spindle arah XY)
    •     Z: 180 mm/menit (kecepatan pindah spindle arah Z; mengebor)

Sesuaikan feed rates XY dengan kemampuan mesin. Lihat di Config -> Motor Tuning and Setup pada Mach3 dan cari bagian Velocity. Bagi nilai Velocity dengan 3 atau 4.Sesuaikan feed rates Z dengan ketajaman bor, semakin tumpul harus semakin kecil serta tidak melebihi kecepatan Motor Tuning)

  • Misc:
    • Epsilon: 0.00254 mm (jarak terdekat perpindahan spindle yang ditolelir. Sumbu X,Y maupun Z)
    • DDRF: biarkan kosong, kecuali jika CNC mampu mengganti bor otomatis
  • Z Axis:
    • Z High: 12 mm (Jarah terjauh/tertinggi bor ke PCB untuk istirahat)
    • Z Up: 2 mm (Jarak bor ke PCB saat pindah dari satu tempat ke tempat lain)
    • Z Down: -0.05 mm (kedalaman miling/guratan PCB, sesuaikan dengan ketebalan lapisan tembaga pada PCB)
    • Drill Depth: -2 mm (sesuaikan dengan tebal PCB + 0.5 mm untuk kalibrasi posisi mata bor saat  pengeboran)
    • Drill Dwell: 0.5 detik (Lamanya proses pengeboran)
  • Tool Change: (posisi spindle saat mengganti bor)
    • Position X: 0 mm
    • Position Y: 0 mm
    • Position Z: 21 mm (sesuaikan dengan panjang colet/dudukan mata bor)
  • GCOde Option, Plugins dan Other: Untuk sementara, biarkan default

Jika parameter sudah diisi semua, maka tekan tombol Accept and make my board. Jendela preview akan muncul.

contohko1

Cek kondisi preview milling/guratan. Jika ada yang tidak tergurat. Ganti/geser letak jalur atau ganti jalu yang ukuranya lebih kecil. Ukuran jalur terkecil yang diperkenankan adalah 0.6mm (25 mil)

Modifikasi file GCode untuk proses autolevelling

Autoleveling adalah menentukan ketinggian/ketebalan PCB dengan bantuan probe pada mesin CNC pada port 15 menggunakan Software Autoleveling.

Buka software Autoleveler (software ini memerlukan java) lalu pilih mesin Mach3 (Sebelah tombol About). Klik tombol Browse for Gcode dan arahkan ke file hasil pengubahan ke GCode. File ditandai dengan akhiran .bot.etch.tap untuk layer bawah dan akhiran .top.etch.tap untuk layer atas.

autolevel

Secara otomatis bagian Probe setting akan terisi. Jika ingin dimodifikasi:

  • Z Feed: 100 mm/menit (kecepatan probing, semakin kecil semakin presisi. Jangan melebihi Z feed Rate pada PCB-GCode)
  • Probe Depth: -0.1 mm (Jika PCB tidak berhasil di-probe, maka secara otomatis dianggab PCB berada di 0.1 mm dibawah mata bor)
  • Probe clearance: 2.5 mm (Mata bor akan berpindah antar titik probe dengan ketinggian 2 mm. Isikan sesuai rumus: Z UP pada PCB-GCode + Probe Depth pada autoleveler Misal: 3mm + (-0.5)mm = 2.5 mm )
  • Probe Spacing: 25 mm (Jarak antar probe. Karena ukuran PCB 100mm x 100mm maka diganti menjadi 20mm agar hasilnya: 100*100 / 25*25 = 16 kali probe saja)
  • Z Safe Heigh: 20 mm (Jarak probe terjauh ke atas untuk berhenti)

Setelah parameter diisikan, klik tombol  CreateLevelledGCode lalu disimpan. file siap dibuka di Mach3.

Modifikasi file GCode drill.tap agar ada waktu untuk mengganti mata bor

Buka file .bot.drill.tap dan ganti perintah: G01 Z0.0000  F254 menjadi M00 (ganti perintah pindah ke posisi Z=0 mm mjd perintah stop). Maksud penggantian kode yaitu agar saat pergantian bor (setelah perintah M06) maka mesin akan berhenti. Saat mesin berhenti, bor dapat diganti sesuai dengan ukuran yang ditunjukkan di GCode setelah tanda ; (titik koma) dalam satuan milimeter.

Nilai F254 mungkin berbeda, karena bergantung dari nilai Feed Rate yang diisikan di PCB Gcode

Pengoperasian Mesin:

Pasang PCB sesuai gambar berikut:

YooCNC - Latiful Hayat
Pastikan PCB tidak menggelembung. Alasi PCB dengan papan yang rata, atau PCB yang sudah tidak terpakai.
Buka Mach3 lalu klik pada tombol SoftLimit hingga border hijau hilang. Ingat Mach3 harus dibuka dahulu sebelung mengaktifkan mesin CNC, agar CNC tidak bergerak sendiri / mengunci jika terjadi error pada port
komputer.

Aktifkan mesin CNC lalu tekan tombol Reset (biasanya berkedip jika belum ditekan) hingga border berwarna hijau.

Arahkan dahulu spindle/bor ke arah atas dengan tombol Page Up agar spindel tidak menabrak PCB. Geser CNC menggunakan tombol tanda panah kiri (<–) atau kanan (–>) untuk mengggerakkan
spindle, serta atur letak PCB agar tidak miring. Awas: YOOCNC memiliki arah X+  dan x- terbalik, maka
hati hati dalam menggerakkan spindle.

Taruh mata bor/bit tepat diatas koordinat titik nol yang dikehendaki sekitar 2 s.d 3 mm, jangan
terlalu dekat dengan PCB. Ada kalanya PCB tidak rata. Lalu gerakkan bor ke semua arah PCB. Jika terlalu mepet dengan PCB, gerakkan ke atas dengan tombol Page Up pada keyboard. Jika terlalu jauh dari PCB, gerakkan ke  arah bawah dengan tombol Page Down. Awas: Hati-hati saat menggerakkan  spindle ke bawah, jika bits/mata bor terkena PCB maka bisa patah, atau PCB berlubang!

Jika sudah siap, mata bor ditaruh di atas PCB dengan tepat pada titik nol yang diinginkan, maka tekan tombol REF ALL HOME pada Mach3. Putar spindle lalu lubangi sedikit untuk titik 0 dengan cara menekan tombol page down pada keyboard. Lubang nantinya dijadikan tanda untuk titik nol pada saat pengboran.

Cek setingan port pada menu tool, pastikan pada port 15 dan active low dicentang. Lihat kondisi probe pada Tab diagnostic. Pastikan saat probe dihubungkan kedua kutubnya, maka bagian Digitize akan berwarna Hijau.

Pasang kutub probe pada spindle, tapi jangan diaktifkan dahulu spindelnya. Pasang kutub yang lain pada PCB. Penting: Pastikan penjepit probe menjepit kuat agar tidak lepas. Kalau sampai lepas, maka bit akan patah, PCB berlubang dan bahkan dasar mesin CNC juga berlubang!

Load file GCode hasil Autoleveler. Lanjutkan dengan pindah spindle menyusuri PCB sesuai pada gambar toolPath, dan pastikan semua area toolpath terkover di PCB (Ukuran PCB tidak kurang) serta tidak menabrak penjepit PCB.

Kembalikan ke titik 0 dengan menekan tombol GOTO Z (Goto Zero). Klik Run dan biarkan CNC
bekerja sambil diamati! Wajib: Sambil diamati! Bila probe atau bits/mata bor menabarak
sesuatu, langsung ditekan tombol EMERGENCY STOP agar CNC tidak rusak lalu ulangi lagi langkah
dari awal.

Saat selesai probing, maka CNC akan berhenti. Ambil probe, jaga jangan sampai terhubung antar
probe dan aktifkan spindle dengan kecepatan maksimum. Saat sudah sampai ke kecepatan maksimum,
tekan Run di Mach3 lagi. (Sekali lagi, wajib: Sambil diamati! Bila probe atau bits/mata bor menabarak sesuatu, langsung tekan tombol EMERGENCY STOP agar CNC tidak rusak lalu ulangi lagi langkah dari awal)

Setelah selesai, biasakan untuk mengembalikan posisi spindle ke home, atau titik nol. Gunakan
fasilitas tombol Goto Z pada Mach3.

Proses pengeboran

Pindah spindle ke atas dengan tombol keyboard Page Up secukupnya, lalu ganti bor dengan ukuran terkecil. Setelah diganti, turunkan mata bor sedikit demi sedikit hingga kurang lebih 1mm jangan terlalu dekat dengan PCB. Lalu tekan REF ALL Home. Lalu gerakkan bor ke semua arah PCB.

Jika terlalu mepet dengan PCB, gerakkan ke atas dengan tombol Page UP. Catat perubahan Z lalu
kembali he home dengan tombol Goto Z lalu naikkan dengan tombol Page Up hingga nilai Z sesuai
pada catatan dan klik REF ALL Home.

Awas: Hati-hati saat menggerakkan spindle ke bawah, jika bits/mata bor terkena PCB maka bisa patah, atau PCB berlubang!

Usahakan jarak terjauh antar PCB dengan mata bor di seluruh permukaan PCM maksimal adalah 0.5 mm
(Sesuai dengan perhitungan Drill Depth pada PCB-GCode). Ulangi langkah pemindahan mata bor ke
seluruh PCB hingga tidah ada PCB yang terlalu mepet pada mata bor.

Jika semua OK maka kembali ke home dengan tekan GOTO Z.

jika home tidak pas pada lubang titik 0 yang tadi ditandai saat miling, maka paskan dengan
menekan tombol panah, namun jangan mengubah ketinggian mata bor. Jika sudah pas, maka tekan
REF ALL Home. Catatan: Jika ternyata spindle berubah ketinggian, atau terpencel tombol page up atau
page down, maka kembalikan ke titik 0 dengan Goto Z.

Tutupi PCB dengan kertas transparan (mika) agar debu pengeboran tidak tercecer! Buka file GCode drill.bot.tap dan kemudian Run (Klik cycle Start) dan biarkan CNC bekerja. (Wajib: Saat CNC bekerja, haris diamati! Bila bits/mata bor menabarak sesuatu, langsung tekan tombol EMERGENCY STOP agar CNC tidak rusak lalu ulangi lagi langkah dari awal)

Proses Penggantian mata bor

Saat GCode sampai pada kode M00, maka proses pengeboran berhenti. Matikan dahulu spindle lalu ganti mata bor sesuai ukuran yang ditunjukkan pada GCode. Jangan sampai posisi berubah dan CNC jangan dimatikan, cukup matikan putaran spindle saja.

AWAS: Mata bor mudah patah, jatuh dari atas meja saja sudah patah!

 

What do you have to know about MAX232

Max232 is designed by Maxim Integrated Products. This IC is widely used in RS232 Communication systems in which the conversion of voltage level is required to make TTL devices to be compatible with PC serial port and vice versa. This chip contains charge pumps which pumps the voltage to the Desired Level. It can be powered by a single +5 volt power supply and its output can reach +_7.5 volts.MAX232 comes in 16 Pin Dip and many other packages and it contains Dual Drivers. It can be used as a hardware layer convertor for 2 systems to communicate simultaneously.Max232 is one of the versatile IC to use in most of the signal voltage level conversion problems.

Construction of MAX232:

Mostly MAX232 used in 16-pin DIP package. it consist of 3 major blocks .It can only be powered by 5 volts to make it power supply compatible with most of the embedded systems. First block is the voltage doubler in this ic switched capacitor techniques is used to make the voltage double .Once the voltage is doubled second block will converts that voltage to +10 and -10. The third block consists of 2 transmitters and 2 receivers which actually convert the voltage levels.

External components:

Max232 requires minimum 4 external capacitor. Their Value can range from 1uf to 10uf and16 volts or more rating. There are many different versions of this versatile ic available each of them Require different capacitor value for proper working.

Application and uses of MAX232:

Premierly MAX232 is used in Serial communication. Problem arises when we have to communicate between TTL logic and CMOS logic based systems. RS232 is internationally defined standard named as EIA/TIA-232-E and in this standard logic 0 is the voltage between +3 to +15 and logic 1 is defined as the voltage between -3 to -15.In TTL logic 0 is defined is by 0 volt and 1 is defined by 5 volt so in this scenario this is a very handy IC to be incorporated.

Other Applications & Uses

  • Battery Powered RS 232 Systems
  • Interface Translation
  • Low Power Modems
  • RS 232 Networks (Multidrop)
  • Portable Computing

PC Serial PORT communication by using MAX232 IC:

Desktop and some old Laptops have Serial port which comes in DB9 package. In Most of the Circuits designer is concerned about the Tx and Rx pins only so the function of the rest of the pins are not used here mostly.

In the above circuit only one Driver is used and second driver can be used for other purpose. TTL data is available on pin 12 and pin 11 and these pins can be attached to Microcontroller or any system which accept TTL logic.

 

GSM Modem Communication:

 

There are many GSM modems available in the market and most of them are on TTL logic but some of them use RS232 standards and again it becomes a problem to communicate wilt GSM modem by using Micro controller, aurdino or any other TTL platform.MAX232 is used to solve this problem.

Types of MAX232:

1)“MAX232N” where “N” Represent PDIP package Style this package is easy to sold and most widely used.

2) MAX232D where “D” indicates the SOIC package which is difficult to sold and required a trained professional to be used correctly.

Common mistakes:

  • Capacitor voltage rating is less than 16.
  • Interchange Tx and Rx pins on one side of MAX232 at one time.
  • Distorted power supply. Use decoupling capacitor to remove distortion.
  • Check all the connections again.
  • Check the capacitor with capacitance meter.
  • Use Tantalum Capacitor for better performance.

Koneksi PHP & Port Serial

Koneksi php ke serialport dengan menggunakan php_dio pada sistem operasi Windows. Caranya adalah dengan menyalin file dll ke subforder ext pada folder php. Edit  file php.ini dengan menambahkan

extension = php_dio.dll (pada windows)

Hentikan (stop) server apache dan jalankan ulang.

Buat sketch arduino untuk menyalakan lampu jika serial menerima huruf w dan mematikan lampu jika serial menerima huruf s, dengan kode berikut:

void setup() {
pinMode(13,OUTPUT);
Serial.begin(9600);
}

void loop() {
if (Serial.available()) {
char inChar = (char)Serial.read();
if (inChar == 'w') {
digitalWrite(13,HIGH);
}
if (inChar == 's') {
digitalWrite(13,LOW);
}
}
}

Buat file serial.php pada forder httdoc dengan kode berikut :

<?php

//ganti com31 dengan alamat port yang digunakan
exec('mode com31: baud=9600 data=8 stop=1 parity=n xon=on');

//ganti COM31 dengan alamat port yang digunakan
$fd = dio_open('\\\\.\COM31', O_RDWR);

sleep(2);
if(isset($_GET['lampu']))
$data = dio_write($fd, $_GET['lampu']);

?>

Ganti alamat port yang digunakan untuk koneksi. Coba dengan membuka firefox atau browser lain dengan alamat http://IPKOMPUTER/serial.php?lampu=w maka lampu menyala. Jika dibuka alamat http://IPKOMPUTER/serial.php?lampu=s maka lampu mati.

Kalibrasi MPU6050

MPU6050 adalah sensor sudut dan percepatan atau biasa disebut gyrometer. Sama seperti kebanyakan sensor lain, MPU6050 perlu dikalibrasi sebelum digunakan. Kinerja gyrometer ini sangat terpengaruh terhadap suhu, jadi pastikan suhu stabil terlebih dahulu sebelum melakukan proses kalibrasi. Beri jarak waktu antara 3 sampai dengan 5 menit setelah power on agar suhu stabil. Hasil proses kalibrasi pun akan berbeda saat dilakukan di suhu ruangan dibandingkan dengan kalibrasi di luar ruangan. Pastikan dikalibrasi pada suhu ruangan yang sama, atau setidaknya hampir sama, dengan dengan suhu dimana alat akan digunakan.

Berikut kode kalibrasi dari Luis Ródenas denga sedikit modifikasi:

Pastikan sudah melakuan instalasi librari I2Cdev dan MPU6050 dan hubungkan MPU6050 dengan skema berikut

 

Taru MPU6050 pada bidang datar, semisal meja dan jangan digerakkan sampai proses kalibrasi selesai.  Selanjutnya, untuk proses kalibrasi, buka dengan serial monitor dengan baud rate 115200 dan kirimkan satu huruf (bebas) lalu tekan send atau klik tombol enter. Tunggi hingga daftar offset muncul dengan ditandai tulisan ‘Your offsets:’