Archive for December, 2008
Wednesday, December 31st, 2008
I finally get my hands on Analog Devices’ accelerometer- the ADXL202E. It’s small,very small.
See what I mean!

However there’s this problem, I usually work on PDIP packages and SMDs do give me a scare,not because I’ve never soldered them,but because I do not have the necessary equipment for it. So I decide to do my thing , and also take a little inspiration from Sparkfun’s Breakout board.
My first step was to find a thinner tip for the soldering iron. It presently has a standard tip,too big to solder the accelerometer. I decide to go shopping for a thinner one and get the finest one available at my local shop.
This is what the tip looks like[It's standard, I need a thinner one]

This is the new tip.

Since I needed to get wires out from the ADXL202 , I used very thin ones.You can easy get these by removing the insulation off normal wires you use in breadboarding. Now comes the difficult part – soldering.
First you need to hold your chip in place.With a little tape,firmly place the accelerometer on the table your working on.


This will prevent the chip from moving around ,when you solder the wires
First, put a little solder on one of the accelerometer’s solder points.Then taking a wire ,heat the wire, add some solder and touch it to the sensor’s pads. Do the same for the other seven “pins” of the sensor This is how it looked when done.[I know it's gory and ugly,but it's the best I could do]

Here’s the top view.

Now to mount the sensor onto a PCB. I chose a simple general purpose PCB[ dot matrix], as it’s easy available.That’s a One Ruppee coin,Indian currency ,the board is next to.

I cut the PCB to half to get a smaller footprint,that will house the ADXL202 and the supporting components. This is the finished version of the board:


If you notice,there are pins at the bottom of the board.These are for the signal and supply lines.I put them ,so that the board can piggy back on a bigger PCB housing the microcontroller…I also put a berg connector on the top,so that I could debug the signals. Following scope traces show the PWM changing as the accelerometer is tilted.
Tilted to one side:

Sensor on level surface:

Tilted to the other side:

Posted in Tutorials | 2 Comments »
Wednesday, December 31st, 2008
You’ve seen robots run on two wheels ,walk on two legs and balance just like us humans.I bet you’ve wondered whats in them that makes them “not tip over.
The device that enables this is a tiny teeny IMEM [aMicro Electro-Mechanical System] which can measure anything between ±1g to ±20g [some of the high g accelerometers measure ±20g to ±250g ]
The sensors:

What’s a “g”?
A “g” is a unit of acceleration having a value of 9.8
if you say 1g of acceleration .Its equivalent to:
1g = 1*9.8 = 9.8 m/s2
2g = 2*9.8 = 19.6m/s2
“g” in reality :
| 1g |
The acceleration exerted by the Earth’s gravity on an object or person (for example, a cell
phone on a desk experiences 1 g of acceleration). |
| 0-2g |
The acceleration range experienced by a person when walking. |
| 10-50g |
The acceleration experienced by an automobile in a typical crash. |
| 100-2,000g |
The acceleration experienced by a laptop if it is dropped from a height of three feet onto a
concrete floor. |
| 50,000g |
The acceleration experienced by a munition when shot from a cannon. |
…….Memsic.com
Where are Accelerometers used:
- Robotics
—To measure Tilt and Acceleration
- Vibration monitoring
—Vibration monitoring of heavy machinery
- Alarms and Motion Detectors
- Cellphones
—To invert the Phone screen so that the screen is always vertical
- Model Airplanes
—Detecting pitch and yaw
- Vehicle headlight aligning
- Disk Drives
- Vehicle Security
The following describes the two most popularly used accelerometers.
Both these accelerometers work on the same principle ,but on different technologies.
The Analog Devices ADXL202

Manufacturer :: Analog Devices
Datasheet :: pdf
Principle
The ADXL202 has a movable mass inside it which responds to vibrations,tilt or jerks.
The sensor element is a differential capacitor whose output is proportional to acceleration. The beam is made up of many interdigitated fingers.
Each set of fingers can be visualized as shown below:


Images Courtesy : Microchip.com
The movement of the beam is controlled by the polysilicon springs holding the beam.
These springs and the beam’s mass obey the laws of physics .
The force (F) on a mass (m) subject to acceleration (a), according to Newton’s Second Law, is
F = m a
The deflection (x) of a restraining spring according to Hooke’s Law is proportional to the applied force:
F = k x
From the above two equations…
a(acceleration) is proportional to x(displacement)
This enables us to compute the acceleration.
Once acceleration is obtained. Tilt can be obtained by monitoring each of the axes
The MEMSIC 2125

Manufacturer :: Memsic
Datasheet :: pdf
Principle
Unlike the Analog Devices ADXL which uses a movable beam, the Memsic accelerometers measure acceleration by monitoring a hot gas inside a chamber. The chamber is lined by a numerous temperature sensors which monitor the movement of the gas.
The picture below illustrates this:

Images courtesy of Parallax Inc. (www.parallax.com), from the Stamps in
Class Forum article”
How to – Accelerometer (1) Fundamentals and Tilt“
The first figure illustrates the accelerometer when it is held level.Note the position of the hot gas. The adjacent figure shows the accelerometer when tilted.The gas now shifts,changing the values of the sensors appropriately.
Output of an Accelerometer
Accelerometers like the ADXL and Memsic output their measurements in terms of PWM [Pulse Width Modulation].
For example take the ADXL202jqc which measures -2g to 2g. According to the ADXL datasheet 0g would translate to a 50% duty cycle.

A < than 0g readout with a lower than 50% duty cycle

A 0g readout with 50% duty cycle

A > than 0g readout with a greater than 50% duty cycle
Accelerometer AXIS
Both the above sensors measure 2 axis i.e the x and the y

Selection of an axis depends on your project requirements. You can even use the sensors to measure a full 360 degree of tilt. by using two accelerometers oriented perpendicular to one another.When one sensor is reading a maximum change in output per degree, the other is at its minimum.

Well thats it..these sensors do not need a lot of interfacing components. The ADXL202 just need 2 resistors and capacitors to set certain parameters while the Memsic needs even fewer components.
Posted in Tutorials | No Comments »
Wednesday, December 31st, 2008
Ever needed to measure temperature and display it? This project details measuring temperature using a temperature sensor ,an ADC and a Microcontroller PIC16f84a with schematics,codes and illustrations. This project was done fairly long ago, so please excuse the quality of the pictures.

Overview
The Temperature control module was a part of my Final year undergraduate project,which consisted of transmitting data wirelessly.
The module uses an inexpensive 8 bit Temperature Sensor the TMP37 from Analog Devices.
Since the data was analog and the PIC16f84 does not have an analog input,an external ADC had to be used.
Texas Instruments’ TLC549 was chosen for this.The advantage of this ADC was that it could communicate with the microcontroller serially.You may also use similar ADCs from Maxim-IC.
The LCD is a normal 16×2 display which uses the Hitachi Controller HD44780.
The module is breadboarded and not done on a PCB.Schematics are included in appropriate places below.
This site was a great help in building the project.
Mark S. Csele’s PIC Temperature Controller Page
Capabilities of the system:
-Show Current Temperature,Set temperature and Alarm Display.
-Go into Set Mode.
-Increment/Decrement Set Point.
-Enter Set point.
Here’s a snap of the module :

The project is divided into the following subparts:
-The Analog to Digital converter TLC 549 [8 bit]
-The Temperature Sensor TMP37
-The PIC16F84 / PIC16F84a Microcontroller
-Input Buttons
-The Liquid Crystal Display [LCD]
-Temperature Control
-Codes
Note:To follow this project you may need to know to program a PIC,there are some helpful links at the bottom of the page if you are not familiar with it.
The Analog to Digital converter TLC 549 [8 bit]
Description : The TLC549 is an analog-to-digital converter (ADC) integrated circuit built around an 8-bit switched-capacitor successive-approximation ADC. This device is designed for serial interface with a microprocessor or peripheral.
Pinouts:

Signals:
The TLC549 has two control lines and one data output line.
They are as follows:
-CS[bar] :: Input signal.The Chip Select signal.When low it selects/activates the chip.When high it disables the chip
-I/O clock :: Input signal.The input/output clock line is used to clock the ADC.
-Data Out :: Output signal.The data out signal clocks out bits into the PIC microcontroller.
ADC TLC549 on the circuit :

Working:
Sequence of events:See also datasheet page 8/10
- -CS is brought low The most significant bit (MSB) of the previous conversion result initially appears on DATA OUT when CS goes low.
- -The falling edges of the first four I/O CLOCK cycles shift out the second, third, fourth, and fifth most significant bits of the previous conversion result.
- -Three more I/O CLOCK cycles are then applied to the I/O CLOCK terminal and the sixth, seventh, and eighth conversion bits are shifted out.
- -The final (the eighth) clock cycle is applied to I/O CLOCK. After the eighth I/O CLOCK cycle, CS must go high or the I/O clock must remain low.
Resources:
Device Manufacturer :: Texas instruments
TLC549 Datasheet :: pdf
The Temperature Sensor TMP37
Description:
The TMP37 is a low voltage, precision centigrade temperature sensor. It provides a voltage output
that is linearly proportional to the Celsius (Centigrade) temperature. The TMP37 does not require any external calibration to provide typical accuracies of ±1°C at +25°C and ±2°C over the –40°C to +125°C temperature range. It is intended for applications over the range 5°C to 100°C and provides an output scale factor of 20 mV/°C.
Calculation:
If the Temperature is around 28 Degree Celsius. The TMP37 would be giving out a voltage of around 560mV
[.02*28=0.56V ie 560mV]
Pinouts:

Signals/Pins
-The Middle Pin [pin2]ie the Vout is directly connected to pin no 2 of the ADC TLC549.
-The rest of the 2 pins are the supply voltage of 5.0V and GND
TMP37 on the circuit :

Resources:
Device Manufacturer :: Analog devices
TMP37 Datasheet :: pdf
The PIC16F84 / PIC16F84a Microcontroller
There are two PIC16f84 microcontrollers handling the ADC/Temperature sensor/LCD and the input buttons.
The reason is that there weren’t enough pins on one PIC to control all the peripherals.So i had to use 2 of them and distribute the peripherals among them and also since I had a bunch of the same model.The two controllers communicate with each other serially.
Note : You may even use the PIC16f877 /A or the PIC17F874 /A microcontrollers from Microchip.They have alot more pinouts and the whole module can be controlled by a single controller.
The peripherals are distributed among the two microcontrollers in the following way:
-PIC-1 Handles the ADC TLC549 and Temperature Sensor TMP35
-PIC-2 Handles the LCD and the four Input Switches/Buttons to control the menu on the LCD
PIC-1
The first PIC16F84a ie PIC-1 collects data from the ADC and transmits them serially to the second PIC16F84a ie PIC-2.
The connection between the PIC-1,ADC and Temperature Sensor TMP37 is shown below:

PIC-1 with ADC and TLC549 on the circuit :

PIC-2
The PIC-2 handles all the LCD control signals ,the Temperature control and the Input buttons
Using the Input Buttons ,you can :
-Go into the Set Temperature Menu
-Increment the Set Point
-Decrement the Set Point
-Enter the Set point
The connections between the PIC-2 ,the LCD and Input buttons is shown below:

PIC-2 with the LCD and Input buttons :

Resources:
Device Manufacturer : Microchip
PIC16F84a Datasheet : pdf
Codes:
The code for both the PICs are given at the end of the page.
I’ve also used subroutines from other programs on the net and the author names are also mentioned in the included codes. Please give them credit and leave the names intact if you are planning to use the codes.
The Input Buttons
There are four input buttons for controlling the menu on the LCD.
-Button1 : Enter Set Mode
-Button2 : Decrement till released
-Button3 : Increment till released
-Button4 : Enter the desired set point
If the button is not pressed ,the PIC always gets a high.
If the button is pressed, the respective PIC pin goes low.
All the four buttons are connected to PortA of PIC-2
The input buttons on the circuit:

The Liquid Crystal Display [LCD]:
The LCD is a normal 16×2 Line display using the Hitachi controller HD44780. The LCD works in a 4 bit nibble mode,which means that the PIC first sends the lower bits of a byte and then the upper bits.
The connections to the 16×2 LCD are shown above under PIC-2 connections.
The LCD on the circuit:

References:
You may learn more about interfacing the LCD using the following links
Beginners Guide To LCD Interfacing :: RoboticsIndia.com
PIC Tutorial – LCD Board :: Nigel Goodwin
LCD Interfacing Reference Page :: Myke Predko
Build your own printer cable LCD Display :: Overclockers Australia
Resources:
Device Manufacturer : Hitachi Semiconductor
HD44780 Datasheet : pdf
Temperature Control
Temperature control is achieved using a simple on/off algorithm
Example :
If the desired Set Point is 29 Degree C.
The Alarm will activate if the tremperaturre >= 29 Degree C.
Sequence of events:
Initial display:

Display after initialisation:

Display on pressing the SET Button:

Deciding the Set point using the Increment /Decrement buttons:

Entering the Set Point at 29 Deg C [Enter button]:

Main Display after inserting the setpoint:

SET point exceeded..Alarm ON:

Codes:
ASM Code for PIC-1
ASM Code for PIC-2
Links for constructing your own PIC programmer
El Cheapo PICmicro Programmer :: Myke Predko
Pony Prog serial device programmer :: Claudio Lanconelli
Classic PIC Programmer :: bobblick.com
WinPic – A PIC Programmer for Windows
PICLIST.com :: A Heavy PIC resource
Posted in Microcontrollers, Tutorials | 12 Comments »
Wednesday, December 31st, 2008
Disclaimer : The information provided here is correct to my best knowledge.You may use it at your own risk.
This is a followup of the first tutorial which described using the port as an output. This tutorial demonstrates how to use the parallel port as an input. This feature is a great help in robotics as it is used to collect data of what the robot really is encountering.
The INPUT PINS

Picture Courtesy :: Ian Harries
The 10,11,12,13,15 pins of the STATUS PORT are the basic input pins.
Though the CONTROL PORT pins can also be used as inputs,only accessing the status pins are described here.Follow these steps to read an input
Step1
Construct the following TEST circuit.
In this example I have taken pin 13 of the STATUS port as an input.
WARNING Please do not feed your port more than 5V.You’ll blow it up.
Check all the voltages with a Multimeter before proceeding

Step2
Fire up your C compiler and typre the following program:

The program scans the STATUS[0x379] port and give an appropriate integer number,depending on what combinations of pins have gone high or low.
In this example ,since I have used pin 13 and connected to a high value i.e a binary “1″, I get a value of “127″ on my PC. Please note that this number will differ from PC to PC. Now we test for a Low value i.e a binary “0″. Modify the above circuit as shown below:

Short pin13 to GND.
When you do this and run the above program ,you get a different number.
On my PC ,i get a “230″
Step3
Now using a simple switch case statement you can monitor the input at pin13.

When pin13 is set HIGH:

When pin13is set LOW:

This is for monitoring a particular pin.
You can use all the status pins as inputs ,note down the numbers for different combinations and then write your program.Please note that the 11th pin is inverted i.e If u give a HIGH to it ,the port reads it as LOW.
That’s it for the parallel port inputs.
Posted in Tutorials | No Comments »
Wednesday, December 31st, 2008
Disclaimer: The information provided here is correct to my best knowledge.You may use it at your own risk .
This tutorial will help you get a taste of controlling your machine using the printer port. Though the parallel port isn’t being used for many applications ,it is a boon for us hobbyists. This tutorial’s main aim is to get you working , so that you can send signals from the port like control a motor. Taking inputs
from the port will be covered in a subsequent tutorial.
Parallel Port Anatomy:
Following are the pinouts:

Picture Courtesy :: Ian Harries
- 8 Output pins [D0 to D7]
- 5 Status pins [S4 to S7 and S3]
- 4 Control pins [C0 to C3]
- 8 ground pins [18 to 25]
The Pins having a bar over them ,means that the signal is inverted by the parallel port’s hardware.If a 1 were to appear on the 11 pin [S7], the PC would see a 0. The Status pins are mainly used by the PC to know the status of the printer, like if there is paper in the printer, end of paper etc. Only the Data Port will be covered in this segment.

Parallel Port Female Connector
The Data Port
Sending commands involves only the data pins [D0 to D7].Though it is possible to use the some other pins as input, we’ll stick to the basics.
Please remember that the Data pins are from pin 2 to pin 9 and not from pin 1.
If you have a good eyesight, check your parallel port connectors. Both the connectors [male/female], have numbers etched next to their pins, so people like us don’t screw up our ports, connecting them the wrong way.The word “Parallel” means sending an entire set of 8 bits at once to the PC [That's why term Parallel Port].However we can use the individual pins of the port; sending either a 1 or a 0 to a peripheral like a motor or LED.
Sending Commands to the Port:
This part is easy.Just a single line of code does the trick.
C program for the motor
#include{stdio.h} //replace {} with <>
#include{dos.h} //replace {} with <>
void main(void){
outportb(0×378,0xFF);
}
That’s it ,you just set all your data pins to 1.

If you take an LED and put one terminal at pin2 and the other to pin 18,it would glow.[Use a 2K resistor in series with the LED, otherwise you will end up ruining your LED, or source too much current from the port pin].
If you wish to switch it off. Type this:
outportb(0×378,0×00); instead of the above line.
What did you do?:

0×378 is the parallel port address. Usually this is the default address.Sometimes it is 0×278 too
0×00 is the command appearing at the output pins. The Format is in Hexadecimal. So if u want to make pin no2 high, that’s the first pin you type.
0×01 which would mean 0000 0001 for the data port.
0x04 would mean 00000100
0x55 would mean 01010101
0x0A would mean 00001010
see the table below for reference
0000-0
0001-1
0010-2
0011-3
0100-4
0101-5
0110-6
0111-7
1000-8
1001-9
1010-A
1011-B
1100-C
1101-D
1110-E
1111-F
That finishes your basics so that you can run your motor.
Material to control a Motor via a parallel port:
- 1 parallel port Male connector
- 1 DC Motor
- 1 Motor Driver [L293D]
- 1 5V regulator [7805]
Before trying out anything ,please remember that your parallel port is not meant or designed to handle more than 5Volts.If possible, trying accessing your parallel port using Windows 98.Windows XP does not allow access to the parallel port. You’ll need special drivers for that.
Steps to Control a Motor:
-
- outportb(0×378,0×00); ———STOP
MOTOR
- outportb(0×378,0×03);———MOVE
MOTOR(Break!))
- outportb(0×378,0×01);———MOVE
MOTOR(CCW)
- outportb(0×378,0×02);———MOVE
MOTOR(CW) .
- C program for the motor
#include{stdio.h}
#include{conio.h}
#include{dos.h}
[Please replace the {} bracket to <>]
main()
{
outportb(0×378,0×00); ———STOP MOTOR
sleep(2);
outportb(0×378,0×01);———MOVE MOTOR(CCW)
sleep(2);
outportb(0×378,0×02);———MOVE MOTOR(CW)
sleep(2);
outportb(0×378,0×03);———MOVE MOTOR(Break!)
sleep(2);
return 0;
}
The Sleep(n) function tells the port to hold [Latch] the command for (n) seconds.
eg: sleep(2)——————delay or sleep for 2 seconds
If you want to work in milliseconds ,use the delay(n) command
eg: delay(500) ————–delay for 500 milliseconds
That’s it, you can now control a motor using the parallel port. Use 2 motors and you have a moving machine. You can actually control the motors using the arrow keys using the Bioskey() function. Check “C” help for this. Hope you found this tutorial useful.
Helpful links:
Interfacing the printer port
Introduction to Parallel Ports
Books I used:
Parallel Port Complete By Jan Axelson [Rs 350]
Posted in Tutorials | 2 Comments »
Tuesday, December 30th, 2008
Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!
Posted in Uncategorized | No Comments »