Nathan Campos


MintyVCAtt – Altoids Tin VCA

For the last couple of months I’ve been pretty hooked into audio projects, specially music creation related. This was the first quick project I’ve built to hopefully end up with a semi-modular synthesizer in a very distant future. The main idea is to basically build a bunch of the simple building blocks of a modular synth in the worst way possible, using Altoids tins and project boxes instead of a rack, which will make patching a real nightmare, but I’m sure will look even messier than a rack modular synth.

The final project

The project turned up rather well, it was designed to be extremely simple and easy to build, and had to fit inside the tin with the 9V battery and the connectors, this lead to some restrictions in the size of the circuit (compromises).

Schematic

As you can clearly see the circuit is extremely simple, but gets the job done quite well. I’ve used the simplest method of voltage controlled attenuation, the LED coupled with a LDR, this gives it very low distortion, but a very slow attack speed compared to other designs. The circuit accepts a 0-3V CV signal which controls the current thought the LED, so more CV means the input signal will be attenuated!

You can also notice something weird in the CV input jack, that’s a very handy trick to incorporate a power switch into a project, I learned this method from DIY stompboxes around the internet. The idea is that you connect your power negative to the ring (right channel) of a stereo jack, so that when you connect a mono plug into the socket, the ring and sleeve will be shorted out, connecting your power negative to your circuit’s ground.

Close-up of the circuit

The circuit is pretty simple and was made as a quick hack to do some audio experiments, but feel free to play around with it, and feedback is always welcome!


Flower Pot Night Light

A couple of months back (April if I recall) I was bored and looking for a nice project to kill some time in a rainy saturday. I decided to build a nice night light for my bedroom. I had a set of restrictions put in place so that I would be pleased with the final result, these were:

  • Must run on AAs
  • Adjustable intensity
  • Small and cute
  • Should be built entirely with parts that I had on hand
In use

The first challenge was to find a nice enclosure, since this was going to be used as decoration it couldn’t just be a bare protoboard with some LEDs or a boring project box. While looking through the pile of stuff (most people would call trash) I had stored in various places around the house, I found a couple of cubic flower pots made in various materials. I thought the ceramic one would fit my bedroom quite well, so that part was done.

Sanding the lens

The next thing would be to find a diffuser to cover the LEDs and and give a more uniform light. My first idea was to use acrylic or something like that, but sadly I didn’t have any on hand so I had to improvise. Again I went looking through my stuff and found an empty Ferrero Rocher enclosure (I knew I would use it some day), all I had to do was sand and cut it so it would fit the flower pot.

The finalized board

The last and most boring part was to solder all the LEDs, they are in a series parallel arrangement, with 9 parallel groups of 2 in series so that I could use a 9V supply. For driving them I decided to build a simple constant current sink with the two NPN transistors in a feedback configuration and designed it in such a way that it would be adjustable up to 100mA.

If you want to see more pictures of the whole process they are all available in this album:


Incredible Chinese USB Car Power Supply

Recently I bought a couple of those super ultra cheap cigarette plug extensions to distribute 12V in the lab for various things. As usual with everything chinese, I decided to open it up to see how horrible it was inside, but I also did that to upgrade the wiring since I would be pulling a couple of amps from this and I want to minimize the voltage drop.

This is the incredible thing I found inside the thing as the 5V supply for the USB socket. A 7805 regulator and a 20 ohm 1/4W resistor in series with the 5V output. I guess it could have been worse, they could have used a 5.2V zener or the worst of all just a resistive voltage divider.

China never ceases to amaze me.


MintyUSBoost: A tiny boost converter for low power projects

First of all a bit of a back story: This is my first attempt at a DC-DC converter, I’ve always thought they were magic black-boxes that you just had to accept and building one yourself without a dedicated chip was something extremely difficult, something that could only be done with some high-speed complex analog circuitry or high-speed microcontrollers. I think a lot of people think the same way and I decided to try out my luck and it worked fine, switchmode converters are not black magic (now only RF is black magic), and I hope I dismistify them for you too in this article.

The idea for this project came because I built a nice portable Class-A headphone amplifier (blog post coming in the future) and I wanted a simple power supply for it when I was using it with my computer, so I had to step the 5V from the USB to the 9V required by the amplifier circuit, the amplifier even though it’s Class-A has a low current consumption, so the 2.5W from a normal USB was more than enough. Taking into consideration all this I needed a boost converter with the following specs:

  • 5V input at 450mA maximum to work with any USB port
  • 9V output able to source up to 110mA (more than enough for my amp)
  • Acceptable voltage ripple and noise since this will be used with pre-amps and the headphone amp

As you can see there’s not a lot happening, and that’s the beauty of this design, since it was made for low power projects it doesn’t require any of the complexities, it was designed to be minimalistic and easy to build for someone that is new to switchmode converters. The entire feedback control loop is contained inside the PIC12F683 microcontroller, it is a pretty tiny and under-powered micro, but as you will see it works perfectly for this task.

First the power input goes through a 3.3V regulator which provides power to the PIC and also acts as a voltage reference, then the microcontroller takes control of things and starts the PWM, pulsing current through the main inductor L1 while sensing the output voltage, if the voltage is lower than the set voltage it increases the PWM duty cycle, if the voltage is higher than the set voltage it decreases the PWM duty cycle, and that’s all you need to create a simple switchmode converter. Here’s the code that runs the whole thing (I still need to improve it, so changes are coming):

/*
 * File:   MintyUSBoost.c
 * Author: Nathan Campos <nathanpc@dreamintech.net>
 *
 * Created on February 14, 2016, 2:45 PM
 */

//                        12F683
//                      +---------+
//                     -|Vdd   Vss|-
// 18MHz XTAL = CLKIN  -|GP5   GP0|- AN0  = Vout Sense
// 18MHz XTAL = CLKOUT -|GP4   GP1|-
//                     -|GP3   GP2|- CCP1 = PWM Output
//                      +---------+

#include <xc.h>
#include <pic12f683.h>
#include <stdint.h>

#pragma config MCLRE = OFF, CP = OFF, CPD = OFF, BOREN = OFF, WDTE = OFF
#pragma config PWRTE = OFF, FOSC = INTOSCIO

#define VREF 3.25
#define VSET 602
#define _XTAL_FREQ 8000000
#define HIGH 1
#define LOW  0

uint8_t sGPIO = 0;

void main(void) {
    OSCCONbits.IRCF = 0b111;  // 8MHz clock frequency.
    OSCCONbits.SCS = 1;  // Internal clock.
    
    // Setup the pins.
    TRISIO = 0b110001;
    ANSEL = 0;
    GPIO = sGPIO;

    // Setup ADC.
    ANSELbits.ADCS = 0b001;  // Fosc / 8 = 2.0us (4MHz clock).
    ANSELbits.ANS = 0b0001;  // Enable AN0.
    ADCON0bits.ADFM = 1;     // LSB of result in ADRESH<7>
    ADCON0bits.VCFG = 0;     // Voltage reference set to Vdd.
    ADCON0bits.CHS = 0b00;   // Select channel AN0.
    ADCON0bits.ADON = 1;     // Turn ADC ON.
    
    // Initialize the PWM module.
    T2CONbits.T2CKPS = 0b00;     // Timer2 Prescaler = 1.
    T2CONbits.TMR2ON = 1;        // Enable Timer2.
    PR2 = 0x19;                  // Period = 76.92kHz from datasheet.
    CCP1CONbits.CCP1M = 0b1100;  // Single output active high PWM.
    
    CCP1CONbits.DC1B  = 0;
    CCPR1L = 0;
    
    uint8_t pwm = 0;
    
    // ADC value.
    unsigned int res = 0;

    while (1) {
        __delay_us(10);  // Acquisition delay.
        ADCON0bits.GO = 1;
        while (ADCON0bits.nDONE)
            ;
        res = (ADRESH << 8) | ADRESL;
        
        if (res < VSET) {
            if (pwm < 253) {
                pwm++;
                
                CCP1CONbits.DC1B = pwm & 0b0000000011;
                CCPR1L = pwm >> 2;
            } else {
                pwm = 0;
            }
        } else if (res > VSET) {
            if (pwm > 0) {
                pwm--;
                
                CCP1CONbits.DC1B = pwm & 0b0000000011;
                CCPR1L = pwm >> 2;
            }
        }
    }
}

If you’re a bit more experienced with DC-DC converters you’ll notice that the components used are a bit overkill, but that’s by design because I wanted very low ripple at the output, also in the topic of components, I selected a IRL520 MOSFET and this is very important, since I’m driving the gate with very low voltages a logic-level MOSFET is a must, if you want to use a regular MOSFET you’ll have to increase the gate voltage using a technique shown here.

A very handy tool for everyone designing their own DC-DC converters is Adafruit’s DIY DC-DC Boost Calculator, it was extremely useful to choose the components used in this project and it’ll surely help you in yours too. I’ve also written a R script to have a offline version of the calculator, it’ll be improved in the future, but it’s usable right now.

The only issue that I’m having with this project so far is the fact that no matter what I try, I can’t get the crystal to oscillate, I checked everything, set all the registers correctly and I still can’t get it to work, if anyone wants to help it’ll be greatly appreciated.

Since all my designs have a lot of local decoupling to keep any noise or ripple from the power source away from sensitive parts I didn’t care too much about having extremely low ripple/noise, but if you want to upgrade this you can add a small shunt regulator to really kill any ripple or just add a LC filter to the output.

If you’ve got any questions feel free to ask and I’m open to suggestions for improvement.


I’m Back!

Sorry for this extremely long break, I’ve been extremely busy with a bunch of stuff from university and wasn’t feeling inspired to write any blog posts, but now I’m hopefully back and I have a lot of plans for interesting future posts.

This year I got overwhelmed by a shitton of university assignments and to top all that I’ve been exposing my projects at a bunch of trade shows together with my friends. If you’ve ever exposed things in trade shows you’ll know that it’s extremely stressing (before, during, and after) and time consuming, so I’ve been putting a lot of effort into that. The last trade show I’ve been to was called InnovaCities and it happened in Foz do Iguaçu, pretty far from home, and I had a great time there showing a much improved version of the lightwave transmitter and a automatic shower and sink that focuses on saving water which was a project I did with a friend that had the idea. We even had the pleasure of meeting some polish researchers and the prince of Nigeria.

Of course during this year I did a bunch of projects for myself including headphone amps, pre amplifiers, battery chargers, LED lighting, electronic loads, power amplifiers, and a lot more! I’ve also been experimenting with DC/DC conversion and power inverters which will be subjects of future blog posts.

One of the most notable projects I’ve been working on almost during the entire year is a battery capacity database ,which I plan to include all the batteries I can find, and be extremely helpful to determine which battery to buy next or estimate the battery life of your project with a certain battery, I’m currently working to create mathematical models of each battery. I’m so focused on this project that I’ve ditched the old super simple electronic load, which consisted of just a potentiometer, a op-amp, and a power transistor with a data logging multimeter, to a much better, automated, computer-controlled load that I named miniload. Discharging batteries now is a lot faster and a lot less problematic.


Power12: The Mini6 Again, But Better

I’m back with another amplifier project, but this time it’s kinda like a remake instead of a completely new amp. The story behind this project started 4 days after I completed the Mini6.

While I was drilling the holes for the jacks on the Mini6, I accidentally put too much pressure on the acrylic enclosure and it cracked, it was very small crack, practically impossible to see, between the two RCA jacks on the front, but after using it for a while and noticing how the crack would open a little bit every time I plugged something in, I decided to fix it using super glue (facepalm) and while I was using the glue I didn’t notice that one small drop fell in the PCB. I put everything back together and tested, it sounded horrible and when I looked inside I could see the stain of the glue which was destroying the sensitive part of the circuit. So in a moment of rage I decided to throw the whole amp in the trash and design a better one and put it in a better enclosure. So that’s how the Power12 was born.

The first thing I did to the original design was add a Zobel network to increase the stability of the amplifier. The other modification I did was the addition of a active load in the gain stage. Sadly when I was designing it I forgot to add another active load for the differential pair, but this will be fixed in the next revision of the board (I’ll also add a SIM).

Populating the board was a pretty straight forward process since there aren’t a lot of components to be placed and as usual the most difficult port was soldering the spade terminals to the ground plane.

This time I decided to use a very nice extruded aluminium enclosure that I found on AliExpress. I was a bit skeptical at first about the quality of the enclosures, but when they arrived I was surprised how beautiful they were, and the quality of the extrusion was really good. The seller was great, emailed me to ask about the customs, shipped extremely fast, and packed everything extremely well to make sure nothing would scratch the very fragile black paint of the case and the panels.

Since I decided to use a aluminium enclosure, the best combination would be a very minimalist design, so the only thing in the front panel is the power switch. This decision gave me the idea to place the power LED on the back, giving it a really cool look when it’s powered on.

Drilling the holes for the 2.1mm power connectors was a pain in the ass since I didn’t have a drill bit that was bigger than 8mm, so I was forced to use the “wiggle” technique to make the holes bigger and because of that the drill bit escaped the hole a couple of times and damaged a bit of the back plate, but since it’s on the back no one will ever see my mistakes.

The distortion figures are not the best you’ve probably seen (it’ll be a lot better when I add the second active load in Rev B), but it’s low enough that you won’t be able to notice it. The plot was created using a script I’ve created called plot_thd.py, running this SPICE circuit. Sadly I don’t have the equipment to measure the real figures, but I’m planing to buy a Keithley 2015 next month.

One thing that I actually was able to measure was the temperature profile of the amplifier, and as you can see it runs pretty cool with those FA-T220-38E heatsinks. Those figures were measured with the lid closed and with the amplifier right at the point of clipping with a 1kHz sine wave into a 8 ohm load. I’ve used my Agilent U1242B multimeter in conjunction with a program I wrote called dmmlog to grab the data, then plotcsv to generate the graph you see. Sadly I forgot to take pictures of the test setup.

If you want to see all the pictures of the project this Imgur album contains all of them. If you want to have access to all of the files related to this project check out the GitHub repo, and if you want to discuss it the best place to go would be the diyAudio thread.


Mini6 Amplifier

I was a bit bored a couple of weeks ago so I decided to design a very simple discrete amplifier rated for 6W/channel just to make sure it would’t oscillate and be more confident to build bigger ones.

As you can see it’s a fairly simple design with a op-amp pre-amplifier and a discrete power amplifier. Building it was extremely simple, the difficult part is always mounting all the panel components and wiring everything.

A while ago I built a program called build-bom to help me quickly find the component values when assembling a board. It’s a great use for a old EeePC that you may have laying around.

One thing that you may have noticed is that I’ve used canned transistors instead of your typical plastic TO-92. The only reason I did this was because they looked cool and I have a bunch laying around.

If you want to know more about the amplifier check out the GitHub repo.


Building the Mini12

Update: This project was my first try at building an amplifier, because of this it is pretty awful in terms of performance, it has very noticeable crossover distorsion. For better designs please look at newer posts here.

Last week, I decided to take on a very simple project: build a very low distortion, reasonably powerful, battery-powered amplifier that could fit in a very small, transparent enclosure that I had.

The main idea was to have this very small amplifier that could be moved around the house and powered from some 18650 cells so that I could enjoy some music with my friends when they come for our regular LAN parties. Usually we use one of those crappy iPod dock/speaker things that everyone loves, but, personally, they don’t sound very good to me.

Since this was a quick project, I decided to make it as simple as possible to avoid any trouble. The easiest it could be was to use an audio op-amp driving a class B output made with darlington transistors with some negative feedback to keep the distortion really low, so that’s what I did:

I also designed a very simple peak detector to detect any clipping on the output to make sure the signal was as clean as possible, but, sadly, my case was so small that I couldn’t fit it in. Since it would be powered from 2 18650 packs (3 cells each) or a pair of 9V batteries, the power supply is extremely simplistic.

When all of the parts arrived, I decided to get everything prepared to be assembled the next day.

Choosing where to put the jacks and switches was a bit tricky since the space inside the enclosure was extremely small.

Since I wasn’t patient enough to wait for a PCB, I decided to build the whole thing on a piece of protoboard which was a bit tricky because of the space the jacks took.

After soldering the headphone jack and on/off switch, mounted from the inside, it was time to solder the RCA jacks which had to be mounted from the outside. This was very difficult since I had to make the shortest cable possible while making sure that I could still lift the board up to solder the cable to the PCB.

Sliding the board back into place was extremely difficult, but after a lot of wiggling, it was perfectly placed on the bottom of the enclosure, and I was ready to plug the power jacks into the JST connectors on the board. It was the only way to mount them, otherwise I wouldn’t be able to lift the board to solder them.

Since it was 1:38AM, I was quite tired, and since I had been working on this thing for 7 hours and 12 minutes, I decided that it was time to sleep and leave the enclosure closing and testing for the next day. (Obligatory picture of the pile of wires and component leads)

First thing to do in the morning was to test the little beast. This was the test setup (after using my oscilloscope and a dummy load to make sure everything was working fine). I had to use the living room table since my bench was a mess (as usual), and there was no space for the 2 speakers.

And that’s all! If you want more technical information about the project, be sure to visit the GitHub repo. If you want to discuss it, jump on over to the diyAudio thread.


Low Power 120V+240V Isolation Transformer

Since I was tired of using the flash circuit hack (my version) to power my tube experiments I finally decided to build a isolation transformer using two identical step-down transformers as suggested by Mike in his nixie clock documentation. Here are some photos of it:

I’m planing to build a adjustable HV lab power supply in the future (which I may sell as a kit), so stay tuned.


Generic Chinese MP3 Player Teardown

As I’ve described in Unbelievable Prices, I bought a crappy chinese MP3 player to use as a “true” sound source (instead of the function generator I use while early-testing my audio projects) for testing my audio circuits without having to worry about accidentally shorting 12V into my iPod’s headphone jack or something like that while probing around.

Yesterday it arrived and as it was expected, it’s the best of Shenzhen. Horrible plastics and build quality, the buttons are super stiff, and overall a shitty product as it was expected to be, but since I’m only going to use it for testing, I don’t care. Here are some pictures of the “beautiful” thing:

As you can see it’s a typical chinese product. The LiPo battery has no markings, except for a weird XI logo, it doesn’t look like a protected pack and the flimsy wires that connect it to the main board can snap off at any second and short the thing out.

Board View

Right next to what looks like the main processor, which sadly I couldn’t find any information about it, there’s a very nicely heat-shrunk clock crystal. On the center of the board you can see a generic 4871 audio power amplifier, and on the left side there’s a BK1080 FM receiver IC.

On the other side of the board all you can see is the horrible LCD and the shittiest buttons you can buy in the Shenzhen market.