0% found this document useful (0 votes)
69 views13 pages

Unit - 5 - notes-CCP Module of PIC 18f458 Microcontroller

The document provides an overview of the Capture/Compare/PWM (CCP) and Enhanced CCP (ECCP) modules of the PIC 18f458 microcontroller, detailing their operational modes, control registers, and applications. It explains the functionalities of CCP in capture, compare, and PWM modes, as well as the interfacing of the microcontroller with stepper and DC motors. Additionally, it discusses the importance of using external drivers for motor control due to the current and voltage limitations of the microcontroller.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views13 pages

Unit - 5 - notes-CCP Module of PIC 18f458 Microcontroller

The document provides an overview of the Capture/Compare/PWM (CCP) and Enhanced CCP (ECCP) modules of the PIC 18f458 microcontroller, detailing their operational modes, control registers, and applications. It explains the functionalities of CCP in capture, compare, and PWM modes, as well as the interfacing of the microcontroller with stepper and DC motors. Additionally, it discusses the importance of using external drivers for motor control due to the current and voltage limitations of the microcontroller.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

UNIT 5

CCP AND ECCP PROGRAMMING

Q.1 Explain CCP module of PIC 18f458 microcontroller


Capture/Compare/PWM (CCP) Modules
 Each CCP module requires the use of timer resource.
 In capture or compare mode, the CCP module may use either Timer1 or Timer3 to
operate.
 In PWM mode, either Timer2 is used.
 The operations of all CCP modules are identical, with the exception of the special event
trigger mode present on CCP1 and CCP2.
 The operation of a CCP module is controlled by the CCP1CON and CCP0CON
registers.
 It uses the RC2 pin for the CCP mode.
 CCP registers:
CCP module supports 3 registers.
1. CCP1CON register.
2. 16 bit register CCPR1H:CCPR1L.
3. 10 bit duty cycle register in the PWM mode.

Q.2 Explain CCP1CON control register.


 CCP1CON register is used to select the operating mode of CCP module.
 It also performs control operation.

7 6 5 4 3 2 1 0

----------- ---------- DC1B1 DC1B0 CCP1M3 CCP1M2 CCP1M1 CCP1M0

Bit 5 and 4 DC1B1:DC1B0:


capture mode: unused
compare mode: unused
PWM mode: These two bits are the LSBs (bit 1 and bit 0) of the 10-bit PWM duty cycle.
Bit 3 to 0 CCP1M3:CCP1M0:
0000 = capture/compare/PWM disabled (resets CCP1 module)
0001 = reserved

1
0010 = compare mode, toggle output on match (CCP1IF bit is set)
0011= compare mode CAN message received
0100 = capture mode, every falling edge
0101 = capture mode, every rising edge
0110 = capture mode, every 4th rising edge
0111 = capture mode every 16th rising edge
1000 = compare mode, initialize CCP pin low, on compare match force CCP pin high
(CCP1IF bit is set)
1001 = compare mode, initialize CCP pin high, on compare match force CCP pin low
(CCP1IF bit is set)
1010 = compare mode, generate software interrupt on compare match (CCP pin
unaffected, CCP1IF bit is set).
1011 = compare mode, trigger special event (CCP1IF bit is set). For CCP1 and CCP2: Timer1
or Timer3 is reset on event. For all other modules: CCP1 pin is unaffected and is configured as
an I/O port.
11xx = PWM mode.

Q.3 Explain CCP Compare Mode


 By programming the CCP1CON register bits the compared mode is selected.
 In compared mode Timer1 or timer3 is used for the operation.
 The 16-bit CCPR1(CCPR1H:CCPR1L) register is compared against the TMR1 (or
TMR3).
 When they match, one of the following actions may occur on the associated CCP1 pin:
1. driven high
2. driven low
3. toggle output
4. remains unchanged
How to Use the Compare Mode?
1. Makes a copy of the 16bit timer value (Timer1 or Timer3)
2. Adds to this copy a delay count
3. Stores the sum in the CCPR1H:CCPR1L register pair
Special Event Trigger
 The CCP1 and CCP2 modules can also generate this event to reset TMR1 or TMR3
depending on which timer is the base timer.

2
 The control bits CCP1M3:CCP1M0 in the CCP1CON register are used for selecting
these actions. The interrupt flag bit CCP1IF in the PIR1 register is set.
 Only special events clear the timer. For all other action we need to clear timer.

Q.4 Explain CCP in Capture Mode


 By programming the CCP1CON register bits the capture mode is selected.
 In capture mode Timer1 or timer3 is used for the operation.
 Main use of CCP is to capture event arrival time.
 An event is represented by a signal edge.
 The PIC18 event can be one of the following:
1. every falling edge
2. every rising edge
3. every 4th rising edge
4. every 16th rising edge
Capture Operation
 When a capture is made, the interrupt flag bit, CCP1IF is set.
 The CCP1IF flag must be cleared by software.

3
 In capture mode, the CCP1 pin must be configured for input.
 The timer to be used with the capture mode must be running in timer mode or
synchronous counter mode.
 To prevent false interrupt, the user must disable the CCP module when switching
prescaler.

Applications of Capture Mode


•Event arrival time recording
•Period measurement Plidtht
• Pulse width measurement
•Interrupt generation
•Event counting
•Time reference
•Duty cycle measurement

4
Q.5 Explain PWM mode.
 Pulse width modulation is feature of CCP.
 This feature allows the programmer to generate pulses that are having variable widths.
 Mostly PWM is used for DC motor control.
 The timer 2 and register PR2are used by the CCP module for PWM generation.
 Two important factors considered during PWM generation are:
1. Duty cycle of the pulse.
2. Period of the pulse.
 The duty cycle of a pulse is the part for which the pulse is high for the given period of
time.
 Generally, it is expressed in terms of percentage.

Fig. Period and duty cycle


 PWM period (Tpwm) = [(PR2)+1]*4*TOSC*(TMR2 prescaler factor)
Fosc
PR2 = ------------------ -1
Fpwm * 4* N

CCPR1L= Duty cycle *PR2

5
Duty cycle of PWM
DC1B1 DC!B1 Decimal point

0 0 0%

0 1 25%

1 0 50%

1 1 75%

Q.6 Explain Enhanced capture/compare/PWM (ECCP) module.

 The PIC 18f458 microcontroller has one Enhanced ECCP module.


 It uses the RD4 pin the ECCP module.
 In PWM mode, the ECCP module can have up to 4 available outputs, depending on
which operating mode is selected. These outputs are multiplexed with PORTD.

6
 In ECCP mode Capture and Compare mode uses Timer1 or Timer 3 and PWM mode
uses Timer 2.

 ECCP registers:
1.ECCP1CON control register.
2. 16 bit ECCPR1H:ECCPR1L
3. PWM duty cycle register.

Q.7 Explain ECCP1CON control register.


7 6 5 4 3 2 1 0

----- EPWM1M0 EDC1B1 EDC1B0 ECCP1M3 ECCP1M2 ECCP1M1 ECCP1M0

Bit 7 – Unimplemented
Bit 6-
Bit 5 and 4- EDC1B1: EDC1B0
PWM Duty cycle
Bit 3 to 0 ECCP1M3:ECCP1M0:
0000 = capture/compare/PWM disabled (resets CCP1 module)
0001 = reserved
0010 = compare mode, toggle output on match (CCP1IF bit is set)
0011= compare mode CAN message received
0100 = capture mode, every falling edge
0101 = capture mode, every rising edge
0110 = capture mode, every 4th rising edge
0111 = capture mode every 16th rising edge
1000 = compare mode, initialize CCP pin low, on compare match force CCP pin high
(CCP1IF bit is set)
1001 = compare mode, initialize CCP pin high, on compare match force CCP pin low
(CCP1IF bit is set)

7
1010 = compare mode, generate software interrupt on compare match (CCP pin
unaffected, CCP1IF bit is set).
1011 = compare mode, trigger special event (CCP1IF bit is set). For CCP1 and CCP2: Timer1
or Timer3 is reset on event. For all other modules: CCP1 pin is unaffected and is configured as
an I/O port.
11xx = PWM mode.

Q. 8 Explain PIC18 interfacing to stepper motor.


 Stepper motor is device that translates electrical pulses to mechanical movement.
 It is used in applications like robotics, dot matrix printers, disk drives for position
control.
 Stepper motor is a brushless, synchronous DC electric motor, which divides the full
rotation into a number of equal steps.
 Stepper motor is divided into unipolar and bipolar types.
 The motor has 6 leads, 4 leads representing four stator winding and 2 leads for 2
commons for the centres tapped leads.
 There are many sequences for rotation. Each sequence has a different degree of
precision.
 Step angle is defined as the minimum degree of rotation associated with single step.
 Fig. shows some step angles.
Step angle Step per revolution

0.72 500

1.8 200

2.0 180

2.5 144

5.0 72

7.5 48

15 24

 Fig. shows 2 phase 4 step stepping sequence.

8
Step Winding Winding Winding Winding Clockwise Anti-
A1 A2 A3 A4 Rotation Clockwise
Rotation
1 1 0 0 1

2 1 1 0 0

3 0 1 1 0

4 0 0 1 1

 Four step sequence and 8 step sequence.


 The four step sequence is also called as full stepping sequence.

Step Winding Winding Winding Winding Clockwise Anti-


A1 A2 A3 A4 Rotation Clockwise
Rotation
1 1 0 0 1

2 1 0 0 0

3 1 1 0 0

4 0 1 0 0

5 0 1 1 0

6 0 0 1 0

7 0 0 1 1

8 0 0 0 1

 Interfacing of PIC18f458 to stepper motor.

9
 From fig. the four leads of stator winding are controlled by port D bits RD0-RD3.
 The PIC 18 does not have sufficient current to drive the stepper motor windings. Hence,
a driver like ULN 2003 is required to energize the stator

Q.9 Explain DC motor.


 The DC motor rotates continuously.
 It is the device that translates electrical pulses into mechanical movements.
 Direct current machines can be considered consisting of four main parts namely; Stator,
Rotor, Air Gap, and Commutators and Brushes.
 We can’t drive a DC Motor (depends) directly with a Microcontroller, as DC Motors
requires high current and high voltage than a Microcontroller can handle.
 Microcontrollers usually operates at +5 or +3.3V supply and it I/O pin can provide only
up to 25mA current.
 Commonly used DC Motors requires 12V supply and 300mA current, moreover
interfacing DC Motors directly with Microcontrollers may affect the working of
Microcontroller due to the Back EMF of the DC Motor.
 Thus it is clear that, it not a good idea to interface DC Motor directly with
Microcontrollers.

10
 The solution to above problems is to use H-bridge circuit.

 L293D and L293 are two such ICs. These are dual H-bridge motor drivers, i.e. by using
one IC we can control two DC Motors in both clock wise and counter clockwise
directions.
 The L293D can provide bidirectional drive currents of up to 600-mA at voltages from
4.5 V to 36 V while L293 can provide up to 1A at same voltages.
 Both ICs are designed to drive inductive loads such as dc motors, bipolar
stepping motors, relays and solenoids as well as other high-current or high-
voltage loads in positive-supply applications.
 All inputs of these ICs are TTL compatible and output clamp diodes for inductive
transient suppression are also provided internally. These diodes protect our circuit from
the Back EMF of DC Motor.

11
 In both ICs, drivers are enabled in pairs, with drivers 1 and 2 are enabled by a high
input to 1,2EN and drivers 3 and 4 are enabled by a high input to 3,4EN. When drivers
are enabled, their outputs will be active and in phase with their inputs. When drivers
are disabled, their outputs will be off and will be in the high-impedance state.

12
 Interfacing of DC motor with PIC18 using PWM.

 PWM is an effective method for adjusting the amount of power delivered to the load.
 PWM technique allows smooth speed variation without reducing the starting torque and
eliminates harmonics.
 In PWM method, operating power to the motors is turned on and off to modulate the
current to the motor.
 The ratio of on to off time is called as duty cycle.
 The duty cycle determines the speed of the motor. The desired speed can be obtained
by changing the duty cycle.
 The Pulse-Width Modulation (PWM) in microcontroller is used to control duty cycle
of DC motor drive.
 PWM is an entirely different approach to controlling the speed of a DC motor. Power
is supplied to the motor in square wave of constant voltage but varying pulse-width or
duty cycle.
 Duty cycle refers to the percentage of one cycle during which duty cycle of a continuous
train of pulses. Since the frequency is held constant while the on-off time is varied, the
duty cycle of PWM is determined by the pulse width. Thus the power increases duty
cycle in PWM.

13

You might also like