Вы находитесь на странице: 1из 82

JSPMs

Imperial College of Engineering and Research, Wagholi, Pune.


(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

LAB MANUAL
For

MECHATRONICS

T E (E&TC) 2015C

Electronics and Telecommunication


Engineering

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Lab Objectives:
1. To learn an IDE (Integrated Development Environment) like Keil IDE for 8051
microcontroller based practicals
2. To learn assembly language programming to perform 8051 based practicals
3. To learn an IDE like MPLAB IDE for PIC microcontroller based practicals
4. To learn an Embedded C programming to perform PIC microcontroller based practicals

Course/Lab Outcomes:
I. Course Outcomes:

Course outcome Statement


(CO)

II. Lab Outcomes:

Lab outcome (LO) Statement

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Experiment Level Outcomes (ELOs):

LO No. ELO ELO statement

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

List of Experiments

Class: T.E. Sub.: Mechatronics

Sr.
Experiment
No.
Position Control Using Servomechanism with Photo Electric Pick up or with
1 appropriate sensor.

Displacement and velocity measurement using encoder / suitable sensor.


2
Liquid flow measurement using appropriate transducer.
3
Weight Measurement using Load cell or any appropriate sensor.
4
Liquid Level measurement using appropriate sensor.
5
Interfacing of any two Sensors to DAQ
6
Demonstration of Hydraulic /Electro hydraulic components and Circuits.
7
Demonstration of Pneumatic/ Electro pneumatic Components and Circuits.
8
Case Study 1 (Implementation and Demonstration)
9
Case Study 2 (Study Report or Industrial Visit Report)
10

Experiment beyond syllabus

11 Study of LVDT

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Experiment No. 1
Title: Demonstration of Pneumatic/ Electro pneumatic Components and Circuits

Date of Performance: Roll No:

Date of Submission: University Seat No:

Signature of Staff:

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Experiment No. 1
Simple memory transfer program

Title: Memory transfer program

Problem statement:

Write an assembly language program to copy a block of 05 bytes of data from RAM memory locations
starting at 30H to RAM locations starting at 40H.

Aim:

1. To understand instructions of 8051 microcontroller.


2. To understand the concept of to store data in internal memory.

3. To understand the use of Keil IDE.

4. To write a simple program in Assembly language program.

Equipments Required:
S/W packages AND H/W used:

Keil version 3 software

Theory:

Understanding any processor or controller needs familiarity with its architecture and
instruction set. Any architecture can be best understood using its instruction set through
different programs.

One may use assembly language or embedded C for writing programs. Programs
written in assembly language are completely processor dependent and need major changes
when converting to other processor. While programs written in C are generally independent
of processor and needs minor changes during conversion to other processors.

C is thus preferred for programming. But to know and understand a processor better,
one must be familiar with assembly language.

Some development environment is needed to prepare any application. An editor is


needed first to provide a platform for writing programs i.e. source code. A source code
written in assembly/C language is needed to be converted to machine language (hex code)
before programming into processor. This conversion is done by compiler which converts
assembly/C language code to hex code. IDE i.e. Integrated Development Environment, serves

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

both these purposes as well as provide debugging facility. Assembly language file will be
stored by extension .asm, C file by extension .c and hex file by extension .hex.

RAM memory space allocation in the 8051:


There are 128 bytes of RAM in the 8051. The 128 bytes of RAM inside the 8051 are assigned address 00H
to 7FH.

Address Allocation
00 07H Register Bank 0
08 0FH Register Bank 1
10 17H Register Bank 2
18 1FH Register Bank 3
20 2FH Bit-Addressable RAM
30 7FH Scratch pad RAM

Register Indirect Addressing Mode:

In register indirect addressing mode, a register is used as a pointer to the data. If the data is
inside the CPU, only registers R0 & r1 are used for this purpose. In other words, R2-R7
cannot be used to hold the address of an operand located in RAM when using this
addressing mode. When R0 & R1 are used as pointers that is, when they hold the addresses
of RAM locations, they must be preceded by the @ sign as below,

MOV A, @R0 ; move contents of RAM location whose address is held in R0 to A


MOV @R1, A ; move contents of A into RAM location whose address is held by R1.

External Memory:

1) The 16-bit external memory address is held by the DPTR register.

MOVX A, @DPTR

This moves into the accumulator a byte from external memory whose address is pointed to
by DPTER. In other words, this brings data into the CPU from the off-chip memory of the
8051.

MOVX @DPTR, A

This moves the contents of the accumulator to the external memory location whose address
is held by DPTR, In other words, this takes data from inside the CPU (register A) to memory
outside of the 8051.

2) The 8-bit address of the external memory is held by R0 or R1.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

MOVX A, @R0

This moves to the accumulator a byte from external memory whose 8-bit address is pointed
to by R0.

MOV @Ri, A

This moves a byte from register A to an external memory whose 8-bit address is held by R)
or R1.

Algorithm Steps:
1] Start.
2] Store the first value in general purpose register i.e. initialize the starting address of memory
block1 from which values to be copied.
3] Store the second value in general purpose register i.e. initialize the starting address of memory
block2 to which values to be copied.
4] Initialize counter of the values i.e. how many values to be transferred.
5] Copy value of first location of memory block1 into accumulator register (A).
6] Copy content of accumulator register (A) into first location of memory block2.
7] Increment location of memory block 1.
8] Increment location of memory block 2.
9] Decrement counter & if condition satisfies then go to Step no. 5 & continue further till counter
becomes zero.
10] End.
Experimental Procedure:

1) Click on Keil Vision3 icon for getting started.


2) Click on Project tab>Make new project> Select target device.
3) Click on File>New file.
4) Prepare a test code in assembly language as shown in editor window. Save it with .asm
extension.
5) Add this created file to project. One may add one or more than one file in a single project.
6) Click Target1 (at left side pane)>Source Group> Right click to add code file.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

7) Open Project tab> Options for target target1> Output tab>check create hex file
option.
8) Open Project tab> Build target. This will generate compiled .hex file from the .asm or .C
file, in the project created.
9) Click on Start/Stop debug session. Load values in locations of memory block1.
10) Click on Run to start code execution & check content of memory block2.
Result:

Before execution

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

After execution

Conclusion:

In this experiment, we have performed memory transfer from one memory block to
another memory block. Also we have learned the steps of execution in Keil IDE.

Experiment No. 2
Title: Parallel port interacting of LEDs

Date of Performance: Roll No:

Date of Submission: University Seat No:

Signature of Staff:

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Experiment No. 2
LED interfacing

Title: Parallel port interacting of LEDs

Problem statement:
Write an assembly language program to flash (or blink) LEDs connected to port considering a time
delay.

Aim:

5. To understand instructions of 8051 microcontroller.


6. To understand the use of Keil IDE.
7. To write a simple program in Assembly language program for LED flashing.
8. To understand interfacing of microcontroller with peripherals.

Equipments Required:
S/W packages AND H/W used:
Keil version 3 software, Flash Magic software, P89V51 microcontroller board, LED bank,
RS232 cable, FRC cables, Power adaptor etc.

Theory:

The general View of LED is shown in Fig. 1

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Fig. 1 View of LED

Current flows from anode to cathode. A 330 register is connected between port lines and
LED. Resistance of an LED is almost zero. Hence current flowing through LED is I=V/R which
is approximately in mA.
In this experiment, the LEDs are connected to port of the microcontroller. The LEDs
will glow alternatively with a time delay.

FLOW CHART:

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Fig. Flowchart

Experimental Procedure:

11) Click on Keil Vision3 icon for getting started.


12) Click on Project tab>Make new project> Select target device.
13) Click on File>New file.
14) Prepare a test code in assembly language as shown in editor window. Save it with
.asm extension.
15) Add this created file to project. One may add one or more than one file in a single
project.
16) Click Target1 (at left side pane)>Source Group> Right click to add code file.
17) Open Project tab> Options for target target1> Output tab>check create hex file
option.
18) Open Project tab> Build target. This will generate compiled .hex file from the .asm
or .C file, in the project created.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

19) Now burn hex code onto microcontroller with Flash Magic software. Then observe
output on peripherals.

Conclusion:

In this experiment, we have interfaced LEDs to microcontroller. The LEDs flashed


alternatively with a time delay.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Experiment No. 3
Title: Interfacing of LCD

Date of Performance: Roll No:

Date of Submission: University Seat No:

Signature of Staff:

Experiment No. 3
LCD interfacing

Title: Interfacing of 16x2 LCD

Problem statement:
MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Write an assembly language program to interface 16x2 LCD with 8051 microcontroller.
Aim:

1. To understand the concept of interfacing of LCDs with port of 8051 microcontroller.


2. To write program to display message with and without checking busy flag of LCD.

3. To configure LCD in different modes.

4. To understand different LCD commands.

Equipments Required:
S/W packages AND H/W used:
Keil version 3 software, Flash Magic software, P89V51 microcontroller board, LCD
module, RS232 cable, FRC cables, Power adaptor etc.

Theory:

LCD stands for Liquid Crystal Display. It is used to display message in the form of
letters, numbers, and alphabets. There are various configurations of LCD (1 line by 20 X char
up to 8 lines X 80). The forms of LCDs are 8x2,16x1, 16x2, 16x4, 20x2, 24x2,40x2, 40x4. The
LCD display has two registers as Command register & Data register. These registers can be
selected using RS register. The Data lines (DB7-DB0) used to transfer data and commands.

Pin description
The most commonly used LCDs found in the market today are 1 Line, 2 Line or 4 Line
LCDs which have only 1 controller and support at most of 80 characters, whereas LCDs
supporting more than 80 characters.

The schematic of LCD is shown in Fig. 1 below.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Fig. 1 LCD

Table 1: LCD pins

Pin no. Function Pin no. Function


01 Ground 02 Supply voltage+5V
03 Contrast (10K) 04 RS [0-cammand, 1-data]
05 R/W [1-R, 0-W] 06 EN [L-H strobe]
07 D0 08 D1
09 D2 10 D3
11 D4 12 D5
13 D6 14 D7 [Busy]
15 Supply voltage+5V 16 Ground 4.7K backlight

Busy Flag (BF)

When the busy flag is 1, the LCD is in the internal operation mode, and the next instruction
will not be accepted. When RS = 0 and R/W = 1 (see the table above), the busy flag is output
to DB7 (MSB of LCD data bus). The next instruction must be written after ensuring that the
busy flag is 0.

ALGORITHM STEPS
General steps for programming of LCD

1. Initialize LCD using format function set


2. Command word for display on Blinking/no blinking
3. Command word for clear LCD screen
4. Command for cursor shift (Right or Left )
5. Command for position of cursor 80+ for line 1 & C0+ for line 2
6. load characters to be displayed
MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

7. While writing each command be sure that RS=0, R/W=0 E=1 H-L pulse, E=0.
Before start writing LCD for Display of information it is necessary to check for busy
flag.
Check for busy flag (D7) bit
- RS=0, and R/W=1, D7=1 -- LCD is busy taking care of internal operations and
not accept any data.
- RS=0, and R/W=1, D7=0 -- LCD is ready to accept any data.
For command RS=0 is passed through port line
For Data RS=1 is passed through port line
Send high to low pulse to E pin to enable the internal latch of LCD
Call delay for completion of internal operations
Send different command words
Pass data to be displayed

Algorithm for Checking the Busy Flag

You can use subroutine for checking busy flag or just a big (and safe) delay.

1. Set R/W Pin of the LCD HIGH(read from the LCD)


2. Select the instruction register by setting RS pin LOW
3. Enable the LCD by Setting the enable pin HIGH
4. The most significant bit of the LCD data bus is the state of the busy flag (1=Busy,
0=ready to accept instructions/data). The other bits hold the current value of the
address counter.

If the LCD never come out from busy" status because of some problems. The
program will hang", waiting for DB7 to go low. So in real applications it would be wise to
put some kind of time limit on the delay--for example, a maximum of 100 attempts to wait
for the busy signal to go low. This would guarantee that even if the LCD hardware fails, the
program would not lock up.

Algorithm for Command word

1. Select the instruction register by setting RS pin LOW


2. Set R/W Pin of the LCD low(write to LCD)
3. Enable the LCD by Setting the enable pin HIGH
4. Delay
5. Latch the data E=0

Algorithm for Data write to LCD

1. Select the instruction register by setting RS pin high


MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

2. Set R/W Pin of the LCD low (write to LCD)


3. Enable the LCD by Setting the enable pin HIGH
4. Delay
5. Latch the data E=0

FLOW CHART:

Start
Start
Initialize LCD By sending different
command words1. Function set,
cursor condition, clear memory etc Select command register
REGISTER SELECT RS= 0

To write in command SET RS=0,


R/W=0 and E = 0-1-0 short time
Check the busy flag of LCD

Call delay routine between


each command word
Set RW as 0 for writing into LCD

Load character to be displayed

Give low-high low pulse to


enable signal by setting &
To write in Data register SET RS=1, resetting the port line P0.5
R/W=0 and E = 0-1-0

Transfer bit pattern to port used for LED


Call delay routine between
interface Move data from 89C52 to LCD data
each character pins

RETURN
Stop

Fig. Flowchart

Experimental Procedure:

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

1) Click on Keil Vision3 icon for getting started.


2) Click on Project tab>Make new project> Select target device.
3) Click on File>New file.
4) Prepare a test code in assembly language as shown in editor window. Save it with .asm
extension.
5) Add this created file to project. One may add one or more than one file in a single project.
6) Click Target1 (at left side pane)>Source Group> Right click to add code file.
7) Open Project tab> Options for target target1> Output tab>check create hex file
option.
8) Open Project tab> Build target. This will generate compiled .hex file from the .asm or .C
file, in the project created.
9) Now burn hex code onto microcontroller with Flash Magic software. Then observe output
on peripherals.

Conclusion:

In this experiment, we have interfaced 16x2 LCD with microcontroller & displayed a
message on LCD. Also studied LCD commands, data register mode & command register
mode.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Experiment No. 4
Title: Interfacing of Stepper motor

Date of Performance: Roll No:

Date of Submission: University Seat No:

Signature of Staff:

Experiment No. 4
Stepper motor interfacing

Title: Interfacing of Stepper motor

Problem statement:
Write an assembly language program to interface stepper motor with 8051 microcontroller.
Aim:

10) To understand instructions of 8051 microcontroller.


11) To understand the use of Keil IDE.
12) To write a simple program in Assembly language program.
13) To understand interfacing of microcontroller with peripherals.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Equipments Required:
S/W packages AND H/W used:
Keil version 3 software, Flash Magic software, P89V51 microcontroller board, Stepper
motor, RS232 cable, FRC cables, Power adaptor etc.

Theory:

A stepper motor is a brushless, synchronous electric motor that converts digital pulses into
mechanical shaft rotation. Every revolution of the stepper motor is divided into a discrete number of
steps, in many cases 200 steps, and the motor must be sent a separate pulse for each step. The
stepper motor can only take one step at a time and each step is the same size. Since each pulse
causes the motor to rotate a precise angle, typically 1.8, the motor's position can be controlled
without any feedback mechanism. As the digital pulses increase in frequency, the step movement
changes into continuous rotation, with the speed of rotation directly proportional to the frequency
of the pulses. Step motors are used every day in both industrial and commercial applications
because of their low cost, high reliability, high torque at low speeds and a simple, rugged
construction that operates in almost any environment.

Stepper Motor Advantages


8. The rotation angle of the motor is proportional to the input pulse.
9. The motor has full torque at standstill (if the windings are energized).
10. Precise positioning and repeatability of movement since good stepper motors have an
accuracy of 3 to 5% of a step and this error is non-cumulative from one step to the next.
11. Excellent response to starting/stopping/reversing.
12. Very reliable since there are no contact brushes in the motor. Therefore the life of the step
motor is simply dependant on the life of the bearing.
13. The stepper motors response to digital input pulses provides open-loop control, making the
motor simpler and less costly to control.
14. It is possible to achieve very low speed synchronous rotation with a load that is directly
coupled to the shaft.
15. A wide range of rotational speeds can be realized as the speed is proportional to the
frequency of the input pulses.

Types of Step Motors


There are three basic types of step motors: variable reluctance, permanent magnet, and hybrid. This
discussion will concentrate on the hybrid motor, since these step motors combine the best
characteristics of the variable reluctance and permanent magnet motors. They are constructed with
multi-toothed stator poles and a permanent magnet rotor. Standard hybrid motors have 200 rotor
teeth and rotate at 1.8 step angles. Because they exhibit high static and dynamic torque and run at
very high step rates, hybrid step motors are used in a wide variety of commercial applications

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

including computer disk drives, printers/plotters, and CD players. Some industrial and scientific
applications of stepper motors include robotics, machine tools, pick and place machines, automated
wire cutting and wire bonding machines, and even precise fluid control devices.

Step Modes
Stepper motor "step modes" include Full, Half and Micro step. The type of step mode output of any
stepper motor is dependent on the design of the driver. stepper motor drives with switch selectable
full and half step modes, as well as microstepping drives with either switch-selectable or software-
selectable resolutions.

FULL STEP
Standard hybrid stepping motors have 200 rotor teeth, or 200 full steps per revolution of the motor
shaft. Dividing the 200 steps into the 360 of rotation equals a 1.8 full step angle. Normally, full step
mode is achieved by energizing both windings while reversing the current alternately. Essentially
one digital pulse from the driver is equivalent to one step.

HALF STEP
Half step simply means that the step motor is rotating at 400 steps per revolution. In this mode, one
winding is energized and then two windings are energized alternately, causing the rotor to rotate at
half the distance, or 0.9. Although it provides approximately 30% less torque, half-step mode
produces a smoother motion than full-step mode.

MICROSTEP
Microstepping is a relatively new stepper motor technology that controls the current in the motor
winding to a degree that further subdivides the number of positions between poles. Omegamation
microstepping drives are capable of dividing a full step (1.8) into 256 microsteps, resulting in
51,200 steps per revolution (.007/step). Microstepping is typically used in applications that require
accurate positioning and smoother motion over a wide range of speeds. Like the half-step mode,
microstepping provides approximately 30% less torque than full-step mode.

Linear Motion Control


The rotary motion of a stepper motor can be converted to linear motion using a lead screw/worm
gear drive system (See figure B). The lead, or pitch, of the lead screw is the linear distance traveled
for one revolution of the screw. If the lead is equal to one inch per revolution, and there are 200 full
steps per revolution, then the resolution of the lead screw system is 0.005 inches per step. Even finer
resolution is possible by using the step motor/drive system in microstepping mode.
Series vs. Parallel Connection
There are two ways to connect a stepper motor, in series or in parallel. A series connection provides
a high inductance and therefore greater torque at low speeds. A parallel connection will lower the
inductance which results in increased torque at faster speeds.

Driver Technology

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

The stepper motor driver receives step and direction signals from the indexer or control system and
converts them into electrical signals to run the step motor. One pulse is required for every step of the
motor shaft. In full step mode, with a standard 200-step motor, 200 step pulses are required to
complete one revolution. The speed of rotation is directly proportional to the pulse frequency.
Speed and torque performance of the step motor is based on the flow of current from the driver to
the motor winding.
The factor that inhibits the flow, or limits the time it takes for the current to energize the winding, is
known as inductance. The effects of inductance, most types of driver circuits are designed to supply
a greater amount of voltage than the motor's rated voltage. The higher the output voltage from the
driver, the higher the level of torque vs. speed. Generally, the driver output voltage (bus voltage)
should be rated at 5 to 20 times higher than the motor voltage rating. In order to protect the motor
from being damaged, the step motor drive should be current-limited to the step motor current
rating.

Experimental Procedure:

Click on Keil Vision3 icon for getting started.


Click on Project tab>Make new project> Select target device.
Click on File>New file.
Prepare a test code in assembly language as shown in editor window. Save it with
.asm extension.
Add this created file to project. One may add one or more than one file in a single
project.
Click Target1 (at left side pane)>Source Group> Right click to add code file.
Open Project tab> Options for target target1> Output tab>check create hex file
option.
Open Project tab> Build target. This will generate compiled .hex file from the .asm
or .C file, in the project created.
Now burn hex code onto microcontroller with Flash Magic software. Then observe
output on peripherals.

Conclusion:

In this experiment, we have interfaced Stepper motor with microcontroller. The


motor revolved with different steps. Also we have connected a driver for motor
controlling action.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Experiment No. 5
Title: Interfacing button, LED, relay & buzzer

Date of Performance: Roll No:

Date of Submission: University Seat No:

Signature of Staff:

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Experiment No. 5
LED, BUZZER, BUTTON & RELAY INTERFACING

Title: Interfacing Push buttons, LEDs, Relay & Buzzer to PIC Microcontroller

Problem statement:
Interface Push buttons, LEDs, Relay and Buzzer to PIC Microcontroller. Write a program in
Embedded C to interact with peripherals as follows.
a. LEDs start chasing from left to right and turn ON Relay, buzzer whenever pushbutton 1 is
pressed.
b. LEDs start chasing from right to left and turn OFF Relay, buzzer whenever pushbutton 2 is
pressed.

Aim:

9. To understand the PORT Structure of PIC Microcontroller.


10. To study the SFRs to control the PORT Pins.
11. To interface common peripherals like pushbuttons, LEDs, relay.
12. To understand the use of MPLAB IDE and C18 Compiler.
13. To write a simple program in Embedded C.

Equipments Required:
S/W packages AND H/W used:

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

MPLAB IDE, C18 Compiler, ExplorePIC Development Board

Theory:

Depending on the device selected, there are up to five general purpose I/O ports available on
PIC18F Microcontroller devices. Some pins of the I/O ports are multiplexed with an alternate
function from the peripheral features on the device. In general, when a peripheral is enabled, that pin
may not be used as a general purpose I/O pin.

Each port has three registers for its operation.

TRIS register (Data Direction register): To select PORT pin as input or output. All port pins are input
by default. Whenever a bit in the TRISx register is a 0, the corresponding bit in PORTx is an output. If
the bit in TRISx is a 1, the corresponding bit in PORTx is an input.

PORT register (reads the levels on the pins of the device)


LAT register (output latch): The data latch (LAT register) is useful for read-modify-write operations
on the value that the I/O pins are driving.

Algorithm Steps:

1. As LED connected to PORTD configure these pins as output by writing 0x00 to the
appropriated TRES register.
2. As buttons are connected to RB.4 and RB.5 so configure these pins as input by writing 1 to
the appropriated bits of TRES register.
3. Check the status of RB.4, if it is zero then move 1 bit of PORTB from right to left.
4. Else check the status of RB.5, if it is zero then move 1 bit of PORTB from left to right.
5. Repeat step 3 to 4.

Experimental Procedure:

1. Open MPLAB IDE. Open Project menu and select project wizard. Then click on Next
button and select device as PIC18F4550. Click on Next button.

2. Select Active Toolsuite as Microchip C18 Toolsuite and select Toolsuite contents as
MPLAB C18 C compiler (mcc18.exe). Click on Next button.

3. Click on Browse button. Create a new folder on desktop (or any drive location) and
save file. Then click on Next button and again click on Next button. Click on Finish
button.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

4. Open File menu and select New file and write a program. Save this program in a folder
which is created for your project.

5. Right click on Source Files and add C file from your project folder.

6. Build project file and check errors in C code. If code is free then you will get Hex file
for your C code.

7. To burn this Hex file into PIC18F4550, connect PICkit2 programmer to Kit. Open
Programmer menu and select programmer as PICkit2. Then you will get message as
PICkit2 is ready in output window.

8. Then click on Program the target device and then click on Bring target MCLR to VDD.

9. Then observe the output on respective port and peripheral.

Conclusion:

In this experiment, we have interfaced LED, buttons, relay and buzzer with
PIC18F4550

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Experiment No. 6
Title: Generation of Square wave using timer with interrupt

Date of Performance: Roll No:

Date of Submission: University Seat No:

Signature of Staff:

Experiment No. 6
Generation of Square wave using timer with interrupt

Title: Generation of Square wave using timer with interrupt.

Problem statement:
Write a program to generate a square wave of 10 Hz on the port pin RB0 (pin no. 33). Use
timer0 interrupt for ON period and OFF period delay.

Aim:

c. To understand the basic concepts of Timer and Counter


d. To study in detail Timer0 of PIC Microcontroller
e. To Study interrupt structure of PIC Microcontroller
f. To use timer interrupt and its related SFR.
MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Equipments Required:
S/W packages AND H/W used:
MPLAB IDE, C18 Compiler, ExplorePIC Development Board

Theory:

1. Timer
The microcontroller oscillator uses quartz crystal for its operation. Even though it is not the
simplest solution, there are many reasons to use it. The frequency of such oscillator is precisely
defined and very stable, so that pulses it generates are always of the same width, which makes them
ideal for time measurement. Such oscillators are also used in quartz watches. If it is necessary to
measure time between two events, it is sufficient to count up pulses generated by this oscillator. This
is exactly what the timer does. Most programs use these miniature electronic stopwatches. These
are commonly 8- or 16-bit SFRs the contents of which are automatically incremented by each coming
pulse. Once a register is completely loaded and overflowed, an interrupt may be generated.
If the timer uses an internal quartz oscillator for its operation then it can be used to measure
time between two events (if the register value is A at the moment measurement starts, and B at the
moment it terminates, then the elapsed time is equal to the result of subtraction B - A). If registers
use pulses coming from external source then such a timer is turned into a counter.

1.1 How does the timer operate?


In practice, pulses generated by the quartz oscillator are once per each machine cycle,
directly or via a prescaler, brought to the circuit which increments the number stored in the timer
register. If one instruction (one machine cycle) lasts for four quartz oscillator periods then this
number will be incremented a million times per second (each microsecond) by embedding quartz
with the frequency of 4MHz. It is easy to measure short time intervals, up to 256 microseconds, in
the way described above because it is the largest number that one register can store. Figure 1.1
shows timer operation. This restriction may be easily overcome in several ways such as by using a
slower oscillator, registers with more bits, prescaler or interrupts. The first two solutions have some
weaknesses so it is more recommended to use prescaler or interrupt.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Fig. 1.1 Timer operation

1.2 Using a prescaler in timer operation


A prescaler is an electronic device used to reduce frequency by a predetermined factor. In
order to generate one pulse on its output, it is necessary to bring 1, 2, 4 or more pulses on its input.
Most microcontrollers have one or more prescaler built in and their division rate may be changed
from within the program. The prescaler is used when it is necessary to measure longer periods of
time. If one prescaler is shared by timer and watchdog timer, it cannot be used by both of them
simultaneously. Figure 1.2 shows timer operation with a prescaler.

1.3 Using interrupt in timer operation


If the timer register consists of 8 bits, the largest number it can store is 255. As for 16-bit
registers it is the number 65535. If this number is exceeded, the timer will be automatically reset and
counting will start at zero again. This condition is called an overflow. If enabled from within the
program, the overflow can cause an interrupt, which gives completely new possibilities. For example,
the state of registers used for counting seconds, minutes or days can be changed in an interrupt
routine. The whole process (except for interrupt routine) is automatically performed behind the
scenes, which enables the main circuits of the microcontroller to operate normally. This figure 1.3
illustrates the use of an interrupt in timer operation. Delays of arbitrary duration, having almost no
influence on the main program execution, can be easily obtained by assigning the prescaler to the
timer.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Fig. 1.2 Timer operation with prescaler

2. Counters
If the timer receives pulses from the microcontroller input pin, then it turns into a counter.
Obviously, it is the same electronic circuit able to operate in two different modes. The only
difference is that in this case pulses to be counted come over the microcontroller input pin and
their duration (width) is mostly undefined. This is why they cannot be used for time
measurement, but for other purposes such as counting products on an assembly line, number of
axis rotation, passengers etc. (depending on sensor in use).q

3. Timers / Counters in PIC Microcontroller


There are 3 - 5 timers on board in PIC microcontroller. These timers can also be used as
counters when external pulses are applied. The timers are programmable, and sometimes share
with other peripheral devices. These are named as TMR0, TMR1, TMR2, TMR3 and TMR4. There
are few other timers, not to be discussed here like Watchdog Timer and Brown-Out timers. These
timers are useful in measuring the time delays in various events as well as counting and timing
external events.

4. Time delay generation using timer


The following steps are taken to generate a time delay using polling method

1. Load the proper value in T0CON indicating which timer mode, clock source, prescaler
assignment.
2. Load the registers TMR0H first and then TMR0L with initial count values. Delay
generated is Depends upon the initial count value.
3. Start the timer by setting TMR0ON bit in T0CON.
4. Keep the monitoring the timer flag (TMR0IF).
5. Get out of the loop when TMR0IF becomes high.
6. Stop the timer.
7. Clear the TMR0IF flag for the next round.
8. Go back to the step 2 to load TMR0H and TMR0L values.

The following steps are taken to generate a time delay using interrupt method
i. Load the proper value in T0CON indicating which timer mode, clock source,
prescaler assignment.
ii. Load the registers TMR0H first and then TMR0L with initial count values. Delay
generated is Depends upon the initial count value.
iii. Enable the Timer0 Interrupt and Global Interrupt using INTCON Register
iv. Start the timer by setting TMR0ON bit in T0CON.
MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

v. Write the ISR at Interrupt vector 0x0018.


a. In ISR Clear the TMR0IF flag for the next round.
b. In ISR reload TMR0H and TMR0L values.

Algorithm Steps:

1. Configure Port pin RB0 as output and initial value 0.


2. Load the value 0x02 in T0CON indicating which timer in 16-b it mode, clock source Fosc/4,
prescaler assignment with 1:8.
3. Load the registers TM R0H first and then TMR0L with calculated initial count values.
4. Enable the Timer0 Interrupt and Global Interrupt using INTCON Register
5. Start the timer by setting TMR0ON bit in T0CON.
6. Write the ISR at Interrupt vector 0x0018 which contains following.
a. Toggle the PORT pin RB0
b. In ISR Clear the TMR0IF flag for the next round.
c. In ISR reload TMR0H and TMR0L values.

Experimental Procedure:

1. Open MPLAB IDE. Open Project menu and select project wizard. Then click on Next
button and select device as PIC18F4550. Click on Next button.

2. Select Active Toolsuite as Microchip C18 Toolsuite and select Toolsuite contents as
MPLAB C18 C compiler (mcc18.exe). Click on Next button.

3. Click on Browse button. Create a new folder on desktop (or any drive location) and
save file. Then click on Next button and again click on Next button. Click on Finish
button.

4. Open File menu and select New file and write a program. Save this program in a folder
which is created for your project.

5. Right click on Source Files and add C file from your project folder.

6. Build project file and check errors in C code. If code is free then you will get Hex file
for your C code.

7. To burn this Hex file into PIC18F4550, connect PICkit2 programmer to Kit. Open
Programmer menu and select programmer as PICkit2. Then you will get message as
PICkit2 is ready in output window.

8. Then click on Program the target device and then click on Bring target MCLR to VDD.
MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

9. Then observe the output on respective port and peripheral.

Conclusion:

We have generated square wave using timer with interrupt and output is observed on
LEDs.

Experiment No. 7
Title: Serial Communication between PC and PIC Microcontroller

Date of Performance: Roll No:

Date of Submission: University Seat No:

Signature of Staff:

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Experiment No. 7
Serial communication between PC and PIC microcontroller

Title: Interfacing serial port with PC both side communication

Problem statement:
Write a program in Embedded C to transfer the message and receive serially at 9600
baud, 8 bit data.

Aim:

g. To study the RS232 standard for serial communication


h. To Study the on-chip USART of PIC Microcontroller
i. To calculate the desired baud rate.
j. To interface MAX232 with PIC Microcontroller for serial communication.

Equipments Required:
S/W packages AND H/W used:
MPLAB IDE, C18 Compiler, ExplorePIC Development Board

Theory:

1. Serial Communication:

The microcontroller is parallel device that transfers eight bits of data simultaneously
over eight data lines to parallel I/O devices. However, in many situations, parallel data
transfer is impractical. For example, parallel data transfer over a long is very expensive.
MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Hence, a serial communication is widely used in long distance communication.


In serial data communication, 8-bit data is converted to serial bits using a parallel in
serial out shift register and then it is transmitted over a single data line. The data byte is
always transmitted with least significant bit first.
Serial ports are a type of computer interface for serial communication that complies
with the RS-232 standard. They are 9-pin connectors that relay information, incoming or
outgoing, one byte at a time. Each byte is broken up into a series of eight bits, hence the term
serial port. Serial ports are controlled by a special chip call a UART (Universal Asynchronous
Receiver Transmitter).
1.1 Communication links:
Serial communication is classified into three types of communication.
a. Simplex communication link: In simplex transmission, the line is dedicated for
transmission. The transmitter sends and the receiver receives the data.
b. Half duplex communication link: In half duplex, the communication link can be used
for either transmission or reception. Data is transmitted in only one direction at a
time.
c. Full duplex communication link: If the data is transmitted in both ways at the same
time, it is a full duplex i.e. transmission and reception can proceed simultaneously.
This communication link requires two wires for data, one for transmission and one
for reception.

1.2 Types of Serial communication:


Serial data communication uses two types of communication.
0 Synchronous serial data communication: In this transmitter and receiver
are synchronized. It uses a common clack to synchronize the receiver and the
transmitter. First the synch character is sent and then the data is transmitted.
This format is generally used for high speed transmission. In Synchronous
serial data communication a block of data is transmitted at a time.

1 Asynchronous Serial data transmission: In this, different clock sources are


used for transmitter and receiver. In this mode, data is transmitted with start
and stop bits. A transmission begins with start bit, followed by data and then
stop bit. For error checking purpose parity bit is included just prior to stop bit.
In Asynchronous serial data communication a single byte is transmitted at a
time.

1.3 Baud rate:


The rate at which the bits are transmitted is called baud or transfer rate. The baud

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

rate is the reciprocal of the time to send one bit. In asynchronous transmission, baud rate is
not equal to number of bits per second. This is because; each byte is preceded by a start bit
and followed by parity and stop bit. For example, in synchronous transmission, if data is
transmitted with 9600 baud, it means that 9600 bits are transmitted in one second. For bit
transmission time = 1 second/ 9600 = 0.104 ms.

2. RS-232 standards:
To allow compatibility among data communication equipment made by various
manufactures, an interfacing standard called Rs232 was set by the Electronics Industries
Association (EIA) in 1960. In 1963 it was modified and called RS232A. RS232B and RS232C
were issued in 1965 and 1969, respectively. Today Rs232is the most widely used serial I/O
interfacing standard. This standard is used in PCs and numerous equipments. However,
since the standard was set long before the advent of logic family, its input and output voltage
levels are not TTL compatible. In RS232, a logic one (1) is represented by -3 to -25V and
referred as MARK while logic zero (0) is represented by +3 to +25V and referred as SPACE.
For this reason to connect any RS232 to a microcontroller system we must use
voltage converters such as MAX232 to convert the TTL logic level to RS232 voltage levels
and vice-versa. MAX232 IC chips are commonly referred as line drivers.

2.1. Serial Data Format


The serial data format includes one start bit, between five and eight data bits, and
one stop bit. A parity bit and an additional stop bit might be included in the format as well.
The figure 4.1 below illustrates the serial data format.

Fig. 1.1 Serial data format

The format for serial port data is often expressed using the following notation:
Number of data bits - parity type - number of stop bits.
For example, 8-N-1 is interpreted as eight data bits, no parity bit, and one stop bit,
while 7-E-2 is interpreted as seven data bits, even parity, and two stop bits.
The data bits are often referred to as a character because these bits usually represent
an ASCII character. The remaining bits are called framing bits because they frame the data
bits.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

3. EUSART Module in PIC Microcontroller


The Enhanced Universal Synchronous Asynchronous Receiver Transmitter (EUSART)
module is one of the two serial I/O modules. (Generically, the USART is also known as a
Serial Communications Interface or SCI.) The EUSART can be configured as a full-duplex
asynchronous system that can communicate with peripheral devices, such as CRT terminals
and personal computers. It can also be configured as a half duplex synchronous system that
can communicate with peripheral devices, such as A/D or D/A integrated circuits, serial
EEPROMs, etc. The Enhanced USART module implements additional features, including
automatic baud rate detection and calibration, automatic wake-up on Sync Break reception
and 12-bit Break character transmit. These make it ideally suited for use in Local
Interconnect Network bus (LIN bus) systems. The EUSART can be configured in the
following modes:
Asynchronous (full-duplex) with:
- Auto-wake-up on Break signal
- Auto-baud calibration
- 12-bit Break character transmission
Synchronous Master (half-duplex) with
selectable clock polarity
Synchronous Slave (half-duplex) with selectable
clock polarity

3.1 Pin description


The pins of the Enhanced USART are multiplexed with PORTC. In order to configure
RC6/TX/CK and RC7/RX/DT/SDO as an EUSART:
1. bit SPEN (RCSTA<7>) must be set (= 1)
2. bit TRISC<7> must be set (= 1)
3. bit TRISC<6> must be set (= 0)

3.2 EUSART Register Map:


The operation of the Enhanced USART module is controlled through three registers:
Transmit Status and Control (TXSTA)
Receive Status and Control (RCSTA)
Baud Rate Control (BAUDCON)

3.3 Baud Rate Generator (BRG)


The BRG is a dedicated 8-bit, or 16-bit, generator that supports both the
Asynchronous and Synchronous modes of the EUSART. By default, the BRG operates in 8-
bit mode. Setting the BRG16 bit (BAUDCON<3>) selects 16-bit mode. The SPBRGH:SPBRG

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

register pair controls the period of a free-running timer. In Asynchronous mode, bits
BRGH (TXSTA<2>) and BRG16 (BAUDCON<3>) also control the baud rate. In Synchronous
mode, BRGH is ignored. Table 1.1 shows the formula for computation of the baud rate for
different EUSART modes which only apply in Master Mode (internally generated clock).
Given the desired baud rate and FOSC, the nearest integer value for the SPBRGH:SPBRG
registers can be calculated using the formulas in Table 1.1. From this, the error in baud
rate can be determined. It may be advantageous to use the high baud rate (BRGH = 1), or
the 16-bit BRG to reduce the baud rate error, or achieve a slow baud rate for a fast
oscillator frequency. Writing a new value to the SPBRGH:SPBRG registers causes the BRG
timer to be reset (or cleared). This ensures the BRG does not wait for a timer overflow
before outputting the new baud rat
Table 1.1: Baud rate formulae

Configuration Bits Baud Rate Formula


SYNC BRG16 BRGH BRG Mode / EUSART Mode [n= SPBRGH:SPBRG]
0 0 0 8-bit / Asynchronous BR = Fosc/[64(n+1)]
0 0 1 8-bit / Asynchronous
BR = Fosc /[16(n+1)]
0 1 0 16-bit / Asynchronous
0 1 1 16-bit / Asynchronous
1 0 x 8-bit / Synchronous BR = Fosc/[4(n+1)]
1 1 x 16-bit / Synchronous

3.4 Baud rate Calculation Mode selection


a. BRG Mode = 8-bit by setting BRG16 bit in BAUDCON Register
b. EUSART mode = Asynchronous by clearing SYNC bit in TXSTA Register
c. Formulae Desired Buad Rate = Fosc / [4(SPBRGH:SPBRG+1)] selected by setting
BRG16 bit in TXSTA Register

For Fosc = 20MHz, Baud rate = 9600

SPBRGH:SPBRG = [Fosc/4(Baud rate)]-1


= [20x106/(4x9600)] 1
= [519]10 = [0207]16

% Error = (Calculated baud rate - Desired Baud Rate)/Desired Baud Rate


= (Fosc / [4(SPBRGH:SPBRG+1)] 9600)/Desired Baud Rate
= ([20x106/[4x(520+1)]] 9600)/Desired Baud Rate
MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

= (9615 9600)/9600
% Error = 0.16 %

Therefore to reduce error we have selected SPBRGH = 0x02 and SPBRG = 0x08
For Fosc = 48MHz, Baud rate = 9600
SPBRGH:SPBRG = [Fosc/4(Baud rate)]-1
= [48x106/(4x9600)] 1
= [1249]10 = [04E1]16
Therefore SPBRGH = 0x04 and SPBRG = 0xE1

% Error = (Calculated baud rate - Desired Baud Rate)/Desired Baud Rate

= (Fosc / [4(SPBRGH:SPBRG+1)] 9600)/Desired Baud Rate


= ([48x106/[4x(1249+1)]] 9600)/Desired Baud Rate
= (9600 9600)/9600
% Error = 0.0 %

Therefore we have selected SPBRGH = 0x04 and SPBRG = 0xE1

3.5 To set up an Asynchronous Transmission:


8. Initialize the SPBRGH:SPBRG registers for the appropriate baud rate. Set or clear the
BRGH and BRG16 bits, as required, to achieve the desired baud rate.
9. Enable the asynchronous serial port by clearing bit SYNC and setting bit SPEN.
10. If the signal from the TX pin is to be inverted, set the TXCKP bit.
11. If interrupts are desired, set enable bit TXIE.
12. If 9-bit transmission is desired, set transmit bit TX9.
13. Enable the transmission by setting bit TXEN which will also set bit TXIF.
14. If 9-bit transmission is selected, the ninth bit should be loaded in bit TX9D.
15. Load data to the TXREG register (starts transmission).
16. If using interrupts, ensure that the GIE and PEIE bits in the INTCON register
(INTCON<7:6>) are set.

3.6 To set up an Asynchronous Reception:


1. Initialize the SPBRGH:SPBRG registers for the appropriate baud rate. Set or clear the
BRGH and BRG16 bits, as required, to achieve the desired baud rate.
2. Enable the asynchronous serial port by clearing bit SYNC and setting bit SPEN.
3. If the signal at the RX pin is to be inverted, set the RXDTP bit.
4. If interrupts are desired, set enable bit RCIE.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

5. If 9-bit reception is desired, set bit RX9.


6. Enable the reception by setting bit CREN.
7. Flag bit, RCIF, will be set when reception is complete and an interrupt will be generated
if enable bit, RCIE, was set.
8. Read the RCSTA register to get the 9th bit (if enabled) and determine if any error
occurred during reception.
9. Read the 8-bit received data by reading the RCREG register.
10. If any error occurred, clear the error by clearing enable bit CREN.
11. If using interrupts, ensure that the GIE and PEIE bits in the INTCON register
(INTCON<7:6>) are set.
4. Interfacing Diagram

Fig. 1.2 Serial communication PC and PIC microcontroller

Algorithm Steps:
a. Calculate the SPBRG H: SPBRG value for desired baud rate. Load the calculated value
in SPBRGH: SPBRG.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

b. Configure Port pin RC6 as output and port pin RC7 as input.
c. Set BRG Mode = 8-bit by setting BRG16 bit in BAUDCON Register
d. Set EUSART mode = Asynchronous by clearing SYNC bit in TXS TA Register
e. Enable the Serial Port by setting SPEN bit in RCSTA Register
f. Enable the Transmission by setting TXEN bit in TXSTA Register
g. Check TRMT bit in TXSTA register for TXREG empty. Load data to the TXREG register
if TRMT = 1;
h. Repeat the step 6 until complete message transmitted.
i. Enable the continuous reception by setting CREN bit in RCSTA register.
j. Poll the RCIF bit in PI R1 register to check data is received.
k. Read the 8-bit received data by reading the RCREG register.
l. Do the control action as per data received.
m. Repeat the steps from 10.

Experimental Procedure:

1. Open MPLAB IDE. Open Project menu and select project wizard. Then click on Next
button and select device as PIC18F4550. Click on Next button.

2. Select Active Toolsuite as Microchip C18 Toolsuite and select Toolsuite contents as
MPLAB C18 C compiler (mcc18.exe). Click on Next button.

3. Click on Browse button. Create a new folder on desktop (or any drive location) and
save file. Then click on Next button and again click on Next button. Click on Finish
button.

4. Open File menu and select New file and write a program. Save this program in a folder
which is created for your project.

5. Right click on Source Files and add C file from your project folder.

6. Build project file and check errors in C code. If code is free then you will get Hex file
for your C code.

7. To burn this Hex file into PIC18F4550, connect PICkit2 programmer to Kit. Open
Programmer menu and select programmer as PICkit2. Then you will get message as
PICkit2 is ready in output window.

8. Then click on Program the target device and then click on Bring target MCLR to VDD.

9. Then observe the output on respective port and peripheral.


MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Conclusion:

In this experiment, we have performed serial communication between PC and PIC


microcontroller PIC18F4550. Also we have learnt the role of MAX 232 in RS232
communication.

Experiment No. 6
Title: Generation of Square wave using timer with interrupt

Date of Performance: Roll No:

Date of Submission: University Seat No:

Signature of Staff:

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Experiment No. 6
Generation of Square wave using timer with interrupt

Title: Generation of Square wave using timer with interrupt.

Problem statement:
Write a program to generate a square wave of 10 Hz on the port pin RB0 (pin no. 33). Use
timer0 interrupt for ON period and OFF period delay.

Aim:

k. To understand the basic concepts of Timer and Counter


l. To study in detail Timer0 of PIC Microcontroller
m. To Study interrupt structure of PIC Microcontroller
n. To use timer interrupt and its related SFR.

Equipments Required:
S/W packages AND H/W used:
MPLAB IDE, C18 Compiler, ExplorePIC Development Board

Theory:

1. Timer
The microcontroller oscillator uses quartz crystal for its operation. Even though it is not the
simplest solution, there are many reasons to use it. The frequency of such oscillator is precisely
defined and very stable, so that pulses it generates are always of the same width, which makes them
ideal for time measurement. Such oscillators are also used in quartz watches. If it is necessary to
measure time between two events, it is sufficient to count up pulses generated by this oscillator. This
is exactly what the timer does. Most programs use these miniature electronic stopwatches. These
are commonly 8- or 16-bit SFRs the contents of which are automatically incremented by each coming
pulse. Once a register is completely loaded and overflowed, an interrupt may be generated.
If the timer uses an internal quartz oscillator for its operation then it can be used to measure
time between two events (if the register value is A at the moment measurement starts, and B at the
moment it terminates, then the elapsed time is equal to the result of subtraction B - A). If registers
MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

use pulses coming from external source then such a timer is turned into a counter.

1.1 How does the timer operate?


In practice, pulses generated by the quartz oscillator are once per each machine cycle,
directly or via a prescaler, brought to the circuit which increments the number stored in the timer
register. If one instruction (one machine cycle) lasts for four quartz oscillator periods then this
number will be incremented a million times per second (each microsecond) by embedding quartz
with the frequency of 4MHz. It is easy to measure short time intervals, up to 256 microseconds, in
the way described above because it is the largest number that one register can store. Figure 1.1
shows timer operation. This restriction may be easily overcome in several ways such as by using a
slower oscillator, registers with more bits, prescaler or interrupts. The first two solutions have some
weaknesses so it is more recommended to use prescaler or interrupt.

Fig. 1.1 Timer operation

1.2 Using a prescaler in timer operation


A prescaler is an electronic device used to reduce frequency by a predetermined factor. In
order to generate one pulse on its output, it is necessary to bring 1, 2, 4 or more pulses on its input.
Most microcontrollers have one or more prescaler built in and their division rate may be changed
from within the program. The prescaler is used when it is necessary to measure longer periods of
time. If one prescaler is shared by timer and watchdog timer, it cannot be used by both of them
simultaneously. Figure 1.2 shows timer operation with a prescaler.

1.3 Using interrupt in timer operation


If the timer register consists of 8 bits, the largest number it can store is 255. As for 16-bit
registers it is the number 65535. If this number is exceeded, the timer will be automatically reset and
counting will start at zero again. This condition is called an overflow. If enabled from within the
program, the overflow can cause an interrupt, which gives completely new possibilities. For example,

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

the state of registers used for counting seconds, minutes or days can be changed in an interrupt
routine. The whole process (except for interrupt routine) is automatically performed behind the
scenes, which enables the main circuits of the microcontroller to operate normally. This figure 1.3
illustrates the use of an interrupt in timer operation. Delays of arbitrary duration, having almost no
influence on the main program execution, can be easily obtained by assigning the prescaler to the
timer.

Fig. 1.2 Timer operation with prescaler

2. Counters
If the timer receives pulses from the microcontroller input pin, then it turns into a counter.
Obviously, it is the same electronic circuit able to operate in two different modes. The only
difference is that in this case pulses to be counted come over the microcontroller input pin and
their duration (width) is mostly undefined. This is why they cannot be used for time
measurement, but for other purposes such as counting products on an assembly line, number of
axis rotation, passengers etc. (depending on sensor in use).q

3. Timers / Counters in PIC Microcontroller


There are 3 - 5 timers on board in PIC microcontroller. These timers can also be used as
counters when external pulses are applied. The timers are programmable, and sometimes share
with other peripheral devices. These are named as TMR0, TMR1, TMR2, TMR3 and TMR4. There
are few other timers, not to be discussed here like Watchdog Timer and Brown-Out timers. These
timers are useful in measuring the time delays in various events as well as counting and timing
MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

external events.

4. Time delay generation using timer


The following steps are taken to generate a time delay using polling method

9. Load the proper value in T0CON indicating which timer mode, clock source, prescaler
assignment.
10. Load the registers TMR0H first and then TMR0L with initial count values. Delay
generated is Depends upon the initial count value.
11. Start the timer by setting TMR0ON bit in T0CON.
12. Keep the monitoring the timer flag (TMR0IF).
13. Get out of the loop when TMR0IF becomes high.
14. Stop the timer.
15. Clear the TMR0IF flag for the next round.
16. Go back to the step 2 to load TMR0H and TMR0L values.

The following steps are taken to generate a time delay using interrupt method
vi. Load the proper value in T0CON indicating which timer mode, clock source,
prescaler assignment.
vii. Load the registers TMR0H first and then TMR0L with initial count values. Delay
generated is Depends upon the initial count value.
viii. Enable the Timer0 Interrupt and Global Interrupt using INTCON Register
ix. Start the timer by setting TMR0ON bit in T0CON.
x. Write the ISR at Interrupt vector 0x0018.
a. In ISR Clear the TMR0IF flag for the next round.
b. In ISR reload TMR0H and TMR0L values.

Algorithm Steps:

1. Configure Port pin RB0 as output and initial value 0.


4. Load the value 0x02 in T0CON indicating which timer in 16-b it mode, clock source Fosc/4,
prescaler assignment with 1:8.
5. Load the registers TM R0H first and then TMR0L with calculated initial count values.
7. Enable the Timer0 Interrupt and Global Interrupt using INTCON Register
8. Start the timer by setting TMR0ON bit in T0CON.
9. Write the ISR at Interrupt vector 0x0018 which contains following.
a. Toggle the PORT pin RB0
b. In ISR Clear the TMR0IF flag for the next round.
c. In ISR reload TMR0H and TMR0L values.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Experimental Procedure:

1. Open MPLAB IDE. Open Project menu and select project wizard. Then click on Next
button and select device as PIC18F4550. Click on Next button.

2. Select Active Toolsuite as Microchip C18 Toolsuite and select Toolsuite contents as
MPLAB C18 C compiler (mcc18.exe). Click on Next button.

3. Click on Browse button. Create a new folder on desktop (or any drive location) and
save file. Then click on Next button and again click on Next button. Click on Finish
button.

4. Open File menu and select New file and write a program. Save this program in a folder
which is created for your project.

5. Right click on Source Files and add C file from your project folder.

6. Build project file and check errors in C code. If code is free then you will get Hex file
for your C code.

7. To burn this Hex file into PIC18F4550, connect PICkit2 programmer to Kit. Open
Programmer menu and select programmer as PICkit2. Then you will get message as
PICkit2 is ready in output window.

8. Then click on Program the target device and then click on Bring target MCLR to VDD.

9. Then observe the output on respective port and peripheral.

Conclusion:

We have generated square wave using timer with interrupt and output is observed on
LEDs.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Experiment No. 7
Title: Serial Communication between PC and PIC Microcontroller

Date of Performance: Roll No:

Date of Submission: University Seat No:

Signature of Staff:

Experiment No. 7
Serial communication between PC and PIC microcontroller

Title: Interfacing serial port with PC both side communication

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Problem statement:
Write a program in Embedded C to transfer the message and receive serially at 9600
baud, 8 bit data.

Aim:

o. To study the RS232 standard for serial communication


p. To Study the on-chip USART of PIC Microcontroller
q. To calculate the desired baud rate.
r. To interface MAX232 with PIC Microcontroller for serial communication.

Equipments Required:
S/W packages AND H/W used:
MPLAB IDE, C18 Compiler, ExplorePIC Development Board

Theory:

1. Serial Communication:

The microcontroller is parallel device that transfers eight bits of data simultaneously
over eight data lines to parallel I/O devices. However, in many situations, parallel data
transfer is impractical. For example, parallel data transfer over a long is very expensive.
Hence, a serial communication is widely used in long distance communication.
In serial data communication, 8-bit data is converted to serial bits using a parallel in
serial out shift register and then it is transmitted over a single data line. The data byte is
always transmitted with least significant bit first.
Serial ports are a type of computer interface for serial communication that complies
with the RS-232 standard. They are 9-pin connectors that relay information, incoming or
outgoing, one byte at a time. Each byte is broken up into a series of eight bits, hence the term
serial port. Serial ports are controlled by a special chip call a UART (Universal Asynchronous
Receiver Transmitter).
1.1 Communication links:
Serial communication is classified into three types of communication.
d. Simplex communication link: In simplex transmission, the line is dedicated for
transmission. The transmitter sends and the receiver receives the data.
e. Half duplex communication link: In half duplex, the communication link can be used
for either transmission or reception. Data is transmitted in only one direction at a
time.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

f. Full duplex communication link: If the data is transmitted in both ways at the same
time, it is a full duplex i.e. transmission and reception can proceed simultaneously.
This communication link requires two wires for data, one for transmission and one
for reception.

1.2 Types of Serial communication:


Serial data communication uses two types of communication.
2 Synchronous serial data communication: In this transmitter and receiver
are synchronized. It uses a common clack to synchronize the receiver and the
transmitter. First the synch character is sent and then the data is transmitted.
This format is generally used for high speed transmission. In Synchronous
serial data communication a block of data is transmitted at a time.

3 Asynchronous Serial data transmission: In this, different clock sources are


used for transmitter and receiver. In this mode, data is transmitted with start
and stop bits. A transmission begins with start bit, followed by data and then
stop bit. For error checking purpose parity bit is included just prior to stop bit.
In Asynchronous serial data communication a single byte is transmitted at a
time.

1.4 Baud rate:


The rate at which the bits are transmitted is called baud or transfer rate. The baud
rate is the reciprocal of the time to send one bit. In asynchronous transmission, baud rate is
not equal to number of bits per second. This is because; each byte is preceded by a start bit
and followed by parity and stop bit. For example, in synchronous transmission, if data is
transmitted with 9600 baud, it means that 9600 bits are transmitted in one second. For bit
transmission time = 1 second/ 9600 = 0.104 ms.

2. RS-232 standards:
To allow compatibility among data communication equipment made by various
manufactures, an interfacing standard called Rs232 was set by the Electronics Industries
Association (EIA) in 1960. In 1963 it was modified and called RS232A. RS232B and RS232C
were issued in 1965 and 1969, respectively. Today Rs232is the most widely used serial I/O
interfacing standard. This standard is used in PCs and numerous equipments. However,
since the standard was set long before the advent of logic family, its input and output voltage
levels are not TTL compatible. In RS232, a logic one (1) is represented by -3 to -25V and
referred as MARK while logic zero (0) is represented by +3 to +25V and referred as SPACE.
For this reason to connect any RS232 to a microcontroller system we must use

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

voltage converters such as MAX232 to convert the TTL logic level to RS232 voltage levels
and vice-versa. MAX232 IC chips are commonly referred as line drivers.

2.1. Serial Data Format


The serial data format includes one start bit, between five and eight data bits, and
one stop bit. A parity bit and an additional stop bit might be included in the format as well.
The figure 4.1 below illustrates the serial data format.

Fig. 1.1 Serial data format

The format for serial port data is often expressed using the following notation:
Number of data bits - parity type - number of stop bits.
For example, 8-N-1 is interpreted as eight data bits, no parity bit, and one stop bit,
while 7-E-2 is interpreted as seven data bits, even parity, and two stop bits.
The data bits are often referred to as a character because these bits usually represent
an ASCII character. The remaining bits are called framing bits because they frame the data
bits.

3. EUSART Module in PIC Microcontroller


The Enhanced Universal Synchronous Asynchronous Receiver Transmitter (EUSART)
module is one of the two serial I/O modules. (Generically, the USART is also known as a
Serial Communications Interface or SCI.) The EUSART can be configured as a full-duplex
asynchronous system that can communicate with peripheral devices, such as CRT terminals
and personal computers. It can also be configured as a half duplex synchronous system that
can communicate with peripheral devices, such as A/D or D/A integrated circuits, serial
EEPROMs, etc. The Enhanced USART module implements additional features, including
automatic baud rate detection and calibration, automatic wake-up on Sync Break reception
and 12-bit Break character transmit. These make it ideally suited for use in Local
Interconnect Network bus (LIN bus) systems. The EUSART can be configured in the
following modes:
Asynchronous (full-duplex) with:
- Auto-wake-up on Break signal
- Auto-baud calibration
- 12-bit Break character transmission

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Synchronous Master (half-duplex) with


selectable clock polarity
Synchronous Slave (half-duplex) with selectable
clock polarity

3.2 Pin description


The pins of the Enhanced USART are multiplexed with PORTC. In order to configure
RC6/TX/CK and RC7/RX/DT/SDO as an EUSART:
1. bit SPEN (RCSTA<7>) must be set (= 1)
2. bit TRISC<7> must be set (= 1)
3. bit TRISC<6> must be set (= 0)

3.2 EUSART Register Map:


The operation of the Enhanced USART module is controlled through three registers:
Transmit Status and Control (TXSTA)
Receive Status and Control (RCSTA)
Baud Rate Control (BAUDCON)

3.3 Baud Rate Generator (BRG)


The BRG is a dedicated 8-bit, or 16-bit, generator that supports both the
Asynchronous and Synchronous modes of the EUSART. By default, the BRG operates in 8-
bit mode. Setting the BRG16 bit (BAUDCON<3>) selects 16-bit mode. The SPBRGH:SPBRG
register pair controls the period of a free-running timer. In Asynchronous mode, bits
BRGH (TXSTA<2>) and BRG16 (BAUDCON<3>) also control the baud rate. In Synchronous
mode, BRGH is ignored. Table 1.1 shows the formula for computation of the baud rate for
different EUSART modes which only apply in Master Mode (internally generated clock).
Given the desired baud rate and FOSC, the nearest integer value for the SPBRGH:SPBRG
registers can be calculated using the formulas in Table 1.1. From this, the error in baud
rate can be determined. It may be advantageous to use the high baud rate (BRGH = 1), or
the 16-bit BRG to reduce the baud rate error, or achieve a slow baud rate for a fast
oscillator frequency. Writing a new value to the SPBRGH:SPBRG registers causes the BRG
timer to be reset (or cleared). This ensures the BRG does not wait for a timer overflow
before outputting the new baud rate.

Table 1.1: Baud rate formulae

Configuration Bits Baud Rate Formula


SYNC BRG16 BRGH BRG Mode / EUSART Mode [n= SPBRGH:SPBRG]

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

0 0 0 8-bit / Asynchronous BR = Fosc/[64(n+1)]


0 0 1 8-bit / Asynchronous
BR = Fosc /[16(n+1)]
0 1 0 16-bit / Asynchronous
0 1 1 16-bit / Asynchronous
1 0 x 8-bit / Synchronous BR = Fosc/[4(n+1)]
1 1 x 16-bit / Synchronous

3.4 Baud rate Calculation Mode selection


d. BRG Mode = 8-bit by setting BRG16 bit in BAUDCON Register
e. EUSART mode = Asynchronous by clearing SYNC bit in TXSTA Register
f. Formulae Desired Buad Rate = Fosc / [4(SPBRGH:SPBRG+1)] selected by setting
BRG16 bit in TXSTA Register

For Fosc = 20MHz, Baud rate = 9600

SPBRGH:SPBRG = [Fosc/4(Baud rate)]-1


= [20x106/(4x9600)] 1
= [519]10 = [0207]16

% Error = (Calculated baud rate - Desired Baud Rate)/Desired Baud Rate


= (Fosc / [4(SPBRGH:SPBRG+1)] 9600)/Desired Baud Rate
= ([20x106/[4x(520+1)]] 9600)/Desired Baud Rate
= (9615 9600)/9600
% Error = 0.16 %

Therefore to reduce error we have selected SPBRGH = 0x02 and SPBRG = 0x08
For Fosc = 48MHz, Baud rate = 9600
SPBRGH:SPBRG = [Fosc/4(Baud rate)]-1
= [48x106/(4x9600)] 1
= [1249]10 = [04E1]16
Therefore SPBRGH = 0x04 and SPBRG = 0xE1

% Error = (Calculated baud rate - Desired Baud Rate)/Desired Baud Rate

= (Fosc / [4(SPBRGH:SPBRG+1)] 9600)/Desired Baud Rate


= ([48x106/[4x(1249+1)]] 9600)/Desired Baud Rate
= (9600 9600)/9600
MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

% Error = 0.0 %

Therefore we have selected SPBRGH = 0x04 and SPBRG = 0xE1

3.5 To set up an Asynchronous Transmission:


17. Initialize the SPBRGH:SPBRG registers for the appropriate baud rate. Set or clear the
BRGH and BRG16 bits, as required, to achieve the desired baud rate.
18. Enable the asynchronous serial port by clearing bit SYNC and setting bit SPEN.
19. If the signal from the TX pin is to be inverted, set the TXCKP bit.
20. If interrupts are desired, set enable bit TXIE.
21. If 9-bit transmission is desired, set transmit bit TX9.
22. Enable the transmission by setting bit TXEN which will also set bit TXIF.
23. If 9-bit transmission is selected, the ninth bit should be loaded in bit TX9D.
24. Load data to the TXREG register (starts transmission).
25. If using interrupts, ensure that the GIE and PEIE bits in the INTCON register
(INTCON<7:6>) are set.

3.6 To set up an Asynchronous Reception:


10. Initialize the SPBRGH:SPBRG registers for the appropriate baud rate. Set or clear the
BRGH and BRG16 bits, as required, to achieve the desired baud rate.
11. Enable the asynchronous serial port by clearing bit SYNC and setting bit SPEN.
12. If the signal at the RX pin is to be inverted, set the RXDTP bit.
13. If interrupts are desired, set enable bit RCIE.
14. If 9-bit reception is desired, set bit RX9.
15. Enable the reception by setting bit CREN.
16. Flag bit, RCIF, will be set when reception is complete and an interrupt will be generated
if enable bit, RCIE, was set.
17. Read the RCSTA register to get the 9th bit (if enabled) and determine if any error
occurred during reception.
18. Read the 8-bit received data by reading the RCREG register.
10. If any error occurred, clear the error by clearing enable bit CREN.
11. If using interrupts, ensure that the GIE and PEIE bits in the INTCON register
(INTCON<7:6>) are set.

5. Interfacing Diagram

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Fig. 1.2 Serial communication PC and PIC microcontroller

Algorithm Steps:
a. Calculate the SPBRG H: SPBRG value for desired baud rate. Load the calculated value
in SPBRGH: SPBRG.
b. Configure Port pin RC6 as output and port pin RC7 as input.
c. Set BRG Mode = 8-bit by setting BRG16 bit in BAUDCON Register
d. Set EUSART mode = Asynchronous by clearing SYNC bit in TXS TA Register
e. Enable the Serial Port by setting SPEN bit in RCSTA Register
f. Enable the Transmission by setting TXEN bit in TXSTA Register
g. Check TRMT bit in TXSTA register for TXREG empty. Load data to the TXREG register
if TRMT = 1;
h. Repeat the step 6 until complete message transmitted.
i. Enable the continuous reception by setting CREN bit in RCSTA register.
j. Poll the RCIF bit in PI R1 register to check data is received.
k. Read the 8-bit received data by reading the RCREG register.
l. Do the control action as per data received.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

m. Repeat the steps from 10.

Experimental Procedure:

1. Open MPLAB IDE. Open Project menu and select project wizard. Then click on Next
button and select device as PIC18F4550. Click on Next button.

2. Select Active Toolsuite as Microchip C18 Toolsuite and select Toolsuite contents as
MPLAB C18 C compiler (mcc18.exe). Click on Next button.

3. Click on Browse button. Create a new folder on desktop (or any drive location) and
save file. Then click on Next button and again click on Next button. Click on Finish
button.

4. Open File menu and select New file and write a program. Save this program in a folder
which is created for your project.

5. Right click on Source Files and add C file from your project folder.

6. Build project file and check errors in C code. If code is free then you will get Hex file
for your C code.

7. To burn this Hex file into PIC18F4550, connect PICkit2 programmer to Kit. Open
Programmer menu and select programmer as PICkit2. Then you will get message as
PICkit2 is ready in output window.

8. Then click on Program the target device and then click on Bring target MCLR to VDD.

9. Then observe the output on respective port and peripheral.

Conclusion:

In this experiment, we have performed serial communication between PC and PIC


microcontroller PIC18F4550. Also we have learnt the role of MAX 232 in RS232
communication.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Experiment No. 8
Title: Demonstration of Pneumatic/ Electro pneumatic Components and Circuits

Date of Performance: Roll No:

Date of Submission: University Seat No:

Signature of Staff:

Experiment No. 8
Demonstration of Pneumatic/ Electro pneumatic Components and Circuits

Title: Demonstration of Pneumatic/ Electro pneumatic Components and Circuits

Aim:
MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Study of Different Components of Pneumatic /Electro Pneumatic Systems with


symbols and specifications

Study of Pneumatic Motor and Flow Control Valve

Study of Pressure Gauge

Study of Sequencing of Single Acting Cylinder & Double Acting Cylinder through Relay

Study of Non Return Valve with Single Acting Cylinder

Study of 3/2 Hand Lever Valve with Single Acting Cylinder

Study of Pneumatic Motor (Rotary Actuator) By Using Direction Control Valve

To Study of Shuttle Valve (OR Gate Valve)

Study of AND Gate Valve.

Study of 5/3 Hand Lever Valve

Equipments required:

Electro Pneumatic Trainer Kit

Air Compressor

Theory:

The technology of pneumatics deals with the study of the behavior and application of
compressed air. Today, air operated tools and accessories are a common sight in every
industry, not only in technologically advanced countries but even in countries where
industrial activities are still at the stage of sheer infancy. With the introduction of
pneumatics in manufacturing process, the industry is benefited with a cheaper medium off
industrial automation, which if judiciously used, may bring down the cost of production to a
much lower level. Now, compressed air is used in every walk of industrial life, starting with
pneumatic cranes to the use of air in the brake system of automobiles, railway coaches,
wagons, printing presses and what not.

The following features of pneumatics make it advantageous and exceptionally suitable in


handling:

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Wide availability of air


Compressibility of air
Easy transportability of compressed air in pressure vessels, containers and in long pipes
Fire proof characteristics of the medium
Simple construction of the pneumatic elements and easy handling
High degree of controllability of pressure, speed and force.
Easier maintenance
Explosion proof characteristics of the medium
Comparatively cheaper in cost than other systems
Compared to hydraulic system, pneumatic system has better operational advantages but it
cannot replace hydraulic system so far as power requirement and accuracy of operations are
concerned.

FRL UNIT

The air that is sucked by the air compressor is evidently not clean because of the presence of
various types of contaminants in the atmosphere; moreover, the air that is supplied to the
system from the compressor is further contaminated by virtue of generation of
contaminants downstream. Hence, to enable supply of clean pure and contamination free
compressed air, the air requires to be filtered. The three main elements of an FRL unit are

Air filter
Pressure regulator
Lubricator

AIR FILTER
Air filters are used in a pneumatic system to perform the following main functions:-
1. To prevent the entrance of solid contaminants
to the system.
2. To condense & remove the water vapor that is
present in the air passing through it.
3. To arrest any submicron particles that may
pose a problem in the system components.

PRESSURE REGULATOR

The main function of this valve is to regulate the incoming pressure to the system so that
the desired pressure is capable of flowing at a steady condition. The valve has a metallic
body with the two openings primary and secondary openings. The pressure regulation is
achieved by opening the poppet valve to a measured amount commensurate with the
desired pressure level to be achieved. This is done by an adjustable screw. The adjusting
screw will move the diaphragm upward and thus will make the poppet unseat, thereby
creating an opening to allow air to flow from the primary side to secondary side.
MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

LUBRICATOR
In most pneumatic systems the compressed air is first filtered and then regulated to the
specific pressure and made to pass through a lubricator in order to form a mist of oil and
air for the sole purpose of providing lubrication to the mating components of valves,
cylinders etc. To form the mist, a lubricator unit is used. All lubricators follow the principle
of venturimeter.

AIR MANIFOLD

The Manifold distributes air from hoses attached to each side of the unit. Several trunk
lines lead off the Main Air Manifold. They are connected to the components using PU
tube. The air flow from the compressor is controlled using the FRL UNIT and then
distributed as per the designed Pneumatic Circuits.
PNEUMATIC CYLINDERS

Pneumatic cylinders offer a straight rectilinear motion to mechanical elements. Cylinders


are classified as light, medium, and heavy duty with respect to their application.
The pneumatic power is converted to straight line reciprocating motions by pneumatic
cylinders. According to the operating principle, air cylinders can be subdivided as 1. Single
acting, 2.Double acting cylinders.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

SINGLE ACTING CYLINDER

Single Acting Cylinder with cylinder mounted flow control valve.

In a single acting cylinder, the compressed air is fed only in one side. Hence, this cylinder
can produce work only in one direction. The return movement of the piston is effected
by a built in spring or by application of external force. The spring is designed to return
the piston to its initial position with a sufficiently high speed.
There are two types of single acting cylinders:
Diaphragm cylinder
Rolling diaphragm cylinder
DOUBLE ACTING CYLINDER

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

The force exerted by the compressed air moves the piston in two directions in a double
acting cylinder. They are used particularly when the piston is required to perform work not
only on the advance movement but also on the return. In principle, the stroke length is
unlimited, although buckling and bending must be considered before we select a particular
size of piston diameter, rod, length and stroke length

The MSSP module has three associated control registers. These include a status
register (SSPSTAT) and two control registers (SSPCON1 and SSPCON2). The use of these
registers and their individual Configuration bits differ significantly depending on whether
the MSSP module is operated in SPI or I2C mode.
The SPI mode allows 8 bits of data to be synchronously transmitted and received
simultaneously. All four modes of the SPI are supported. a) Master Mode Transmitter b)
Master Mode - Receiver c) Slave Mode Transmitter d) Slave mode Receiver.
Pin description
Signal Pin No. Symbol

Serial Data Out (SDO) 26 RC7/RX/DT/SDO

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Serial Data In (SDI) 33 RB0/AN12/INT0/FLT0/SDI/SDA

Serial Clock (SCK) 34 RB1/AN10/INT1/SCK/SCL

Slave Select (SS) 7 RA5/AN4/SS/HLVDIN/C2OUT

25C128/256: SPI based Serial EEPROM


The 25C128 / 25C256 are 128Kbit/ 256 Kbit Serial Electrically Erasable PROMs. The
memory is accessed via a simple Serial Peripheral Interface (SPI) compatible serial bus. The
bus signals required are a clock input (SCK) plus separate data in (SI) and data out (SO)
lines. Access to the device is controlled through a Chip Select (CS) input. Communication to
the device can be paused via the hold pin (HOLD). While the device is paused, transitions on
its inputs will be ignored, with the exception of Chip Select, allowing the host to service
higher priority interrupts.

CS Chip Select
SCK Serial Data Clock
SI Serial Data Input
SO Serial Data Output
WP Write Protect
HOLD Suspends Serial Input
GND Ground
VCC Power Supply

Functional Description
The AT25128/256 is designed to interface directly with the synchronous serial
peripheral interface (SPI) of microcontrollers. The AT25128/256 utilizes an 8-bit
instruction register. The list of instructions and their operation codes are contained in Table
1.1. All instructions, addresses, and data are transferred with the MSB first and start with a
high-to-low CS transition.

WRITE ENABLE (WREN): The device will power-up in the write disable state when VCC is
applied. All programming instructions must therefore be preceded by a Write Enable
instruction.
WRITE DISABLE (WRDI): To protect the device against inadvertent writes, the Write Disable
instruction disables all programming modes. The WRDI instruction is independent of the

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

status of the WP pin.


READ STATUS REGISTER (RDSR): The Read Status Register instruction provides access to
the status register. The Ready/Busy and Write Enable status of the device can be determined
by the RDSR instruction. Similarly, the Block Write Protection bits indicate the extent of
protection employed. These bits are set by using the WRSR instruction.

WRITE STATUS REGISTER (WRSR): The WRSR instruction allows the user to select one of
four levels of protection. The AT25128/256 is divided into four array segments. Top quarter
(1/4), top half (1/2), or all of the memory segments can be protected. Any of the data within
any selected segment will therefore be READ only. The block write protection levels and
corresponding status register control bits are shown in Table 1.2. The three bits, BP0, BP1,
and WPEN are nonvolatile cells that have the same properties and functions as the regular
memory cells (e.g. WREN, tWC, RDSR).

Table 1.1 Instruction set for 25Cxxx SPI EEPROM

Table 1.2 Block Write Protect Bits

READ SEQUENCE (READ): Reading the AT25128/256 via the SO pin requires the following
MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

sequence. After the CS line is pulled low to select a device, the READ op-code is transmitted
via the SI line followed by the byte address to be read. Upon completion, any data on the SI
line will be ignored. The data (D7 D0) at the specified address is then shifted out onto the
SO line. If only one byte is to be read, the CS line should be driven high after the data comes
out. The read sequence can be continued since the byte address is automatically
incremented and data will continue to be shifted out. When the highest address is reached,
the address counter will roll over to the lowest address allowing the entire memory to be
read in one continuous read cycle.
WRITE SEQUENCE (WRITE): In order to program the AT25128/256, two separate
instructions must be executed. First, the device must be write enabled via the WREN
instruction. Then a Write instruction may be executed. Also, the address of the memory
location(s) to be programmed must be outside the protected address field location selected
by the block write protection level. During an internal write cycle, all commands will be
ignored except the RDSR instruction.
Interfacing diagram

Fig. 1.1 SPI interfacing with PIC18F4550

Algorithm Steps:
Initialization of SPI Module in Master Mode
MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

1. Configure SCK, SDO pins as output and SDI as input through TRIS Register.
1. Configure one of port pin as output to use as chip select/slave select.
2. Set CKE and SMP bit in SSPSTAT register
3. Enable Master SPI mode in SSPCON1 register
SSPM3:SSPM0=0010 = SPI Master mode, clock = FOSC/64
5. Enable SPI in SSPCON1 register by setting SSPEN bit in SSPCON1

To send data to a slave device


Select slave device by making chip select or slave select low.
Send the data. SSPBUF = data.
Poll the BF bit from SSPSTAT for successful transmission
De-select slave device by making chip select or slave select high.

To receive data from a slave device


Select slave device by making chip select or slave select low.
Send the dummy data. SSPBUF = dummy data.
Poll the BF bit from SSPSTAT for successful reception
Read the SSPBUF for received data.
De-select slave device by making chip select or slave select high.

Experimental Procedure:

1. Open MPLAB IDE. Open Project menu and select project wizard. Then click on Next
button and select device as PIC18F4550. Click on Next button.

2. Select Active Toolsuite as Microchip C18 Toolsuite and select Toolsuite contents as
MPLAB C18 C compiler (mcc18.exe). Click on Next button.

3. Click on Browse button. Create a new folder on desktop (or any drive location) and
save file. Then click on Next button and again click on Next button. Click on Finish
button.

4. Open File menu and select New file and write a program. Save this program in a folder
which is created for your project.

5. Right click on Source Files and add C file from your project folder.

6. Build project file and check errors in C code. If code is free then you will get Hex file
for your C code.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

7. To burn this Hex file into PIC18F4550, connect PICkit2 programmer to Kit. Open
Programmer menu and select programmer as PICkit2. Then you will get message as
PICkit2 is ready in output window.

8. Then click on Program the target device and then click on Bring target MCLR to VDD.

9. Then observe the output on respective port and peripheral.

Conclusion:

In this experiment, we have interfaced SPI based EEPROM (25Cxxx) to PIC


Microcontroller PIC18F4550. SPI is a synchronous serial data link that operates in full duplex.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Experiment No. 9
Title: On chip ADC programming

Date of Performance: Roll No:

Date of Submission: University Seat No:

Signature of Staff:

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Experiment No. 9
On-chip ADC programming

Title: Interfacing analog voltage 0-5V to internal ADC and display value on LCD

Problem statement:
Interface analog voltage 0 5v to PIC microcontroller and Write a program in Embedded C to
convert analog voltage into digital using on-chip ADC Module. Display the Digital result in Voltage
form on 16x2 LCD display.

Aim:

s. To understand the working of A/D converter


t. To study the on-chip ADC section of PIC Microcontroller
u. To interface analog input to PIC Microcontroller

Equipments Required:
S/W packages AND H/W used:
MPLAB IDE, C18 Compiler, ExplorePIC Development Board

Theory:

ADC Devices:
Analog to digital converters are among the most widely used devices for data
acquisitions. Digital computers use binary (discrete) value but in physical world everything
is analog (continuous). A physical quantity is converted to electrical signals using device
called transducer or also called as sensors. Sensors and many other natural quantities
produce an output that is voltage (or current). Therefore we need an analog - to - digital
converter to translate the analog signal to digital numbers so that the microcontroller can
read and process them.
The ADC chips are either parallel or serial. In parallel ADC, we have 8 or more pins
dedicated to bring out the binary data, but in serial ADC we have only one pin for data out.
Some of the major characteristics of ADC are a) resolution b) conversion time c)
reference voltage (Vref).
MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Resolution
An ADC has an n bit resolution where n can be 8, 10, 16, 0r even 24 bits. The higher
resolution ADC provides a smaller step size, where step size is smallest change that can be
discerned by an ADC. This is shown in Table 8.1. Although the resolution for ADC chip is
designed at the time of its design and cannot be changed, we can control the step size with
the help of reference voltage (Vref).

Table 1.1: Resolution verses step size for ADC

n - bit Number of steps Step Size (mV)

8 256 5/256 = 19.53

10 1024 5/1024 = 4.88

12 4096 5/4096 = 1.2

16 65536 5/65536 = 0.076

Conversion time
Conversion time is defined as the time it takes the ADC to convert the analog input to
digital (binary) number. The conversion time is dictated by the clock source connected to
the ADC in addition to the method used for data conversion and technology used in the
fabrication of the ADC chip.
In addition to conversion time, acquisition time is another major factor in judging an
ADC. Acquisition time is defined as the time it takes to sample the analog voltage using
sample and hold circuit. Sampled analog input is applied to actual conversion unit of ADC.
In some of the ADCs, conversion time doesnt contain the acquisition time but
specified separately. Therefore effective conversion time is addition of specified conversion
time and specified acquisition time.

Reference Voltage (Vref)

Vref is an input voltage used for the reference voltage. The voltage connected to this
pin, along with resolution of the ADC chip, gives us the step size.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

step size = Vref / 2n where n= no. of bits

For example if the analog input range needs to be 0 to 3 Volts, Vref is connected to 3
Volts. That gives 3V/1024 = 2.92 mV step size for 10-bit ADC.

Table 1.2 Relation between Vref, Vin and step size

Vref (V) Vin (V) Step Size (mV)


5.00 0 to 5 5/1024 = 4.88
2.56 0 to 2.56 2.56/1024 = 2.5
1.024 0 to 1.024 1.024/1024 = 1

Bit Analog-To-Digital Converter (A/D) Module of PIC microcontroller


The Analog-to-Digital (A/D) converter module has 10 inputs for the 28-pin devices
and 13 for the 40/44-pin devices. This module allows conversion of an analog input signal
to a corresponding 10-bit digital number.
ADCON1 Register in our Program,
Bit7-6 This two bits are Unimplemented so we write this bit as 00
Bit 5 In our application (VREF-) supply as 0 volt so we write this bit as 0.
Bit 4 In our application (VREF+) supply as 5 volt so we write this bit as 0.
Bit3-0 Here we are using only one analog channel AN1. Therefore we write this bit as
PCFG3:PCFG0 - 1101.

A/D Control Register 2 (ADCON2)


ADCON2 register is shown in below Figure 1.1. Table 1.3 shows the ADCON2 register
description.

Fig. 1.1 ADCON2 register


MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Table 1.3 ADCON2 register description


Bit No. Control Bit Description
Bit 7 ADFM A/D Result Format Select bit
1 = Right justified; 0 = Left justified

Bit 6 Un Unimplemented Read as 0


Bit 53 ACQT2:ACQT0 A/D Acquisition Time Select bits
000=0 TAD 001=2 TAD 010=4 TAD 011 =6 TAD
100=8 TAD 101=12 TAD 110=16 TAD 111 =20 TAD
bit 20 ADCS2:ADCS0 A/D Conversion Clock Select bits
000=FOSC/2 001=FOSC/8 010=FOSC/32 011=FRC*
101=FOSC/1
100=FOSC/4 6 110=FOSC/64 111=FRC*
FRC* - clock derived from A/D RC oscillator

A/D Result Format Select bit (ADFM):


We need right justified data. Therefore ADFM = 1. If you write 1 then result is right
justified as shown below;

If you write 0 then result is left justified as shown below;

A/D Conversion Clock Select bits (ADCS2:ADCS0)


The A/D conversion time per bit is defined as TAD. The A/D conversion requires 11
TAD per 10-bit conversion. The source of the A/D conversion clock is software selectable.
There are seven possible options for TAD as shown in table 8.4
For correct A/D conversions, the A/D conversion clock (TAD) must be as short as
possible but greater than the minimum TAD. Table 8.4 shows the resultant TAD times

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

derived from the device operating frequencies and the A/D clock source selected.
TAD = 4 * Tosc where Tosc = 1/Fosc Minimum TAD = 0.7 us (to be maintained as per
datasheet)
Therefore for 10bit ADC,
Typical conversion time = 11 TAD = 11 * 0.7 us = 7.7 us.

Table 1.4 TAD vs. device operating frequencies

AD Clock Source (TAD) Maximum Device Frequency


Operation ADCS2:ADCS0 PIC18FXXXX
2 TOSC 000 2.86 MHz
4 TOSC 100 5.71 MHz
8 TOSC 001 11.43 MHz
16 TOSC 101 22.86 MHz
32 TOSC 010 45.71 MHz
64 TOSC 110 48.0 MHz
RC(3) x11 1.00 MHz

A/D Acquisition Time Select bits (ACQT2:ACQT0)


The acquisition time (TACQ) depends on amplifier settling time, capacitor charging
time and temperature coefficient.

TACQ = TAMP + TC + TCOFF

Where
TAMP : Amplifier Settling Ti me = 0.2 us (Typical value) TC :
Holding Capacitor C harging Time
= -(CHOLD)(RIC + RSS + RS) ln(1/2048) s
= -(25 pF) (1 kL + 2 kL + 2.5 kL) ln(0.0004883) s (Typical value)
= 1.05 s

TCOFF : Temperature Coefficient = (Temp 25C)(0.02 s/C)


= (85C 25C)(0.02 s/C) (Typical temp)
= 1.2 s

Therefore minimum calculated acquisition time is


TACQ = 0.2 s + 1.05 s + 1.2 s = 2.45 s
Derived A/D acquisition time Calculated acquisition time TACQ
MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Derived A/D acquisition time = n * TAD


where n is depends on A/D Acquisition Time Select bits (ACQT2:ACQT0). So select A/D
Acquisition Time Select bits (ACQT2:ACQT0) such that the we meet above timings.
Calculations

a. For Fosc = 20MHz


Tosc = 1/20MHz = 50 ns
Selected ADC clock source ADCS2:ADCS0 = 110 i.e Fosc/64
TAD = 64Tosc = 64 * 50 ns
TAD = 3.2 us which is much greater than minimum TAD = 0.7 us
Conversion Time = 11TAD = 11 * 3.2 us = 35.2 us
Selected A/D Acquisition Time Select bits ACQT2:ACQT0 = 001 i.e n= 2 Derived
A/D acquisition time = n * TAD = 2 * TAD= 2 * 3.2 us
= 6.4 us
Which is much greater than calculated acquisition time = 2.4 us
Effective conversion time = acquisition time + conversion time
= 35.2 us + 6.4 us
= 41.6 us
b. For Fosc = 48MHz
Tosc = 1/48MHz = 20.83 ns
Selected ADC clock source ADCS2:ADCS0 = 110 i.e Fosc/64
TAD = 64Tosc = 64 * 20.83 ns
TAD = 1.33 us which is greater than minimum TAD = 0.7 us
Conversion Time = 11TAD = 11 * 1.3 us = 14.66 us

Selected A/D Acquisition Time Select bits ACQT2:ACQT0 = 001 i.e n= 2 Derived
A/D acquisition time = n * TAD = 2 * TAD = 2 * 1.33 us
= 2.67 us
Which is greater than calculated acquisition time = 2.4 us

Effective conversion time = acquisition time + conversion time


= 14.66 us + 2.67 us
= 17.33 us

Algorithm Steps:
Following steps should be followed to perform an A/D conversion:
1. Configure the A/D module :
Configure analog pins, voltage reference and digital I/O (ADCON1)

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Select A/D input channel (ADCON0)


Select A/D acquisition time (ADCON2)
Select A/D conversion clock (ADCON2)
Turn on A/D module (ADCON0)
2. Configure A/D interrupt (if desired):
Clear ADIF bit
Set ADIE bit
Set GIE bit
3. Wait the required acquisition time (if required).
4. Start conversion:
Set GO/DONE bit (ADCON0 register)
5. Wait for A/D conversion to complete, by either:
Polling for the GO/DONE bit to be cleared OR
Waiting for the A/D interrupt
6. Read A/D Result registers (ADRESH:ADRESL); clear bit ADIF, if required.
7. For next conversion, go t o step 1 or step 2, as required. The A/D conversion time per bit
is defined as TAD. A minimum wait of 3 TAD is required before the next acquisition starts.

Experimental Procedure:

1. Open MPLAB IDE. Open Project menu and select project wizard. Then click on Next
button and select device as PIC18F4550. Click on Next button.

2. Select Active Toolsuite as Microchip C18 Toolsuite and select Toolsuite contents as
MPLAB C18 C compiler (mcc18.exe). Click on Next button.

3. Click on Browse button. Create a new folder on desktop (or any drive location) and
save file. Then click on Next button and again click on Next button. Click on Finish
button.

4. Open File menu and select New file and write a program. Save this program in a folder
which is created for your project.

5. Right click on Source Files and add C file from your project folder.

6. Build project file and check errors in C code. If code is free then you will get Hex file
for your C code.

7. To burn this Hex file into PIC18F4550, connect PICkit2 programmer to Kit. Open
Programmer menu and select programmer as PICkit2. Then you will get message as
PICkit2 is ready in output window.
MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

8. Then click on Program the target device and then click on Bring target MCLR to VDD.

9. Then observe the output on respective port and peripheral.

Conclusion:

In this experiment we have done analog to digital conversion. The corresponding


result is displayed in terms of voltage on 16x2 LCD display.

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Experiment No. 10
Title: Generation of PWM signal for DC motor control

Date of Performance: Roll No:

Date of Submission: University Seat No:

Signature of Staff:

Experiment No. 10
Generation of PWM signal

Title: Generation of PWM Signal for DC motor

Problem statement:
Interface DC Motor (9V 12V; 200 300 rpm) to PIC microcontroller. Write a program in
Embedded C to control the speed of DC motor using on-chip PWM Module of PIC Microcontroller.

Aim:

v. To understand the working of PWM


w. To study the on-chip CCP Module (PWM section) of PIC Microcontroller
x. To interface DC motor, via Driver IC L293D, to PIC Microcontroller
y. Apply the PWM signal to control the speed of DC Motor

MECHARONICS (2015 Course) Semester-I


JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Equipments Required:
S/W packages AND H/W used:
MPLAB IDE, C18 Compiler, ExplorePIC Development Board

Theory:

CCP Module of PIC microcontroller

Depending upon the device selected there are 14 CCP (Capture/Compare/PWM) modules in
PIC microcontroller. Each module contains a 16-bit register, which can operate as a 16-bit Capture
register, a 16-bit Compare register or a PWM Master/Slave Duty Cycle register. Each
Capture/Compare/PWM module is associated with a control register (generically, CCPxCON) and a
data register (CCPRx). The data register, in turn, is comprised of two 8-bit registers: CCPRxL (low
byte) and CCPRxH (high byte). All registers are both readable and writable.

The CCP modules utilize Timers 1, 2 or 3, depending on the mode selected. Timer1 and
Timer3 are available to modules in Capture or Compare modes, while Timer2 is available for
modules in PWM mode.
The pin assignment for CCP2 (Capture input, Compare and PWM output) can change, based
on device configuration. The CCP2MX Configuration bit determines which pin CCP2 is multiplexed to.
By default, it is assigned to RC1 (CCP2MX = 1). If the Configuration bit is cleared, CCP2 is multiplexed
with RB3. Changing the pin assignment of CCP2 does not automatically change any requirements for
configuring the port pin. Users must always verify that the appropriate TRIS register is configured
correctly for CCP2 operation, regardless of where it is located.

Capture Mode Applications


0 Event arrival time recording
1 Period measurement
2 Pulse-width measurement
3 Interrupt generation
4 Event counting
5 Time reference
6 Duty cycle measurement

Compare Mode Applications


Generate
o Single pulse
o Train of pulses
o Periodic waveform Start ADC conversion Time reference

PWM Mode of CCP Module


MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

In Pulse-Width Modulation (PWM) mode, the CCPx pin produces up to a 10-bit resolution
PWM output. Since the CCP2 pin is multiplexed with a PORTB or PORTC data latch, the appropriate
TRIS bit must be cleared to make the CCP2 pin an output. A PWM output has a time base (period)
and a time that the output stays high (duty cycle). The frequency of the PWM is the inverse of the
period (1/period).

Algorithm Steps:
The following steps should be taken when configuring the CCP module for PWM operation:
0 Set the PWM period by writing to the PR2register.
1 Set the PWM duty cycle by writing to the CCPR1L register and CCP1CON<5:4>
bits.
2 Make the CCP1 pin an output by clearing the appropriate TRIS bit.
3 Make the RC6 and RC7 as output to TURN ON the Motor.
4 Set the TMR2 prescale value, and then enable Timer2 by writing to T2CON.
5 Configure the CCP1 module for PWM operation.

Experimental Procedure:

1. Open MPLAB IDE. Open Project menu and select project wizard. Then click on Next
button and select device as PIC18F4550. Click on Next button.

2. Select Active Toolsuite as Microchip C18 Toolsuite and select Toolsuite contents as
MPLAB C18 C compiler (mcc18.exe). Click on Next button.

3. Click on Browse button. Create a new folder on desktop (or any drive location) and
save file. Then click on Next button and again click on Next button. Click on Finish
button.

4. Open File menu and select New file and write a program. Save this program in a folder
which is created for your project.

5. Right click on Source Files and add C file from your project folder.

6. Build project file and check errors in C code. If code is free then you will get Hex file
for your C code.

7. To burn this Hex file into PIC18F4550, connect PICkit2 programmer to Kit. Open
Programmer menu and select programmer as PICkit2. Then you will get message as
PICkit2 is ready in output window.

8. Then click on Program the target device and then click on Bring target MCLR to VDD.

9. Then observe the output on respective port and peripheral.


MECHARONICS (2015 Course) Semester-I
JSPMs
Imperial College of Engineering and Research, Wagholi, Pune.
(Approved by AICTE, Delhi & Govt. of Maharashtra, affiliated to Savitribai Phule Pune University)
Gat No.720, Pune-Nagar road, Wagholi, Pune-412207
Department of Electronics and Telecommunication Engineering

Conclusion:

In this experiment, we have interfaced DC motor with PIC18F4550. The PWM signal
is utilized to control the speed of DC motor. In PWM mode, the CCPx pin produces up to a 10-
bit resolution PWM output. Speed of DC motor can be controlled by duty cycle and period.

MECHARONICS (2015 Course) Semester-I

Вам также может понравиться