Sunday, February 13, 2011

3 Digit Binary Clock

Introduction

This digital clock displays the time in binary format. Binary clock s have become very popular recently, many hobbyists create their own version of it and they are even available commercially. To decode the time you need to be familiar with the binary number system and have to decode it pretty fast, before the time changes :-).



Note: If you want to build this circuit and need help, please let me know - I can provide you with any or all the parts for this project, including a preprogrammed PIC.

Saturday, February 12, 2011

PCB Smartphone Stand

Introduction

Ever since I got my first smartphone, I wanted to make a stand/holder for it because most of its time it spends on my desk. There are plenty of smartphone designs available on the net, but I wanted to reuse some pieces of hardware I already had and also give it a personal touch. Finally, I came up with this design - I think this is the first of its kind:

Please meet the SmartPhone PCB Stand!

6 Digit Display Module

Introduction

During the development of embedded projects debugging sometimes can get difficult. There are a number of ways to help troubleshoot problems - a scope or a logic analyzer go a long way narrowing down the problem (although a bit expensive for the hobbyist), a serial connection is extremely useful (but needs a PC). A dedicated debug screen is also an easy and cheap way to make sure variables/levels/counters/peripherals do what they are supposed to do. I created this simple 6 digit 7 segment display out of inexpensive materials that only use 3 pins of the microcontroller and can display information in human readable format. The display module can be used with any microprocessor/microcontroller and can be used as an actual display for other projects that need to display data on 7 segment displays.

Schematics

The design is based on the 74HC595 CMOS Serial-In-Paralel-Out shift register. One shift register belongs to each 7 segment display (7 bits for the 7 segments + 1 bit for the decimal point). The data displayed is fully static, not multiplexed. As you can see from the schematics there are two connectors on the board: CN1 is the port where data comes in (normally from a microcontroller) and CN2 is an output port that can connect to another similar board. In theory, many display modules like this can be daisy chained to make up a longer display.
Jumper JP1 allows the use of common cathode and/or common anode 7 segment modules of your choice.
The current limiting resistors are to be selected according to the specifications of the actual 7 segment displays.

Capacitors C8-C13 are only needed if a great number of such modules are chained together at higher frequencies. I use mine as a single module with a 8 MHz PIC micro with no capacitors and have never observed any problem.

Board, hardware

Since I wanted to use the same circuit for a clock project as well, the first step in designing the board was to find 7 segment displays I liked. After some browsing I found one that I liked. It comes in several colours and in common anode and common cathode versions. I got some red and blue, common cathode versions. The size of these 7 segment displays defined the overall size of my board. The size of the board is exactly the size of 6 of these displays next to each other. Looking at it from the front you can't see the board, just the displays.
Front view: Note the PCB is the same size as the total area of the 7 segment displays
One could make the board even smaller (after all, there are only a handful of components on it, even those are SMT), but then you would have to use cables, connectors to connect the board with the displays - something I don't personally like. It just doesn't look good, in my opinion.
Back view: All the SMD parts are on this side
(Apart from the 7 segment displays) the board contains only SMT components. Most components are on one side of the board.

Side view: In this prototype I used IC sockets for the 7 segment display modules, but they can be omitted in a final module and the displays can sit straight on the PCB.

Conclusion

This simple circuit is an excellent way to add some debug functionality to any microprocessor based digital circuit. It can display basic information about almost anything that goes on in the microprocessor. In a daisy chained configuration, although there are some limits to the number of devices chained together, the displayed information doesn't have practical limits. The module can also be used as the main display module of a particular embedded system that requires many 7 segment displays as a display device.


4th Hand (Helping Hand) Workbench

Introduction

"A good technician has 3 hands - it is the fourth one that's missing sometimes." I think the famous proverb sums it up: Many times there are many, possibly tiny, parts that need to be balanced in an awkward position with one hand, while using a screwdriver/pliers/tweezers/soldering iron with the other one. This often tries even the most patient ones. And I am not one of them. After many trials and failures I ended up with this design that seems to work for me.


The finished product with 3 hands

Bill of materials

  • A big chunk of wood in the desired size - I went to the local carpenter shop and checked what scrap material they have. I found in the corner (under a pile of waste pieces waiting to be thrown away) a leftover piece of a kitchen's working surface. It's 4 cm thick, made of compressed chipwood with a "nice" coating to fit someone's kitchen. I had it cut to a 20 cm * 30 cm rectangle. The resulting piece is small enough to be portable (in my extremely limited working corner nothing is permanent) yet heavy enough to be not wobbly when working with it. This is very important as I had found out by using other, lighter designs.
  • A few pieces of Multi Direction Plastic Water Oil Switch Pipe Adapter . I used 3 pieces in my design but you may want to use more or less. Make sure you get the ones that have a screwy end at the bottom. The advantage of this kind of pipe is that it can be tailored to ones needs. You can any time add, remove sections of it, change the endings etc. - the limit is your imagination.
  • Alligator clips for the end of the pipes to hold whatever you may want to hold. It can be a PCB, some wires or a magnifying glass.

Close-up of the hands

Tools

  • Drilling machine with drill bits matching the diameter of the pipe adapter's bottom section.
  • Pliers to help screwing in the bottom sections into the wooden base

Assembly

  1. Mark the place where you want the pipe sections to be based on the wood. Don't put them too close to the edge - the chipwood won't last that way. I found that a distance of around 2.5 cm is sufficient from the edges.
  2. Drill holes for the base sections in the wooden base. When drilling big holes I always start with a small drill bit then work my way up to the desired diameter. The bottom of the pipe section I used is 12.5 mm, so I drilled 12 mm holes for them. This will allow them to be screwed in easily with pliers (remember, it's a very soft material).
  3. Screw in the bottom pieces in the holes. If needed, use a pair of pliers.
  4. Insert the alligator clips into the pipe endings. You may want to use pliers to adjust the diameter and shape of the alligator clips you have. If needed, you can also apply some hot glue or other kind of glue to secure it in place.
  5. The Helping Hands are now ready! You can twist them, turn them any way you wish and the base won't move.

The first section of the pipe after the bottom piece is a tap. I don't use it in this design but left it there to add extra length to the assembly.

Spindicator Clone

Introduction

Some time ago I came across a website where I saw a novel way of showing the disk activity of a computer. I liked the idea very much and decided to make one on my own. Since the working of the circuit is explained in detail and very well on the original web site, in this entry I focus on the implementation.

This is a demonstration video of the finished gadget demonstrating slow and fast movements as well:



Circuit

I took over the schematics from the original web site with minor differences:
  • I used a 210 ohm current limiting resistor, so the LEDs and the output driver of the 4017 are safe.
  • I used a PC817 optocoupler to separate my complete circuit from the PC, because I had a few of these at hand already. It doesn't really matter what optocoupler you use as long as its internal LED's electrical parameters roughly resemble the LED used on the PC's front panel. You can go through datasheets to make sure all is OK, or simply try it.
  • Although the schematics says C1 is 470 nF (and it does work very well with that), I ended up using a 100 nF capacitor because I couldn't find any bigger than that in SMT. I thought, that if it's not enough, I can still solder an extra capacitor on top of it. Luckily, it works perfectly with the 100 nF one.
Schematics of my Spindicator

Implementation

First, in fact, the moment I saw the original web site, I put together the whole circuit on a test board to see if I really like the results. I did. I also experimented with several different values for R1 and C1, but no other combination gave me better results, so I just left them as they were in the original.

After I was happy with the way it worked on the test board, I designed a PCB for it. To save space and manufacturing costs I used all SMT parts for the resistors and capacitor. I couldn't find an SMT version of the 4017 IC, so that and the optocoupler (and the LEDs) are TTH (through-the-hole) parts. Since I had an idea on how big circle I want to arrange the LEDs in, it didn't make much sense to further miniaturize the board - all the parts fit in the area under the circle (well, the smallest square around it anyway).

Assembly, part 1

First, I checked the board for short circuits and incomplete wires. This is good practice, since it is a LOT easier when the board is empty than when it is populated. Next I soldered on the SMT parts: R1, R2, C1, then the IC and the optocoupler. I rarely solder in ICs into PCBs, but since this circuit is soooooo simple, I decided that it WOULD WORK straightaway. (I got lucky this time :) )


Bottom view after all the parts save the LEDs are in place
Top view before the LEDs are inserted

Assembly, part 2 (preparing holes for the LEDs)

This step really depends on the actual faceplate one wants to install the Spindicator behind. I found an old CD with some drivers that I don't need any more.


This is a small, 225MB CD that came with some hardware.
I measured, double measured, then messed up the first one. I still don't understand how... Anyway, the second time I was successful and managed to mark and drill 10 holes in a circle. I used 5 mm blue LEDs, so a 5 mm drill bit was used for the holes. I started out with a very thin drill bit, then worked my way up to 5 mm. This way I could achieve smooth edges and better aim.


The CD with 10 holes - the marks won't be visible at the end
The punched CD from the bottom - this will be the face of the device

Assembly, part 3 (mounting the LEDs)


Mounting the LEDs is a bit tricky, but since I have built similar "display devices" in the past, I had an idea how to go about it. If you have a better idea, please share it in the comments area!

First I inserted each LED in its own place in the PCB. When I designed the board, I paid special care to two things:
  1. The LEDs are arranged in a way (in a circle) that there will be no extra cable used to connect the board to the LEDs.
  2. Since LEDs are polarity dependent, I designed the board so that all LEDs "look" the same direction, i.e. the cathode of each LED is on the right. This makes assembly time errors less likely.

The LEDs are well adjusted
Notice, I say "inserted", not soldered! This is important. When all the LEDs are in place (without soldering), I moved the faceplate, the CD, above it, and very slowly with the help of some tweezers, I pushed each LED into its own hole.


Parallel planes
When they were all in, I turned the assembly to its side and made sure the planes of the CD and the PCB are parallel. This is not strictly required, but makes it look better. When I was happy with the arrangement of the LEDs, I turned the board over and soldered in the LEDs.


All LEDs in place, telephone cable soldered in

Assembly, part 4 (cables to the PC)

I planned to have this "Spindicator" placed on my computer desk. For this reason I needed fairly long (~1 meter) cables. There are four cables needed altogether: power+, power-, HDD activity LED+, HDD activity LED-. To avoid having to use multiple threads, I decided to use an ordinary telephone cable. I had plenty of 4 wire telephone-modem cables (RJ-11) in the cables section of my junk... I simply cut off the two ends.
For the PC end of the cable I soldered on some female headers for the HDD LED connection and repurposed an old PC power cable (the red-black-black-yellow one) for the 5V. On the other end I simply soldered the cables into their designated locations on the PCB.


The big blob is some hot glue I used to strengthen the connector, which otherwise tends to fall apart...

Assembly, part 5 (housing)

I haven't put the whole thing in a housing or box yet, so this section is going to wait a bit until I figure out what to cover the assembly with.

Summary

This is a great beginners' project for several reasons:
  • No difficult circuitry
  • Small number of cheap and common components used
  • Components have wide tolerance, it's difficult to damage them.
  • Once the optocoupler is in its place, the PC cannot be harmed since it's decoupled from the rest of the circuit.
  • Can be assembled in less than an hour (on a breadboard, or further time needed to make or order the PCB)
  • Only 3 SMT components (6 pads) to solder, but can be easily converted to TTH design
Ever since I built one, I always keep an eye on it - it's not so productive, but so much fun!!

Rotary Encoder Test Circuit

Introduction

Definition (from Wikipedia): A rotary encoder, is an electro-mechanical device that converts the angular position of a shaft or axle to an analog or digital code.

I have been playing with a device like this for some time and thought I'd share what I learnt. I am not going to describe the theory of rotary encoders, there are plenty of places on the internet that have done an excellent job doing that. I will rather focus on its real life application complete with a working sample circuit with assembly code.

Having read a lot on the theory of its operation I was sure it was something easy and straightforward to implement. However, when I tried it I failed miserably. After hours and hours of experiments, research on the internet I found out out that my test circuit was working correctly, but my code was incomplete.

The test circuit


I created the circuit on a test board
At the heart of it is a 16F628A microcontroller. I used this particular microcontroller, because I already had a few ones at hand. Also, I think, it's an easy to use microcontroller with plenty of I/O ports and other peripherals for small projects. The 16P628A also has an internal oscillator (max. 4 MHz) which means it doesn't really need any extra external components for normal operation.

The rotary encoder is connected to PORTB, which is configured to use its built-in pull-up resistors, further reducing the number of external components. To help debouncing a 100nF capacitor is used paralel to each pin of the rotary encoder. Further debouncing is done in code.

The feedback is built with a Serial-In-Parallel-Out shift register (74HC595) and an LED strip. I could have just used some LEDs directly connected to the microcontroller, since we have plenty of free I/O pins, but I used my own LED strip to make the test board simpler.

As always, I used an ICSP interface to program the PIC, greatly reducing the development time of a new application.

Code

The code was written in assembly, compiled with the MPLAB IDE 8.5 built in compiler.

All we need to do in the main loop is to poll the lines from the rotary encoder to see if they have changed:

;check rotary encoder - left
btfss Encoder_L
call Encoder_CheckNext_L

;check rotary encoder - right
btfss Encoder_R
call Encoder_CheckNext_R

The following are the routines used for deciding if the rotary encoder was moved indeed (debouncing) and also to carry out any actions as necessary when the rotary encoder was indeed rotated:

; ------------------------------------------
; rotary encoder routines
; ------------------------------------------
Encoder_CheckNext_L
btfsc Encoder_R
goto Encoder_RightAction
return

Encoder_CheckNext_R
btfsc Encoder_L
goto Encoder_LeftAction
return

Encoder_RightAction
bcf STATUS, C
btfsc COUNT, 0
bsf STATUS, C
rrf COUNT

goto Encoder_RotationEnds

Encoder_LeftAction
rlf COUNT
goto Encoder_RotationEnds
Encoder_RotationEnds
btfss Encoder_L
goto Encoder_RotationEnds
btfss Encoder_R
goto Encoder_RotationEnds
return
This last part (Encoder_RotationEnds) is the one that I was missing from my code. Thanks to this excellent site now my test board works. I already used the above circuitry and code in actual projects and they work great: the rotary encoder never skips a step, and never gives extra steps.

Conclusion

Rotary encoders are simple to use user input devices that can simplify user interface significantly - think of menu systems, etc. I am sure I will use them in many projects to come.

LED Fade in / Fade out

Introduction

I found a small project at another site about fading an LED in and out smoothly, without a microcontroller. I changed it a bit. In my version I removed one of the transistors and changed some resistor values. This is supposed to result in lower costs and smaller footprint. I know it's a very small difference, but still.

The circuit

In default state (when S1 button is depressed) capacitor C1 is discharged, so transistor T1 is closed, hence the LED is off. When the button is pressed, C1 gradually charges, which gradually opens T1 lighting up the LED slowly. When the button is released, C1 discharges through R1-R2, slowly closing T1, gradually fading the LED. (If we omit R2, the discharge process would take forever a very long time.) By changing the values R1, R2, C1 one can change the speed of fade in, fade out. The given values result in roughly 1.5 second for both fade in and fade out.
The simpified circuit

ATX Bench Power Supply

Introduction

This project involves creating a bench supply from an old ATX power supply. The resulting bench power supply provides +5V DC, +12V DC, and, optionally, a variable voltage ( +1.25V .. +10.3V DC) power source for the hobbyist.

Probably a good beginner's project, since this project is, although a bit time consuming, if you want to do it nicely, very straightforward, hard to mess up. I had most parts already in my Big Basket of Junk: an old ATX power supply, a pretty large (electrician's waterproof) plastic box, banana plugs & sockets, LED Volt meter unit, etc. I only had to get a small PCB done for the variable voltage part. Although I will include it in this page, if you only need 5V DC and 12V DC, you can skip the next part.

Variable voltage circuit



I found this basic circuit somewhere on the internet. I only modified it to contain an LED, meter, etc. It uses an LM317 in a datasheet configuration with only a few external components. It is able to provide current upto 1.5A from 1.25V to 10.3V with an input voltage of 12V (taken from the ATX power suply). I designed a dedicated PCB for the circuit. It worked for the first time. I also put a heatsink on the LM317, just in case. At and above 1A it starts getting hot.

This is the front view of the PCB I had made:




You can see it's very simple - could be done easily at home if you are into this stuff.

Assembly

I had an electrician's waterproof plastic box (the one that can be put outside in the rain) I had no use of. Although a bit too big for this project, it was easy to work with: since it is made of plastic drilling/cutting/filing it was no difficult. It also came with some holes or mounting points which made it easy to mount the different modules to it. Steps I took to build the power supply box:

1.Using the mounting holes in the box I mounted a piece of plexiglass that I had already cut to size - this made mounting all the other modules easy as I could drill mounting holes on the plexiglass whereever I wanted.
2.I removed the PCB from the ATX power supply. In this step I also desoldered the mains connector. This step is not necessary, but it saves a lot of space in the box.
3.I mounted the ATX power supply on my main board (see step 1).
4.Right next to it I mounted the fan of the ATX power supply.
5.I drilled many 6mm holes on the side of the box so that they are aligned with the fan.
6.I mounted the variable voltage module in the free area of the main board.
7.I created a weird shape hole at the back of the box for the mains supply connector salvaged from the ATX power supply. Although this hole came out perfectly (the socket did not come out on its own) I secured it with two screws, just in case.
8.On the front panel of the box, I measured and drilled holes for all the banana sockets, on/off switch, on/off LED, LED display, potenciometer I wanted to have. When ready, I populated the holes with the corresponding hardware element.
9.Last step is to wire up the "UI" with the "back-end".

Finished look

This is my finished bench ATX power supply:

Front and side: you can clearly see the ventillation holes on the side. Not so clearly, or hardly at all, the display actually says something, but it's not visible because of the flash used.

Back: The standard computer mains cable connected
Inside: The blue layer is main board (plexiglass). The plexiglass is transparent, but I left the blue protective foil on it, in case one day I want to repurpose it to something else... I also left all the cables coming from the power supply untouched. This way the power supply can still be used in a PC should the sudden need arose :-).
Inside - UI: Here the connections are visible.
Throughout the construction of this unit I color-coordinated/coded things - e.g. red cables/sockets/plugs are for 5V, yellow cables/sockets/plugs are for 12V, black cables/sockets/plugs are for 0v (or ground). This is in line with the color codes used with cables in a standard ATX power supply.

The whole process took me one day, including cleaning up afterwards :-)

Staircase Light Timer

Introduction

We have a timer in our staircase that controls the light after dark: when someone presses a button (a button is located on each floor) the lights light up for a preset period. Lately, the timer in our staircase light has started to behave weirdly - no matter what settings we used, the ON time kept shrinking. By now, not even the fittest can make it after dark from one button to the next while the lights are on. Instead of buying a new timer (for about €5 :-) ) I decided to make it a learning project for myself, as I have been learning PIC micros for a while now. This way, while learning, I also create something useful - for a price that is about 10-15 times higher... The difference is the price of education :-)

Materials

Most of the hardware parts I purchased online, through eBay although I am sure all the parts are usually available in any local hardware/electronics/DIY shop. The problem form me is that there are no such shops in the vicinity of my home.

This is a non-exhausting list of the components used (apart of the electronic components in the circuit). I may have missed an item or two, but the whole list is fairly obviuos.

  • 1 * plastic box (12 * 15 * 6 cm approx) with metallic parts for wall mounting as the project box. Since dedicated project boxes are ridiculously expensive in my area and/or the shipment is very expensive from abroad, I had to settle for this box that is sold as housing for electrical installations. It's not airtight and it has a big window on the front which I had to cover with a scrap piece of plexi glass I had lying around. It would certainly look better in a "proper" project box, but it does the job and in normal operation it will be out of sight anyway.
  • 3 * pushbuttons for testing purposes (up, down, test)
  • Assorted cables, connectors as necessary

Circuit

At the heart of the circuit is Microchip's 16F628A microcontroller. I chose this microcontroller because it is cheap and I had used this previously for other experiments and had some already.

The 16 (red) indicator LEDs are driven from 3 pins of the PIC using SIPO shift registers (74HC595).

There are also a green LED (power indicator) and a blue LED (state of the relay).

Since most components I used are SMT, I also included an ICSP header on the PCB so that I could program and reprogram the PIC after it has been soldered to the board.

The schematics can be downloaded from here:


Since I designed the circuit I have changed my mind about a number of things. This is due to my inexperience with the PIC microcontroller. If we need another timer controller in the future, I promise I will correct all the inefficiencies in the circuit, the software and the mechanical layout. For now it is working just fine.

Software

As one of my first projects (learning PIC micros as we speak :-) ) the software is not very elegant, to say the least. There are no interrupts used, the microcontroller never sleeps, constantly polling the buttons, etc. I am fully aware of all the shortcomings of it and in any future versions it will be improved. As for now, I was happy that is was working for the first time I put it together.

The software was written in assembly, using Microchip's MPLAB (it's not the most user friendly IDE I have seen, but it's free). The compiled code for the 16F628A can be downloaded from here: stairlight_v1.0.

Operation

When powering up the device first does self check - it lights up all the indicator LEDs one by one, then turns them off one by one. Then for a few seconds it switches on the staircase lights just to show that the relay works OK and all the connections are satisfactorily.

After the initial self test the device enters a waiting mode. In this mode the user may change the length of the ON time for the lights by pressing the UP and/or DOWN buttons. With each push one indicator LED gets switched on/off. There are 16 LEDs in total. At the moment it is programmed so that each LED means 15 seconds of ON time. This means the lights can be configured to be on for 15 seconds to 4 minutes in 15 second steps. For most scenaria this should be OK, but it can be changed in the firmware.

The user may also press any of the LIGHTS ON buttons in the staircase. This switches on the relay in the circuit (and all the lights in the staircase that it switches) and a control LED (blue). The top indicator LED will start blinking. After 15 seconds the blinking LED stays off and the one next to it (in the direction of 0) starts blinking. This procedure keeps repeating until all the indicator LEDs are exhausted. At this point all the indicator LEDs (until the preset interval) light up, and the relay switches off - switching off the lights in the staircase.

During the countdown process the user can press any of the LIGHTS ON buttons in the staircase resetting the countdown timer to expand the time the lights are on.

Extra stuff

The same circuit with only a slight modification in firmware can be used in various other applications that require similar timing, such as delayed switch off of car/boat/etc. cabin light, car wiper intervalled operation, camera interval shooting, etc.

Possible improvements, future plans...

... or what I would do differently if I had to do it again - in no particular order:

  • I would incorporate the relay on the PCB - this would make the whole device look less cluttered.
  • When the microcontroller is in waiting mode, it should sleep and it could be waken up by an interrupt when a button is pressed.
  • I would use a cooler project box ;-)

Update

With the original 12VDC power supply the regulator 7805 IC needed a very large heatsink which I really didn't like. So I was looking around what else I can do. A few days later I found on eBay a 5VDC and 12VDC power supply in one and a compact size. It's the one that are used for external hard disks or DVD drives. I just removed all cables and the enclosure that I don't need, and bypassed the power supply part of my circuit. Now the device works with its own switching mode power supply.

Buttons for Digital Projects

Introduction

The aim of this simple project is to provide simple button input to any digital circuit. I use it in conjunction with the LED strip in microcontroller projects on breadboards. It consists of 8 tactile switches (momentary pushbuttons). The circuit is complete with a pull-up resistor for each pushbutton. The included pin header allows easy connection to a test board or breadboard.


The circuit


The circuit is very simple

Pin 10 of the header is the common one. Typically, the common pin (pin 10) can be a 0V, pin 1 is Vcc, and pins 2-9 can be connected to a microcontroller's input pins.

The board

To save on manufacturing costs (which seems to be the highest for every circuit I have made so far) I used SMT resistors. I also arranged the buttons in a specific shape: rather than having them lined up one next to another, I made up the below shapes. This will help in various projects to easily distinguish between them. Now I have a button for Up, Down, Left, Right, and some extra ones on the right.
The empty PCB
The fully populated PCB. You can see all the SMT resistors and buttons in a particular arrangement.

Friday, February 11, 2011

LED Strip

Introduction

The aim of this simple project is to provide simple debugging capabilities to any digital circuit. It is nothing more than 8 LEDs on a piece of PCB with a pin header to connect easily to a test board or breadboard.

The circuit

The circuit doesn't get any simpler than this:


Pin 1 of the header is the common. The above schematics shows the LEDs in a common cathode configuration, but it's possible to reverse them making a common anode configuration if that is what a particular project demands. Also, the value of the resistors must be chosen according to the requirements of the circuit at hand. The shown values are just examples. Typically, the common pin (pin 1) can be a 0V and pins 2-9 can be connected to a microcontroller's output pins.

The board

To save on manufacturing costs (which seems to be the highest for every circuit I have made so far) I used SMT resistors. The LEDs could also be SMT, but I wanted them to be big and I wanted them to shine.

Some more images

The empty PCB

You can see all the SMT resistors, all the LEDs and the header on the back.