Feed on
Posts
Comments

24VAC to 5VDC Conversion

Voltage conversion from 24VAC to 5VDC is quite useful, because a lot of home automation devices use 24VAC, including sprinkler solenoids, home surveillance systems etc. Having a conversion module makes it easy to use a single power supply, without a separate 5V adapter for your control circuit. There are plenty of resources you can find online about it. But these resources are rather scattered. So in this blog post I will summarize and discuss the common choices.


AC to DC Rectification

Before we begin, the first step is to have a rectifier that converts voltage from AC to DC. The common choices are half-wave rectifier (which requires just one diode) or full-wave rectifier (which requires four diodes). For simplicity, I will use half-wave rectifier as an example. The typical schematic of a half-wave rectifier is as follows:

half-wave-rectifier

It’s simply a diode followed by a capacitor to smooth out the rectified AC waves. As we know, diode only allows current to flow in one direction, so after the AC voltage passes through the diode, only positive voltage remains. The diode must be selected based on the maximum reverse voltage and the maximum current. One thing easy to forget is that when we talk about 24VAC, we mean the RMS (root-mean squared) magnitude of the voltage is 24V. Since AC voltage is a sine wave, the peak voltage is actually 24 * sqrt(2) = 34V, which is quite a bit higher. The maximum reverse voltage applied on the diode is therefore 34 – (-34) = 68V, which is when the AC voltage runs to the negative peak. So a diode with 70V peak reverse voltage is sufficient.

In practice, transformers that are rated 24VAC usually have a higher no-load voltage, which can vary between 26VAC up to 28VAC. This is typical, and the voltage is supposed to drop close to 24VAC under maximum load (i.e. the current rating of the transformer). As a result, when the circuit is powered on, the transformer can output a peak instantaneous voltage of up to 28 * sqrt(2) = 39.6V.

In the schematic above, I’ve picked a 1N4002 diode (70V reverse voltage, 1A current) and a 100uF/50V capacitor. These should work well for common scenarios. Note that the voltage output on the capacitor is approximately 34V – 1V (diode’s forward drop voltage) = 33VDC. Again, when the transformer is well below maximum load, the output voltage can go as high as 39.6V – 1V = 38.6V.

So next time if you see a power transformer rated 24VAC, after rectification, gives 39VDC, don’t be surprised!!


Now that we have a DC voltage, the next part is to step it down to 5VDC. We want it to be regulated, so that the voltage won’t fluctuate much. There are a variety of solutions:

1. Zener Diode

Probably the simplest solution is to use a Zener diode. As we know, a Zener diode can force the voltage across it to remain constant (break-down voltage) when it’s in the break-down condition. This condition is met when the current flowing through it (in reverse direction) is at least a few milli-amps (5mA typical) but less than the maximum current allowed (e.g. the diode’s power rating divided by its break-down voltage). For example, a 5V/1W Zener will remain in break-down condition when the reverse current is between 5mA and 1W/5V = 200mA. The typical schematic is shown as follows:

zener_regulator

Here resistor R1 is used for current limiting. Assume D2 is a 5V Zener diode, and the circuit on the right-hand side draws about 180mA current. R1 must be selected such that the current flowing through it is 180mA plus at least 5mA to keep D2 in break-down condition. So we have R1 = (33 – 5) / 0.185 = 150 ohm. Note that D2 should be rated at least 1W, because in case of open-circuit, it needs to absorb the entire 185mA without burning out.

Now let’s take a look at the power rating of the resistor R1. Since the current flowing through it is 185mA, the power is 0.185 A * 0.185 A * 150 ohm = 5.1 Watt. Wholly crap — this is gotta be a big resistor, isn’t it :). Well, this is the unfortunate drawback of a Zener diode based regulator, that is, it can waste a lot of power and require a bulky resistor. Fundamentally, it regulates the voltage by converting the voltage differential to heat. In this case, the voltage differential is quite big (33V vs. 5V), and the current draw is fairly large (180mA) too, so it ends up wasting a lot of power in heat.

Another drawback is that to increase the current draw, we must decrease R1. Otherwise, if the output circuit starts to draw, say 250mA, that will take D2 out of its break-down condition, and the output voltage is not regulated any more. So overall it is only suitable if the current draw is constant and small (e.g. tens of milliamps).


2. Linear Regulator

Another simple solution is to use a linear regulator, such as the popular 7805. The typical schematic is as follows:

linear_regulator

The circuit is quite simple, and the output current can vary across a wider range. However, linear regulator shares the same drawback with Zener diodes, that is, it fundamentally works by converting voltage differential to heat. As a result, it wastes the same amount of energy (5.1 Watt in this case) in heat. This is not only a matter of waste, but also it requires a large heat sink to dissipate the heat, otherwise the regulator will burn and smoke. So clearly not an efficient solution. In fact, the efficiency of a linear regulator is the ratio between the output and input voltages. In this case, it is 5 / 33 = 15.15%, which is very poor.


3. Switching Regulator

Now we have come to my favorite topic: switching regulator, also known as switching converter, or switch-mode power supply (SMPS). It uses transistors and a reactive component, namely inductor, to convert voltages much more efficiently. Ideally the switching converter works by simulating the following:

smps_ideal

That is, imagine there is an automated switch between the input and output. When the switch is turned on, it connects the input to output, and when it turns off, the input and output are disconnected. This essentially generates a square wave with 33V peak voltage, and the duty cycle is determined by the switch. Suppose the duty cycle is 15.15%, as long as the switching frequency is sufficiently high, at the output it would seem as if you have a constant voltage of 33 * 15.15% = 5V. That’s it, simple!

The main advantage of switching regulator is that since there is no resistive element, theoretically there is no energy loss at all, so the conversion efficiency is 100%! Of course in practice there will be some energy loss due to the imperfections of electronic components. Still, even at 75% efficiency, we are talking about a power waste of only (5V * 0.18A / 0.75) – (5V * 0.18A) = 0.3 Watt, much better than the 5.1 Watt waste you saw previously with a linear regulator.

The schematic above may look very simple. But it doesn’t tell the whole story. Implementing the switch is more complicated than you might think. That brings out the drawback of a switching regulator, namely cost and circuit complexity. It typically involves a transistor or MOSFET that functions as a digitally controlled switch, an oscillator circuit that generates a control square wave, a voltage reference and feedback module that monitors the output voltage, and finally a current sensing or thermal shutdown module that protects the regulator. That’s why switching regulators are typically provided as integrated circuits.

MC34063
Probably the cheapest and most widely used switching regulator is MC34063. The volume pricing (quantity 100+) is only 20 to 30 cents. Dave Jones at the EEVblog has a nice video tutorial about how to use MC34063. Also, there are a lot of MC34063 calculators you can find online, which will help you figure out the component values and parameters.

The schematic on the left below shows what I have been using for OpenSprinkler. MC34063 has a maximum input voltage of 40V (and some manufacturers make it 45V), so it’s perfect for our purpose. The main peripheral elements include inductor L1 (150uH), Schottky diode D2 (1N5819), timing capacitor CT (which controls the switching frequency), current limiting resistors Rsc (0.5 ohm), and feedback resistors RT and RB. This circuit can provide 5V 300mA output. The image on the right below shows a picture of the switching regulator section on OpenSprinkler 1.42u DIY kit.

mc34063_schIMG_2627

IMG_2666On OpenSprinkler Pi, Rsc is reduced to 0.33 ohm (three 1 ohm resistors in parallel) in order to provide higher current required by RPi. The picture on the left shows the switching regulator section on OpenSprinkler Pi, which uses all surface mount components.

MC34063 is quite flexible. It’s not only useful for step-down voltage conversion, but it can also do step-up conversion (i.e. the output voltage is higher than input voltage), and voltage inversion. On the other hand, it requires a number of peripheral components, and picking the right component values can be tricky, especially if the output current can vary across a wide range. It’s also prone to noise (remember those annoying humming noise from cheap power adapters), and its maximum current is limited to 1.5A.

Overall if you want a cheap switching regulator, and your circuit draws roughly a fixed amount of current well below 1.5A, then MC34063 is a great choice to consider.

LM2596
More recently I’ve started using LM2596 as a replacement for MC43063. I came across it when I was shopping for a modular step-down converter and noticed this one from Amazon.com. LM2596 provides up to 3A output current, requires only a small number of peripheral components, and is more reliable and less noisy. In fact, when I started working on OpenSprinkler, I have used a similar product LM2574 for a while, but that has a current limit ot 500mA, and the switching frequency is much lower.

Here is the new design of the voltage conversion section in the upcoming OpenSprinkler 2.0 and OpenSprinkler Pi 1.1:

lm2596_schIMG_2709

It uses LM2596-5.0, which has a fixed output voltage of 5.0V. The number of peripheral elements is minimal, and the circuit design is very clean. The main downside is that it is considerably more expensive than MC34063. So the extra capabilities don’t come for free 🙂 Still, for reliability and clean design, I have decided to adopt it for all future circuits.


4. Other Solutions

The above has summarized the common choices I’ve learned through my experience. There are certainly other solutions as well. For example, you can use a transformer to step 24VAC down to 5VAC, then from that point on you can use a rectifier followed by a linear regulator to convert it further to 5VDC. This is fairly efficient because transformers can have high efficiency, and the linear regulator in this case is also efficient because the voltage differential is small. However, transformers are bulky and expensive. and this solution is not suitable if the input voltage varies across a wide range.

Another choice is to use a capacitor for current limiting, in conjunction with a rectifier and a 5.6V Zener diode for voltage regulation. The idea is similar to solution 1 above, except it uses the capacitor’s reactance (instead of resistor’s resistance) to limit current. Since there is little energy loss, this is very efficient and is similar to the transformerless power supply design, which is frequently found in small wall adapters. Unfortunately, to provide sufficiently high output current (more than tens of milliamps), you will a capacitor that has high capacitance (e.g. 100uF) and is non-polarized. This is not easy to find in real life.

transformerless_sch

Finally, you may be wondering why not use a resistor-based voltage divider to split 5VDC out of the 33V rectified input? Well, this is a terrible idea in almost any circumstance I can think of. The reason is that the output voltage will fluctuate considerably depending on the current draw. In other words, it is not regulated. So I can’t think of any real use of it other than providing voltage reference.

That’s all. I hope this blog post provides useful information for your own power supply design.


Hi All, OpenSprinkler will have a booth at the Bay Area Maker Faire again this year. Due to a number of reasons, I cannot make it myself, but Aaron Newcomb from California has generously volunteered to host the booth for me. He will be showing demonstrations with the OpenSprinkler controller. There will also be flyers and promotional materials distributed there.

In order to make this a success, we would like to have a few more people to help. If you are going or planning to go to the Maker Faire and can help at the booth even for just a couple of hours, that would be great and much appreciated. I am happy to send free gifts to you. Anyone who can help at the booth for at least 4 hours either Saturday or Sunday will additionally get a free Maker entry pass. This is covered by the exhibit.

If you are interested in helping, please respond to this forum post by Aaron, or email me. Thanks!


Bay Area Maker Faire Web Badge

Recently a random crashing issue has surfaced on the forum regarding some of the OpenSprinkler 2.0 development boards that we sent out a few weeks ago. The background is that we have started shipping a development version of 2.0 for any recent order of the assembled OpenSprinkler. The symptom is that some of the units started crashing and losing network connection, and this seems to be always correlated with the timing running crazy off the charts. Initially I thought this issue may have been caused by a bad RTC crystal, which leads to incorrect timing, and which in turn causes the controller to get stuck. Then at some point I realized all the problematic cases happened on a particular PCB version dated Nov 2012. This helped me narrow down the search range. After a thorough comparison to the more recent version, I discovered that the problem is actually caused by a noise coupling issue with DS1307 RTC. Specifically, according to the datasheet (right image below), the region around traces between the 32.768kHz crystal and DS1307 should be shielded by a ground trace. If this is not implemented, the crystal may pick up noise from nearby traces and cause the clock to run significantly off the charts. When I designed OpenSprinkler PCBs, I had not paid attention to this recommended layout at all. Jeese, why did’t I read the datasheet carefully!

IMG_2704ds1307_recommended_layout

After discovering the issue, I panicked a little bit. Since I didn’t know about the issue previously, and there are hundreds of boards in production at SeeedStudios, am I screwed? It turns out that the situation is not as bad as I thought. First of all, I usually add a ground plane to fill the empty spaces between traces. As a result, on most PCB versions, there is indeed a ground plane around the traces from the crystal to the RTC. Below are examples of the traces on OpenSprinkler 1.4s, the more recent version 2.0, and the version in production at SeeedStudios:

pcbtrace20pcbtrace14

pcbtrace20_new

Although they don’t match the recommended layout exactly, they are pretty good at shielding the crystal pins from picking up noise. You know, I have always questioned about those ground planes and wondered whether it’s worth my effort of adding them. Well, in this case it did save me from potentially deep trouble.

Now, in comparison, on the Nov 2012 version of 2.0, the ground plane is missing around that region (probably because there is not enough space between the traces to allow a ground plane). As a result, here is the PCB image:

pcbtrace20_alpha

Not only it is missing the ground plane in that region, but also there are all kinds of signal traces nearby, which makes is extra easy to pick up noise. This is bad, bad, bad. Now, that being said, even with the careless design, it’s not like you are guaranteed to have the problem. It more of a reliability thing: it increase the chance of noise coupling, but in many cases the issue probably doesn’t show up. In fact I was trying to reproduce the problem today on a particular PCB version that has no ground plane. After testing 8 of these, one showed a problem of extremely fast clock (5x faster than normal). And it turned out that I forgot to cut the crystal leads, which make them act like antenna to happily pick up noise. After cutting the leads, the clock went back to normal speed. This probably explains why the problem didn’t surface earlier even though I have never paid attention to the PCB trace around RTC previously.

The DIY version 1.42u is also missing the ground traces around that region. So I won’t be surprised if users have encountered a clock speed problem (although so far I have not received any report of it). In case this happens, an easy thing to try is to re-solder the 32.768kHz crystal and try to push it down to the PCB holes as much as you can. This will help reduce the length of the crystal pins and in turn reduce the chance of picking up noise. Another possibility is to simply solder the crystal directly onto the IC pins,

So overall this is a very valuable learning experience for me. I am grateful to those who reported the issue on the forum, and helped me figure out the problem as quickly as I can. There are about 10 of those Nov 2012 assembled boards out there, and I am happy to replace them for free. With that, it’s now time for me to revisit the datasheets. Never overlook them again!

The Cost of Development

During the process of cleaning up my workshop today, I collected all the OpenSprinkler prototype boards that have had design mistakes or were built and failed in the past, and looks at this whole box of lovely PCBs:

IMG_2671

Probably no less than 30 boards in the box. It’s quite shocking to realize how many there are. By far getting prototype PCBs has been the most time-consuming and costly part of the development process. First of all, each round of prototype PCBs costs about $50 and takes 9 to 12 days of lead time (using the fastest shipping option), from places like SeeedStudio or Smart-Prototyping. The cost is not dramatic, but the lead time is quite significant unless if I am willing to pay hundreds of dollars to order from US-based services. Also, these boards are unfortunately complex enough that home DIY PCBs are no longer a viable solution.

Then, no matter how careful I am in designing the PCB, there are always a couple of unforeseen issues that had to be discovered when I actually start assembling. For example, a component might be too far away from the enclosure cutout, a component footprint might be wrong, two components might be too close to each other, the pin headers were placed in the wrong orientation, and sometimes I forget to add a ground plane. Because these issues are only discovered after one round of PCBs have arrived (then I will fix the issues, refine the design, and order another round), they make the development process sequential and cause the overall time and cost to quickly add up. The good thing is that over time I learn from lessons and accumulate tips to help me maximally avoid potential mistakes. Still, it’s inevitable to produce design issues, which can only be fixed by putting in more money and time.

When I get the finalized PCB, however, I often feel proud, as if it’s a work of art which has been refined and polished and is ready to be seen by the public. Then I get a sense of achievement. That’s the joy of working on electronic circuits 🙂

I’ve made a minor update to OpenSprinkler Pi (OSPi), and the new version v1.02 has improved design of the separation pillars in order to make use of the screw holes available on Raspberry Pi rev. 2. See the picture below:
IMG_2669_a
This way, the Raspberry Pi rev. 2 can be more securely attached to the OSPi even with just two screws.

If you own a Raspberry Pi rev. 1 instead, don’t worry, you can still attach it to OSPi using the two edge screws (see the picture on the right below), in the same way as the original OSPi. To do so, you will need to move one of the separation pillars. See the picture on the left below (sorry, the arrow is pointing in the reverse direction).

IMG_2670_aIMG_2666_a

So in sum, the updated version OSPi v1.02 allows you to make better use of the screws holes available on RPi rev. 2 while still being compatible with RPi rev. 1.

Tags: , ,

« Newer Posts - Older Posts »