Monday, 5 May 2014

Building Your Own Bench Power Supply

After looking around online at expensive bench power supplies, I decided they were often much too costly, and cheaper ones used boring resistor voltage dividers. I decided to set out on my own journey... I probably should have just bought one...

I decided that I would build a bench supply with DC 5v and a variable output as well. I am trying to use as many parts that I already own as possible to reduce cost. I dug through my pile of voltage regulators, and pulled out the trusty old LM7805 for 5v, and the LM317 for Variable. Those regulators are classic and tried and true. The data sheets also contain diagrams for building power supplies, it couldn't get easier! well... no.
It looks like I know what I'm doing, eh? HA!

It looks like it's fine, 15V no ripple...

So, this thread really isn't complete, I'm only half way into the project. Instead of an AC transformer, and bridge rectifier, I tried to fast track by re-purposing an old laptop 18.5v supply. (FAIL). Stepping down directly from that high of a voltage down to 5v produced an insane amount of heat on the LM7805 - it could actually only run with a load on it for a few minutes (1/3 of an amp). On the other side, with the LM317, if I set the voltage to 15v I could hold a full amp for 5-10 minutes without getting some voltage drop and thermal shut down issues.

 Ooops! Melted breadboard and resistor!
(Note the added heat sink on regulator)
This was actually my fault and not the resistor. I was using this 5 watt resistor as a test load. It's 15 ohms, and I was running it at 15 volts as a test load. That's 1 amp and 15 watts... 10 watts more than the ceramic resistor rating - after 20 minutes it became really really hot, I put a heat sensor on it, and it exceeded 300 degrees Celsius! This load had nothing to really do with the operation of the circuit, but it entertained me anyway. 

I still do have heat issues with both regulators going into shut down. I added small heat sinks that helped, but they aren't making the cut. I also need to consider perhaps using two transformers, one dedicated to the 5V rail that is maybe only 9-12 volts. Heat issues with the variable side are also concerning, I'll try tracking down a better heat sink and consider a cooling fan as well. I suspect most the variable supplies you see people make online are not handling much load, or aren't pushed very hard or for very long. The ideal simplistic versions of LM317 supplies don't seem to deal with the issues that arise when you test them. I am very glad I bread boarded this and am working out the kinks slowly.

The main project goal is to have the finished project on a solder board and in an enclosure. I posted this prematurely, but I think posting this will help to prevent me from shelving the project.

Once I have what I feel is the best configuration, I will post a schematic and some pictures.
Stay tuned!

Friday, 21 March 2014

ULN2803 interfaced with a Raspberry Pi

One of the issues with using an ARM based system or a micro-controller such as an Arduino or a Microchip is using the I/O pins to drive any real load, anything other than an LED seems to cause issues. So what do we do? In the case of a Raspberry Pi we have outputs that are only sitting at 3.3v, and conversations on forums seem to point to you not pulling more than 50mA from any one pin. I'd recommend only pulling a few mA if possible, and if you used 8 outputs at 50mA each, that would be 400mA, which just won't work well, something will fry. Anyway, introducing the ULN2803 (link to datasheet). What is it? It's called a "Darlington Array" which consists of a bunch of Darlington pairs, which is two transistors back to back per channel.
(Schematic from datasheet)

It has 8 inputs and 8 outputs arranged neatly so the package is easy to use and works well on a breadboard.
 (Schematic from datasheet)

What do they do? You can attach a secondary supply of a voltage between 0-30VDCs and pull a current of up to 500mA per output (you can gang them together for increased current too). What does this mean? Lots of POWER! Traditionally you would use an NPN transistor, and use a current limiting resistor that you had to determine its value based on the beta characteristics of the transistor, and use diodes to prevent kick back from relays, yadda yadda. This package includes a limiting resistor as well as diodes to prevent fly-back from those pesky collapsing electromagnetic fields on coils. Maybe that was a dramatization, but here is a video demonstration to enjoy:

 

In the video I complain that the mA's I pulled through are lower than what I calculated. I looked into it more, and it turns out that I can't read - I thought one of the ceramic resistors was 5 ohms, but it was actually 15. So the reading on the multimeter was actually (Vcc - Vbe) / (22ohm + 15ohm) which came out to around 120 mA. I originally thought the ohms would be 27, not 37.

I also prepared a schematic that doesn't show anything too exciting, however, it shows a byte of LED's being driven directly by the GPIO, as well as having a parallel connection to the ULN2803 which is driving more LED's. It isn't terribly exciting, but you can see that a different supply voltage is used for the 2nd set of LED's, and a relay could easily be dropped in, and the voltage could be different as well. 
(Made with Fritzing)

One other thing to pay attention to is that the voltage is being supplied to the components and not sourced (grounding it to the outputs on the ULN2803).
I've also seen some discussion about putting a limiting resistor on the inputs of the ULN2803, and I haven't come to any real solid best practice, so I did the lazy thing and did nothing. 
I would recommend fusing the power supply connection to your chip, and also placing a bypass capacitor between the + and - on the chip: 0.1uF should be fine (104 ceramic code).
Also check out the ULN2003, which is similar, except it has 7 inputs and outputs. These chips can supply small motors and steppers too!

I hoped that helped!

Monday, 17 February 2014

C Programing - Introductory to Linux/Unix terminal, file editing and using a C compiler!

Let's see if we can figure out how to write a C program that produces a box made with "X" characters and with a hollowed centre. The size will be defined and you will be able to change it.
This example will be done using a linux command prompt, but should work the exact same with your Mac's terminal.

To do this I have connected to my Raspberry Pi which is a small computer running a Linux distribution known as Raspbian. I've connected to it using a Windows program called Tera Term. You don't really need to know much about any of those things for today, but I will be hopefully discussing them later on in other posts. If you know how to open a terminal window on your Mac or Linux computer, you should be good to go. If you're running Windows, my method won't work, but the code will work if you're using a different compiler for C in Windows.

At this point I'm going to assume you have your terminal window open, but don't know how to use it, so I'll walk step-by-step through what to do.
When you first open your terminal you should be in your home directory.

Let's make a directory called "cStuff" so you have somewhere for your projects. type in: mkdir cStuff - you must press the return/enter key after each command. You can name it whatever you want, but you should learn about naming conventions and remember that you need to type the name to access the directory, so don't get carried away.

You can now move into that directory, type: cd cStuff.
We can now make a new folder for the square we are going to make today. Go ahead and type in: mkdir square. now move into that directory by typing: cd square
You should now be in the directory we will be using to make the square.

In the window above you can see that my prompt has the current directory listed in the prompt, like this:
jarret@raspberrypi:~/cStuff/square $

If you're interested in the full path you can type in "pwd" - present working directory to see where you are.

To create the file we will use to do the work in, we can use the "touch" command. This command will create a file with the name you specify. We could also just open a text editor, and save our work with whatever file name we want, but if we do it this way, the editor will know what type of file we are working on, and will use a profile to colour code some of our C statements for us.

typing in "touch square.c" will create the file square.c. Go ahead and do that. With the ".c" file extension, our editor will know we are programming in C!
To see the file we can type in "ls" to see the contents of the directory.  If you do this now, the only file you should see is square.c

let's get down to business. To do the actual C programming we're going to use an editor called nano. It should already be installed on your system, as it is a very popular command line editor.

To tell nano you want to open square.c you can simply type in "nano square.c". When it opens up, you should not see anything in the file, as it is empty, but you will see at the top of the screen that you're working on File: square.


You can see the colour coding it uses in the above picture for different keywords, this will happen while you're writing your code. The software I wrote is very basic, and should be very short for programming drills like the one in this example.

You can use any text editor, even notepad to do this work. I recommend looking into gedit, or notepad++ if you will be writing software often. Using nano at the command line is good practice and I recommend programmers play with it a little to get the feel. You can also use it for configuring and editing system files and viewing logs.

Here is the cut & paste version of my code if you want to bypass the exercise and play more with the command prompt and the method we are using:

#include <stdio.h>

#define boxSize 9

int main ()
{
        unsigned char counter, i;

        for (counter =  0; counter < boxSize; counter++){
                if ((counter < 2) || (counter >= boxSize - 2)){
                        for (i = 0; i < boxSize; i++){
                                printf ("X");
                        }
                        printf ("\n");
                }
                else {
                        printf("XX");
                        for (i = 0; i < boxSize - 4; i++){
                                printf(" ");
                        }
                        printf("XX\n");
                }
        }
}


I do recommend you attempt to solve this on your own, or try different exercises such as making diamonds or pyramids....

You can also change the value assigned to boxSize in the second line of the program to change the size of the square on the output.

Create your program or paste this code into the file.
At the bottom of the screen while you're in nano, you will see various options you can select.
^X Exit is what we will use to save and exit. "^X" simply means press ctrl+X to quit. Do that when you are finished.


press "y" to save your changes. It will then confirm the file name, you can press enter to save, and ignore the other options it presents for today.

We now need to compile our program. This is done at the command line using gcc. This is a program that will convert our square.c file into a program that the computer can execute. This program should already be on your computer, You can check by typing: "gcc -v" which will also tell you the version. If it doesn't work, try typing: "sudo apt-get install gcc" It will ask you for a password since you're changing the files on your computer. You can use this command even if you have gcc already installed to ensure you have the latest version.

The easiest way to get it to output a file is to use the command like this:

gcc square.c -o square

The first part is telling the prompt what program we want to use (gcc), followed by what file we want it to use (square.c) and -o is telling it we want to output to a file, and (square) is the name we want the program to use for the output.

If everything goes well, it won't say anything, you will just have a command prompt. If it does find any problems while compiling the code, it won't generate the file, and it will give you some clue as to the problem. If this is the case, open up the file again: nano square.c

Make sure you have all the brackets correct and that you have no typos, then save and try the compiler again.

If you use the "ls" command now, you should see the directory contains both "square.c" and "square".

To run your program, use the command:
./square

Depending on how things are set up, it may require you to use the password associated with your username.

If you're happy with everything, you can type in: "exit" to end your terminal session. It's considered bad practice to click the x in the corner to close this window (There are reasons, but another day).

I would like to see if anyone can write a shorter program to do the same thing as the one I wrote. I intentionally kept it short and sweet. Please give me feed back on this post and let me know if something needs to be cleared up, or if I'm wrong about anything. It was really meant as a C crash course for Linux/Unix users.

We will look at the code later too!

Thursday, 24 October 2013

Social Media & Society - Digging up some stuff on Vine, and presenting it with Prezi!

For my Social Media and Society class we were given the task of doing some research and a presentation of our findings. I chose to learn about Vine, which at the time I knew almost nothing about. I also decided to use an online presentation creator called Prezi. Both of these things were new to me, and I had quite the learning curve with learning how to use Vine and Prezi.

I hope you have as much fun watching it as I had making it!
Here is a list of some of the sources, which a worth a look to learn more.
 Sippey, Michael (Jan 24, 2013). Vine: A new way to share video. Retrieved Oct 23, 2013 from
https://blog.twitter.com/2013/vine-a-new-way-to-share-video

(Oct 24, 2013). Vine (software). Retrieved Oct 24, 2013 from
http://en.wikipedia.org/wiki/Vine_%28software%297

Coddington, Mark (Feb 1, 2013). This Week in Review: Vine’s potential and problems, and the new face of The New Republic. Retrieved Oct 24, 2013 from
http://www.niemanlab.org/2013/02/this-week-in-review-vines-potential-and-problems-and-the-new-face-of-the-new-republic/

Munro, Edward (Oct 4, 2013). Vine is popular – Six ways to make it Creative. Retrieved Oct 24, 2013 from
http://redrokk.com/2013/10/04/vine-is-popular/

Ang, Sarah (Sept 6, 2013). 15 Brands Kicking Butt on Vine. Retrieved Oct 24, 2013 from
http://mashable.com/2013/09/06/vine-brands/

Friday, 20 September 2013

Friday night - wine and programming! Teaching myself pointers in C

I made this blog for a different class... but I figured I might as well post other stuff on blogger now that I have it going.
I suspect this will turn up in a few search results too.

In one of my digital classes we are reviewing C programming practices, and one of the hard concepts to get is pointers. I thought I would sit down and play with them for a while to figure it all out.
This is what I came up with:

Sample program:

//========================================================
//== The purpose of this C program is to simplify the
//== mystery behind pointers with a minimal amount of
//== other crazy stuff going on at the same time.
//==                    
//== Compiled under gcc on linux, ver. 4.7.2
//== Sept. 20, 2013
//========================================================
#include <stdio.h>
#include <stdlib.h>

char msg[] = "I like cheese"; //declared here to give global scope

int main ()
{       
    char msg2[] = "CHEDDAR ROCKS!"; //declared here to put it on the stack.
                                                                 // -= only visible in the main =-
           
    char * string = msg; //create variable of type address to hold base address of msg           
    char * string2 = msg2;   
   
    printf("\n\nA string stored on the activation record: \n");   
    printf("%s at address %p, the first character is %c \n", msg, msg, *msg);
    //above code uses format specifiers for showing a string, an address
    // and the contents at the first memory location for 'msg'.
   


    while (*string != '\0')    //loop increments until the examined memory address contains
                                          //null character (\0)
    {
        printf("address: %p, Character %c \n",string, *string);    //shows address
        string++;                                                                           //and its contents
    }
   
    //The following while loop is identical to the one above, except the string is located
    //in a different area of the memory
   
    printf("\nA string stored on the stack: \n");

    while (*string2 != '\0')
    {       
        printf("address: %p, Character %c \n",string2, *string2);
        string2++;
    }
    return (0);
}


Let's look at the output:



So this might look like a lot of junk, but it's pretty interesting to see how stuff is stored in memory on your computer. This same code could be made to work on many other devices too.
Hopefully this finds its way to someone trying to understand the topic. I did this to help myself, so maybe it can help you!

Hopefully I don't geek myself up too much for my social media class :)

Friday, 13 September 2013

My first Blogger blog - let's blog about it!

Hello world of blogging!

This is my very first blog, and it is a skill I am learning because of my Social Media & Society course I am taking as a continuing education course to earn my General Business Certificate!

This should be interesting, as I hadn't even heard of blogger until I started this course. I will be using this blogging medium to participate in the course, so I'm not entirely sure how entertaining it will be to read, however, I'll probably post some other exciting stuff later.

Cheers!