9V/1kV DC/DC converter

Currently I'm working on a device to electrocute home insects like cockroaches, progress is small because they are smarter than I thought, but that's a different story. For that project I had to find a source of sufficient high voltage and output power. Presented in previous post 5V/400V converter had insufficient voltage and power, another option, flyback transformer was too dangerous to be used here.

Finally, I have made a new high voltage supply based on an inverter transformer and voltage doubler. It seems to be ok for this job, but it can be used in various other applications so I'm presenting it in a separate entry.

Warning! the device produces high voltage that can be lethal, if you want to build it, please take cautions.

The transformer was salvaged from old LCD monitor, it was used there to power fluorescent tube. It costs around 6$, so they are not expensive. Unfortunately I couldn't find Eagle component library for it, so I had to make a new one. Q1 initially hasn't had a radiator, but later I added a small one because it was getting warm.

Full output voltage is present on R11, so it was protected against accidental touch by using a shrink tube. It's not the best way, but it's still better than nothing. All connectors have latches to avoid accidental slip out - important, especially for high voltage ones.

High voltage traces have bigger clearance to prevent spark gaps. Positive power supply rail has bigger width, because the current is around 330mA.

As visible on the rendering, by an accident I swapped top/bottom layer of two diodes. Opss!

A square generator is made from IC1A and IC1B, frequency depends on C1, R3, R4, pulse width depends on an R3 and R4 ratio. The signal is buffered by using IC1C and IC1D. Voltage doubler is made from C9, C10, D4, D5.

Output voltage = 1kV is at frequency around 11-14kHz, to minimize power consumption, I decided reduce output voltage to around 850V, this is equivalent to 5kHz from the generator.

If nothing is connected to the output, then even after power was turned off, C9, C10 can store enough power to provide unpleasant shock. To protect against that, discharge resistor R5 was added. C9 doesn't have one, so it keeps a high charge even after the device was powered off.

Input voltage = 9V DC, power consumption = 3W.

R3, R4, C1 may be chosen differently in order to provide a a bit lower/higher voltage and smaller power consumption.

Below is the signal on Q1 gate.

Output voltage changes over time mainly due to temperature changes, it's visible on below picture. No load, temperature of room, voltage on the output. Graph was made using scripts that I presented in this post.

Please ignore SV1 and R1 - this part is completely wrong - pin 1 of IC1A should be connected to Vdd or to pin 2 of the same gate. This area was supposed to turn on or off the generator by using an external control module, but it should be connected with pin 8 of IC1C and 12 of IC1D. In the current implementation, when the generator is disabled, t1 is fully opened. Dummy error.

Eagle files for this project can be downloaded from my GitHub repository.

At the end, just to show what I'm working on now, below is a movie of an electrocuted cockroach. Don't watch if you are sensitive!

Conway's Game of Life - online JavaScript version

Game of life is an example of a system with very simple rules but unpredictable state in the long term.

Each square represents a living space available for a single cell. If there aren't enough cells in the neighborhood, the space is empty, if the cell was present there it dies from loneliness. If in the neighborhood is enough of other cells, the cell can survive in its square, or a new cell is born if it was empty before.

It's interesting to notice that we can't compute the n-th iteration directly, we have to go through all previous iterations.

Controls: generate new map / start / pause-unpause.

I wrote this implementation almost ten years ago, so it may not be how it should be done today, especially the table should be replaced by canvas, but it's still usable and shows the concept.

If you are interested, how it works, please take a look on the source code of this page.

Fractal way of map generation by using diamond-square algorithm

Diamond-square algorithm is a simple way to generate maps by using fractal approach. The idea is to generate recursively a point based on the values of its neighbors and an additional fluctuation.

The main disadvantage is that landscapes aren't realistic and there exist visible edges created during recursive slicing of the terrain during recursive computing

Below you may see how the diamond-square algorithm works. Availability to change perspective is not part of the algorithm, but I've added it to make the visualisation more user-friendly.

up
left create new right
down

To check exactly, how the scripts are working please take a look on the source code of this page.

Above scripts were created a couple of years ago, they may not be aligned with the modern way of doing things in JavaScript. The code can be hard to read, I've written it when I was a student, back in those days I've been in love in short variable names and lack of comments.

Julia set, Cantor set and Fern fractal implemented in JavScript

In the previous post, I presented a simple fractal - bifurcation diagram of the logistic map. Today I will show more fractals and their implementation in JavaScript, they are embedded below so it's possible to run them on this page.

Julia set

The equitation for Julia set is given for complex numbers:

fc(x) = x2 + c

This implementation uses random numbers to create the fractal.

Click to draw Julia set. This can take a while.

function drawJuliaFractal(canvasID)
{
    // get canvas to be able to draw into it
    var canvas = document.getElementById(canvasID)
    var ctx = canvas.getContext("2d")

    var width = canvas.width
    var height = canvas.height

    var c_r = -0.73
    var c_i = 0.19
    var step = 0.002

    // z= a+bi
    for(var a = -2; a < 2; a+=step)
    {
        for(var b = -2; b < 2; b+=step)
        {
            var za = a
            var zb = b
            for(var n = 0; n < 160; n++){
               var za_temp = (za * za) - (zb * zb)
               zb = 2 * za *zb
               za = za_temp

               // add c constant
               za+=c_r
               zb+=c_i
            }

            if(Math.sqrt((za * za) + (zb * zb)) < 2)
            {
                var zoom = width / 3
                var x_print = (zoom * a) + (width / 2)
                var y_print = (zoom * b) + (height / 2)
                putPixel(ctx, x_print, y_print)
            }

        }
    }
}

Fern fractal

Unfortunately, I don't remember the direct mathematics formula.

This implementation uses random numbers to create the fractal.

Click to draw Fern fractal.

function drawFernFractal(canvasID)
{
    // get canvas to be able to draw into it
    var canvas = document.getElementById(canvasID)
    var ctx = canvas.getContext("2d")

    var width = canvas.width
    var height = canvas.height

    var max_step = 20000
    var x = 0
    var y = 0

    for(var i=0; i<max_step; i++)
    {
        var r = Math.random()

        if(r <= 0.01)
        {
            x = 0
            y = 0.16 * y
        }
        else if(r <= 0.08)
        {
            x = (0.2 * x) - (0.26 * y)
            y = 0.23*x+0.22*y+1.6
        }
        else if(r <= 0.15)
        {
            x = (-0.15 * x) + (0.28 * y)
            y = (0.26 * x) + (0.24 * y) + 0.44
        }
        else 
        {
            x = (0.85 * x) + (0.04 * y)
            y = (-0.04 * x) + (0.85 * y) + 1.6
        }


        // scale fractal to best fit to the canvas object
        var zoom = width / 10
        x_print = width - ((x * zoom) + (width / 2))
        y_print = height - (y * zoom)

        putPixel(ctx, x_print, y_print)
    }
}

Cantor set

The equitation for Cantor set is given by formula:

Cn = Cn-1/3 ∪ (2/3 + Cn-1/3), C0 = [0,1]

This implementation uses recursion to create the fractal.

Click to draw Cantor set.

// Note, initial invocation should be with xb = canvas width
function drawCantor(canvasID, level, xa, xb)
{
    // get canvas to be able to draw into it
    var canvas = document.getElementById(canvasID)
    var ctx = canvas.getContext("2d")

    var width = canvas.width
    var height = canvas.height

    var level_max = 10;
    if(level < level_max)
    {
        // put bar
        var bar_height = 3
        for(var i = xa; i < xb; i++)
        {
            var h = level * 6

            for(var j = h; j != (h + bar_height); j++)
            {
                var y_print = j +( height / 2)
                putPixel(ctx, i, y_print)
            }
        }

        //  call itself to print two child bars
        drawCantor(canvasID, level+1, xa, xa+ (xb-xa)/3)
        drawCantor(canvasID, level+1, xb - (xb-xa)/3, xb)
    }
}

To check exactly, how the scripts are working please take a look on the source code of this page.

Above scripts were created a couple of years ago, they may not be aligned with the modern way of doing things in JavaScript.

Bifurcation diagram of the logistic map [online version]

One of the reasons why mathematics is so amazing is that even a simple at first glance concepts have interesting behaviors and features. I think that the bifurcation diagram of the logistic map is a great example.

The logistic map is given by the equitation:

xn+1 = rxn(1 - xn), x0 < 1, r ∈ (0,4]

Below you may generate its bifurcation diagrams for different ranges and for different values of the x0. It's amazing that those diagrams have fractal nature - self-similarity is even visible at first glance.

X-axis represents values for different r values, Y-axis represents x0...n element value, n < 90 because in real world we can't show elements ad infinimum.

rstart>0: rstop≤4: x0<1:

The script was originally created a couple of years ago, so it may not be aligned with the modern JavaScript way of doing things. If you are interested how it works, please take a look on the source code of this page.

5V/400V DC/DC converter

A small and cheap 5V/400V DC/DC converter can be useful in many DIY projects, e.g Geiger–Müller counters. I will present here one of such DC/DC converter based on popular MC34063 chip in step-up configuration.

One big limitation of this device is little output power, but for many applications this won't be a problem. Another problem is poor temperature stability, but this could probably be improved by using low tolerance C1, R7-R11.

Q1, L1, D2 are coil-based step-up converter. Q1 should be a power MOSFET rated a bit more than the output voltage. Empirical tests have shown that Q1 didn't heat up, so I didn't mount it on a radiator. D2 and C4 rectifie output voltage, they also should be rated for bigger voltage than the output. To improve performance, D2 can be replaced by a Schottky diode, capacitance C4 can be increased. R3-R11, C3 provide output feedback to the MC34063. S1 is used to select output voltage if needed.

Idle power consumption is 85mW. Below presented fluctuation in output voltage at constant temperature and constant load.

Unfortunately, the device output voltage highly depends on room temperature, the lower the temperature, the higher is output voltage. Example of this is visible on below picture. Temperature measured near the transistor. Negative spike of temperature visible on the picture was created using canned air spray - easy way to temporary decrease temperature. The picture was generated using set of scripts that I presented in one of my posts.

Such high output voltage can be dangerous (even while the maximum curent iof this converter s small), so if you make the same or similar device, please be careful. If you are interested in higher voltage, you ma take a look on High voltage supply (10-30kV) made from CRT television flyback transformer.

Eagle files for this project can be downloaded from my GitHub repository.