ss_blog_claim=726e70d7c87c20ae33aa7a61f06eb8aa

Thursday, June 19, 2008

About LCD interfacing

Previously we have seen how to interface stepper motor using TIP122, now let us see interfacing LCD with PIC16F877A

LCD introduction

LCD’s i.e, Liquid Crystal Displays utilize two sheets of polarizing material with a liquid crystal solution between them. An electric current passed through the liquid causes the crystals to align so that light cannot pass through them. Each, crystal, therefore, is like a shutter, either allowing light to pass through or blocking the light. The most commonly used alphanumeric displays are 1x16 (single line and 16 characters), 2x16 (double line and 16 characters per line) and 4x20 (four lines and twenty characters per line).

In LCD interfacing we are using HY-1602F6 LCD. It is a two line display with 16 characters on each line. Let us see how to interface an LCD with PIC16F877A.

LCD interfacing

LCD interfacing has two modes 8-bit mode and 4-bit mode.The LCD requires 3 control lines (RS, R/W and EN) and 8(or 4) data lines. The number of data lines depends on the mode of operation. If operated in 8-bit mode then 8 data lines + 3 control lines i.e, total 11 lines are required. And if operated in 4-bit mode then 4 data lines + 3 control lines i.e, total 7 lines are required. The 4-bit mode takes twice as more time as compared to 8-bit mode but it requires less number of data lines. The pin details of 16x2 LCD is shown below.
        • pin 1 - vss - ground
        • pin2 - vdd - supply voltage
        • pin3 - vc - contrast setting
        • pin4 - rs - register select
        • pin5 - r/w - read/write select
        • pin6 - en - chip enable signal
        • pin7 to pin 14 - DB0 to DB7 - data lines
        • pin 15 - vcc for backlight
        • pin16 - gnd for backlight
When RS is low (logic 0), the data is to treated as command. When RS is high (logic 1), the data being sent is considered as text data which should be displayed on the screen.

When R/W is low (logic 0), the information on the data bus is being written to the LCD. When R/W is high (logic 1), the program is effectively reading from the LCD. Most of the times there is no need to read data from the LCD so this line can directly be connected to GND thus saving one controller line.

The EN pin is used to latch the data present on the data pins. A HIGH to LOW signal is required to latch the data. The LCD interprets and executes our command at the instant the EN line is brought low. If you never bring EN low, your instruction will never be executed.

Display Data Ram (DDRAM) stores the display data. So when we have to display a character on LCD we basically write it into DDRAM. For a 2x16 LCD the DDRAM address for first line is from 80h to 8fh and for second line is 0c0h to 0cfh. So if we want to display 'H' on the 7th position pf the first line then we will write it at location 87h.

Tuesday, June 17, 2008

code snippet for LCD interfacing

code for interfacing LCD with PIC16F877A in CCS C compiler

//PIN CONFIGURATION: LCD DATA LINE(D4,D5,D6,D7) CONNECTED TO PORTD(3,4,5,6)PINS; CONTROL LINE(RS,RW,ENABLE) CONNECTED TO PORTD(0,1,2)PINS;

//THIS PROGRAM IS USED TO DISPLAY " welcome to LCD INTERFACING ";

//SEE THE FOLLOWING PROGRAM;

#include<16f877a.h> //HEADER FILE;

#use delay(clock=20000000) //CRYSTAL FREQUENCY IS 20MHZ;

#fuses HS,NOWDT,NOPROTECT,NOLVP //SETTING FUSES;

#include //LCD DRIVER FILE;

#byte portb=0x06 //SPECIFY PORTB ADDRESS;

#byte trisb=0x86

#byte portd=0x08 //SPECIFY PORTD ADDRESS;

#byte trisd=0x88

main()

{

lcd_init();

set_tris_d(0x00); //PORTD IS CONFIGURED AS A O/P;

portd=0x00;

while(1)

{

lcd_gotoxy(1,1);

printf(lcd_putc,"welcome to"); //IN 1ST ROW "welcome to";

delay_ms(3);

lcd_gotoxy(1,2);

printf(lcd_putc,"LCD INTERFACING"); //IN 2ND ROW "LCD INTERFACING";

delay_ms(3);

}

}

Tuesday, June 10, 2008

Nokia secret codes

Hi friends do you have a phone from NOKIA, then here are some secret codes. Note the information provided below is not verified fully so please be careful while trying these codes.

On the main screen type :

*#06# - for checking the IMEI (International Mobile Equipment Identity).

*#7780# - reset to factory settings (don’t do this if you are not sure).

*#67705646# - this will clear the LCD display (operator logo).

*#0000# - to view the software version.

*#2820# - Bluetooth device address.

*#746025625# - sim clock allowed status.

#pw+1234567890+1# - shows if sim have restrictions.

*#92702689# - takes you to a secret menu where you may fine some of the information below:

1. Displays Serial Number.

2. Displays the month and year of manufacture.

3. Displays (if there) the date where the phone was purchased (MMYY).

4. Displays the date of the last repair – if found (0000)

5.Shows life timer of phone (time passes since last start).

*#3370# - Enhanced Full Rate Codec (EFR) activation. Increases signal strength, better signal reception. It also helps if u want to use GPRS and the service is not responding or too slow. Phone battery will drain faster though.

*#3370* - (EFR) deactivation – Phone will automatically restart. Increase battery life by 30% because phone receives fewer signals from network.

*#4720# - Half Rate Codec activation.

*#4720* - Half Rate Codec deactivation – the phone will automatically restart.


If you forgot wallet code for Nokia S60 phone, use this code to reset: *#7370925538#

Note, your data in the wallet will be erased. Phone will ask you the lock code. Default lock code is: 12345

Press *#3925538# to delete the contents and code of wallet.

Unlock service provider: Insert sim, turn phone on and press vol up (arrow keys) for 3 seconds, should say pin code. Press C, then press * message should flash, press * again and 04*pin*pin*pin#\

*#7328748263373738# resets security code.

Default security code is 12345

Change closed caller group (settings->security settings->user groups) to 00000 and your phone will sound the message tone when your are near a radar speed trap. Setting it to 500 will cause your phone 2 set off security alarms at shop exits, (works with some NOKIA phones) press and hold “0” on the main screen to open wap browser.

Sunday, June 8, 2008

Designing a gear box

as seen in my previous post ,the gear reduction ratio (using spur gear) which we required was 128:1, and we achieved it through software and hardware. We made the 64:1 gear reduction box using three 4:1 gears, 4:1 gear reduction is achieved by using a 20 teeth and an 80 teeth gear. All the gears are cut using 1 module cutter. The basic formula involved in gear design is,

OD = (N+2) x M

OD is the outer diameter
N is the number of teeth
M is the module of the cutter used


So all the 20 teeth gear has outer diameter of 22mm ((20+2)x1) and all the 80 teeth gear has outside diameter of 82mm ((80+2)x1). Before starting with the manufacturing process, you must draw a neat sketch of your gear box in a paper, showing its front view and top view, it will be good if you know a mechanical enginner who knows AUTOCAD or SOLIDWORKS. Knowledge of Engineering graphics is essential because you are going to have your gear box in your mind and draw its front and top view.

Three machines where used for gear box manufacuting, which are
  • Gear hobbing machine - used for cutting gears automatically, you have to just feed the information to the machine and it will cut the gears perfect. The gears made using the gear hobbing machine will have perfect finish, less time consuming. Best way to make a gear, but the problem is you have to convince the owner to make the gear for you because they will have big orders. Changing the setting for the gear requires more time and manual work. The below figure shows a gear hobbing machine.


  • Milling machine - used for cutting the gears manually, requires more time and labour cost for making a gear. They will cost Re.1 for each teeth i.e, 100 teeth gear will cost Rs.100. Please go for this machine if you are not finding any Gear hobbing machine in your locality.The below figure shows a milling machine.


  • Lathe - Before making a gear, you must make a circle having the specified OD, so you go for a lathe. Only after the turning and facing operation the circle must be taken to the gear hobbing machine or milling machine for making gear. Be careful in marking the center hole in the circle. The figure below shows a lathe machine.

The materials which we used for making gears are
  • acrylic material - half the weight of normal plastic, will look transparent and nice, strength is less when compared to nylon material. much attention must be paid while cutting the gears in this material, failure will result in breakage of gears.
  • nylon material - completely made synthetic fiber, has high strength and flexibility. less smooth when compared to acrylic material. no problem in cutting gears through nylon material.
  • brass metal - kind of bronze, an alloy of copper, tin and some zinc. Its a soft metal which can mesh easily with an acrylic or nylon material. Gear which is attached to the shaft of stepper motor is made using this gun metal.

Saturday, June 7, 2008

types of gears

In my previous post i have given details about the introduction to gears, now let us see the different types of gears. Many different forms of gears are used and the types most commonly used are,
  • Spur gear - Gears whose axes are parallel and whose teeth are parallel to the centerline of the gear are called spur gears. They are used to transmit power from one shaft or element to another in case where those shafts have their axes parallel.

  • Helical gear - Gears in which the teeth are cut in the form of helix around the gear. Helical gearing is used to connect parallel shafts as well as non-parallel, non-intersecting shafts. The pitch surfaces are cylindrical as in spur gearing, but the teeth, instead of being parallel to the axes, wind around the cylinders helical like screw threads.
  • Spiral gear - Skew or spiral gearing is used to connect non-parallel, non-intersecting shafts. The pitch surfaces are cylindrical and the teeth have point contact. suitable for transmitting only small power.
  • Bevel gear - When two shafts, the axes of which intersect, are to be connected by gearing, the wheels are known as bevel gears. The teeth are cut on a conical surface, such as would be represented by a truncated cone. Majority of bevel gear drives the shafts are at right angles, but in some cases the angles between the shafts may be either greater or less than 90 degrees, these are called as angular bevel gears.
  • Worm and worm wheel - Worm gearing is essentially a special form of helical gearing in which the teeth have line contact and the axes of the driving and driven shafts are usually at right angles and do not intersect. The distinction between helical gearing may be explained as follows : if the number of threads or teeth is such that no one thread makes a complete turn, the gear is called a helical gear. Of on the other hand, a thread makes a complete turn, the result is a worm and the mating material is called worm wheel.
  • Rack and pinion - The function is to transform circular motion to rectilinear motion : small gears are called pinions and racks are a series of teeth on a straight line. They may be considered as spur gears with infinite radii.

Friday, June 6, 2008

about gears

New to gears.. let us see the introduction to gears, later on we will discuss about the type of gears and the machines used in manufacturing gears..

Introduction :

There was a need for us to develop a gear box with a speed reduction ratio of 128:1 for my project, but there was no one to guide us in designing a gear box. Later on, i sought the help of some teachers in a polytechnic college and completed my gear box. I will now share my ideas regarding how to design a gear box (using spur gears) which will be useful to you. First let us see about the introduction to gears. The below figure shows our gear reduction box.


A gear is a component within a transmission device that transmits rotational force to another gear of device. Gears are the most common means of transmitting power in mechanical engineering. There are tiny gears for devices like wrist watches and there are large gears that some of you might have noticed in the movie Titanic. Gears form vital elements of mechanisms in many machines such as vehicles, metal tooling machine tools, rolling mills, hoisting and transmitting machinery, marine engines, and the like. Toothed gears are used to change the speed, power and direction between an input and output shaft. A gears most important feature is that gears of unequal sizes can be combined to produce a mechanical advantage, so that the rotational speed and torque of the second gear are different from that of the first.

The desired speed reduction (128:1) was obtained by a combination of software and hardware. By hardware, we designed a gear box with a speed reduction ratio of 64:1 (4x4x4) using three gear trains each having a gear ratio of 4:1. By software, we made the stepper motor to run in half step mode, thus achieving the final gear reduction of 128:1(64x2). That is for every 128 rotations of the gear attached to the shaft of stepper motor, the final gear will rotate only once.

Wednesday, June 4, 2008

principle of laser tracking system

We have already seen about laser tracking system in my previous post, now let us see the working principle of laser tracking system. Here we are going to track the tip of the finger as shown in the figure below. The laser beam from the source is made to incident over the steering mirror. The steering mirror is tilted in such a way that the reflected beam falls on the finger tip. The laser beam will form a circular saccade on the tip of the finger.

Fig.Laser Tracking System

The photodetector will detect the backscattered laser signal from the finger(see the diagram below). The saccade is supposed to remain fully inside the tip of the finger while tracking [fig (a)]. The backscattered signal will be high when the saccade remains fully inside the finger tip. As the object moves, a small portion of the saccade may fall outsid the finger tip, and the backscattered signal will momentarily drop. Due to the synchronous operation of the beam-steering mirrors and the photdetection, an accurate recentering vector(blue arrow) is computed [fig (b)]. The center of the saccade is updated accordingly [fig (c)]. By repeating these three steps continously we can track the movement of the finger tip.

Tuesday, June 3, 2008

about laser tracking system

why laser based tracking became famous?

The tracking system at present, scans the entire background along with the object to be tracked and by using intense image processing it separates the object from its background. After separating the object, the motion of the object is detected. This method is complex and expensive. But in laser tracking system instead of scanning the entire background along with the object, we will scan only the object. So no image processing is required at all. We can directly detect the motion of the object. This method requires only few components, hence very simple and inexpensive.


Components used in laser tracking system

The laser tracking system requires three main components. Performance of these components decides the accuracy and efficiency of tracking system. They are
  • Laser source - a focusable laser diode delivering required optical power. The required optical power depends on the distance between the object and the tracking system. When the object is at greater distance, high optical power is required and vice versa. since the target is likely to represent a small portion of the total field of view, the illuminating energy can be efficiently concentrated, and therefore the system will be extremely power-efficient and work equally well with distant targets. based on safety the laser source is classified into six types. they are class 1, class 2, class 2a, class 3a, class 3b and class 4.
  • Steering mirrors - can be tilted in both x and y axis, which is used for focusing the laser beam towards the object which is being tracked. please see the post regarding steering mirrors.
  • Photodetector - a transducer capable of accepting an optical signal and producing an electrical signal containing the same information as in the optical signal. As the requirements for applications vary a lot concerning wavelength, maximum optical power, dynamic range, linearity, quantum efficiency, bandwidth, size, robustness and cost, there are many types of photodetectors. For laser tracking application we require very narrow bandwidth, wide angle photodetectors.

Monday, June 2, 2008

working of steering mirrors

Steering mirror consist of a mirror(reflecting surface) and actuators. The actuators are used to tilt the mirror to required angle. It is of two types
  • single axis : mirror can be tilted with single axis freedom
  • two axis : mirror can be tilted with two axis freedom


since the mirror has to be tilted precisely, piezoelectric actuators are usually used. Piezoelectric actuators uses "inverse piezo effect" i.e, when exposed to an electric potential, piezoelectric materials change shape. The precise motion that results when an electric potential is applied to a piezoelectric material is used for tilting the mirror. fast steering mirrors can be used for laser beam steering mechanism.

Sunday, June 1, 2008

code for driving stepper motor in mikro c and ccs c compiler

code in mikroc for wave drive, half step and high torque stepping

//wave drive mode

main()
{
TRISB=0x00;
PORTB=0x00;

while(1)
{

Delay_ms(3);
PORTB=0b00001000;
Delay_ms(3);
PORTB=0b00000100;
Delay_ms(3);
PORTB=0b00000010;
Delay_ms(3);
PORTB=0b00000001;
}
}

//half step mode

main()
{
TRISB=0x00;
PORTB=0x00;

while(1)
{
Delay_ms(2);
PORTB=0b00001000;
Delay_ms(2);
PORTB=0b00001100;

Delay_ms(2);
PORTB=0b00000100;
Delay_ms(2);
PORTB=0b00000110;

Delay_ms(2);
PORTB=0b00000010;
Delay_ms(2);
PORTB=0b00000011;

Delay_ms(2);
PORTB=0b00000001;
Delay_ms(2);
PORTB=0b00001001;
}
}

//high torque stepping mode

main()
{
TRISB=0x00;
PORTB=0x00;

while(1)
{
Delay_ms(2);
PORTB=0b00001100;
Delay_ms(2);
PORTB=0b00000110;
Delay_ms(2);
PORTB=0b00000011;
Delay_ms(2);
PORTB=0b00001001;
}
}

code in ccs c compiler for driving stepper in wave drive mode

#include<16f877a.h> //including the PIC16F877A header file
#fuses HS,NOWDT,NOPROTECT,NOLVP //setting the fuses(please be careful in setting them)
#use delay(clock=20000000) //setting the clock frequency
#byte PORTB=0x06 //initializing the ports(please refer the memory organization in PIC datasheet)
#byte PORTC=0x07

int run( int r);
int temp;

int run( int r)
{
switch(r)
{
case 1:{
PORTb=0b00000001;
return(2);
}
case 2:{
PORTb=0b00000010;
return(3);
}
case 3:{
PORTb=0b00000100;
return(4);
}
case 4:{
PORTb=0b00001000;
return(1);
}
}
}

VOID main()
{
SET_TRIS_b(0X00);
PORTb=0x00;
temp=1;

while(1)
{
Delay_us(1000);
temp=run(temp);
}
}

i believe the following code snippet will be helpful to you in controlling stepper rotation