MC Instruction Manual - 2023-24
MC Instruction Manual - 2023-24
MICROCONTROLLER
INSTRUCTION MANUAL
CLASS: TE E&TC
2019 PATTERN
Prepared by
V.P.Patil & T. A. Rajbhoj
Experiment List
Experiment
CO
Learning Title of Experiment PO mapped
mapped
Outcomes
1. Demonstrate Parallel port interacting
of LEDS.
ELO-1: Students
2. Analyse & Demonstrate Waveform PO1, PO2,
will be able to
demonstrate Generation using DAC. PO3,PO4,PO5,
different 3. Describe & Demonstrate Interfacing CO304.2
PO8, PO9 &
interfacings of Stepper motor to 8051- software
using 8051 delay using Timer PO12
microcontroller.
Experiment No. 1
Problem Statement: Write a C program to Interface 8 bit LED Section to 8051 microcontrollers
for LED flashing.
ELO-1: Students will be able to demonstrate different interfacings using 8051 microcontroller.
OBJECTIVE:
1. To understand the PORTs of 8051 Microcontroller.
2. To interface common peripherals like LEDs.
3. To understand the use of Micro vision Keil 5.
4. To write a simple program in Embedded C.
Keil development tools for the 8051 Microcontroller Architecture support every
level of software developer from the professional applications engineer to the
student just learning about embedded software development.
Features
MCU Simulator
Macro assembler
Hardware tools
Disassembler
THEORY:
Light Emitting Diodes or LEDs are the mostly commonly used components in many
applications. These are the semiconductor light sources, commonly used LEDs will have a cut-
off voltage of 1.7V and current of 10mA. When an LED is applied with its required voltage and
current it glows with full intensity. The Light Emitting Diode is similar to the normal PN diode
but it emits energy in the form of light. The colour of light depends on the band gap of the
semiconductor.
The four 8-bit I/O ports P0, P1, P2 and P3 each uses 8 pins .All the ports upon RESET are
configured as input, ready to be use as input ports When the first 0 is written to a port, it
becomes an output. To reconfigure it as an input, a 1 must be sent to the port. To use any of
these ports as an input port, it must be programmed It can be used for input or output, each pin
must be connected externally to a 10K ohm pull-up resistor.
ALGORITHM:
1. Start
2. Make port 0 as output port.
3. Send 0XFF to port 0.
4. Call delay routine.
5. Send 0X00 to port 0.
6. Call delay routine.
7. Stop
INTERFACING DIAGRAM:
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
ORAL QUESTIONS:
Experiment No. 2
ELO-1: Students will be able to demonstrate different interfacings using 8051 microcontroller.
OBJECTIVE:
Keil development tools for the 8051 Microcontroller Architecture support every
level of software developer from the professional applications engineer to the
student just learning about embedded software development.
Features
MCU Simulator
Macro assembler
Hardware tools
Disassembler
THEORY:
Digital-to-analog (DAC) converter:
The digital to analog converter (DAC) is a widely used to convert digital pulses to analog
signals. There two methods of creating DAC: 1. binary weighted, 2. R/2R ladder. The vast
majority of integrated circuit DACs use the R/2R method since it can achieve a much higher
degree of precision. The first criterion judging a DAC is its resolution, which is a n function of
the number of binary inputs. The common ones are 8, 10 and 12 bits. The number of data bit
inputs decides the resolution of the DAC since the number of analog output levels is equal to
2n,
where n is the number of data bit inputs. Therefore, an 8-bit input DAC such as the DAC0808
provides 256 discrete voltage (or current) levels of output. Similarly, the 12-bit DAC provides
4096 discrete voltage levels.
DAC 0808
In the DAC 0808, the digital inputs are converted to current (I out), and by connecting a
register to the I out pin, we convert the result to voltage. The total current provided by the I out
pin is a function of the binary numbers at then D0 – D7 inputs of the DAC0808 and the
reference current (I out), and is as follows:
Where D0 is the LSB, D7 is the MSB for the inputs, and I ref is the input current that must be
applied to pin 14. The Iref current is generally set to 2.0 mA. Figure shows the generation of
current reference (setting Iref = 2mA) by using the standard 5-V power supply and 1K and
1.5Kohm
standard resistors. Now assuming that Iref = 2mA, if all the inputs to the DACare high, the
Ideally we connect the output pin Iout to a resistor, convert this current to voltage, and monitor
the output on scope. In real life, however this can cause inaccuracy since the input resistance of
the load where it is connected will also affect the output voltage. For this reason, the Iref current
output is isolated by connecting it to an op-amp such as 741 with Rf = 5K ohms for the feedback
resistor.
INTERFACING DAIGRAM:
Procedure:
1) Open Micro Vision KEIL Software.
2) Create New Project.
3) Select the Microcontroller.
4) Write code in Editor Window and save file.
5) Add the file to target.
6) Compile the code.
7) Create Hex file.
8) Build the project & observe output on port & logic analyzer.
FLOWCHART:
Fig 2.3 Flowchart for DAC interfacing for square wave generation
CONCLUSION:
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
ORAL QUESTIONS:
EXPERIMENT NO 3
PROBLEM STATEMENT:
Interface Stepper motor to 8051 Microcontroller. Write a program in to rotate the motor through
clockwise & anticlockwise direction.
ELO-1: Students will be able to demonstrate different interfacings using 8051 microcontroller.
OBJECTIVE:
Keil development tools for the 8051 Microcontroller Architecture support every
level of software developer from the professional applications engineer to the
student just learning about embedded software development.
Features
MCU Simulator
Macro assembler
Hardware tools
Disassembler
THEORY:
A stepper motor is a widely used device that translates electrical pulses into mechanical
movement. In applications such as disk drives, dot matrix printers, and robotics, the stepper
motor is used for position control. Stepper motors commonly have a permanent magnet rotor
(also called the shaft) surrounded by a stator. There are also steppers called variable reluctance
stepper motors that do not have a PM rotor. The most common stepper motors have four stator
windings that are paired with a center-tapped common as shown in Figure 8.2. This type of
stepper motor is commonly referred to as a four-phase or uni-polar stepper motor. The center
tap allows a change of current direction in each of two coils when a winding is grounded,
While a conventional motor shaft runs freely, the stepper motor shaft moves in a fixed
repeatable increment, which allows one to move it to a precise position. This repeatable fixed
movement is possible as a result of basic magnetic theory where poles of the same polarity repel
and opposite poles attract. The direction of the rotation is dictated by the stator poles. The stator
poles are determined by the current sent through the wire coils. As the direction of the current
is changed, the polarity is also changed causing the reverse motion of the rotor. The stepper
motor discussed here has a total of 6 leads: 4 leads representing the four stator windings and 2
commons for the center-tapped leads. As the sequence of power is applied to each stator winding,
the rotor will rotate.There are several widely used sequences where each has a different degree of
precision. Table No. 3.1 shows a 2-phase, 4-step stepping sequence.
It must be noted that although we can start with any of the sequences in Table 8.1, once we start
we must continue in the proper order. For example, if we start with step 3 (0110), we must
continue in the sequence of steps 4, 1, 2, etc.
STEP ANGLE:
How much movement is associated with a single step? This depends on the internal
construction of the motor, in particular the number of teeth on the stator and the rotor. The step
angle is the minimum degree of rotation associated with a single step. Various motors have
different step angles. Table shows some step angles for various motors. In table 8.4, notice the
term steps per revolution. This is the total number of steps needed to rotate one complete
rotation or 360 degrees (e. g., 180 steps * 2 degrees =360).
It must be noted that perhaps contrary to one’s initial impression, a stepper motor does not
need more terminal leads for the stator to achieve smaller steps. All the stepper motors
discussed in this section have 4 leads for the stator winding and 2 COM wires for the center tap.
Although some manufacturers set aside only one lead for the common signal instead of two,
they always have 4 leads for the stators. Next we discuss some associated terminology in order
to understand the stepper motor further.
Formula:
Procedure:
ALGORITHM:
1. Start
2. Make port 0 as output port.
3. Send 0XFF to port 0.
4. Call delay routine.
5. Send 0X00 to port 0.
6. Call delay routine.
7. Stop
INTERFACING DIAGRAM:
Gaming machines.
Medical imaging machinery.
Small robotics.
CNC milling machines.
Welding equipment.
ORAL QUESTIONS:
EXPERIMENT NO 4
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. LED’s start chasing from left to right and turn ON Relay, buzzer whenever
pushbutton 1 is pressed.
b. LED’s start chasing from right to left and turn OFF Relay, buzzer whenever
pushbutton 2 is pressed.
2 C Programming language
3 Assembly language
S/W PACKAGES AND H/W USED:
2 PickLAB IDE:
Piklab is an open source integrated development environment (IDE) for applications devised
on Microchip PIC and digital signal processor IC (dsPIC) microcontroller (MCU) that can be
compiled only with Qt on Linux and Windows. Qt, being a cross platform framework, allows
Piklab to develop non-graphical user interface (non-GUI) programs. Based on general public
licence version 2 (GNU GPL v2), Piklab is a complete development environment, providing
access to different toolchains.
Features:
1. Provides tools for the complete development process that includes editing and
compilation of the source, programming the device and debugging.
2. Integrates with several types of compilers, assembler toolchains and gpsim simulators.
3. Supports most common programmers, ICD2 debugger and several types of bootloaders.
It also supports some direct programmers for most of the devices with PIC18F MCUs
and PIC24C EEPROM
The PIC18 Ports have both the latch and buffer. Therefore, when reading the ports there are two
possibilities:
4. Reading the input pin
5. Reading the latch
ALGORITHM
1. Start
2. Select the Oscillator to HS
3. Disable Watchdog timer
4. Disable Low Voltage Programming
5. Disable PORTB Analog inputs
6. Define the lrbit and rlbit
7. Define relay as RC1
8. Initialize buzzer and relay to 0
9. If not lrbit then set the buzzer and relay to 1 and shift the PORTD to left by 1, If PORTD
value is 0x00 then make the MSB bit equal to 1
10. If not rlbit then set the buzzer and relay to 0 and shift the PORTD to right by 1, If PORTD
value is 0x80 then make the LSB bit equal to 1
11. Stop
INTERFACING DIAGRAM:
CONCLUSION:
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
Home Applications (TVs, VCR, Video Games, Camcorder, Music Instruments, Home
Security Systems, Garage Door Openers, etc.)
ORAL QUESTIONS:
1] What is mean by common anode and common cathode connection of LED’s? Explain with
the diagram.
2] Explain the working of Relay.
3] Explain working of a Switch.
4] What is features of PIC microcontroller?
5] Differentiate between PIC and 8051.
EXPERIMENT NO 5
TITLE : Interfacing of LCD to Pic Microcontroller.
PROBLEM STATEMENT: Interface LCD to PIC Microcontroller. Write a program in
Assembly Language to display a message on LCD.
2 C Programming language
3 Assembly language
S/W PACKAGES AND H/W USED:
PickLAB IDE:
Piklab is an open source integrated development environment (IDE) for applications devised
on Microchip PIC and digital signal processor IC (dsPIC) microcontroller (MCU) that can be
compiled only with Qt on Linux and Windows. Qt, being a cross platform framework, allows
Piklab to develop non-graphical user interface (non-GUI) programs. Based on general public
licence version 2 (GNU GPL v2), Piklab is a complete development environment, providing
access to different toolchains.
Features:
4. Provides tools for the complete development process that includes editing and
compilation of the source, programming the device and debugging.
5. Integrates with several types of compilers, assembler toolchains and gpsim simulators.
6. Supports most common programmers, ICD2 debugger and several types of bootloaders.
It also supports some direct programmers for most of the devices with PIC18F MCUs
and PIC24C EEPROMs.
THEORY:
In LCD 16×2, the term LCD stands for Liquid Crystal Display that uses a plane panel
display technology, used in screens of computer monitors & TVs, smartphones, tablets, mobile
devices, etc. Both the displays like LCD & CRTs look the same but their operation is different.
Instead of electrons diffraction at a glass display, a liquid crystal display has a backlight that
provides light to each pixel that is arranged in a rectangular network. Every pixel includes a
blue, red, green sub-pixel that can be switched ON/OFF. Once all these pixels are deactivated,
then it will appear black and when all the sub-pixels are activated then it will appear white. By
changing the levels of each light, different color combinations are achievable. This article
discusses an overview of LCD 16X2 & its working with applications.
An electronic device that is used to display data and the message is known as LCD 16×2. As the
name suggests, it includes 16 Columns & 2 Rows so it can display 32 characters (16×2=32) in
total & every character will be made with 5×8 (40) Pixel Dots. So the total pixels within this LCD
can be calculated as 32 x 40 otherwise 1280 pixels.
Working Principle
The basic working principle of LCD is passing the light from layer to layer through modules.
These modules will vibrate & line up their position on 90o that permits the polarized sheet to
allow the light to pass through it. These molecules are accountable for viewing the data on every
pixel. Every pixel utilizes the method of absorbing light to illustrate the digit. To display the
value, the position of molecules must be changed to the angle of light. So this light deflection
will make the human eye notice the data that will be the ingredient wherever the light gets
absorbed. Here, this data will supply to the molecules & will be there till they get changed At
present, LCDs are used frequently in CD/DVD players, digital watches, computers, etc. In
screen industries, LCDs have replaced the CRTs (Cathode Ray Tubes) because these displays
use more power as compared to LCD, heavier & larger.
The displays of LCDs are thinner as compared to CRTs. As compared to LED screens, LCD has
less power consumption because it functions on the fundamental principle of blocking light
instead of dissipating.
Registers of LCD
The registers used in LCD are two types like data register & command register. The register can
be changed by using the RS pinout. If we set ‘0’ then it is command register and if it is ‘1’ then
it is data register.
Command Register
The main function of the command register is to save instructions illustrated on LCD. That
assists in data clearing & changes the cursor location & controls the display.
Data Register
The data register is used to save the date to exhibit on the LCD. Once we transmit data to LCD,
then it shifts to the data register to process the data. If we fix the register value at one that the
data register will start working.
Procedure:
1. Open MPLAB IDE Software.
2. Create New Project by selecting the suitable device.
3. Write code in Editor Window and save file.
4. Add the file to target.
5. Compile the code .
6. Make connections as per the interfacing diagram.
7. Download the code & observe the required output on the development board.
Program:
INTERFACING DIAGRAM:
CONCLUSION:
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
It is used in instruments panel where all the lab instruments uses LCD screens for display.
https://www.youtube.com/watch?v=u2V
PLtELzZ4
ORAL QUESTIONS:
EXPERIMENT NO 6
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
2 C Programming language
3 Assembly language
S/W PACKAGES AND H/W USED:
2 PickLAB IDE:
Piklab is an open source integrated development environment (IDE) for applications devised
on Microchip PIC and digital signal processor IC (dsPIC) microcontroller (MCU) that can be
compiled only with Qt on Linux and Windows. Qt, being a cross platform framework, allows
Piklab to develop non-graphical user interface (non-GUI) programs. Based on general public
licence version 2 (GNU GPL v2), Piklab is a complete development environment, providing
access to different toolchains.
Features:
7. Provides tools for the complete development process that includes editing and
compilation of the source, programming the device and debugging.
8. Integrates with several types of compilers, assembler toolchains and gpsim simulators.
9. Supports most common programmers, ICD2 debugger and several types of bootloaders.
It also supports some direct programmers for most of the devices with PIC18F MCUs
and PIC24C EEPROMs.
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.
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. 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.
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
f. Interrupt on overflow
The T0CON register (Register 11-1) controls all aspects of the module’s operation, including the
prescale selection. It is both readable and writable. A simplified block diagram of the Timer0
module in 8-bit mode is shown in Figure 1.1. Figure 1.2 shows a simplified block diagram of the
Timer0 module in 16-bit mode.
certain requirements to ensure that the external clock can be synchronized with the internal
phase clock (TOSC). There is a delay between synchronization and the onset of incrementing
the timer/counter.
4.2 Prescaler
An 8-bit counter is available as a prescaler for the Timer0 module. The prescaler is not directly
readable or writable; its value is set by the PSA and T0PS2:T0PS0 bits (T0CON<3:0>) which
determine the prescaler assignment and prescale ratio. Clearing the PSA bit assigns the
prescaler to the Timer0 module. When it is assigned, prescale values from 1:2 through 1:256,
in power-of-2 increments are selectable. When assigned to the Timer0 module, all instructions
writing to the TMR0 register clear the prescaler count
4.3 Timer0 Interrupt
The TMR0 interrupt is generated when the TMR0 register overflows from FFh to 00h in 8-bit
mode, or from FFFFh to 0000h in 16-bit mode. This overflow sets the TMR0IF flag bit.
The interrupt can be masked by clearing the TMR0IE bit (INTCON<5>). Before reenabling the
interrupt, the TMR0IF bit must be cleared in software by the Interrupt Service Routine. Since
Timer0 is shut down in Sleep mode, the TMR0 interrupt cannot awaken the processor from
Sleep.
Bit
Calculations:
Procedure:
1) Open MPLAB IDE Software.
2) Create New Project by selecting the suitable device.
4) Write code in Editor Window and save file.
5) Add the file to target.
6) Compile the code .
8) Make connections as per the interfacing diagram.
9) Download the code & observe the required output on the development board.
Algorithm:
1. Start
2. Select the Oscillator to HS
3. Disable Watchdog timer
4. Disable Low Voltage Programming
5. Disable PORTB Analog inputs
6. Define the timer isr function
7. Configure the RB0 as output
8. Set the Initial value for RB0
9. Clear Timer0 overflow flag
10. Start the Timer0
11. Continue Program execution until the timer overflow interrupt is generated
12. load timer value to generate delay 50ms
13. Stop
Interfacing Diagram
DACs are commonly used in music players to convert digital data streams into analog
audio signals.
They are also used in televisions and mobile phones to convert digital video data into
analog video signals
https://www.youtube.com/watch?v=6IhI
WbMGMIU
ORAL QUESTIONS:
3. What is the execution speed of instructions in PIC specially while operating at maximum
value of clock rate?
4. What are the standard waveforms that can be generated using the DAC component?
EXPERIMENT NO 7
TITLE : 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, 1 stop bit.
OBJECTIVE :
a. To study the RS232 standard for serial communication
b. To Study the on-chip USART of PIC Microcontroller
c. To calculate the desired baud rate.
d. To interface MAX232 with PIC Microcontroller for serial communication.
S/W PACKAGES AND H/W USED:
MPLAB IDE, C18 Compiler, Explore PIC Development Board
DIFFERENT SOFTWARE TOOLS AVAILABLE IN USE CURRENTLY:
1. MPLAB IDE
2. PickLAB
COMPARE AND CONTRAST EXISTING SOFTWARE OR HARDWARE TOOLS:
MPLAB IDE
MPLAB IDE runs as a 32-bit application on MS Windows, is easy to use and includes a host of
free software components for fast application development and super-charged debugging.
MPLAB IDE also serves as a single, unified graphical user interface for additional Microchip
and third party software and hardware development tools. Moving between tools is a snap, and
upgrading from the free software simulator to hardware debug and programming tools is done
in a flash because MPLAB IDE has the same user interface for all tools.
Features:
Create and edit source code using the built-in editor
Assemble, compile and link source code.
Debug the executable logic by watching program flow with the built-in simulator or in
real time with in-circuit emulators or in-circuit debuggers.
Make timing measurements with the simulator or emulator.
View variables in Watch windows.
PickLAB IDE:
Piklab is an open source integrated development environment (IDE) for applications devised
on Microchip PIC and digital signal processor IC (dsPIC) microcontroller (MCU) that can be
compiled only with Qt on Linux and Windows. Qt, being a cross platform framework, allows
Piklab to develop non-graphical user interface (non-GUI) programs. Based on general public
licence version 2 (GNU GPL v2), Piklab is a complete development environment, providing
access to different toolchains.
Features:
1. Provides tools for the complete development process that includes editing and
compilation of the source, programming the device and debugging.
2. Integrates with several types of compilers, assembler toolchains and gpsim simulators.
3. Supports most common programmers, ICD2 debugger and several types of bootloaders.
It also supports some direct programmers for most of the devices with PIC18F MCUs
and PIC24C EEPROMs.
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).
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.
3.3.1 Transmit Status & Control Register
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.
CALCULATIONS
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
Procedure:
1) Open MPLAB IDE Software.
2) Create New Project by selecting the suitable device.
4) Write code in Editor Window and save file.
5) Add the file to target.
6) Compile the code .
8) Make connections as per the interfacing diagram.
9) Download the code & observe the required output on the development board.
Algorithm:
Transmission
1. Start
2. Select the Oscillator to HS
3. Disable Watchdog timer
4. Disable Low Voltage Programming
5. Disable PORTB Analog inputs
6. Configure RXD line as input
CONCLUSION:
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
ORAL QUESTIONS:
EXPERIMENT NO 8
TITLE: Generation of PWM Signal for DC motor control.
PROBLEM STATEMENT:
Interface DC Motor to PIC microcontroller. Write a program in Embedded C to
control the speed of DC motor using on-chip PWM Module of PIC Microcontroller.
OBJECTIVE :
a. To understand the working of PWM.
b. To study the on-chip CCP Module (PWM section) of PIC
Microcontroller.
c. To interface DC motor, via Driver IC L293D, to PIC Microcontroller
d. Apply the PWM signal to control the speed of DC Motor.
S/W PACKAGES AND H/W USED:
MPLAB IDE, C18 Compiler, Explore PIC Development Board, DC Motor, CRO
DIFFERENT SOFTWARE TOOLS AVAILABLE IN USE CURRENTLY:
1. MPLAB IDE
2. PickLAB
COMPARE AND CONTRAST EXISTING SOFTWARE OR HARDWARE TOOLS:
1 MPLAB IDE
MPLAB IDE runs as a 32-bit application on MS Windows, is easy to use and includes a host of
free software components for fast application development and super-charged debugging.
MPLAB IDE also serves as a single, unified graphical user interface for additional Microchip
and third party software and hardware development tools. Moving between tools is a snap, and
upgrading from the free software simulator to hardware debug and programming tools is done
in a flash because MPLAB IDE has the same user interface for all tools.
Features:
Create and edit source code using the built-in editor
Assemble, compile and link source code.
Debug the executable logic by watching program flow with the built-in simulator or in
real time with in-circuit emulators or in-circuit debuggers.
Make timing measurements with the simulator or emulator.
2 PickLAB IDE:
Piklab is an open source integrated development environment (IDE) for applications devised
on Microchip PIC and digital signal processor IC (dsPIC) microcontroller (MCU) that can be
compiled only with Qt on Linux and Windows. Qt, being a cross platform framework, allows
Piklab to develop non-graphical user interface (non-GUI) programs. Based on general public
licence version 2 (GNU GPL v2), Piklab is a complete development environment, providing
access to different toolchains.
Features:
1. Provides tools for the complete development process that includes editing and
compilation of the source, programming the device and debugging.
2. Integrates with several types of compilers, assembler toolchains and gpsim simulators.
3. Supports most common programmers, ICD2 debugger and several types of bootloaders.
It also supports some direct programmers for most of the devices with PIC18F MCUs
and PIC24C EEPROMs.
THEORY:
1. PWM Technique:
Depending upon the device selected there are 1 – 4 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
Event arrival time recording
Period measurement
Pulse-width measurement
Interrupt generation
Event counting
Time reference
Duty cycle measurement
PWM Mode of CCP Module
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). The simplified block diagram of the CCP1 configured to
generate PWM is shown in Figure 9.1, with example waveforms in Figure 9. 2. The block
diagram for CCP2 is similar to CCP1. It can be seen that Figure 9.1 contains CCPR1L, Timer 2,
comparator and the PR2 register working together. Although not shown, Timer 2 is still driven
from the on-chip oscillator, through its own prescaler. The comparator output drives an R–S
flip-flop. When the value in PR2 equals Timer 2, then the comparator clears the timer and sets
the flip-flop, whose output goes high. This is seen in Figure 9.2. This action sets the PWM
period.
Timer 2 Module
The Timer2 module timer incorporates the following features:
• 8-bit timer and period registers (TMR2 and PR2, respectively)
• Readable and writable (both registers)
• Software programmable prescaler (1:1, 1:4 and 1:16)
• Software programmable Postscaler (1:1 through 1:16)
• Interrupt on TMR2 to PR2 match
• Optional use as the shift clock for the MSSP module
The module is controlled through the T2CON register which enables or disables the timer and
configures the prescaler and Postscaler. Timer2 can be shut off by clearing control bit, TMR2ON
(T2CON<2>), to minimize power consumption. A simplified block diagram of the module is
shown in Figure.
Timer2 Operation
In normal operation, TMR2 is incremented from 00h on each clock (FOSC/4). A 2-bit
counter/prescaler on the clock input gives direct input, divide-by-4 and divide-by-16 prescale
options. These are selected by the prescaler control bits, T2CKPS1:T2CKPS0 (T2CON<1:0>). The
value of TMR2 is compared to that of the period register, PR2, on each clock cycle. When the
two values match, the comparator generates a match signal as the timer output. This signal also
resets the value of TMR2 to 00h on the next cycle and drives the output counter/ Postscaler.
The TMR2 and PR2 registers are both directly readable and writable. The TMR2
register is cleared on any device Reset, while the PR2 register initializes at FFh. TMR2 is not
cleared when T2CON is written. Both the prescaler and postscaler counters are cleared on the
following events:
1 a write to the TMR2 register
2 a write to the T2CON register
3 any device Reset (Power-on Reset, MCLR Reset, WDT Reset or Brown-out)
Timer2 Interrupt
Timer2 also can generate an optional device interrupt. The Timer2 output signal (TMR2 to PR2
match) provides the input for the 4-bit output counter/postscaler. This counter generates the
TMR2 match interrupt flag which is latched in TMR2IF (PIR1<1>). The interrupt is enabled by
setting the TMR2 Match Interrupt Enable bit,TMR2IE (PIE1<1>). A range of 16 postscale options
(from 1:1 through 1:16 inclusive) can be selected with the postscaler control bits,
T2OUTPS3:T2OUTPS0 (T2CON<6:3>)
Calculation
Desired PWM Frequency = 4 KHz
by 1,2EN and drivers 3 and 4 enabled by 3,4EN as shown in pin diagram and function table.
When an enable input is high, the associated drivers are enabled, and their outputs are active
and in phase with their inputs. When the enable input is low, those drivers are disabled, and
their outputs are off and in the high-impedance state. With the proper data inputs, each pair of
drivers forms a full-H (or bridge) reversible drive suitable for solenoid or motor applications.
Interfacing diagram
CONCLUSION:
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
ORAL QUESTIONS:
a. What are the types of DC motor?
b. Explain the principal of operation of DC motor?
c. Which DC motor is preferred for constant speed?
d. What is PWM DC control?
e. Why PWM is used to control motors?