Академический Документы
Профессиональный Документы
Культура Документы
LAB MANUAL
For
MECHATRONICS
T E (E&TC) 2015C
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:
List of Experiments
Sr.
Experiment
No.
Position Control Using Servomechanism with Photo Electric Pick up or with
1 appropriate sensor.
11 Study of LVDT
Experiment No. 1
Title: Demonstration of Pneumatic/ Electro pneumatic Components and Circuits
Signature of Staff:
Experiment No. 1
Simple 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:
Equipments Required:
S/W packages AND H/W used:
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.
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.
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
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,
External Memory:
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.
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:
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
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
Signature of Staff:
Experiment No. 2
LED interfacing
Problem statement:
Write an assembly language program to flash (or blink) LEDs connected to port considering a time
delay.
Aim:
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:
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:
Fig. Flowchart
Experimental Procedure:
19) Now burn hex code onto microcontroller with Flash Magic software. Then observe
output on peripherals.
Conclusion:
Experiment No. 3
Title: Interfacing of LCD
Signature of Staff:
Experiment No. 3
LCD interfacing
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:
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.
Fig. 1 LCD
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
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
You can use subroutine for checking busy flag or just a big (and safe) delay.
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.
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
RETURN
Stop
Fig. Flowchart
Experimental Procedure:
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.
Experiment No. 4
Title: Interfacing of Stepper motor
Signature of Staff:
Experiment No. 4
Stepper motor interfacing
Problem statement:
Write an assembly language program to interface stepper motor with 8051 microcontroller.
Aim:
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.
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.
Driver Technology
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:
Conclusion:
Experiment No. 5
Title: Interfacing button, LED, relay & buzzer
Signature of Staff:
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:
Equipments Required:
S/W packages AND H/W used:
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.
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.
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.
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.
Conclusion:
In this experiment, we have interfaced LED, buttons, relay and buzzer with
PIC18F4550
Experiment No. 6
Title: Generation of Square wave using timer with interrupt
Signature of Staff:
Experiment No. 6
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:
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.
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
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
Algorithm Steps:
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
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
Signature of Staff:
Experiment No. 7
Serial communication between PC and PIC microcontroller
Problem statement:
Write a program in Embedded C to transfer the message and receive serially at 9600
baud, 8 bit data.
Aim:
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
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.
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.
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
= (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
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.
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.
Conclusion:
Experiment No. 6
Title: Generation of Square wave using timer with interrupt
Signature of Staff:
Experiment No. 6
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:
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.
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.
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
external events.
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:
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.
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
Signature of Staff:
Experiment No. 7
Serial communication between PC and PIC microcontroller
Problem statement:
Write a program in Embedded C to transfer the message and receive serially at 9600
baud, 8 bit data.
Aim:
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.
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.
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.
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.
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 = 0.0 %
5. Interfacing Diagram
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.
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.
Conclusion:
Experiment No. 8
Title: Demonstration of Pneumatic/ Electro pneumatic Components and Circuits
Signature of Staff:
Experiment No. 8
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 Sequencing of Single Acting Cylinder & Double Acting Cylinder through Relay
Equipments required:
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.
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
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
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
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
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).
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
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
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.
Conclusion:
Experiment No. 9
Title: On chip ADC programming
Signature of Staff:
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:
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).
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.
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.
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.
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.
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
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
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)
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.
Conclusion:
Experiment No. 10
Title: Generation of PWM signal for DC motor control
Signature of Staff:
Experiment No. 10
Generation of PWM signal
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:
Equipments Required:
S/W packages AND H/W used:
MPLAB IDE, C18 Compiler, ExplorePIC Development Board
Theory:
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.
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.
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.