WS2812 level translator

WS2812 LEDs are one of my favourite toys. Apart from all the things that you can do with them in terms of lighting, displays or even light painting you can also use them for your projects as indicator lights.

The great advantage comes from the fact that you can use a single pin to drive so many of them and it takes just 3 wires ran across the whole box for practically any number. This in turn comes with the disadvantage of more complex control and problems driving them(5V devices) from a 3.3V microcontroller.

Although the data sheet states that you would need at least 3.5V for them to recognize as HIGH level(70% of 5V), many seem to have no problem being driven from a 3.3V micro. With the signal regeneration that each does, it is only a problem for the first one in the chain. But, as I found out, some LEDs simply don’t work as the first device, and to be safe it is best to use a level translator. Unless you completely forget about it and find yourself in need of driving a display with WS2812 which does not like 3.3V signals.

ws2812_level_translator_schematic

Luckily there is a simple solution with parts that you have available: just another WS2812 LED (or two) and a diode. The trick is to power the first LED in the chain from 5V via a diode dropping its supply to 4.3V*. At this level the 3.3V signal from the microcontroller is within specifications to be recognized as a high level. As each LED does signal regeneration the output of the first LED will be at a 4.3V level which is in specification for the next LED powered at 5V. If you need a longer cable between the microcontroler board and the LEDs, a second one may be included in on the board which will be supplied by 5V in turn regenerating the control levels to 5V.

 Below you can see the original 3.3V signal and the 4.3V signal after the first LED. Also notice there is stronger ringing on the 3.3V control signal due to longer wire from the microcontroller.3v3_to_4v3

And now the original 3.3V signal and the 5V signal after the second LED:3v3_to_5v

*Datasheet doesn’t specifically say what is the normal supply range for these LEDs, although many specs are provided for 4.5 to 5.5V supply. I found no problem with them at 4.3V in normal ambient conditions.

Update:

I decided to test the frequency of the PWM signal used in the LEDs as it seems to be unclear. The datasheet claims “scan frequency not less than 400Hz/s” but there was doubt whether or not this is the PWM frequency on some forums. With a resistor in series with the power supply I turned on only one color and tested the PWM frequency which was around 44oHz for a few of the LEDs that I looked at.

pwm freq and current

Heatsink Tester

Intro

It’s quite a common problem when building electronics that some components need cooling which is usually done through some sort of heatsink and optional fans. Choosing the right cooling solution can be a difficult task because the real life behavior of the system is hard to predict or model. In my case I have faced the simple question quite a few times: how much heat can a cooling system dissipate? The thermal resistance of a particular heatsink may vary quite a lot depending on the surroundings or it can simply be unknown to start with. The aluminum side wall of an enclosure made me build this thing.

 Design

This is why I have made this little device: a thermometer, a transistor and a microcontroller with a simple command line interface. I could have answered my questions in quite a lot of simpler ways, but since I made a simple thermometer not much else is needed to control the transistor when a DAC is available in the microcontroller.

The device works in a simple way: a specific power is dissipated on a transistor while a DS18s20 temperature sensor measures the temperature on the heatsink as close as possible to the transistor. The circuit uses a serial connection and is controlled via the terminal. A few preset values are available for the power to be dissipated.

The micro at the center of the project is an ATXMEGA32A4U and I am using a small board I designed for another project and another proto board which contains a current sensing resistor and a voltage divider to measure the supply. A TL431 is used as a 2.5V reference. The circuit uses two supplies, one for the micro which also contains a 3.3V LDO and one for the dissipating transistor. The schematic is shown below:

hs_test_schematic

The reason for leaving the supplies separate was to be able to use a wide range of supplies for the dissipating transistor; the circuit is designed to measure up to 52V input. Such a supply is too high for a normal regulator for the micro. If the allowed maximum is lowered, a regulator can power the micro as well. In practice it turned out the low power levels (0.5 – 5W) are regulated better when a low voltage supply is used for the transistor (3V). For higher output power (5W to 50W) a 19V laptop power supply worked just fine. The limit simply comes from the ADC precision and the value of the current sensing resistor.

An IRL540 transistor is chosen as the dissipating element due to its low threshold value. This is necessary to allow driving from a 3.3V DAC, considering the voltage drop on the current sensing resistor as well. This was chosen as 0.1 ohm, which corresponds to about 0.25V of drop while dissipating 50W from a 19V supply.

DSC_0852DSC_0838

Due to the high thermal inertia of the system, a very simple regulating method was chosen: if the dissipated power is too low, the DAC output is increased, otherwise it is decreased. This produces some oscillations around the set value, but if the power is averaged over one second a very stable value is obtained. The control loop runs a few hundred times a second, data averaging and display is controlled by the RTC.

The microcontroller calculates the thermal resistance of the heatsink assuming that the start of the experiment is at ambient temperature. The circuit needs to run until the temperature of the heatsink stabilizes to the new value. The time required depends on the system, but in practice I found 1h to be sufficient.

The software allows for very simple functions, but I found it to be sufficient: choose the power to be dissipated and start and stop the experiment. The software is available for personal use. Data is sent out through the serial port and can be viewed in a terminal, the supply voltage, current, calculated power, DAC set, temperature and calculated thermal resistance are sent out.

NOTE: there is no protection for the overheating of the transistor, since its temperature is not measured directly. It is up to the user to make sure the dissipated power is chosen appropriately for the heatsink size. When mounting the temperature sensor it is important to have it thermally coupled to the heatsink and insulated from the ambient. 

Experiment 1

A small heatsink is placed in a small box and 5W are dissipated. Other components are added around to mimic airflow restrictions. After half an hour the temperature stabilizes around 72°C indicating a thermal resistance close to 10K/W. This is pretty good, considering that the manufacturer rates it at 14K/W.

DSC_0857

 

DSC_0858

Experiment 2

This experiment is actually the real value I was interested into. The side of the enclosure is made of aluminum and it allows for transistors to be easily mounted. But neither the seller nor the producer were able to say anything about the dissipating capabilities.  By dissipating 20W the final temperature reaches 52°C which indicates about 1.3K/W thermal resistance. In practice such a high temperature is uncomfortable to the touch but does not burn, so a circuit should dissipate lower, depending on the application. Plotting the data gives out a nice curve with the temperature variation. The output log is available here. 
DSC_0866

DSC_0868

20W_graph

 

Future work

The whole thing is build as fast as possible using a PCB I already had. A next iteration would include a dedicated PCB, with its own LCD and with a nice PC application. A case would also improve the project.

LED logger V2

Check out Part 1 and Part 3 of the project

UPDATE

Led Logger V3 is up and running!

The experiment is stopped. The Logger has malfunctioned and is in a location that I cannot access. I will fix it and resume as soon as possible.

Intro

I’ve previously wanted to know how much do cheap led strips last: turned out they don’t even pay for themselves over incandescent bulbs. I’ve decided to extend the experiment to more kinds of strips and address some concerns about the experiment expressed by the readers.

 LED logger V 2

In short:  8 channels, internet connected for live data visible by anyone. The experiment is trying to measure the light intensity variation over time, while maintaining the environment conditions constant.

Power supply: all strips are designed by their manufacturer to be powered from 12V. A 12V stabilized supply is used to power everything. In the first experiment I have periodically checked the voltage across the strip and found it to be constant. Now, the voltage is measured and plotted.

Temperature: all the strips together will dissipate around 2-3W and are placed on a big aluminum plate which is the box front panel. With what I have so far (4 working nonstop) the temperature of the panel raises 6 degrees C above ambient. The whole box is placed in a well-ventilated area inside the house, with an ambient temperature around 25 deg C, with small variations throughout the year. Therefore the strips are well cooled and operate in a rather constant temperature.

Sensor degradation: in order to verify that the sensor is still reporting correctly I have installed a strip that will only be lit for a short time at each measurement to check that the sensor has not changed. By measuring a strip identical to the first I have found that the sensor produces identical results, so there is no degradation over the 1400 hour time first experiment.

Current Data:

Here’s how the current data looks like:  https://cosm.com/feeds/82160 . For more information about the strips, see below.

NOTE: At the moment the software has 2 bugs: It sometimes stops updating, although the LEDs remain on. So the values for the LEDs are correct, but may be old; i’ll periodically reset the device to ensure fresh data is available. Also, the PSU voltage seems to have measurement errors at the first readout(I’ve checked with a voltmeter, there’s no fluctuation in the PSU). So, out of order values for PSU voltage should be ignored.

Meet the candidates

The control strip is identical to the strip used in the first experiment, except that is has not been used. It turns out that it produces the exact same readout as the first strip, meaning that the sensor has not been degraded over the 1400 hours of initial test. The control strip and the original strip are the best aligned to the sensor.

Strip 1 is the strip used in the first led logger. It starts with a 1400 hour usage.

Strip 2 is made by Optoflash, it’s similar to the others except that the light is cold white. It’s a bit more expensive, comes from TME and there are no details about lifetime in the datasheet, but at least there is some sort of datasheet.

Strip 3 is an Ikea ledberg strip. It’s rated at 20.000 hours, but without any info as to how this time is measured.

Strip 4 is actually a waterproof module from a local shop that I paid about 1 EUR for. I don’t know anything more.

Strips 5 to 7 will be determined and added later.

The logger

Its PCB is developed from that of the ego box, replacing the 7 segment drivers with 8 channel high power drivers. Everything is based on tuxgraphics.org web client and someone has already done the task of making it work with Cosm (ex Pachube).

Schematic is quite trivial, you have your micro, your Ethernet chip and some MOS transistors to drive and control the LED strips.

Everything is built around the same box used in the previous project. The three wires in the middle are for three extra channels.

The data

The intensity of each channel is measured every hour by turing all channels OFF and then measuring each intensity. After that, all the strips except the control turn back on. Data is uploaded to Cosm and can be found here https://cosm.com/feeds/82160.

Now it only needs time to add data points and check how these strips compare.

 

 

 

 

 

 

Blue Panda

Intro

I was really impressed by how well the Serioux Panda Shaped stereo speakers performed when I received them as a gift. They have a really good sound, there’s a lot of improvement compared to the speakers in my laptop. But this is not what I want to use them for; after all, I’ve got two huge speakers by my laptop. I wanted some portable speakers. With Bluetooth.

 The panda

The Panda speakers are rated at 2x1W (but I suspect they can do more) and contain a TPA6020A2 bridge amplifier. Audio quality is impressively good for their size. This is why I considered them useful for broadcasting music wirelessly in another room.

The energy source is actually very simple: the Panda speakers need either 3 AAA batteries or 5V from a USB port or phone charger or, in my case, a portable battery. So using them with a portable battery makes them portable… except that they are not wireless. I remembered I had a Bluetooth headset bought specially for sending audio from my phone to another room which I don’t need anymore.

DSC_6036

 

The blue panda

When I initially bought the Bluetooth adapter I did not require or expect good quality so I bought the cheapest I could find, but it turned out that it has very good audio quality. So I decided to pair them together. Luckily the Bluetooth adapter fits perfectly inside the three AAA battery case at the bottom of the panda after removing the contacts and some tiny spacers. The buttons stay flush with the panda so they are not pressed when it is seated on something.

DSC_6040DSC_6034

The Bluetooth module is powered by a lithium battery which I removed. To power it I will be using the 5V from the panda with a 1N4148 diode in series. This, along with a Schottky protection diode inside the Panda, brings the voltage down to about 4V, right what it is expected from a battery. The microphone was removed, but i am thinking of installing it back so that I can use the panda as a call speaker.

DSC_6041DSC_6038

I did not want to lose the possibility to send audio through the cable to the panda, so I decided to keep its cable. To make it use both audio from the Bluetooth module and cable I summed both signals through 1K resistors before applying them to the original 10K potentiometer (I matched 4 resistors with the potentiometer since I only had 5% tolerance available). This works perfectly as a mixer letting the panda use both sources at the same time, but I can’t seem to find a situation where I could use it like this.

DSC_6043

The finished blue panda looks just like the original one, except the bottom where there are the controls for the Bluetooth. The final audio quality and power are very good and fits great for my need. I believe that if I were to buy same quality Bluetooth speakers I would have to spend a lot more money than these two cost combined.

Here’s the final device sitting on top of my 4×18650 portable USB charger. Given the capacity of the battery i would say I should get at least 20 hours of music at moderate-high levels.

DSC_6049

 

 

LED logger

Check out Part 2 and Part 3 of the project

Why?

About half a year ago I installed a 3 meter warm white led strip above my desk. Although I didn’t spend a lot of money on it I am really happy with the light quality and intensity. Lately I was thinking about adding more LED strips and was checking the options. One important aspect that comes to mind is about the lifetime of these products, are they better than bulbs, overall? Obviously there’s no specification you can trust anywhere. So, how do I know if cheap strips are good enough or it is worth spending the money on more expensive ones? Measure some data for the cheap ones and see if they are good enough. The experiment was designed to be simple, not extremely accurate.

Update:

The measuring method has been criticized, and some of the claims are fair: there’s no control and the sensor may degrade. I have stopped the experiment after 1400 hours to upgrade it. But first, i replaced the measured strip with an identical, unused one and the sensor reads exactly the same as in the beginning. So, there is NO sensor degradation. Later, when the measurements will reach the 70% threshold i will replace the strip with another identical unused one and compare the sensor readout. This should eliminate the sensor variable and provide control. See new experiment, LED logger v2.

The Logger

I setup a very simple device, for first measurement attempt: a metal project box houses 15 cm of unused strip that shines light on a TLS2550 sensor, everything being isolated from ambient light. The strip is placed on the aluminum front panel of the box, providing a great amount of cooling for the strip, much more than real life applications where it could be mounted on wood or walls. The box is sealed so there’s no ambient light going in of dust.

This sensor is really great: it has I2C interface, high dynamic range and approximates the human eye response, giving the result directly in lux (after some math). I’ve used a microcontroller and an EEPROM memory with a couple of years of space, storing data every 6 hours. There’s a serial port that provides a simple interface with an instant read, memory erase and memory dump. Current is measured over a 2 ohm resistor and stored as ADC counts. The used board is Arduino compatible, but it was not used with the Arduino environment, just your regular C.

 

Results:

The light has been on continuously for about 700 hours, almost a month 1400 hours, two months.. The graph shown below will be updated periodically.  So far, the LED strip has dropped about 12% 18% in brightness compared to the beginning. Current has stayed the same, meaning that they are actually reducing their efficiency.

 

Although it is too soon to tell exactly I decided to try to predict the life of the LEDs. Since they don’t burn but rather fade, I think that the point where they dropped to 70% of initial intensity is a good mark of their end of life in applications where they are used for lighting and not decoration.

Using an exponential projection I found that it will take just 2200 hours until the LEDs drop to 70% of their initial intensity. This is rather disappointing, even for cheap LEDs. In about 2-3 more months I should know for sure how good this initial prediction is, but I doubt it will be too far from the truth. UPDATE: after about 1400 hours of use, the prediction still stands, the strip will fall to 70% around 2200 hours.

 

How bright is a LED strip?

A while ago I made an experiment which tried to find out how much light a 3m led strip could give. Obviously lacking any specialized equipment I tried to compare it to some references. I used a room and cut the strip in 50 cm pieces and grouped them on the ceiling. I used my camera to determine the correct exposure of the whole room. Next I proceeded to replace the LED strip with bulbs that could give me the same exposure. I found that I need a 25W and a 40W incandescent to arrive to this. According to the bulb packages they each give 200 and 400 lm, totaling 600 lumens.

Using my modified power meter I found that the strip consumes 14.3W from the mains. This means that the LEDs are about 42 lumen/watt, which, as an idea, is comparable to the worst CFLs and is still rather poor for LEDs. But, do remember that this takes into account the PSU, which is the right way to evaluate for practical reasons.

 

LED strip vs incandescent: Preliminary conclusion

Based on the price I paid for the LED strip (~4.5 EUR/m), local electricity price of about 0. 09 EUR/KWh and bulb price, but excluding the LED PSU and workmanship for installing everything it takes 2800 hours for the LEDs to become cheaper than the incandescent.

Since my strip is not considered useful after 2200 hours as it becomes too dim, it means that it is not a cost effective solution for illumination, compared to incandescent bulbs. LEDs are supposed to save energy and money. It appease that low cost strips are not a good way for that.

What about more expensive LED strips? I used the same thinking as above and found more expensive strips with Nichia LEDs require about 7000 hours before they become cheaper than incandescent, again excluding the PSU. This is a rather rough estimation considering the brightness and efficiency specs are right. Again, the manufacturer of the strips doesn’t give any data about the intensity decay, so the cost effectiveness of the solution is still unknown.

 

Download

The code for the logger is available for download here. It’s free for non commercial use and rather unpolished.

 

Idle power consumption

Why

I was thinking about building a sensor network based on small wireless routers, like the TP Link TP-WK703N. The OpenWRT page states 0.5W while idle, but the measurement is made for what goes into the router, not what is drawn from the network. So, I wanted to see how much the mains power consumption is, and while here, measure some idle power for other devices around the house.

How

At first I thought about building some energy meter, there are a lot of designs out there, starting with Atmel’s app note for a real meter and ending with simple DIY ATtiny meters. But then I remembered I had one of those simple plug energy meters. It is rated for 5W to 3.6KW, not suitable for my needs, so time for hacking.

I opened up the meter and found two boards inside: one seemed to take care of the display, the other to do the measuring. The display board contains two crystals, one for time keeping and the other for regular use, i suppose.  The connection between the two is power plus another pin, indicating that the metering is probably sent as pulses. So, the easiest way to make this more sensitive is to simply swap the current shunt with a larger one. Two multimeters and one amp later the shunt proved to be 1.5mΩ.

Nothing simpler, I would upgrade that to 150mΩ and make my device 100 times more sensitive, capable of measuring 0.05W to 36W. I built the new shunt out of three 0.1Ω, 1W resistors since this is what I had available.

I tested the new meter using some resistive loads, somewhere around 0.1W, 1W, 5W which is the area of interest, plus 25W. A multimeter provides the exact resistance and mains voltage, computing the power which is the compared to the meter. As I expected, lower powers are underestimated, 0.1W is underestimated by 40%, while 1W just by 9%. 5W and 25W loads are correctly measured. A little work gave me the correction curve for loads under 3W, higher than that needing no correction. The correction formula is as follows: corrected_value = original_value * (-0.107 * ln(original_value)+1.1419), only if original_value < 3W.

Results

I couldn’t test the 703N router because I have accidentally ordered its smaller brother, the 702. Specs are similar, so results should be similar. It turns out it draws under 1W out of the grid while idle, which is good enough.

Next, I grabbed the Raspberry Pi and did some measurements on this, since most available data is just current drawn by the Pi, not total mains consumption.

Power consumption with Ethernet, mouse and keyboard topped at 3.25W, showing insignificant variations with various activities, mostly because there’s no CPU frequency and voltage scaling. There’s a small power reduction by removing the monitor and some by removing the mouse and keyboard. Leaving just the Ethernet connection reduced consumption to around 2.75W.

After that I started measuring all sorts of power supplies and standby appliances from around the house, plus I bugged some neighbors. Data is in the table below.

Most adapters are SMPS, I could only find a couple using classical transformers. All switch mode adapters except one stay below the 0.3W limit while idle, with a few of them going below 50mW which is the lower limit of measurement on the hacked meter, so nothing is read. On the other hand, devices which have some sort of standby mode will be close to 1W, probably because they might need to keep some circuits running.

The adapters using classical transformers, indeed burn more power unloaded. I was surprised to find one that uses 2.7W and that a 10VA PCB mount transformer with just a LED drawing 0.2W draws close to 2W from the mains, no wonder they get so hot unloaded.

The table below gives more data on the measurements, the ‘Corrected Power’ column contains the corrected measurement, based on tests with known loads.


 

Auto AMP

Why

I have realized that amplifiers used around PCs (even if they are just found in active speakers) will be turned on a lot of time without actually being used, thus burning a lot of power for nothing. So, I wanted to build a circuit that will turn on an amplifier only when there is signal present.

Is it worth it?

The circuit below costs about $3 in parts  and  is placed inside a LM1876 amplifier which consumes about 15W when it’s idle. If it saves 10 hours per day worth of idle time, its cost will be made up in electricity savings in just half a year, based on my local electricity prices.

How

Since the amplifier is used for a PC, I decided that a good way is to power the circuit from a free USB port. I wanted to make it as simple and elegant as possible and my thoughts stopped at using a microcontroller. A quick oscilloscope plot showed me that 10-20mVpp applied to an amplifier with the volume knob halfway will produce an output which is borderline low for listening, therefore I had an idea of what magnitude of signal I should detect.

At first I thought that running my microcontroller at 3.3V (which would produce a 3.3mV step with a 10bit ADC) would be better suited. But practice showed that 5V is still ok, with about 5mV in ADC step.  I experimented a little and found that a 15mVpp threshold (3 ADC counts) is sensitive enough to detect even low level music. On a desktop computer that I have tried, turning the volume up to the last 20% or so produces enough hisses from the onboard sound card that will continuously trigger it, but this is not a problem in real life for me, nor was it with other sound cards.

The circuit is built around an ATTINY13 which is what small micro with ADC I had around. Both left and right channels are measured, though one should be sufficient. The AC audio signal is shifted to about half the 5V supply. For each channel, the microcontroller will take a number of samples while retaining the minimum and maximum values. This gives the Vpp measurement of the audio signal which is compared to a threshold (in this case 3 counts). If the signal is high for enough time the amplifier is turned on, and each time signal is detected a turn off counter is reset. Should the counter reach a certain value, the amplifier is turned off.

 

I decided to make each measurement 1 second long, with a sampling frequency of 1 KHz for each channel, which is not that relevant. To turn on the amplifier I require that 3 consecutive measurements show there is signal, which should make sure that short sounds from the computer are ignored. For turn off, I chose e 3 minute timer. Of course, all timings along with the threshold are configurable from the software.

A 5V relay powered from two microcontroller pins is used to power up the amplifier. I have built a prototype of the circuit and installed it in my old LM1876 amplifier. It can put out 2x20W while consuming 15W of idle. The power switch was replaced with a three position siwtch functioning as ON-OFF-AUTO (S1 on the schematic) allowing the amplifier to function either in an auto or in an always on mode, apart from the required OFF. A couple of days of testing showed that the circuit behaved exactly as desired. It’s built on a 4 x 5 cm protoboard, but could easily be made smaller.

Below: the interior of the DIY LM1876 amplifier. The amplifier board is on the top left, while the auto amplifier is in the center of the picture. The relay(in white) is used to switch on the mains power, before the transformer, thus the amplifier itself will consume zero when it is off. The 5V is provided from a USB port of the computer it is used for, making everything off when the computer is off.

 

Download

The source code is available for personal use here.

Digital Power Supply – Part 2: Prototype

Check out Part 1 and Part 3 of the project

Introduction

After learning about the problems with the ADC and DAC of the XMega I gave up building this power supply until recently when I decided to see for myself how bad things are. I’ve used the header board, a 2.56V reference some potentiometers and a lot of patience.

 

DAC

On the DAC side things are quite ok. The minimum output is about 30mV for 0 loaded into the DAC register. Using the factory data to compensate decreases the output for 0 to about 10-12mV, but it is useless since some code values afterward are outputting bad values until it gets to about 100mV when things start to be ok. I’ve tested the DAC for about 40 values throughout the scale (some far from each other, some close) and after manually subtracting the offset it turned out that the DAC  had a consistent gain error of + 1.4 to 1.6% (using factory calibration data). So, all ok here.

 

ADC

I’ve used the recommended settings from here: Use it with external reference, differential mode and measure the ground level. PA0 is used for external reference, PA3 is connected to ground and used as NEG input and the rest of the channels are used as POS inputs. PA4 is connected to ground for measuring the ground level. As it turns out, the ground level fluctuates around -5…-8LSB constantly. I am reading the ground level, then the desired level and subtracting. The result has a lot of noise, so I am averaging 8192 values to get a reasonably stable result. Probably better filter methods will require fewer readings. As with the DAC, I’ve used a potentiometer to feed the ADC different voltages and measured the results for about 50 points. Apart from the huge noise, the error stayed constantly below 1%, except for voltages below 20mV which had a larger error.

 

The prototype

With the above in mind it seems possible to use the XMEGA for a digital power supply. Just after the experiments I’ve discovered that the errata claim large errors for reference voltages above 2.4V so I’ve moved things to 2.048V. Since I didn’t have a proper reference IC, I’ve divided the 2.5V from a LM285 with a pot. With this in mind, my prototype could turn into a 0-20V, 0-2A power supply, with 0.01V setting resolution and 1mA current limiting resolution. But, given the DAC lower limit at about 30mV, the minimum voltage would be about 0.3V and the minimum current limit about 30mA. I can live with this.

I already had a prototype board from long ago (before my enthusiasm was killed by learning about the XMEGA problems), but some modifications were needed. The schematic evolved a bit from the ###previously mentioned prototype. Some additions were required to make the supply stable and adjust it to the above mentioned range. The board requires 5V input because it was meant to connect to a LCD too and has a 3.3V regulator for the XMEGA. For the high power part, I’ve used a 25V input from another power supply.

The schematic for the analog part is below, there’s nothing special about the digital part, I’m just using the USART to get data around.

 

The ADC connections are made as i’ve described at the beginning:

The prototype is built around a tool box, it’s not meant to take a final form as a working PSU. The goal was to put it together in a single piece so I could handle it easily.

Adjustments

So far the software is rudimentary, it just outputs a predetermined DAC value and reads the ADC and sends the corresponding voltage and current through a serial port to display on a computer. There are three adjustments to make. The first one is to set the reference to 2.048V (really high precision is not necessary since it is used both for the ADC and DAC). The second is to adjust the pot on the voltage divider for the voltage measurement. I set the supply to output about 10V then adjust the pot until the multimeter and the supply read the same value. The third is to adjust the current gain pot and it is done in a similar way: the supply is set to limit around 1A and then the pot is adjusted until it measures what the meter reads.

Once this is done, I set the DAC to 100 and measure the output voltage: this will let me calculate the voltage offset. Then I adjust the DAC value until I get 10V output. With these two values I can calculate what I have to put into the DAC to get any voltage I want. The same is done for the current limiting. For the prototype I am using a spread sheet to calculate the DAC value for the desired output value, but a final power supply will do this all on its own.

With the calibration done I’ve tested the supply for some common used voltages and the results are surprisingly good. Below 15V the error is maximum 10mV which is just as desired.

 

For the current limiting I get zero error for larger values (due to multimeter resolution limit) and a bit higher for lower values, but this is not a problem since the current limit is usually not required to be very precise.

 

Transient response

Below is a transient response when connecting a 10 ohm load when the supply output 10V, so a 1A load. As you might see, there is just a slight voltage drop at the output, but it stabilizes quickly. CH1 shows the voltage, CH2 shows the current with 1V/div = 1A/div.

With the current limit set to 1A, the supply is shorted through a 0.1 ohm resistor (which is used for current measurement) . There is a high peak due to the 100uF output capacitor and the supply’s response time. This peak may be reduced by reducing the output capacitor which is a thing that I will have to determine. The supply stabilizes to the set current limit in about 500us which is sufficiently fast.

The same situation as above, but this time the current limit is set to 0.1A. Again, there is a current spike due to the output capacitor:

The more common situation is when the supply has to limit the current but without having a short. The picture below shows what happens when connecting a 36 ohm load while it is set to output 10V and limit the current to 0.1A.

 

Conclusions

With these results in mind I think building this supply is actually achievable using the XMEGA. It can be done as a single board device and for a low desired power it can be made very compact.

Limitations:

– Minimum voltage is 0.3V (for 20V max scale)

-Output voltages below 1V will not be as precise as the rest (for 20V max scale)

-Minimum current limit 30mA (for 2A max scale)

-Output current limiting below 100mA will not be as precise as the rest (for 2A max scale)

-ADC needs a lot of samples to get stable results

 

Things to add for the final version

-lots of software

-temperature measuring for heat sink + maybe fan control

-soft output on/off

-bicolor LED for constant voltage/constant current

-display

-rotary encoder + buttons

-added bonus: 1-2 channel voltmeter: quite often I find that it is required to measure a voltage on the circuit that I am working on. Having this directly in the power supply helps a lot.

 

 

 

 

 

Fun with LEDs

Introduction

I have recently stumbled upon some LED strip at my local electronics shop and decided to give them a try. I bought some which I used to replace the spot lights in the kitchen. It is cold white, which is surprisingly good, especially for night time illumination (think moonlight like hue). It works at 12V and consumes about 0.25A per meter.

After installing the strip, some automation proved to be necessary, and so the following circuits were built. The goal in mind was to keep things as simple as possible and use only parts I had at hand, which is why the solution might not be the best.

The hallway spotlights got new white LEDs as well and a light sensor. Tiny PIR sensors will turn on the lights in the kitchen and bathroom when someone comes in range. The sensors are rather popular modules using a BISS0001 IC; they provide a 3.3V level for an adjustable time when motion is detected.

Overall the results are great. The hallway is lit at night, the there is a small automatic light for the bathroom and the automatic kitchen light is bright enough even for day time illumination of the sink and counter. The slow turn off provides both a visually pleasing effect and a warning in case someone stood still long enough to make the light go off. I am still looking for a simple solution to produce the same effect on turn on, but without the delay.

 

Simple light sensor

The circuit is used to turn on the hallway lights. T2 will turn off when it is dark enough, allowing T1 to turn ON and light up the LEDs. The threshold is determined by the divider formed with a photo resistor and a potentiometer. I gave up using a constant current supply in the favor of a simple current limiting resistor because at around 100mA of current (set with R3) there is no danger of thermal runaway.

The circuit was built inside a small remote control case, here it is at first tests:

 

Simple PIR sensor

The PIR sensors themselves cannot turn on a strip of LEDs so, for the bathroom light I have used a simple transistor amplifier. The light is made up of just 20cm of light strip consuming about 50mA, but it produces enough light for a sleepy person to be able to use the bathroom without the need of the bright waking main light.

Driving the transistor through the diode insures and instant on, but once the PIR turns off, C1 will discharge through R2 slowly turning off the LEDs during a few seconds. My initial desire was to have the same effect at turn on, but the time required to charge the capacitor up to the threshold voltage will produce a few seconds of delay which in practice causes undesirable effect.

Note that I have symbolized the LED strip through its basic cell, 3 LEDs in series with a resistor.

And the assembled circuit on the cap of a wiring box:

PIR and light sensor

For the kitchen strip I wanted both of the functions above: a dim light when it gets dark and motion sensor turn on. The circuit is not exactly the combination of the two since I had to take into account different things.

First, the light sensor was simplified since I found out that 10mA (limited by R7) worth of current through the strip produce enough light for the night (yes, that little current makes the strip give enough light to see what it is in front of me). This means that a single transistor is enough.

The light sensor turn on circuit became a little more complicated, mostly due to the parts I had available. The transistor has to drive more current (close to 0.5A) and support the heating produced during the slow turn off when it will dissipate more power. The only suitable transistor I had available was an IRF9530. This required another transistor to drive it. Just like the previous circuit, turn on carried as fast as possible, but the light turns off in a few seconds. R6 was initially 150K, until I discovered that this produces a delay in turn on. It may be simply shorted.

Schematic:

I first fixed the PIR lens and then inserted the photoressitor inside it:

The finished module (some resistors were still changed  afterwards):

Installed in the kitchen (still needs some to get some wires arranged):

The mounting conditions forced me to use an aluminum profile for first fixing the strip onto it and to split the whole thing in two pieces. Unfortunately, Murphy caught in:

Other notes: The strips were sprayed with a few layers of acrylic to ensure good insulation, just for added safety, as the power supply is insulated from the mains.

 

The math on consumption

I did some math on the consumed energy. The power supply spec says that it should consume less than 0.3W unloaded. So, per month, that gives:

0.3 * 24 * 30 = 216Wh;

Assuming the night lights turn on for an average of 12 hours per day, this gives:

(0.1 + 0.01)  * 12 * 12 * 30 = 475Wh;

2 hours (exaggerated)  of daily kitchen use:

0.5 * 12 * 2 * 30 =  360Wh;

2 hours (exaggerated)  of daily bathroom use:

0.05 * 12 * 2 * 30 =  36Wh;

Monthly total:

216+475+360+36 = 1087 Wh, or approximately 1 KWh per month., which is very little.

Unlocking stuck photo filters

Normally, you shouldn’t mount a polarizing filter on top of an UV filter. If you do, there are big chances that they will be hard to unscrew afterwards, mainly because of the rotating part of the polarizer. You will probably end up removing both of them from the camera, just like below:

There are a few solutions to unlocking them out there, including the professional one of getting filter wrenches, but I’ve got a simpler method. All you need is a ribbon, like this:

Wind it around the filter so that it “grabs” both the fixed and the rotating part of the polarizer. Hold one end of the ribbon between the index and the middle finger and the other one between the index and the thumb.

Make sure you leave a little to have some slack here. Now, use the thumb to press on the little extra ribbon as this creates tension.

The tension is enough to firmly grab hold of the filter and allow you to use the other hand to unscrew the UV filter.

The good thing about this method is the ease of finding a ribbon. You can use one from flower bouquets or even a shoelace!  It is usable just as well to unlock a filter that it is stuck on the camera.

1,922 views since Nov 2016