The post Breaking the Hex: Understanding Hexadecimal Numbers appeared first on Circuit Crush.

]]>In it, you’ll learn why binary numbers are used in digital systems. This will help you understand why hex numbers also often appear in digital systems. You’ll also get a quick review of the decimal system (and number systems in general). Finally, you’ll learn how to read binary, which will help you understand how to translate from binary to hex.

As I said before, if you’re new to digital electronics, it’s a must read.

And if you’re not so new it’s a good review.

Let’s break the hex and learn about hexadecimal numbers!

After binary numbers, hex numbers or base 16 numbers are the most important in digital applications.

The word hexadecimal comes from the Greek root *hex* – which means six, and the Latin root *deci* – meaning ten. Hence, the word hexadecimal refers to sixteen.

Hexadecimal numbers use a base 16 system which means that the positional multipliers in the hex system are powers of 16: 16^{0} = 1, 16^{1} = 16, 16^{2} = 256 and so on. This is just like the decimal system were all familiar with, only instead of powers of 10 we’re dealing with powers of 16.

The chart below will come in handy for figuring out various powers of 16. My, how quickly they grow!

Note that MSD stands for most significant digit and LSD stands for least significant digit. Sorry for the disappointment, LSD is not a drug — at least not in this post.

*Figure 1: various powers of 16.*

The first 9 digits in the hexadecimal system are the same digits 0-9 that you’re familiar with. However, the next 6 are represent by the first few letters of the alphabet: A, B, C, D, E, and F.

The first 16 digits on the hex system are given in the chart below along with their decimal and binary equivalents.

*Figure 2: hex numbers and their decimal and binary equivalents.*

If you’re not too familiar with the hexadecimal system, the use of letters to represent numbers may seem odd at first. Keep in mind though that any number system is only a set of sequential symbols. The form of the symbols is unimportant if you understand what they mean.

Remember also, that regardless of the number system, each digit must be represented by a single symbol.

If we were to use the symbols that make the number ten in decimal (rather than A) when writing numbers in hex, it would be hard to tell whether we were referring to 10 in decimal, or 10 in hex which equals 16 in decimal.

There is also perhaps an even more important reason for this, which we’ll disclose in the next section.

Right now, it may be easy to think something like *why bother with hex numbers? Base 16 is weird and seems complicated…*

Or maybe you’ve already figured out the virtues of using hexadecimal numbers. If not, you will in a minute.

The translation from hex to binary in figure 2 suggest a very important reason hex numbers are popular.

Hexadecimal numbers are ** way** more compact than binary and more compact than decimal numbers. Hex numbers pack more information into fewer digits.

Also, binary numbers are difficult to read and write because it is easy to drop or transpose a bit.

Because of this, hexadecimal is widely used in computer and microprocessor applications.

You’ve undoubtedly been faced with a blue screen on your computer after a crash. In addition, you’ll often see a cryptic message along with some hex numbers like 0xa56b170f.

The hex numbers refer to memory locations and data. If the PC was to spit it out in binary, the whole screen would be filled with 1’s and 0’s.

The prefix 0x tells us that the number is a hex number. The programming languages C and Java use this notation, but you may also see a hex number with the prefix 0h.

Almost all computer data sizes are multiples of 4. Since base 16 is a power of 2 (like 4), converting from binary to hex and vice versa is trivial, as we’ll see in a minute.

As usual, the easiest way to convert a binary number to a hex number or vice versa is to use a calculator. However, you should be able to do it almost as fast after reading this section.

You should know all the hexadecimal numbers from 0 to F (0 to 15).

Figure 2 shows us that for every possible 4-bit binary number, there is a hex equivalent.

To convert a binary number to a hex number, simply break the binary number into 4-bit groups, starting with the LSB (right-most bit). Then replace each 4-bit group with its hexadecimal equivalent.

As you move to the left, you may notice that you have less than 4 binary digits left in the last group.

No sweat. Just pad the last group with enough leading zeros to reach 4 bits, then convert to hex.

Let’s do a couple examples to illustrate this.

__Ex.1 __

Convert 1100101001010111 to hexadecimal.

**Solution:**

First, we break the binary number into groups of 4 bits:

1100 1010 0101 0111

Next, we simply find the hex equivalents of each of the groups of 4 binary digits, starting at the left:

1100 1010 0101 0111

** | | | |**

** C A 5 7**

1100 = 12 in decimal which is C in hex. Following a similar approach, we get A for the next group, 5 for the next and finally 7 for the last group.

Now we write CA57 or 0xCA57 so we know it’s a hex number. Wham, bam, thank you ma’am.

__Ex. 2__

Convert 11100010100110 to hex.

**Solution:**

Starting from the right (LSB), we break the binary number into groups of 4 bits:

11 1000 1010 0110

Since the group on the far left only has 2 digits, we pad it with 2 zeros:

0011 1000 1010 0110

Now, we take the hex equivalent of each of the 4 groups:

0011 1000 1010 0110

** | | | |**

** 3 8 A 6**

Now, we write 0x38A6.

Note that while it’s obvious that if a string of digits contains any of the letters A through F the string is a hex number, not all hex numbers will contain letters. Therefore, to avoid confusion, especially in this case, it’s a good idea to use the 0x prefix when writing or typing hex numbers.

The general algorithm for converting a binary number to a hexadecimal number is as follows:

- Group the digits of the binary number into sets of 4 digits (or bits). Add leading zeros to last group of 4 on left if necessary.
- Convert the binary numbers in each set of 4 into the equivalent hex digits.

The examples above suggest that this is also easy and trivial.

By simply doing the algorithm in reverse, we can convert a hexadecimal number to a binary number.

Let’s do a quick example.

__Ex. 3__

Convert 0xFF09 to binary.

**Solution:**

Starting at the far left, we write each hex digit in its equivalent binary format:

F = 1111, F = 1111, 0 = 0000, 9 = 1001

Stringing it all together, we get: 1111111100001001 or 1111 1111 0000 1001 if we break in up for easier reading.

The general algorithm for converting a binary number to a hexadecimal number is as follows:

- Write each hex digit as a 4-bit binary number
- Remember that 0 in hex is 0000 in binary!

Going from decimal to hex is a bit more complicated than going from binary to hex, but as we’ll see it’s similar to converting decimal to binary and not that hard to do.

There are two ways to convert decimal numbers to hexadecimal: sum of powers of 16 and repeated division by 16. Let’s talk about both.

Also called sum of weighted hex digits method, this method is good for simpler conversions (up to about 3 hex digits).

For example, let’s convert 35 to hexadecimal using this method.

Upon inspection, we note that 35 = 32 + 3

We also note that (2 x 16) = 32 and that (3 x 1) = 3.

So, we have 2 sixteens (or 2 sixteens raised to the first power) and 3 ones (or 3 sixteens raised to the zeroth power).

Therefore 32 in decimal = 0x23.

Remember that any number raised to the zeroth power is one.

The method above can become unwieldy for larger numbers.

Divide the decimal number by 16 and note the remainder. Be sure to write the remainder as a hexadecimal digit.

Repeat this process until the quotient is 0. The last remainder is the most significant digit of the hex number.

__Ex. 4__

Suppose we want to convert 31,581 to hexadecimal.

31,581 / 16 = 1973, remainder 13 (least significant digit, or LSD).

1,973 / 16 = 123, remainder 5

123 / 16 = 7, remainder 11

7 / 16 = 0, remainder 7 (most significant digit, or MSD)

Now we write all the remainders as hex digits: 13 = 0xD, 5 = 0x5, 11 = 0xB, 7 = 0x7

Listing them in proper order (MSD on far left; LSD on far right) gives us:

31,581 = 0x7B5D

One way to do this is to first convert the hex number into binary, then convert into decimal.

Another way to do this conversion is to multiply each digit by its power of 16 positional multiplier and add the products together.

The example below helps illustrate this.

__Ex. 5__

Convert 0x7C6 to decimal.

**Solution:**

First, we note each hex digit’s positional weight starting with the LSD: 6 has a weight of 16^{0}, C has a weight of 16^{1}, and 7 has a weight of 16^{2}.

Now we multiply each digit by its positional weight. We’ll start with the MSD:

7 x 16^{2} = 7 x 256 = 1792

C x 16^{1} = 12 x 16 = 192

6 x 16^{0} = 6 x 1 = 6

Next, we’ll add up our results: 1792 + 192+ 6 = 1990

So now we know how hexadecimal numbers relate to digital circuits and how to convert hex to binary and vice versa. We also know how to convert hexadecimal numbers to decimal numbers and the reverse.

Since hex numbers are quite common in the world of computers and electronics, I’m sure they’ll come up again.

Only now you’ll know how to deal with them. And as a bonus, next time you experience the blue screen of death, you’ll be able to translate those hex digits into the memory address(es) where the error(s) occurred.

Comment and tell us what you prefer working with: hex or binary?

Or you can comment and let me know what other topics you’d like to hear about.

Until next time,

Keep geekin’

The post Breaking the Hex: Understanding Hexadecimal Numbers appeared first on Circuit Crush.

]]>The post Another Powerful Post: A Primer on Electric Power Part 2 appeared first on Circuit Crush.

]]>If you missed it, please read it before you read this one. Here it is: One Powerful Post: A Primer on Electric Power Part 1.

Let’s kick things off by going over some electric power related terms and concepts dealing with reactive circuits.

For now, we won’t really differentiate between reactive circuits that are primarily inductive (RL), capacitive (RC) or both (RLC). We’ll delve into more detail on that stuff in another post.

Important terms are in **bold**.

If we apply the generalized electric power law

P = I x V (eq. 1)

to AC power, we can rewrite it as

p(t) = v(t)i(t) (eq. 2).

This is the **instantaneous power**, where t represents a particular point in time. In AC circuits, this usually involves some nasty looking trig with cosines all over the place due to AC power’s sinusoidal nature.

This quantity is difficult to measure, but the **average power** is a bit easier to measure. In fact, the wattmeter, (you guessed it — it measures power), responds to average power.

To get the average power, the instantaneous power is averaged over one cycle. The equation for average power is given below.

P_{avg} = ½ V_{p} I_{p} cos (ϴ_{v} – ϴ_{i}) (eq. 3).

The subscript p in equation 3 is the **peak value** of the sinusoid, which for a 120 V circuit is 170 V. The trig part is simply the cosine of the phase difference between the voltage and current. Reactive elements like inductors and capacitors cause this phase shift.

Another, even more useful measurement is the **RMS** value, or **root mean square**, also called the **effective value**. The RMS values of AC voltage and current are based upon equating the values of AC and DC power one would need to heat a resistor to the same temperature. In other words, a direct current whose values of I and V equal the RMS values of I and V for an alternating current will produce the same power.

The nice thing about RMS measurements is that they’re independent of time and frequency. The equation below is for 120 VAC circuits.

V_{RMS} = V_{p} x 0.707 (eq. 4).

Equation 4 gives us the RMS voltage where V_{p} is again the peak voltage. The formula for the RMS value of the current is similar – simply substitute peak voltage with peak current.

The actual formula for calculating the RMS value of other waveforms is kind of messy and involves calculus. We’ll save that for another post. Right now, you’ll have to trust me that equation 4 is right *if it’s a 120 VAC circuit*.

The formula for average power and power absorbed by a resistor can be rewritten in terms of the RMS voltage and currents.

P_{avg} = V_{rms}I_{rms} cos(ϴ_{v} – ϴ_{i}) (eq. 6)

P = I^{2}_{rms }R (eq. 7)

The **power factor** is the cosine of the phase difference between voltage and current. A lot can be said about power factor and power factor correction, but for now all we need are the basics. We can also regard the power factor as the ratio of the **real power** (resistive power) dissipated to the apparent power (more on that in a minute).

Purely resistive circuits have a power factor of 1, which is the best you can get. Purely reactive circuits have a power factor of 0. Most practical circuits fall somewhere between the two values.

Power factor can be **leading** or **lagging**. If it is leading, the current leads the voltage by some phase difference. If it’s lagging, the voltage leads the current by some phase difference. Power factor can affect your electric bill, so it’s important.

The real power is the only useful power and is the power the load actually dissipates. The **reactive power** (a.k.a. wattless power) is a measure of the energy exchanged between reactive elements and the load. The **VAR** (for volt-amp reactive) is the unit of measurement.

Purely reactive circuits dissipate no real power. They instead store energy either in a magnetic field or electric field and swap the energy back and forth with the rest of the circuit. Of course, in real life inductors have some resistance and capacitors aren’t perfect either.

The impedance these components show isn’t a real resistance and is instead a reactance. To calculate reactive power, we use a formula similar to equation 1 in that it is straight from Ohm’s Law and easy to apply.

P_{X} = I^{2} x X_{M} (eq. 8)

The subscript X in P_{X} means the power is reactive. The subscript M in X_{M} is either the capacitive reactance or inductive reactance and is measured in ohms just like resistance. The letter X itself is the reactance, be it capacitive or inductive.

The formula for calculating **inductive reactance** is given in equation 9.

X_{L} = 2πfL (eq. 9)

Where f is the frequency in Hertz and L is the inductance or value of the inductor in Henrys.

The formula for calculating **capacitive reactance** is given in equation 10.

X_{C} = 1/(2πfC) (eq. 10)

Where f is again the frequency and C is the capacitance or value of the capacitor in Farads.

The **apparent power** is so called because it seems apparent that the power should be the voltage-current product, as compared to a DC circuit. It is measured in **VA**s (**volt-amps**) and not watts (unless it’s purely resistive). It is the product of the RMS values of voltage and current.

Think of it as the power that appears to be supplied by the load. It includes both real power and reactive power.

An electronics newbie may think that apparent power is simply the sum of the real power and the reactive power.

This is not true. The problem lies in the fact that simple arithmetic on reactive variables can’t be done without considering phase.

If you’re an electrical engineer (or EE student) you take this into account using phasors and imaginary/complex numbers. For the average hobbyist, this can seem daunting and complicated.

Lucky for those who haven’t taken any engineering level circuit analysis classes, there is an easier way to get the apparent power.

To illustrate this, we can use a simple diagram known as the power triangle, which we can see in the figure below.

*Figure 1: the power triangle and how it relates to electric power
*

Understanding the following discussion and examples requires some (very) basic knowledge of trigonometry.

Using a right triangle, the relationship between real power (watts), reactive power (VARs), and apparent power (VAs) can be more easily understood.

You probably already know that in any right triangle the hypotenuse (apparent power in the above figure) is always the longest side. Here we can graphically see that the apparent power is greater than either the real power or reactive power and is the total power used by the circuit.

The cosine of 0 is 1; if we make the power factor angle small (ideally 0), then the triangle collapses on itself and the real power equals the apparent power. This gives us a power factor of 1 and is an ideal situation that only occurs in DC and purely resistive AC circuits.

Looking at the triangle, it is easy to see the amount of reactive power the circuit uses is what determines its efficiency. The more reactive power the greater the power factor angle, which lowers the power factor.

But is reactive power really all a big waste?

Sure, ideally, we should try to keep it to a minimum (especially if we pay for it!) but it turns out we need it. For example, inductive reactive power in electric motors forms the magnetic fields to spin the rotor. Without it the motor would not work.

For most households, employing power factor correction (we’ll talk more about this in a future post) might be a waste and too expensive to justify.

But, for large commercial and industrial facilities who pay tens of thousands per month for electricity, a significant savings can be realized.

Imagine figure 1 sitting in a Cartesian (X-Y) coordinate system with the left point of the triangle sitting at the origin. The real power runs along the x-axis, and the reactive power follows the y-axis. Figure 2 illustrates this.

*Figure 2: the power triangle in Cartesian coordinates.*

One important thing to note is that if the hypotenuse lies in the first quadrant of the coordinate system, the load is inductive with a lagging power factor.

If we were to flip the triangle along the x-axis so the hypotenuse now lies fourth quadrant, the load is capacitive with a leading power factor.

Believe it or not, it is possible for the hypotenuse to also lie in the second or third quadrant. This means that the load impedance has a negative resistance, which is possible in some circuits.

The power triangle is nice because it gives us a more intuitive understanding of electric power, but how do we actually calculate the different types of electric power?

You may have heard of the Pythagorean theorem. Using that and/or some simple trigonometry, we can easily calculate any value if we know any other two values.

The Pythagorean theorem states that in any right triangle:

A^{2} + B^{2} = C^{2} (eq. 11)

Where C is the hypotenuse or long side of the triangle and A and B are the other sides.

Using simple algebra, we can take the square root of both sides which gives us:

C = √A^{2} + B^{2} (eq. 12)

Note that the square root sign covers the whole right side of the equation.

To put it another way:

VA = √P^{2} + VAR^{2} (eq. 13)

Where VA is the apparent power, P is the real power, and VAR is the reactive power.

Here we don’t have to worry about phase angles – the Pythagorean theorem takes care of that for us.

From simple trigonometry, we can also note that:

cos (ϴ) = A/H (eq. 14)

where ϴ is the power factor angle, A the side adjacent to it (the bottom of the triangle in figures 1 and 2), and H is the hypotenuse.

If we re-write this using power as the variables we get:

cos (ϴ) = real power / apparent power

or

cos (ϴ) = P/VA (eq. 15)

This means that if we know the power factor or the power factor angle, we can get any of the three powers (sides of the triangle) as long as we know one of the sides.

Let’s do a few easy examples to illustrate the information given above.

__Ex 1:__

We know our circuit consumes 10 W or real power and 3 VAR of reactive power. How much apparent power does our contraption suck down?

Solution:

From the Pythagorean theorem we get equation 12 and use it here.

VA = √10^{2} + 3^{2 }= √100 + 9 = √109

Apparent power = 10.44 VA

__Ex 2:__

My circuit consumes 5 W of real power, but the apparent power is found to be 6.3 VA. How much reactive power does my creation use?

Solution:

Here we know the reactive power and the real power. All we need to do is algebraically rearrange equation 12 a bit to obtain:

VAR = √VA^{2} – P^{2} or VAR = √6.3^{2} – 5^{2}

Which gives us VAR = √39.69 – 25 = √14.69

Giving us a VAR of about 3.83.

__Ex 3: __

A circuit has a power factor of 0.85 and draws 3 W of real power. How much apparent power does this thing consume?

Solution:

We know that power factor = cos (ϴ) and that the cosine is the adjacent side of the triangle over the hypotenuse. Using this information, we can write:

0.85 = 3 W / some amount of VAs

Rearranging algebraically, we can write:

0.85 x (some amount of VAs) = 3 W

Dividing both sides by 0.85, we see that the apparent power is equal to roughly 3.53 VA.

Note that if we want the phase angle for some reason, we can simply grab a calculator and take the inverse cosine of 0.85, which gives us about 31.79⁰. This means the voltage and current are 31.79⁰ out of phase with each other.

By now we have a reasonable understanding of the difference between power and energy, purely resistive power, and calculating power in AC circuits, both resistive and reactive.

If some of the terms used in this post are unfamiliar, don’t worry. You should still be able to make power calculations using the information presented here.

In another post, we’ll delve into more detail about things we didn’t quite have room for in the two posts.

Things like the concept of impedance are important to understand, but right now you should be able to easily calculate the power your toaster uses or the power rating of the resistor needed in many of your circuits.

We’ll also take a closer look at power (and impedance) in RL, RC, and RLC circuits, since we now know that most AC circuits are not purely resistive.

Until then, drop us a comment and share any tips you have on saving power or choosing components for your circuits with the correct power rating.

The post Another Powerful Post: A Primer on Electric Power Part 2 appeared first on Circuit Crush.

]]>The post One Powerful Post: A Primer on Electric Power Part 1 appeared first on Circuit Crush.

]]>Understanding electric power and the associated concepts is a very important part of circuit design. If a component tries to dissipate too much power, the magic smoke comes out. We’ve all had this happen at one time or another.

At first, I was going to make this one post. It soon grew into a monster as I went on to explain all (ok, some) of the concepts surrounding electric power.

Electric power includes concepts like real power, apparent power, power factor and more.

The first part of this series will start by tackling one of the most confusing, yet fundamental aspects of it – power vs energy. Then, we’ll take a look at power in DC circuits and purely resistive AC circuits. After that, the series will delve into power in circuits that contain reactive components like inductors and capacitors.

If knowledge is power, then knowledge of power is power squared!

This concept is one that seems to confuse a lot of people. The terms power and energy are often used interchangeably, as if they’re the exact same thing, but there is a difference.

Power is the rate at which work is performed. Its unit is the watt, for which joules per second is the measurement. Joules are the unit of measure for energy.

The total energy in any process neither increases or decreases during that process (conservation of energy), it just transforms from one form to another.

So, if I slide a book across the table, I’m not making any “new” energy or destroying it. The kinetic energy of the moving book transforms into thermal energy due to friction, making the book and table slightly warmer.

The amount of energy transformed from one form to another is known as work.

Here’s an intuitive example that illustrates the difference between power and energy:

Suppose 2 people, each weighing the same, circle a track. One person takes their time and walks around the track in 3 minutes, while the other person sprints and circles it in 40 seconds.

Both people use the same amount of energy since they did same amount of work. However, the runner used his energy in a shorter amount of time while the walker spaced it out. Although both used the same amount of energy, the runner used more power since his energy was used up quicker.

Whether we talk about the motor in your car, an electric motor, the runner, or your latest electronic project, the output power is measured in watts, which describes the number of joules of energy used every second.

You may be thinking something like *but* *the motor in my car is rated in horsepower*. That’s right, but 1 horsepower is equal to 746 watts — the base unit is still watts.

For our purpose, we’re going to worry about electric power. Therefore, power, in connection to electronics, is the rate at which electric energy converts into some other form.

Because of this, the formula for power given below holds true.

P = W/t (eq. 1)

Where W is energy in joules, and t is time.

Energy can be given by equation 2 below:

W = Q x V (eq. 2)

Where Q is coulombs of charge and V is voltage (if you want to know more about coulombs, check out the post on batteries).

Substituting the formula for energy (eq. 2) into the formula for power (eq. 1) gives:

P = (Q x V)/t (eq. 3)

Since coulombs of charge Q equals the amount of current times time t, we get, by substituting I x t into eq. 3, the final and familiar equation for power below.

P = I x V (eq. 4)

Where I is current and V is voltage.

Don’t let all the substitution and simple equations above scare you. If you work through it, you’ll see that’s it’s pretty intuitive and easy.

Some books refer to equation 4 as the generalized power law. It is general in the sense that it tells us how much power a circuit uses, but does not tell us how the circuit uses it.

Regardless of what you call it, equation 4 is part of Ohm’s Law and is useful for determining power, current and/or voltage (depending on which ones you already know) in DC circuits and purely resistive AC circuits.

As an example, suppose your flashlight uses 2 D cell batteries, each at 1.5 V. The total voltage is obviously 3 V. Let’s assume the circuit draws 0.2 A of current. How much power does the flashlight consume?

To answer this, we simply multiply the voltage by the current:

3 x 0.2 = 0.6 W or 600 mW.

What if we knew the power and voltage of the flashlight but not the current?

Simply divide the power by the voltage:

0.6/3 = 0.2 A or 200 mA.

Piece of cake.

The same holds true for purely resistive AC circuits. Let’s say your toaster is purely resistive and runs off 120 V from your wall.

The label on the toaster tells us that it draws 1,000 W of power. How much current does it draw?

To answer this, we do as we did before and divide power by voltage:

1,000/120 = 8.33 A.

Easy peasy.

Unfortunately, in the real world, few AC circuits are purely resistive. This complicates things a bit.

So now we know that most AC circuits aren’t purely resistive. Now what?

Things like inductors and capacitors add a reactive component to the total power.

Think you can avoid this just because your appliance or widget doesn’t contain any inductors or capacitors?

Wrong.

The heating element in your hair dryer might be mostly resistive, but if it’s a coil there will also be some parasitic inductance. Then there’s the blower motor on that hair dryer which is made up of – you guessed it — coils of wire.

Electric motors in general cause a lot of unwanted inductance. This includes the compressor in your refrigerator, the motors in your washer and dryer, your blender – you get the idea.

And we didn’t even mention parasitic capacitance yet. All we need for that is two or more wires that are close enough together.

Imagine two wires inside some appliance right next to each other. There’s the conductor on one wire with its insulation, the insulation on the second wire, then the conductor in the second wire. That’s two conductors separated by an insulator (or dielectric) which makes a capacitor.

The figure below is an example to help illustrate this.

*Figure 1: though usually smaller, there are junction boxes like this all over your house. They lurk behind your plugs, switches, light fixtures and other locations.*

It’s not uncommon to open a junction box in your home, an appliance, or even the project you just finished building and see a mess of wires like figure 1. It’s safe to say that this scenario introduces both stray capacitance and inductance.

Once upon a time I was an electrician’s apprentice and was working on wiring a garbage disposal in a new hotel. The disposal had a small junction box where the AC wiring joins the wiring in the unit. Even though the breaker was off, I got a nice spark when I stuck my screw driver in this junction box. Stuffing all the wires into the box created a capacitive effect. I somehow shorted the “capacitor” out with my screw driver.

For the discussion that follows in the rest of the series, I’m going to make several assumptions. First, you’ve heard of capacitive reactance and inductive reactance and have at least some idea what they mean. Next, you’re at least somewhat familiar with the concept of impedance.

Explaining all these concepts would take several posts, so if you’re not sure about some of these things keep checking back. They’ll appear on the blog sooner or later.

By now you should know the difference between power and energy and how to calculate power in DC and purely resistive AC circuits.

You also know that most AC circuits aren’t purely restive and suspect that this can complicate things.

It does a bit, but it’s nothing that’s too difficult to wrap your mind around.

In the next part of this series, we’ll start by going over some common terms associated with electric power.

Then, we’ll go over a helpful little friend that resembles a simple geometric shape that we’re all familiar with and how he can help us.

After that, we’ll delve into calculating electric power in AC circuits that sport a phenomenon known as reactance.

Stay tuned!

Meanwhile, comment and tell us what your biggest questions about power are and maybe I’ll answer them in this series!

The post One Powerful Post: A Primer on Electric Power Part 1 appeared first on Circuit Crush.

]]>The post Test Your Electronics Knowledge With This Quiz appeared first on Circuit Crush.

]]>This post isn’t a post in the sense that it’s a tutorial on a certain topic.

This post is a short electronics quiz to assess your knowledge, maybe learn something along the way, and most of all, have some fun.

The questions in this set aren’t engineering level questions (in other words, they’re not terribly difficult) but some of them may be a little challenging depending on your knowledge and experience.

Don’t worry if this particular quiz didn’t contain a question about a certain topic. There are a myriad of questions one can ask concerning electronics, programming, circuit design, and much more. Rather, keep visiting the blog or subscribe via RSS as I’ll be posting more quizzes like this in the future.

First, you’ll see the questions.

After the last question, I’ll post the answers to each question with an explanation (or I’ll work the problem out, if appropriate).

No peeking!

Now let’s test your electrical knowledge…

1) Imagine an infinite grid of 1 Ohm resistors connected together (like the one in the picture below). If you were able to measure the total resistance of this grid, what would it be?

2) True or false: it takes more heat to melt lead-free solder than regular solder.

3) What is the difference between a primary and a secondary battery?

4) Name this component:

5) What is the value of the resistor below?

6) Five amps flow through a 10 Ohm resistor. How much power is dissipated by the resistor?

7) Your hair dryer draws 500 W of power. The electric company is charging you 11 cents per kilowatt-hour. You use the hair dryer for half an hour. How much did that dry head of hair cost you?

8) How many time constants does it take to charge/discharge a capacitor?

9) The sum of currents entering a node (or point in a circuit) is equal to the sum leaving the node. This is referred to as ___________________________.

10) Find V_{x} in the circuit below.

Space below left intentionally, scroll down for answers.

*

*

*

*

*

*

*

**1) Answer: 0.**

This is because the resistors are connected in parallel. We know that in any group of resistors connected in parallel, the total resistance is always less than the lowest resistance in the group. Since there is an infinite amount of one Ohm resistors in parallel, the total goes to zero.

**2) Answer: true.**

**3) Answer: primary batteries cannot be recharged.**

I wrote two posts on batteries, one covering primary batteries and another about secondary (rechargeable) batteries.

**4) Answer: photoresistor (a.k.a. photocell, light dependent resistor)**

Photoresistors vary their resistance according to the amount of light that hits them.

**5) Answer: 572 Ohms, 2% tolerance.**

It’s a 5 band resistor with bands colored (left to right) green, violet, red, black, red. The first three bands give the first three digits of the resistor’s value. The fourth (black) is the multiplier and is 0 in this case, so we’re not going to tack on any zeros to our answer of 572 Ohms. The last band is the tolerance which, in this case, is 2%. Check out my post on resistor color code if you need help with this.

**6) Answer: 250 W.**

Ohm’s Law is back to haunt us again. The easiest way to answer this problem is to remember that P = I^{2}R. So, we have 5^{2} x 10 = 250 W. Make sure you use a power resistor if you build a circuit like this!

**7) Answer: 2.75 cents.**

Power companies charge by the kilowatt-hour, so we need to convert watts into kilowatts first. 500 W is equal to 0.5 kW. Since we’re only using the device for half an hour, we need to multiply 0.5 kW by 0.5 hours, then multiply by our cost of 0.11 (11 cents):

0.5 x 0.5 x 0.11 = $0.0275 or 2.75 cents.

**8) Answer: 5.**

The exact reason for this involves differential equations and is somewhat complicated. Maybe I’ll tackle it (and try to simplify it) in a future post. For now just take my word for it

**9) Answer: Kirchhoff’s Current Law (a.k.a. KCL).**

KCL is one of the basic tools for analyzing circuits.

**10) Answer: 95 V.**

This was probably the hardest question here. Using another one of Kirchhoff’s laws (KVL or Kirchhoff’s Voltage Law) to solve for V_{x}, we can write the following equation:

20 + 15(5) – V_{x} = 0

Solving algebraically for V_{x}, we get V_{x} = 95 V.

I’ve booked Mr. Kirchhoff and his laws to make a future appearance on the blog

Since there are only ten questions, I decided to use a different grading scale than the one you’re familiar with from school.

You remember that one. If you scored a 90% or better you got an A. Less than 60% and you failed. And getting a D wasn’t considered great, even though it was a passing grade. That would mean you could only miss three questions and still get a decent score. For some of you, that may be child’s play, for others, maybe not.

Here’s the breakdown I decided to use:

- 1-4 correct: Beginner
- 5-7 correct: Intermediate
- 8-10 correct: uber-geek

Now I just have a few more questions for you…

How did you like this? Were the questions too easy? Were they too hard? Should I have 15 questions instead of 10?

Let me know your thoughts in the comments below.

*Like this post? You’ll love the Facebook group. You’ll also love our bi-monthly newsletter & free gift (see below).*

The post Test Your Electronics Knowledge With This Quiz appeared first on Circuit Crush.

]]>The post Types of Capacitors: Pros, Cons, & Applications appeared first on Circuit Crush.

]]>A while ago, I published a post about several common resistor types you’re likely to run into.

This post will be similar in that we’ll take a quick look at the common types of capacitors. Topics like the theory behind capacitors or deciphering their markings will appear in future posts.

The post will give a quick over-view of some of the applications for each type of capacitor, but will not go into great detail about the applications (again, this type of info will appear in future posts).

It will also give the reader an idea of the various common capacitors out there, their strengths and weaknesses, and a quick look at their applications. More exotic capacitor types (such as ultracapacitors and supercapacitors) or rare types will probably pop up in a future article.

This should enable one who’s not totally familiar with the various types of capacitors and their uses to hopefully pick the right one for their application.

Also, I suggest bookmarking this post (and the resistor one) as it will serve as a quick reference for the future.

After all, unless you work for a capacitor manufacturer or have a memory like a steel trap, you may find yourself asking questions like …*which capacitor has the tolerance I need?* Or *what’s the voltage range of this type of capacitor?*

And trust me; you WILL need to use capacitors in your circuits and creations.

Enough said, let’s dive right into the different types of capacitors.

Like resistors, capacitors come in two basic flavors: fixed and variable.

Both operate on the same basic principles.

A **fixed capacitor** is just like it sounds – its value is fixed and cannot be changed.

Of course, the capacitance of a **variable capacitor** *can* be changed.

The type of dielectric (insulating material between the plates) used in the capacitor classifies it.

For variable caps, we have air, mica, ceramic, and plastic.

Fixed value capacitors come in mica, ceramic, plastic, metal film, electrolytic, and more types.

Let’s start by taking a look at two interesting variable capacitors.

If you’re into working on old radios and other older equipment, you’ve likely run into variable capacitors that use air as the dielectric. These are also known as **air core capacitors**.

These work by keeping one set of plates fixed while the other set connects to a rotating shaft. Rotating the shaft varies the effective area of the plates, thus changing the capacitance. The plates are usually made of aluminum to prevent corrosion. Figure 1 shows this type of capacitor.

*Figure 1: old style variable capacitor.*

On top, we see the real deal, an actual picture of a variable air core capacitor. The bottom shows a somewhat simplified diagram of how the device works.

These capacitors are very stable over a wide range of temperatures and leakage losses are low. The downside is that they’re big and bulky. Other types of capacitors can achieve the same capacitance in a much smaller package (though they may not be as stable).

Unfortunately, these types of capacitors are showing up less and less these days due to newer technology and the ever increasing demand to shrink electronics. If you come across one, be sure to grab it, even if just for nostalgia’s sake.

The second common type of variable capacitor often finds its home on circuit boards and is the **trimmer capacitor**.

These usually adjust via a small screw which varies the distance between the plates. They’re good for fine-tuning circuits. Use only a non-metallic tool to adjust these types of capacitors because a metal tool can affect the capacitance making it very difficult to get the right value.

Figure 2 sports a picture of a typical trimmer cap. Note that these capacitors can use several different dielectrics, depending on the application. We’ll go into more detail on specific types of dielectrics when we discuss fixed capacitors.

*Figure2: typical PCB trimmer capacitor.*

On top, we can see what it looks like. Note that they are usually smaller than it appears in the picture. The bottom gives you a good idea on how the trimmer works.

Trimmer capacitors usually have values in the picofarad range.

Mica capacitors are composed of thin foil plates (usually aluminum or silver) that are alternately stacked to form the two plates of the cap. A thin layer of mica isolates the plates from each other. The whole shebang is sealed inside a protective casing.

The figure below depicts some typical silver mica capacitors.

These caps are very stable and have a good temperature coefficient. The cons are that they usually don’t come in high capacitance values and can be more costly than other types (silver is expensive, ya know).

You’ll find them in high frequency filters, resonance circuits, and even high voltage circuits. They have good insulation, and therefore are able to operate at higher voltages.

Capacitance values range from 1 ρF to about 0.1 µF.

Voltage ratings range from 50 V to 500 V.

*Figure 3: silver mica capacitors.*

These types of capacitors come in two main varieties: single layer and multilayer.

Ceramic caps (along with electrolytic caps) are the most widely available and popular capacitors.

You might be familiar with the small, round, disc-like capacitors found on many PCBs. These are **single layer ceramic capacitors** which consist of two plates with a ceramic dielectric in between.

They sport low inductance, so they can find use in high frequency applications.

Using different types of ceramics varies the dielectric constant resulting in several different types of ceramic capacitors.

Therefore, they also have varieties (ultrastable or temperature compensating) that are very stable across a range of temperatures. These can last many years.

The semistable single layer ceramic cap isn’t as temperature stable as the above, but it does have a higher capacitance.

Finally, the HiK ceramic capacitor has a high dielectric constant (and capacitance), but lacks stability and suffers from a phenomenon known as dielectric absorption.

Single layer ceramic caps have a capacitance range of 1 ρF to 0.1 µF.

Voltage ratings range from 50 V to 10,000 V.

Figure 4 shows a typical single layer ceramic capacitor.

*Figure 4: single layer ceramic capacitors.*

Like mica caps, many ceramic capacitors consist of several alternating layers of ceramic and metal plates. These are the **multilayer ceramic capacitors**.

They meet the demand for high density ceramic caps, and, like the mica caps, have many layers to boost the total capacitance.

They are also compact and have better temperature characteristics than the single layer variety.

Just like the single layer type of capacitor, they come in ultrastable, stable, and HiK varieties.

Their capacitance ranges from 0.25 ρF to 22 µF depending on the type.

Voltage ratings range from 25 V to 200 V, again depending on the type.

Many surface mount capacitors are multilayer, as we can see in figure 5.

*Figure 5: an example of multilayer ceramic capacitors.*

There are two main types of electrolytic capacitors: aluminum and tantalum.

**Aluminum electrolytics** have a chemical paste (the electrolyte) filling the space between their foil plates. When voltage is applied, a chemical reaction forms a layer of insulating material on the positive plate. Because this film is very thin, they can pack a good amount of capacitance in a small package.

The film and the plates are then rolled into a cylindrical shape before being placed in a protective case.

The chemical reaction also gives these capacitors a polarity that should be carefully observed. They can explode if the rated voltage is exceeded or the polarity is reversed, therefore do not connect an AC source to an electrolytic cap.

Don’t try this at home, but if you hook an aluminum electrolytic cap to a 120 VAC source, it will explode. Of course, if you do this and injure yourself I take no responsibility.

Both aluminum and tantalum electrolytic capacitors will be marked with either a “+” or a “-“ to indicate which plate is which.

These capacitors are popular due to their low cost and ability to provide a relatively high capacitance in a small package.

Aluminum electrolytics also leak badly, have bad tolerances, and have a high inductance. Because of this, they are good for low frequency applications and not so good for high frequency ones.

They should also not be used if the DC potential is well below the capacitor’s rated voltage.

These capacitors also have a limited life, even if they’re just sitting in your parts bin. When grabbing one that’s more than a few years old, be sure to check to see if it’s still in spec.

Typical values range from 0.1 µF to 500,000 µF or more.

Applications include power supply ripple filters, audio coupling, and bypassing.

A typical aluminum electrolytic capacitor appears in figure 6.

*Figure 6: an aluminum electrolytic capacitor. Notice the stripe on the side that marks the negative plate.*

**Tantalum electrolytic capacitors** are made with tantalum pentoxide and are polarized like their aluminum cousins.

They’re also smaller and more stable. They leak less and have less inductance than aluminum electrolytics. They sport a longer lifespan. The downside is that they’re more expensive and have a lower maximum voltage and capacitance.

Like aluminum electrolytics, tantalum caps can explode and/or burst into flames if the polarity reverses.

They often take up residence in analog signal systems that lack high current spike noise (spikes can damage them). Other applications include blocking, bypassing, decoupling, and filtering.

Tantalum caps are not good for high frequency applications. Like the aluminum versions, they should not be used if the DC potential is far below the rated voltage.

Figure 7 depicts a tantalum capacitor. Notice that they look different than the aluminum versions.

*Figure 7: a tantalum capacitor. Notice the + sign which marks the positive lead.*

These types of capacitors have replaced paper capacitors, which we will not discuss since they’re obsolete.

There are a few varieties of plastic film caps that are common, including polyester film and polypropylene film.

**Polyester film capacitors **(a.k.a. Mylar capacitors) use a thin polyester film as their dielectric (as any logical person may guess). Their tolerance (typically 5-10 percent) is not as good as polypropylene capacitors but they have good temperature stability and are cheap.

Polyester film caps are good for coupling and storage purposes. They often find use in audio and oscillator circuits and moderately high frequency circuits.

Capacitance values range from 0.001 µF to 10 µF.

Voltage ratings range from 50 V to 600 V.

*Figure 8: a typical polyester film (Mylar) capacitor.*

**Polypropylene film capacitors **have a higher tolerance than polyester film caps, so use them in place of polyester for applications that require a tighter tolerance.

Like polyester, they’re good for coupling and storage purposes, but also come in handy for noise suppression, blocking, bypassing, filtering, and timing.

Capacitance values range from 0.001 µF to about 0.47 µF.

Voltage ratings range from 100 V to 600 V.

*Figure 9: a polypropylene film capacitor. Notice the similarity in appearance to the polyester film version.*

**Polystyrene capacitors **aren’t film capacitors, but I lumped them here anyway.

These have a high inductance so they’re not good for high frequency applications. Exposure to temperatures above 160⁰ F (about 70⁰ C) will permanently damage them. Polystyrene is similar to Styrofoam (there is a slight difference; Styrofoam is a brand name, hence the capitalization), and Styrofoam melts. So does polystyrene.

Due to the high inductance, they are good for filtering and timing circuits running at a few hundred kilohertz or less. They’re also cheap with good stability.

Capacitance values range from 100 ρF to 0.027 µF.

Voltage ratings range from 30 V to 600 V.

*Figure 10: various polystyrene capacitors.*

Like the plastic film variety, these also come in both polyester and polypropylene. Since they both exhibit similar traits, we’re not going to treat them separately as we did with the plastic film caps.

Metalized film capacitors are made by using a vacuum deposition process that laminates a film substrate with an extremely thin (literally several atoms thick) aluminum coating.

They take up residence in circuits that use small signal levels (think low current and high impedance) where small physical size is a priority.

They’re not good for large signal AC applications.

One unique trait they possess is their self-healing ability. While shorts permanently destroy other capacitor types, these caps can heal themselves. Metalized film capacitors are also temperature stable with low drift.

You’ll find them in switching power supplies, audio circuits where sound quality is important, noise suppression circuit, snubbers and more.

Capacitance values range from 47 ρF to 22 µF, depending on the type.

Voltage ratings range from 63 V to 1250 V, again depending on the type.

*Figure 11: various metalized film capacitors. I’m not sure what the dots on the side are for, but notice that they can look similar to their plastic film relatives.*

Now we know something about the most common types of capacitors and what they’re good for and not good for.

Don’t forget to bookmark this post. It’ll come in handy.

Below is a nifty little chart that summarizes some of the characteristics of some of the capacitors we talked about.

We didn’t discuss it, but ESR stands for equivalent series resistance. ESR is a measure of the capacitor’s internal resistance and in series with it. Maybe ESR and other capacitor specs we didn’t discuss here will make an appearance in another article.

*Figure 12: a quick run-down of several common capacitor types.*

Until next time, comment and tell us: what types of capacitors do you use the most? Also, why do you pick that particular type?

*References:*

- Cook, Nigel P.
*Introductory DC/AC Electronics, 4th Ed.*Prentice Hall, 1999. Print. - Scherz, Paul & Monk, Simon.
*Practical Electronics for Inventors, 4th Ed.*McGraw Hill, 2016. Print. - Byers, TJ. “Bypass Caps Demystified [the chart].”
*Nuts and Volts*January 2007: 18-19. Print.

The post Types of Capacitors: Pros, Cons, & Applications appeared first on Circuit Crush.

]]>The post AC vs DC: What’s the Difference? appeared first on Circuit Crush.

]]>No, we’re not talking about a hard rock band, we’re talking AC vs DC with regards to electricity.

Some of you may already know this. Even if you’ve been dabbling in electronics for a while and think you have this figured out, I highly recommend reading this whole post as there are some things that may surprise you.

One of the easiest ways to explain the differences between AC vs DC is to treat each one separately and delve into some details about each.

Toward that end, we’ll start with DC first because it’s a bit simpler to explain and most of your creations will use it.

Electric current (or a voltage, as voltage and current are proportional) can be classified as direct current (DC) or alternating current (AC).

Direct current flows in one direction only, while alternating current changes direction periodically.

In the land of electricity, another word for direction is polarity.

But what do we really mean by this?

If we were to plot the voltage of an ideal battery versus time, we’d have a flat line, as you probably already know. With a given DC source, this line can either lie on the positive end of the y-axis or the negative end, but not both.

To see what I mean, take a gander at the simple pictures below.

*Figure 1: positive and negative DC voltages*

The red horizontal lines represent a DC voltage. On the left, we see a positive DC voltage (it could also represent a current if we labeled the y-axis current instead of voltage).

Notice how the line lies above the x-axis (which represents time) and how it will never dip below the x-axis — if we assume a steady-state voltage – even if we drag the x-axis out to infinity.

However, part (*b*) of the figure shows the voltage lying below the x-axis, which makes it a negative DC voltage.

In both parts, the line either dwells above or below the x-axis, but never actually crosses the x-axis, even if we watch this very exciting “waveform” for an infinite amount of time.

To most of us, it’s plainly obvious that a flat horizontal line on a graph represents a DC voltage.

But what about the figure below? Is this AC or is it DC?

*Figure 2: AC vs DC: is it AC or DC?*

* *

If you said DC, you’re right.

Even though this graph does not depict a flat horizontal line, it does not go negative at any point (assuming it remains steady-state and periodic).

Figure 2 depicts what’s known as pulsating DC.

Pulsating DC varies periodically from some minimal voltage (zero in this case) to some maximum voltage, back to minimum and then repeats.

By periodic, we mean that the waveform repeats itself at regular, predictable intervals. I’ll spare you the mathematical definition of periodic.

Remember, pulsating DC does *not* vary from a positive to a negative voltage or vice versa. It stays either positive or negative along the whole x-axis, regardless of the amplitude or wave shape.

This type of voltage/current occurs at the output of certain battery chargers and also at the output of a full-wave bridge rectifier which is part of a circuit that converts AC into DC.

Remember, whether pulsating or steady (like the flat line) direct current is current that flows in only one direction. Figure 3 below shows this concept in a simple circuit.

*Figure 3: a simple circuit*

Using electron flow (for more about electron flow vs conventional current flow see the post), current would flow from the negative terminal of the battery through the resistance to the positive terminal.

This direction does not change unless we change the polarity of the source. If we reverse the polarity of the battery by flipping it around (negative end now on top), current flows the opposite direction of the arrow.

Either way, the current (and voltage) is DC because it will never alternate directions back and forth.

Alternating current, or AC, is electric current first in one direction for a period of time and then in the reverse direction for a period of time.

Direct current can only change in magnitude, but alternating current can change in both magnitude and polarity.

Most of us are familiar with the AC power supplied to our homes.

Some of us may be familiar with the alternator in our vehicle that produces power. An alternator produces AC power (hence the name) before it is rectified and put to use to charge the battery and power the vehicle’s accessories.

The power at the receptacle in your home as well as the power created by the alternator in your vehicle (before rectification) comes in the form of a sine wave.

Sine is short for sinusoidal which, as we can see from a graph of the mathematical/trigonometric sine function, describes the shape of the wave.

The figure below depicts a typical sine wave you’d find at the receptacle in your home.

*Figure 4: a typical AC sine wave*

The AC power in your home is sinusoidal in nature because it is generated by rotating conductors in a magnetic field. If we take one cycle of the sine wave above and fold the negative half over to the left, we see that the resulting shape is somewhat circular in nature.

By cycle, we mean one alternation from zero, up to some maximum positive value, back to zero where it crosses the x-axis, then down to some minimum negative, then back to zero again where the cycle ends.

In figure 4, there is a small “x” where the first cycle ends and the second cycle begins.

Since we are rotating something in a circular motion (with a generator) to produce AC power, it should be no surprise that the sine wave is shaped the way it is. And, since there are 360 degrees in a circle, each cycle of the sine wave also goes through 360 degrees.

We know that alternating current gets its name because it alternates from positive to negative, but what does that really mean?

During one half-cycle electrons flow in one direction. Then, they switch and flow the opposite direction during the other half-cycle.

Figure 5 from Introductory DC/AC Electronics illustrates this.

*Figure 5: how alternating current moves*

In part (b) of the figure, we can see a typical sine wave. Part (C) shows how electrons move during the positive alteration and part (d) shows how they move during the negative alteration.

So, electrons in an AC circuit will move back and forth about a fixed point.

To clarify, consider the simple circuit in figure 3, only there is an AC source there instead of a battery.

Now, imaging that you’re very small and can “sit” in the middle of the resistor and see electrons flowing by.

For one instant, they pass you in one direction, in another instant, the opposite direction.

In fact, if you counted the number of electrons that slip by you during each alteration, you’d see that not only is it the same number each direction, but if you could tell each individual one apart from others, the same electrons would keep passing you — first in one direction, then the other.

Still want more clarification? This fantastic video from Khurram Tanvir should do the trick.

The video shows the basics on how an AC generator works.

It also shows how electrons move back and forth about a fixed point. Notice the needle on the voltmeter moving back and forth (with 0 as the fixed point) as the generator spins creating the sine wave.

One important fact about alternating current is that it doesn’t have to be sinusoidal.

Figure 6 depicts 3 other types of AC waveforms along with a sine wave.

*Figure 6: other types of AC waveforms*

The square wave should look familiar; you’ll see similar waves in digital circuits. Triangular waves are good for testing certain types of devices, like some amplifiers. Complex waves often crop up, too. They may or may not be desirable, depending on the circumstances.

For example, a sine wave with noise injected into it may look like the complex wave in the figure above. Or, an AM radio signal may take on a similar form. One is desirable while the other is not.

Regardless of their shape, they all have one thing in common: they’re positive for some period of time, then negative for some period of time.

I know the m-word is making some of you groan right now while others are rejoicing, but I promise – it won’t be that bad.

The mathematical description of a typical (non-pulsating) DC waveform is stupid-easy:

V (t) = V

Where t is time.

In other words, it’s a flat horizontal line and V is the voltage that remains constant throughout time (that’s why it’s graph is a horizontal line).

The description of a typical AC waveform depends on the shape, but for simplicity’s sake we’re going to assume a sinusoid.

Mathematically, an AC sinewave is technically described by the equation below.

v (t) = V sin (ωt + φ)

Where ω = 2πf.

That equation may be more familiar if you’re an engineer or electronics tech.

The lower-case omega (ω) is the frequency in radians rather than Hertz. Since most hobbyists aren’t super familiar with radians, the equation can be changed to a more familiar form.

v (t) = V sin (2πft + φ)

What follows is a break-down of what each part of this equation means.

*t** represents time.*

*v (t)** is a function of how the voltage varies or changes with time. In other words, v (t) changes as time changes. The stuff on the right of the equal sign describes how this change looks.*

*V **is the amplitude of the sinewave.*

*2**π** is a constant used to convert radians, which is an angular frequency (radians per second) to Hertz, the unit you’re probably more familiar with.*

*f** is the frequency in Hertz, or cycles per second. In a 60 Hz circuit, one cycle takes 1/60 of a second (this is the period of the wave which describes how long one cycle lasts. In general, the period T = 1/f, so one cycle of 60 Hz power lasts for about 17 ms). Conversely, there are 60 cycles in one second in a 60 Hz circuit.*

*Φ **is the phase of the wave. This is a measure of how far the wave is shifted with respect to time and is somewhere between 0 and 360 degrees. Once a sinusoid is shifted 360 degrees, it’s as if the shift never happened. The wave is the same because there are 360 degrees in a circle. In other words, if I were to draw a circle with a compass, once I rotated it 360 degrees the circle would close and start again at 0 degrees.*

You may be wondering how this fits in with the 120 V coming from a receptacle in your home.

In the U.S., AC power has a peak amplitude of 170 V (120 V is the RMS value) and the frequency is 60 Hz. We’ll assume no phase shift.

With this information, we can write

v (t) = 170 sin (2π60t)

to mathematically describe the voltage coming from the wall.

Don’t try this, but if you were to view the AC power in your home on an oscilloscope, you’d see a 60 Hz sine wave with a peak amplitude of 170 V.

If we graph this equation on a graphing calculator or computer, the same thing would show — no scope required.

If you have some experience in electronics, you likely know the answer. If you’re new, it may not be obvious.

Most things that plug into the outlets in your home convert the AC feeding it into DC. This includes your TV, computer, DVD player, Wi-Fi router and more.

There are a few good reasons why the power company supplies AC power rather than DC power.

- With AC power, you can easily step the voltage up or down with a transformer. Doing the same with DC is more complex. This allows the utility to use high voltage and lower current, which is more efficient. Wires have a resistance, which becomes significant if they’re miles long. Remember, Power = I
^{2}More current means more heat lost in the resistance of all those wires. That’s money wasted. So instead of high current they use high voltage (while keeping the current low), which can easily be reduced later. - It is much easier to convert AC to DC than it is to convert DC to AC.
- The generators the power company uses work by spinning conductors in a magnetic field. This naturally give rise to an AC sinusoidal output, as we already know. Some generators can output DC, but they are more expensive and more complex. Also, AC generators are usually larger, meaning they can generate more power.

As an interesting side note, the battle between AC vs DC power distribution settled in the 1890’s with AC as winner. This is why we use it today.

However, new technology has made a DC grid more feasible and efficient. There are a few small areas around the world that are testing this idea. Suffice it to say, it’ll be a while before the whole grid converts to DC, if it ever does.

There is so much more to the world of AC and even DC than we can cover in one post.

For example, we did not talk about transients (DC), nor discuss AC related things like RMS (root mean square), peak value, peak-to-peak value, or phasors in much (or any) detail.

Looks like a job for a future blog post!

Until then, comment and share what topic you would like to see covered in a future post. It might just show up

Like this article? then you’ll love the Facebook group for electronics & computer enthusiasts! Request to join today.

*References:*

- Cook, Nigel P.
*Introductory DC/AC Electronics, 4th Ed.*Prentice Hall, 1999. Print. - Alexander, Charles K. & Mathew, Sadiku N.O.
*Fundamentals of Electric Circuits, 2nd Ed.*Mc Graw Hill, 2004. Print.

The post AC vs DC: What’s the Difference? appeared first on Circuit Crush.

]]>The post A Closer look Inside the Arduino Uno appeared first on Circuit Crush.

]]>Of all the different incarnations, the Uno remains one of the most popular.

In fact, if you’ve been dabbling in electronics for more than a few minutes or have worked with microcontrollers, chances are you’ve used it before or have at least heard of it.

A while ago, I wrote an article about using the Arduino vs a stand-alone microcontroller (like the ATmega328 that powers the Uno or a PIC).

They both have their pros and cons, so if you’re interested check out Getting Naked: Working With Naked Microcontrollers vs Trainers Like Arduino.

Though many of us have used the Arduino Uno, most of us seldom think of how it works or what’s under the hood. We’re going to take a closer look inside the Uno and see what makes it tick.

Actually, this will likely be the first of a series of posts about the inner workings of the Uno and the nuances of working with it. I may not write them in order (I may write about other topics before posting part 2), but they’ll eventually come.

*If you’re looking for the Arduino Uno and ATmega328 pin-out, see figures 1 and 2. *

Now, let’s have a closer look inside the Arduino Uno.

Made in Italy, the Arduino showed up on the scene in 2005. Since then, there have been various incarnations of the board including the Duemilanove (2009 in Italian), the Diecimial (which means 10,000 in Italian to celebrate the making of the 10,000^{th} one), the Mega 2560, and more.

The boards are very versatile and can handle most common things microcontrollers can do, and the price is low.

Then there’s the fact that the software to program it is free and can be used on Windows, Mac, or even Linux.

The hardware and the software are both open source, so others can take the designs and improve them without worrying about licensing fees.

There are many *shields* that are available which easily attach to the board adding functionality.

And finally, they’re great for experimenting and prototyping projects (though my Getting Naked post explains why you may want to go for a stand-alone micro instead).

Refer to figure 1, which shows the Arduino Uno.

*Figure 1: the Arduino Uno board*

Obviously, the rectangular thing in the lower right is the brains of the Uno, the ATmega328.

The power jack on the lower left is a 2.1mm center positive barrel connector. Above that, we can see a USB Type B jack for connecting the Arduino to a PC.

A series of 28 female pin headers allow you to connect other things to the Arduino and are at the top and bottom. These headers are separated into three groups. The digital pins are at the top. On the bottom left we have the power pins, and the analog pins dwell on the lower right (notice the small gap between them). Out of the 28 pins, 20 are for I/O.

The six analog pins can also serve as general purpose digital I/O. Out of the 14-total digital I/O pins, six can be used to generate PWM (pulse width modulation) signals.

The Arduino Uno also supports basic communications standards like TTL serial, SPI, I2C, and 1-wire.

Two of the inputs support hardware interrupts. They trigger on either a LOW, a rising edge or falling edge, or a change in value via software.

The oval-shaped silver object in the middle left is the 16 MHz crystal.

To the right of the power jack are two 47 µF capacitors. We’ll take a closer look at these in a future post.

Directly above the jack lies a 5 V low dropout voltage regulator. Directly above the capacitors closest to the microcontroller we can see a 3.3 V low dropout regulator. It lies near two surface mount capacitors.

Powering the Arduino is an often overlooked, but a very important part in the effective use of the device. Many spurious errors are actually power issues. We’ll go into more detail on properly powering the Arduino in a different post.

An Arduino Uno board measures 2 1/8” x 2 ¾”. The SMD version is *slightly* different but most people want the ability to easily replace the ATmega328 microcontroller if they accidentally kill it. If you’re new to Arduino, electronics, microcontrollers, or some combination of the above I’d skip the SMD version and grab the one in figure 1.

The operating voltage of the Arduino Uno is 5 V which can come from either a USB cable and your PC or some external source.

The recommended input voltage range is 7 – 12 V. You should try to keep that number closer to 7 V if you can as the small regulator will dissipate any excess energy as heat and can become very hot. We’ll go into more detail on this issue in another post.

The Arduino Uno contains two regulators. The 5 V regulator can theoretically provide up to 800 mA and the 3.3 V version can source 50 mA.

Aside from the microcontroller, the Uno has a few other main points of interest.

There is an integrated USB-to-serial communications chip for downloading programs or “sketches” from your PC and for serial communications back to the PC for debugging and monitoring.

This chip is the small black box above the 16MHz crystal in figure 1.

The USB link sports a 500 mA resettable fuse to guard against any possible damage to your PC. When you plug your Arduino into a USB port, the board takes its power from that port. In USB 2.0, the current a port is capable of sourcing is usually 500mA. USB 3.0 ports can source anywhere from 900 mA to 3 A depending on the type of port.

The analog pins connect to an internal 10-bit analog-to-digital converter (ADC). All the I/O pins can function as digital outputs and can sink/source up to 40 mA.

Next to the analog pins lie the power pins which provide access to both the regulated and unregulated power supplies.

The ATmega328 chip on the Arduino isn’t empty, it comes pre-loaded with a small bootloader for use with the Arduino integrated development environment (IDE).

One nice thing about the Arduino is that you can use it to program other ATmega328 chips if you were to build a project with the stand-alone microcontroller.

To do this, you’d program the chip, remove it and then insert it into your own circuit. All it needs is 5 V, a 16 MHz crystal, and two 22 pF capacitors.

There are a few more minor details on this and it’s something that I personally have not done, but I know its possible. Perhaps we’ll revisit the topic in another post once I get a chance to play with it.

*Figure 2: ATmega328 pin-out and Arduino I/O pin mapping*

Feast your eyes upon figure 2, which shows a pin-out diagram of the ATmega328.

One of the first things to note is that the ATmega328 pin numbers are different from the Arduino Uno pin numbers. This is important!

The labels inside the chip are the primary function names for each of the pins, while the parenthetical labels on the outside are any alternative uses for the pin, if any are available. The writing in blue shows the ATmega328-to-Arduino pin mapping.

Figure 3 shows a simplified block diagram of the ATmega328 microcontroller.

The I/O block is the 20 analog and digital pins. The six analog pins go to the ADC, which has a resolution of 4.9 mV because there are 1024 steps (remember, the ADC is 10-bits and that 2^{10} = 1024) and when we divide 5 V by 1024, we get 4.9 mV per step.

*Figure 3: ATmega328 simplified block diagram*

The two external interrupts that the chip supports map to Arduino digital pins D2 and D3.

There was a time when the analog comparator was not accessible through the Arduino IDE.

Personally, I have not tried to use this feature myself, but some quick searching seemed to suggest that there are now ways to use the comparator with the Arduino IDE.

The analog comparator will trigger an interrupt when voltage on one input equals or exceeds the voltage on another input. This could come in handy for certain projects. For example, say you want a fan to come on when the air reaches a certain temperature.

As of this writing, the current version of the Arduino IDE is version 1.8.3.

The Arduino comes with a Java-based IDE with a fully featured text editor. Once you write a sketch, it needs to be compiled which is referred to as *verifying* in the Arduino ecosystem.

Sketches are written in a language similar to C, though a sketch itself is not completely compatible with C.

There’s no *main()* function for one thing, at least not one that’s visible. It’s hidden from view and added for you when you compile or verify your sketch.

The sketch downloads to your Arduino via a USB cable. This process is automatic as the bootloader that resides in ATmega328 detects when a sketch is arriving.

The sketch takes residence in the 32 Kb of flash memory inside the ATmega chip. This memory can endure at least 10,000 read/write cycles, so you’re unlikely to wear it out any time soon. The Arduino also sports 1 Kb of electrically erasable programmable read only memory (EEPROM) which is non-volatile. Finally, there is also 2 Kb of RAM available which *is* volatile.

All Arduino sketches need two parts at a minimum: the *setup()* and *loop() *functions. These two functions take no arguments — so the parentheses are empty — but they still need to be there.

They appear as follows:

Void setup() { any code would go here

}

Void loop() { any code would go here

}

If you’re familiar with C, you know that *void* in front of the functions simply means that the function does not return a value when it’s done processing.

These two functions are a requirement and the Arduino IDE will report an error during compile if any of the two are missing.

Often, the makers of the board will release updated versions of the IDE. When they do, it’s a good idea to download them and install them. You can keep multiple versions of the Arduino IDE on your PC and switch between them if you want, but this isn’t something you should need to do often. If you do install the latest IDE, be sure to take a gander at the readme file for the latest changes.

Many of you have used the Uno in your projects and experiments, but now you have a little more detail on how the board and the brains (the ATmega328) work.

Future installments of this series will go into more detail about powering the board, a very important but often overlooked issue. We’ll also take a closer look at the digital and analog I/O pins, as there are some “gotchas” hiding there.

Meanwhile, comment and let us know about your latest Arduino experiments, projects, and endeavors!

The post A Closer look Inside the Arduino Uno appeared first on Circuit Crush.

]]>The post A Bit of Fun with Binary Number Basics appeared first on Circuit Crush.

]]>Binary information that digital systems work with appear as waveforms that represent a sequence of bits. As an example, see the figure below which relates the 1’s and 0’s to voltage levels on the waveform *A*. As we can see, a 1 is a HIGH and a 0 is a LOW.

*Figure 1: a physical representation of what binary numbers mean in a digital waveform.*

Being able to count in binary (at least zero through fifteen) and translate from binary to decimal and from decimal to binary is a rite of passage for any serious electronics geek.

There are other number systems like hexadecimal and octal which will undoubtedly show up in other posts.

This one focuses on the basics of binary numbers. If you’re new to digital electronics, it’s a must read.

If you’re not so new it’s a good review.

Let’s take a byte out of binary!

In order to better understand binary (and other number systems) a few comments on the number system we’re most familiar with are in order.

Counting in binary is just like counting in decimal, if you’re all thumbs.

Let me explain.

The decimal number system (or base 10 system) is based on ten digits 0-9.

We use 10 for our usual number system because we happen to have 10 fingers.

The fact is, any integer greater than 1 can serve as a base for a number system. Somewhere in this universe there may dwell intelligent creatures with twelve fingers that are counting in base 12.

In elementary school, you learned the meaning of decimal (base 10) notation – to interpret a string of digits as a number, you mentally multiply each digit by its place value.

For example, the number 6,053 can also be written as:

6,053 = (6 x 1,000) + (0 x 100) + (5 x 10) + (3 x 1)

Or we can write 6,053 = 6 x 10^{3} + 0 x 10^{2 }+ 5 x 10^{1} + 3 x 10^{0}

Remember that any number, even zero, raised to the zeroth power is one. This is important.

Looking at these stupid-simple equations, which should make you “duh, I already know this,” we see that the 6 in 6,053 occupies the thousands place, the zero occupies the hundreds place, and so on.

Notice also, that because numbers “need to know their place” zero is just as important as any other digit. So it is in binary also.

As a side note, the word decimal comes from the Latin root *deci*, which means ten.

So, we now know that decimal (or base 10) notation expresses a number as a string of digits in which each digit’s position indicates the power of 10 by which it is multiplied. Truthfully, we’ve known this for a while but probably never explicitly thought of it that way.

Binary comes from the Latin word *bi* which means two.

In binary, there are only ones and zeros. A single one or zero is a called a *bit*, which is a contraction from the words *binary *and* digit*.

Four bits make up a *nibble* and eight bits make up a *byte*. Usually, you’ll be working with *bits* and *bytes *but *nibbles* may appear here and there.

Finally, a *word* is usually 2 *bytes* or sixteen *bits* but with newer processors can be 32 or even 64 *bits*.

Given that all the other references have to do with eating, I wonder why they chose the word *word*. Perhaps they could have called 16 or more *bits* a *munch*?

Anyway, the table below summarizes this.

# OF BITS OR BINARY DIGITS |
NAME |

1 | Bit |

4 | Nibble |

8 | Byte |

16+ | Word, Double Word (32),
Quad Word (64) |

*Table 1: common names for groups of binary digits.*

Now, consider the binary number 1010, which is 10 in decimal.

The left most bit is the most significant bit or MSB. The right most bit is the least significant bit or LSB. More on this in a bit (pun not totally intended but I couldn’t help myself).

The easiest way to convert a binary number to a decimal number or vice versa is to use a calculator.

But real geeks don’t need no stinkin’ calculator, at least to translate four bit numbers back and forth.

You should know all the binary number from 0000 to 1111 (0 to 15).

Converting long binary numbers like 11100001111101010100111 (I have no idea what number this is) into a decimal number without a calculator can be tough. Generally, I use a calculator for anything 5 bits or more.

Remember that like the decimal system, the binary number system is a positional notation system.

So, for any four-bit number we have the positions of:

2^{3} 2^{2} 2^{1} 2^{0}

If we consider the binary number 1101, we have one 8, one 4, zero 2s, and one 1.

1 1 0 1

See how the ones and zeros line up with the powers of two? We have a 1 in the 2^{3} position, a 1 in the 2^{2} position, a 0 in the 2^{1} position, and a 1 in the 2^{0} position.

Figure 2 below clarifies this even further.

*Figure 2: binary number 13*

Once we translate each bit by noting it’s place value and its numerical value, we simply add the numbers together (just like you mentally already do in base 10):

8 + 4 + 0 + 1 = 13

Figure 3 shows all the binary number from zero to fifteen with bit A being the MSB and bit D being the LSB.

*Figure 3: binary numbers 0-15.*

There are a few things we can note about binary to decimal conversion from figure 3.

First, it is common practice to write each number as a 4-bit number and pad the beginning with zeros (up to 7). This developed because each bit has a physical location in a digital circuit, such as an I/O pin on a microprocessor.

Also note that because each bit holds a position, zero is just as important as one.

Finally, notice that the LSB follows a pattern. The bits alternate with every line making the pattern 0, 1, 0, 1 and so on. The second LSB (bit C) follows a similar pattern of 0, 0, 1, 1, 0, 0… and the third LSB (bit B) makes the pattern 0, 0, 0, 0, 1, 1, 1, 1 then it repeats.

The 2’s bit alternates every 2 lines, the 4’s bit every 4 lines. This pattern can be extended to any number of bits with the number of lines between alterations doubling with each bit to the left.

These patterns can help the noob quickly translate 4 bit binary numbers into decimal numbers.

In general, with n bits, you can count to a number equal to 2^{n} – 1.

Why not 2^{n}?

Because 0 is a number and takes up one of the slots.

There are two ways to convert decimal numbers to binary: sum of powers of 2 and repeated division by 2. Let’s talk about both of them.

One can convert a decimal number to binary by adding up the powers of 2 by inspection, adding bits as you need them to fill out the total value.

For example, let’s convert 53 to binary using this method.

We first need to ask ourselves what’s the highest power of 2 that is less than 53?

2^{6} is 64 so that wouldn’t work, but we see that 2^{5} is 32.

64 > 53 > 32

So, we set the 32’s bit to 1 and subtract 32 from 53, as shown.

53 – 32 = 21

The largest power of 2 that is less than 21 is 2^{4}.

32 > 21 > 16

Again, we set the 16’s bit to 1 and subtract 16 from 21.

21 – 16 = 5

Here we see that 2^{3} is 8 which is greater than the remaining total, so we set the 8’s bit to 0.

The largest power of 2 that is less than 5 is 2^{2}.

Set the 4’s bit to one and subtract.

5 – 4 = 1

Like before, we see that 2^{1} is 2 which is greater than 1, so we set that bit to zero. Don’t forget about the zeros!

One is left, so we’ll set the 1’s bit to 1.

Since 1 – 1 = 0, there is nothing left to subtract and we are done.

53_{10} = 110101_{2}

In the beginning, it may be helpful to write boxes underneath each power of 2 then fill them in with either a 1 or a 0. The image below from one of my text books demonstrates this.

*Figure 4: sum of powers of 2 method to convert 92 to binary. From Digital Design with CPLD Applications and VHDL, 2 ^{nd} Ed.*

In the figure above, we start with 64 (2^{6}) because 128 (2^{7}) is bigger than 92. We then go to each decreasing power of 2 and either put a 1 or a 0 in the box.

For example, in the second iteration we place a 0 in the 32 box because 32 is greater than 28. We then write a 1 in the 16 box because 16 is smaller than 28.

Figure 5 shows a table of various powers of 2 which may be helpful.

*Figure 5: powers of 2 table.*

Any decimal integer divided by 2 will leave a remainder of either 1 or 0. Thus, repeated division by 2 will leave a string of 1 and 0 remainders. These remainders are the binary equivalent of the decimal number.

The first remainder is the LSB and the last remainder is the MSB.

As an example, suppose we want to convert 43 to binary.

43 / 2 = 21, remainder 1 (LSB).

We’ll keep the remainder and make it the LSB and divide the quotient by 2. This algorithm is repeated until the quotient is 0. The last remainder will be the MSB.

21 / 2 = 10, remainder 1

10 / 2 = 5, remainder 0

5 / 2 = 2, remainder 1

2 / 2 = 1, remainder 0

1 / 2 = 0, remainder 1 (MSB)

Now all we need to do is read the remainders from the bottom up.

So, 43_{10} = 101011

The figure below, from Digital Fundamentals, 7^{th} Edition, summarizes this process well while converting the number 19 to binary.

*Figure 6: converting 19 to binary using repeated division by 2.*

Converting fractional decimal numbers to fractional binary numbers can be a little trickier than working with whole numbers.

In decimal, we call the period or dot such as the one in 3.14 a decimal point. In binary, this dot is a binary point. Generally, a period in any number system is called a radix point.

When working in base 10, fractional numbers use the same digits as whole numbers, but we write them to the right of the decimal point. The multipliers for these digits are negative powers of ten such as 10^{-1}, 10^{-2} and so on rather than positive powers as they were to the left of the decimal point.

Remember that writing any number n^{-x} is the same as writing 1/n^{x}. So, 10^{-1} is the same as 1/10 or one-tenth.

So it is in the binary system also.

The first four multipliers on either side of the binary point are:

2^{3} 2^{2 }2^{1} 2^{0} **.** 2^{-1} 2^{-2} 2^{-3} 2^{-4}

=8 =4 =2 =1 = 1/2 =1/4 =1/8 =1/16

As another example, let’s write 0.101101 as a decimal fraction.

1 x 1/2 =1/2

0 x 1/4 = 0

1 x 1/8 = 1/8

1 x 1/16 = 1/16

0 x 1/32 = 0

1 x 1-64 = 1/64

If we add all the fractions together, we get 0.703125.

Simple decimal fractions like 0.5 and 0.25 can be converted to binary fractions by the sum of powers of 2 method.

These particular decimal numbers are the same as ½ and ¼.

0.5 = 0.1_{2} and 0.25 = 0.01_{2}.

You might have been able to get these answers just by inspection.

The conversion process becomes more complicated if we convert decimal fractions that cannot be broken into powers of 2. For example, 1/5 (which is 0.2) cannot be exactly represented by a sum of negative powers of 2.

Generally, this is one limitation of computers. Computer scientists, engineers, and programmers have to deal with it sometimes. It will probably come up in future posts about number representation in computers and microcontrollers.

Anyway, for this type of number we need to use the method of repeated multiplication by 2.

The steps below outline the method.

- Multiply the decimal fraction by 2 and note the integer part. This will be either a 0 or a 1 for any number between 0 and 0.9999… This integer part is the first digit to the right of the binary point. Using our example of 0.2 we have: 0.2 x 2 = 0.4, integer part 0.
- Throw out the integer part of the previous product. Multiply the fraction part of the previous product by 2: 0.4 x 2 = 0.8, integer part 0.
- Repeat the above until the fraction either terminates or starts to repeat: 0.8 x 2 = 1.6, integer part 1. We’ll continue our conversion below.

0.6 x 2 = 1.2, integer part 1.

0.2 x 2 = 0.4, integer part 0.

Now we can see that fraction starts to repeat, as the above product is the same as step 1.

Read the integer parts from top to bottom to get the fractional binary number.

0.2 = 0.00110011… which is the same as 0.

The bar shows the portion of the digits that repeat.

So now we know how binary numbers relate to digital circuits and how to convert decimal to binary and vice versa. We also know some lingo for common groupings of bits and something about binary fractions, which is a topic that a lot of other tutorials don’t cover.

Future posts may deal with binary arithmetic and things like 2’s complement and 1’s complement.

Then there’s things like ASCII code, binary coded decimal or BCD, signed binary numbers, floating point, and Gray code to name a few.

The world of electronics has so much to offer.

Until next time,

Keep geekin’

The post A Bit of Fun with Binary Number Basics appeared first on Circuit Crush.

]]>The post Practical Electronics – Hacking My Shark Cordless Vacuum Project, Part 1 appeared first on Circuit Crush.

]]>The batteries on the Shark lasted for about 10 minutes before they were drained and I was constantly recharging the thing. Worse yet, the instructions said to charge it for 16 hours (that’s a long time!).

My Shark vacuum spent more time on the charger than it did cleaning the messes it was designed to tackle. Enough was enough, something had to happen.

*Figure 1: my 15.6 V Shark handheld vacuum*

There is a Batteries + Bulbs store in my area, so I took the vacuum there and told them I wanted to upgrade the batteries to ones with a higher amp-hour capacity. Constructing battery packs with a regular soldering iron can ruin the batteries, and I lacked the spot welding device they used at the store, so I had them build the pack and install it.

The new batteries were 4000mAh NiMH cells. Since the capacity was greater, the charge time was even longer than the original 16 hours. This was unacceptable.

To charge them quicker, I got my hands on a generic laptop charger shortly after I got the vacuum back.

The charger produces 24 V at 1 amp. The connector didn’t fit the unit, so I simply cut the connectors off both chargers and soldered the old one onto the new charger. I then wrapped everything up in electrical tape.

Now, I was able to charge the unit in about 4-5 hours and use it longer between charges than I could before.

This worked fine for about four years.

Then, in early 2017 I went to use the vacuum to clean a mess. Nothing. Completely dead.

I threw it on the charger figuring the batteries were just dead.

Still nothing.

No green LED (which lights up during charging), no motor humming when I flipped the switch, no suction. Now I had a big green paper weight instead of a handheld vacuum.

I’m a pretty busy guy who runs several businesses (and this blog), so the vacuum sat for a month or two before I got a chance to take it apart and look at it.

Finally, I grabbed my screw driver and went to work. Upon opening it and removing the guts, I was face to face with the somewhat simple design shown below in the picture.

*Figure 2: the guts of my Shark*

The design is pretty simple, but sometimes simple things elude us. Instead of connecting my power supply directly to the motor (after disconnecting the batteries) to see if it works I went full throttle and started testing components on the small circuit board.

A close-up of that board is shown below (with one terminal on one of two parallel resistors and a diode unsoldered).

*Figure 3: a close-up the PCB*

* *

On the board, we can see a SPST switch, an LED with its current limiting resistor, two bigger 68Ω resistors in parallel, and two diodes, likely there to prevent inductive kick-back from the motor.

My ohm meter told me the switch was good, as were the two resistors. After unsoldering one of the leads on each of the two diodes, I found that the diode continuity test on my meter did not seem to work right.

*But if the diodes are there just to prevent kickback, the unit should still theoretically function, right*? Was the thought that ran through my mind. My next thought was *perhaps I should buy a new meter*…

No time for this now though, I had to spend some time actually doing work that makes me money. And then there’s that thing about writing new blog posts, too.

A week or so later, I finally decided to disconnect the battery pack and insert my benchtop power supply in its place. See the figure below.

*Figure 4: You can’t tell from the pic, but the motor’s running! The left display is current, the one next to it is voltage.*

I dialed in 15.6 V, hit the switch on the unit, and voila! The motor kicked on right away (even with both large resistors and diodes removed from the circuit!).

I now knew that the problem was the battery pack.

As a side note, it’s interesting to note the voltage drop from 15.6 V to 15 V and the current draw of 4.77 A.

*Would the voltage drop and current draw differ if I soldered the components back into the circuit? *I thought to myself.

To find out, I fired up the soldering iron and repeated the set up. We can see the results were slightly different in the picture below.

*Figure 5: repeat of figure 4, only now the 2 resistors and 2 diodes are back in the circuit.*

As we can see, the voltage drop and current draw is even greater. At almost 5 amps, a 4000 mAh battery pack would theoretically drain after about 48 minutes of use. This is neglecting start-up transients and ignoring other losses. The actual run time is likely shorter. No wonder the original batteries would drain so quickly!

Next, it was time to see exactly what kind of batteries the unit came with and compare them with the new batteries.

After peeling back the label on one of the original batteries and doing a search on the characters printed on the metal case underneath the label (which read WT170311 (RDC-001) (T)), I was able to find no information on the cells.

The vacuum is a 15.6 V model and there are 13 cells, so each cell is 1.2 V. I’m sure they’re either NiCd or NiMH batteries but am not sure on the capacity of the cells.

A picture of the old battery pack can be seen below. The cell that stands alone was wired in series with the otherwise rectangular pack yielding a total of 15.6 V.

*Figure 6: the original Shark batteries*

At this point their capacity doesn’t matter much.

What matters now is figuring out why the new batteries are dead and not taking a charge.

Was it simply their time to go?

Did I force too much current to quickly into them with the new charger? If so, why did they last so long before dying?

I’ll admit that I’m no expert on battery charger design, so I’m hesitant to simply buy another battery pack and repeat the same saga.

The motor has what appears to be a part number on it. The higher the voltage you apply to an electric motor (up to a limit), the faster it spins. This could create more suction and a more powerful vacuum.

The plan is to look up the specs on the motor. Can I turn my 15.6 V Shark into an 18 V Shark? How about a 20.4 V Shark?

Maybe.

The next order of business will be to investigate the batteries.

How should they charge?

How much current is safe?

Will they even fit inside the case of the unit if I increase the total voltage and/or capacity?

Should I build some sort of battery charge control circuit and implant it into the unit, or are the smarts already inside the charger?

Perhaps a tear-down and reverse engineering of the original charger coupled with some research can answer these questions.

But that’s all going to be in part 2 of this series.

When will I get a chance to do these things?

I’m not sure, but I sure do miss the convenience of having a small battery powered vacuum!

And the concept of hacking this thing to make it a better model is motivating.

Right now, I have a Shark handheld vacuum that would be functional if the batteries weren’t shot. I also have a good project to work on.

I’ll keep you updated on the Shark cordless vacuum hack.

Do you have any ideas or suggestions on battery charging or making the vacuum better? Feel free to comment and share your thoughts!

The post Practical Electronics – Hacking My Shark Cordless Vacuum Project, Part 1 appeared first on Circuit Crush.

]]>The post Digital to Analog Converters – An Introductory Tutorial appeared first on Circuit Crush.

]]>Why?

I started gathering information about ADCs. Then it hit me: digital to analog converters (or DACs) are often part of analog to digital converters.

So, the topic this time will be the types of digital to analog converters and a bit (sorry for the pun) on how they work.

This post is an introductory post, so we won’t necessarily cover every single DAC out there, nor will we go into immense detail about how the ones we do discuss work, though we will touch on the basics.

DACs are simpler than ADCs, and unlike ADCs, there are only a few practical ones in use today.

Now, let’s delve into digital to analog converters and their types.

The function of a digital to analog converter is to convert a sequence of digital bits (usually stored in some sort of register) into an analog signal. That is, a DAC takes a binary number and converts it an analog voltage that is proportional to the binary number. If we feed a DAC with different binary numbers in quick succession a complete analog waveform is created.

If you’re not 100% sure what the difference between digital and analog is, my post Analog vs Digital: What’s the Difference? can help.

A typical DAC is an active circuit in the form of an IC and may consist of a data register, solid state switches, resistors, and op-amps powered by an external supply.

They can be either unipolar or bipolar. A unipolar DAC has a single polarity. A bipolar unit can have positive and negative output signals. These often use either offset binary or 2’s complement code rather than straight binary like DACs in unipolar mode do.

Sometimes, you’ll see a particular type of digital to analog converter listed as a multiplying DAC. These produce an output that is proportional to the product of a varying input reference (like a voltage) times a digital code. These commonly find a place in systems that use ratiometric transducers like position potentiometers, strain gauges, and pressure sensors to help correct errors that may occur.

The full-scale voltage (V_{FS}) of a DAC is the maximum analog level that it can reach when applying the highest binary code (which would be 1111 for a 4-bit DAC). In general, at full scale the analog output of an n-bit DAC is given by the equation below.

Eq 1: max output = ((2^{n}-1) / 2^{n}) V_{ref}

So, assuming a V_{ref }of 5 V, the maximum analog output of an 8-bit DAC would be about 4.98 V.

DACs find a home in op-amp gain control circuits, waveform generators, process control and autocalibration circuits, and consumer electronics such as MP3 players (often as part of a microcontroller).

A few examples of DACs you may use are the 8-bit DAC0808 and the 12-bit DAC8083A. Of course, there are others.

There are two main types of digital to analog converters that we’ll talk about in this post.

Below we have a simple, 4-bit binary-weighted digital to analog converter (a.k.a. weighted resistor DAC).

The picture is a bit simplified as it lacks the digital switches that switch the 4 bits on and off, but the basic gist remains the same.

*Figure 1: a weighted DAC. From Digital Fundamentals, 7 ^{th} Edition.*

The resistor values represent the binary weights of the input bits. I_{f }is the sum of currents I_{0 }through I_{3}. Due to the properties of the op-amp, almost no current flows into it, rather, current flows through the feedback resistor R_{f}. Another property of op-amps is that they try to keep both the inverting and non-inverting inputs at the same potential. Because the non-inverting input is grounded, the inverting input is also at 0 volts. This is known as a virtual ground.

If the input voltage is zero (binary 0000), the current is also obviously zero. If the input voltage is some other value (from a binary number greater than 0), then the amount of current depends on the input resistor value and is different for each resistor.

The values of the resistors are inversely proportional to the binary weights of the corresponding bits. For example, the lowest value resistor R corresponds to the MSB, 2^{3} in this case, which is eight (binary 1000). The other resistors are multiples of R.

This design makes the output voltage V_{out} proportional to the binary input value.

In practice, weighted resistor DACs are seldom used.

For example, if we want an 8-bit weighted resistor DAC, not only would we need 8 resistors, but the values of the resistors would need to be extremely precise (a tolerance less than 0.5% in this case) or conversion errors will result. We’ll touch on some conversion errors later.

These values would range from 1kΩ to 128kΩ (assuming R = 1kΩ).

As far as I know, there is no standard 128kΩ resistor in production, not to mention one with a tolerance of less than 0.5%! This is circuit is obviously difficult to manufacture, and as we’ll see in a minute, there is a better solution.

The R/2R ladder DAC overcomes the problems inherent with the weighted resistor DAC in that it requires only 2 resistor values. These values are standard values that are in production and usually range from 2kΩ to 10kΩ.

The circuit is expandable to any number of bits simply by adding one resistor of each value for each bit. This is another advantage of the R/2R DAC.

A simplified representation of an R/2R ladder digital to analog converter is shown below.

*Figure 2: an R/2R ladder DAC.* *From Digital Fundamentals, 7 ^{th} Edition.*

The circuit above requires an op-amp with a high slew rate (the rate at which the output changes after a step change in input). If you grab a standard 741 variety op-amp, the circuit will not accurately reproduce changes introduced by large changes in the digital input.

One way to analyze and understand how this circuit works is to replace the R/2R ladder with its Thévenin equivalent circuit, then treat it as an inverting amplifier.

The topic of Thévenin circuit equivalents is a subject that could at least take up another whole post, so I won’t go into any great detail about how or why it works here. Just know that it’s a way to simplify (or complicate, if you ask the average EE student) the analysis of electric circuits.

Looking in on the circuit from its left end, we see two 2R resistors in parallel. This simplifies to R. Now, the parallel combination of R_{1} and R_{2} are in series with R_{4}, giving us yet again 2R. Now this 2R combination is in parallel with R_{3}.

You get the idea.

The process repeats until we reach the op-amp. At this point, the total resistance of the ladder is just R. This is true regardless of how many inputs or bits we have.

In case you still don’t quite understand how this works, the picture below can help. R_{TH} is the Thévenin equivalent resistance.

*Figure 3: derivation of the Thé**venin equivalent of the R/2R circuit. Analysis starts on the left end with 2R ||2R.*

* *

Like the weighted resistor DAC, very little current flows into the op-amp and both terminals are at 0V. Thus, almost all the current flows through the feedback resistor and V_{out} is equal to -IR_{f}.

Because of this, the value of V_{out }DOES depend on the digital code, though the ladder’s total resistance does not. If we make R_{f} = R, then we can calculate the analog output using the equation below. This of course can be expanded for any number of bits.

Eq 2: V_{out} = -[d_{3}/2 + d_{2}/4 + d_{1}/8 + d_{0}/16] V_{ref}

Where V_{ref }is a logic HIGH and d_{x} is either a 1 or a 0.

The R/2R ladder and op-amp are at the heart of most types of digital to analog converters you’ll see today.

In fact, making a digital to analog converter from scratch isn’t worth it. You’re better off buying a DAC IC or using the one built into your microcontroller or ecosystem board.

Several factors affect the performance of a DAC. Here are a few of the major ones to watch out for. Of course, I can’t cover every single possible spec a DAC could have in one blog post.

**Monotonicity**: Math geeks call a mathematical function monotonic if it is either increasing or decreasing on its entire domain. For example, X^{3} is monotonic (it always gets bigger whether X is negative or positive) and X^{2} is not (it decreases in the left quadrant and increases in the right quadrant). Such is similar with DACs. A DAC is monotonic if the output voltage increases every time the input code increases.

**Resolution**: The resolution of a DAC is the smallest voltage change the device can output for the smallest input change, such as when the LSB of a binary number changes. In other words, it is the measure of how finely its output may change between discrete, binary steps. This metric often results in confusion, for reasons we’ll tackle in a minute.

The resolution of a DAC can also refer to number of bits it can handle.

Resolution is often expressed as either a percentage or a voltage.

When expressing resolution as a percentage, we calculate it with the formula below.

Eq. 3: Resolution = [1 / (2^{n} – 1)] x 100

Where n is the number of bits.

When we want to express resolution as a voltage we can use the formula below.

Eq. 4: Resolution = V_{FS} / 2^{n}

Where n is again the number of bits and V_{FS} is the DAC’s full scale output voltage for the maximum binary input.

Note that sometimes you may see the formula for DAC resolution written as equation 5 below.

Eq.5: Resolution = V_{FS} /(2^{n}-1)

After poring over dozens of websites and books, I could not find any explanation as to why one would pick equation 5 over 4 or vice versa. Regardless, the difference in the answers you get is very small.

Below is my best educated guess as to why this is so. If I’m wrong and you know which formula is correct, please comment and let us know why.

My educated guess: People who use this formula are counting “steps” instead of voltage levels.

Remember that zero is a number and that the highest 8-bit number we can write is actually 255 (binary 1111 1111), not 256. This is because the “missing count” is used by the number zero (binary 0000 0000), so though we can represent 256 different numbers in 8 bits, our range is from 0-255, not 1-256.

Since zero is not a “step” from one level to another, we subtract 1 from the total number of possible values (2^{n}) in equation 5.

Since zero volts is technically a voltage level, many use the formula in equation 4. It really depends on the perspective you use. As always, be consistent with which ever you pick!

Anyway, onward we march…

**Settling time**: This is the time the output needs to switch and settle to within +/- ½ LSB when the input code switches from all 0s to all 1s. As a general rule of thumb, the settling time should be about half of the data arrival time, maybe less.

**Linearity**: A linear error is a deviation from the ideal straight-line output of the DAC. A linearity error of more than +/- ½ LSB can result in a nonmonotonic output. An offset error is a special case of a linear error. It is the amount of output voltage when all input bits are zero. A graph of the ideal output of a DAC looks like a straight line starting at the origin and increasing. Offset errors shift that line up or down so it does not start at the origin.

**Relative accuracy**: This is more frequently used than absolute accuracy (measure of output voltage with respect to its expected value). It measures the deviation of the actual from the ideal output voltage as a fraction of the full-scale voltage. Shoot for an accuracy no worse than +/- ½ LSB when picking a DAC.

You’ve now read over 2000 words, so that’s it for this post on the types of digital to analog converters.

There’s a lot more to say about these devices, so I’m sure we’ll see DACs appear again in a future post. Until next time, comment and tell us what you’re favorite DAC is. Is it a dedicated IC? Does it come as part of the package for a microcontroller or eco board? Let us know.

The post Digital to Analog Converters – An Introductory Tutorial appeared first on Circuit Crush.

]]>