Wednesday, October 12, 2011

INCREMENTAL ROTARY ENCODER

An incremental rotary encoder, as used in many applications, can be considered the digital equivalent of a potentiometer. Instead of a variable resistance, an encoder provides a digital on/off output. There are two basic types, contacting (mechanical contacts) or non-contacting (optical or magnetic). The most common low cost encoders are mechanical and have 12 or 24 pulses per revolution, with or without detents. Some models also have built-in switches. Also, an encoder has no mechanical stops, which allows continuous rotation in either direction. Optical and magnetic encoders are a better choice when rotational speeds are greater than about 100 RPM.

The most basic encoder typically has two outputs called “A” and “B” and since the outputs are 90 degrees out of phase they are referred to as a quadrature output encoder. Having two outputs gives the ability to determine the direction of rotation either clockwise or counter-clockwise.

The outputs are usually connected to a microcontroller which is programmed to determine the pulse count and direction of rotation. Mechanical encoders generally require some form of contact conditioning using either an RC filter or software delay or polling to eliminate contact bounce. Optical and magnetic encoders do not have a contact bounce problem, however a schmitt trigger circuit maybe needed to square-up the output pulses.

This is what the quadrature output looks like:

FOR CLOCKWISE ROTATION

PHASE            A         B
     1                 0         0
     2                 0         1
     3                 1         1
     4                 1         0

FOR COUNTER-CLOCKWISE ROTATION

PHASE            A         B
     1                 1         0
     2                 1         1
     3                 0         1
     4                 0         0

I created a simple PWM control with an LCD display that uses an encoder to adjust the PWM duty cycle from 0 to 100%. The LCD display was helpful to ensure that the encoder pulses were being counted correctly. Since I was using a 24 pulse per turn encoder, I was able to confirm that I was getting a count of 24 for every revolution of the encoder shaft – both in a clockwise (up count) and counter-clockwise (down count) direction.

The encoder I used was a Model EN16 made by BI Technologies.
Bourns also makes some unique encoders that have LED lighted shafts.

The microcontroller was a FREESCALE MC9S08QG8. I used the keyboard interrupt (PORT PTA1/KBIP2) connected to the “B” output. The “A” output was connected to PORT PTA2. The program compares the pre-interrupt encoder value (located in main function) to the encoder value found during the interrupt routine.  There are four switch/case statements to determine if the rotation is clockwise or counter-clockwise and also increments or decrements the PWM value by 1. The program also limits the PWM range from 0 to 100%.

The output driver consists of a 4N37 optoisolator which provides complete isolation between the microcontroller circuit and the output load. This also allows the load to have its own power source separate from the microcontroller power supply. The 4N37 output provides gate drive to a pair of 2N7000 MOSFET'S in parallel. The MOSFET'S supply the base drive to a 2N3055 power transistor. The 2N3055 controls the ground side of the load.


ENCODER OUTPUT AND FILTER DIAGRAM

CLICK ON FOR LARGER IMAGE
















PWM OUTPUT DRIVER


CLICK ON FOR LARGER IMAGE





















Below is a picture of the PWM control prototype board supplying power to a small incandescent lamp at a PWM output of 15%. There is a tricolor LED that provides another visual indication of the PWM output, changing from red at small PWM values, to yellow at intermediate PWM values, to green at high PWM values.





This is a close-up of the encoder. Also, you can see the tricolor LED and the 4N37 optoisolator just to the right of the encoder.


CLICK ON FOR LARGER IMAGE


Wednesday, October 5, 2011

DIY CIRCUIT BOARDS

When designing a new electronic project, the final step after testing and debugging a prototype is usually a printed circuit board. Going to a professional board house is one possibility. However, this can be a rather expensive solution since in small quantities a board house may charge as much as $25 each with a $250 minimum.

There is a way to make your own single or even double sided circuit boards.
Below is an explaination of the negative photo process that I have used.

1.)  PCB DESIGN SOFTWARE: I have been using a program called DIPTRACE, Lite Edition from NOVARM. It is a reasonably priced “do everything” program that allows you to create schematics, components, patterns and PCB layouts. The reason I chose DIPTRACE is it allows you to purchase in the form of the maximum number of pins that you think you would need, for current and future designs. Choices such as 250 pins maximum (Starter), 500 pins maximum (Lite Edition), etc. Some of the other PCB layout programs limit you to a certain maximum board size. Something that I find restrictive.

DIPTRACE also has a “CONVERT TO PCB” function that will convert a schematic to a PCB. Components still need to be arranged in an orderly manner on the circuit board. There is an “AUTO-PLACEMENT” feature for this as well as an “AUTOROUTER” which will route the PCB traces. I have found that these features work well for simple designs. However, I prefer to do these functions manually. Gerber files can be created if you decide to have PCB’s made professionally.

There are other choices for PCB design software. A web search should reveal alternate possibilities.

2.)  PCB ARTWORK: Once the circuit board is designed, you need to create the 1:1 artwork that will be used to transfer the PCB layout to the circuit board material. The best way is to use a laser printer to print the PCB design to either mylar or vellum. I have tried using clear mylar, however I was not getting good print transfer with the printer I was using. I found that a good quality tracing paper works very well with clean, sharp traces down to about 0.020 in. Smaller traces should also be possible. Since we are using a negative photo process, you must print a negative image (be certain it is 1:1 or 100% print scale as well) of the artwork. Most PCB programs will have this option.

3.)  CIRCUIT BOARD MATERIAL: Once you have the artwork created, you must transfer the image to a copper clad circuit board. I have been using 1/32 in
copper clad fiberglass material with ½ oz copper. This material is easy to cut with a swing arm type paper cutter. Make the board slightly larger than the artwork.

4.)  DARKROOM: The following steps must be performed in a dark room with red safe lamps for illumination. I have been using two 25w red decorative lamps made by Phillips Lighting. You could also use a low wattage (< 25w) incandescent lamp placed at least six feet away. This should not affect the light sensitive film that we will be using. You will also need at least a 15 watt daylight rated fluorescent light bulb (wavelength of approximately 400nm) or a F15T8 black light fluorescent light to expose the artwork. I use two 15w black light bulbs.

5.)  DARKROOM / RESIST APPLICATION: Thoroughly scrub the copper side of the circuit board with a green Scotch Brite pad. It is important that all contamination be removed. Dry the board and handle it by the edges only. Cut a piece of Negative Dry Film Resist about 1 inch larger than the width and length of the board. Use a heat gun to heat the copper side of the PCB to about 40 - 50 °C. Remove a portion (across the entire width) of the protective film on the bottom of the resist.

Carefully place the resist against the right edge of the board and smooth it in place on the warm board with a cloth covered finger. Continue to remove the protective film a little at a time and rub it down against the board with a sweeping motion being careful to avoid including air bubbles. Once the board is covered with the resist, reheat the board to about 60 – 70 °C and rub down the entire board, especially the edges and corners. I would repeat this step at least one more time.

The board should now be completely covered with resist. A few small bubbles are no cause for concern and will be dealt with later.

Note: The above procedure is the one I have been using. It is also possible to use a laminator instead. However, I was getting a lot of trapped bubbles when I tried the laminator I had so I stopped using it. I think the problem may have been the rollers were getting to hot even though I had it set to the lowest temperature setting. Feel free to experiment if you have one.

6.)  DARKROOM / EXPOSURE: Place the artwork with the toner side against the resist film and place a clean piece of window glass on top of the artwork. This will keep the artwork firmly against the resist. Make sure the artwork is evenly centered on the circuit board. Turn on the exposure lamp and begin timing.

I am using two 15w black light bulbs about 8 inches above the board and have found 3 minutes exposure time works well. If you are using a daylight rated bulb, 8 to 10 minutes might be a good starting point.

7.)  DARKROOM / DEVELOPING: At the end of the exposure time, turn off the exposure lamp and remove the glass and artwork. Pour about 250ml of the developer solution (dilute to the correct strength per bottle instructions) into a glass or plastic tray. Remove the protective film from the board and place it in the developer solution.

While wearing rubber gloves, brush the board gently with a foam brush for several minutes. Carefully examine the board and verify the resist is being removed. When the resist is completely removed from the unexposed areas, rinse the board with water. This completes the darkroom steps.

8.)  VERIFYING PATTERN: Carefully examine the board. Any resist remaining in the wrong areas can be scraped off with an x-acto knife. If there are any flaws in the resist due to bubbles or voids you can touch them up with any acrylic paint.

9.)  ETCHING BOARD: There are several different etching solutions that can be used. Ferric Chloride, Ammonium Persulfate and Cupric Chloride are just a few. I have found that Ferric Chloride works the fastest and is the least noxious. It does stain! You must wear rubber gloves and wearing a lab apron is also advisable. Make sure there is adequate ventilation. Place about one ounce of Ferric Chloride in a glass or plastic tray. Do not use metal! For faster etching, place this tray into another tray filled with about one inch of very warm water. Using a cotton ball or a small foam brush, gently flow the etchant over all the copper areas of the board.

Periodically rinse the board in water and examine the board under a bright light. The fiberglass substrate is thin enough that you can easily see through the board and find any unetched areas. Continue to etch the needed areas and rinse thoroughly in water when the board is completely etched.

10.) STRIPPING THE RESIST: First strip any areas that were touched up with acrylic paint with lacquer thinner. The stripper solution is a 3% by weight of either Sodium Hydroxide or Potassium Hydroxide. Place about 250ml of stripper in a glass or plastic tray and place the board in the solution. After several minutes you will notice the resist lifting off the board. When the resist is completely removed, rinse the board well with water.

11.) TIN PLATING: It is not necessary to tin plate the board. However, doing so
prevents the copper from oxidizing and also makes soldering a bit easier.
DATAK has a kit called “TINNIT” which works well and does not require electricity. I suggest scrubbing the board again with Scotch Brite just before plating.  It is important to heat the solution to about 50 – 60 °C. Immerse the board for about ten minutes while agitating the solution every few minutes. Neutralize the plating solution by washing the board with household Ammonia and rinse it thoroughly with water.

 12.) DRILLING: The last step is to drill component holes using a #67 and #64 drills. Use other sizes as necessary. Carbide drills will stay sharp longer.

 13.) SILK SCREEN: It is possible to add a silk screen to the component side of the etched and drilled PCB. It involves using a special release paper and a laser printer. The silk screen graphics are printed (as a mirror image) onto the transfer paper and then it is placed on top of the PCB and then both are run through a laminator. Both pieces are then soaked in water to remove the paper, leaving the laser image on the surface of the PCB. The silk screen will be black in color (if using black toner). If a white silk screen is desired, a special toner foil can be applied with a laminator. Finally, it is a good idea to apply a light coat of clear matte finish lacquer (Testors Dullcote) to protect the silk screen.


I have sucessfully used this process to make about two dozen boards from 1 in by 2 in, all the way up to 5 in by 6 in with IC pads as close as 0.008 inches. The cost for each being just a few dollars apiece or less.

The process does require some attention to detail to be successful. My suggestion is to start with a small board about 2 in by 4 in.




PCB ARTWORK







 PCB WITH RESIST








PCB ETCHED AND PLATED

























PRODUCT SOURCES

MOUSER ELECTRONICS

PCB MATERIAL
PART # 5165-PCB-SINGLE

DRY FILM RESIST
PART # 590-416DFR-5

NEGATIVE DEVELOPER
PART # 590-4170-500ML

RESIST STRIPPER
PART # 590-4185-500ML

TONER TRANSFER PAPER
PART # 5165-TTS10

WHITE TRF FOIL
PART # 5165-WTRF

MPJA
TIN PLATING KITS

DRILL BIT CITY
CARBIDE DRILL BITS

LM34 PRECISION TEMPERATURE SENSOR

The LM34 is a linear Fahrenheit temperature sensor with an output of 10mV / °F.

Typical accuracy is +/- 0.5 °F at room temperature and +/- 1.5 °F over a range of -50 °F to +300 °F. The LM34C is rated for a range of -40 °F to +230 °F and the LM34D is rated for +32 °F to +212 °F.

It is possible to measure the output from this sensor directly with a voltmeter. Since the output is a linear 10mV / °F, a temperature of 75 °F would be shown on a voltmeter as 750 mV.

However, adding a scaling circuit that can be interfaced to a microcontroller has a couple of advantages. Having a zero and gain potentiometer allows us to use the entire 0-5 VDC range of the microcontrollers ADC input. It also allows the temperature display to be calibrated at both the low and high ends of the temperature range.

The circuit can be simplified using only a gain pot if the desired temperature range does not have to go to zero or less than zero.

Shown below are three circuits that I have tested. The first two circuits require only a gain pot. The first has a temperature range of +5.0 °F to +99.5 °F and has a 0.1 °F resolution. The second has a range of +5 °F to 240 °F. The third circuit has a temperature range of -20 °F to +120 °F and has both a zero and a gain pot.

When using a sensor such as this, it is important to insure that the sensor is firmly attached to the surface that is being measured and also is insulated from the ambient air temperature. Also adding a small thermal mass to the sensor will make the sensor more immune to random air currents and provide a steadier display reading.

Three conductor shielded cable is recommended for remote applications.

The microcontroller circuit consists of a FREESCALE MC9S08QD4 MCU used as an analog to digital converter and also provides a bit-banged SPI output to control a FREESCALE MC14489 to drive the LED displays.


99.5 DEGREE TEMPERATURE  CIRCUIT


CLICK ON FOR LARGER IMAGE


















 

240 DEGREE TEMPERATURE CIRCUIT

 
CLICK ON FOR LARGER IMAGE


















 

-20 TO +120 DEGREE TEMPERATURE CIRCUIT


CLICK ON FOR LARGER IMAGE























This picture shows the prototype that was used to test the three circuits described.




















This picture shows a close-up of the temperature scaling circuits. To the left is the circuit that can be used for either the 5.0 °F to 99.5 °F or the 5 °F to 240 °F temperature readout.  It requires a gain potentiometer only. A jumper is used to change the gain resistor value.

On the right side is the circuit used for the -20 °F to +120 °F temperature readout. This circuit has both a zero and gain potentiometer.