Академический Документы
Профессиональный Документы
Культура Документы
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 1 / 16
Outline
1 Introduction
Timer Resource
CCP Module
CCP Module - Control Register Format
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 2 / 16
Introduction
Outline
1 Introduction
Timer Resource
CCP Module
CCP Module - Control Register Format
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 3 / 16
Introduction
Introduction
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 4 / 16
Introduction Timer Resource
Timer Resource
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 5 / 16
Introduction CCP Module
CCP Module
CCP1 module
CCP2 module
CCP1 module
Capture/Compare/PWM Register1 (CCPR1) is comprised of two
8-bit registers: CCPR1L (low byte) and CCPR1H (high byte)
CCP1CON register controls the operation of CCP1
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 6 / 16
Introduction CCP Module
CCP Module
CCP1 module
CCP2 module
CCP2 module
Capture/Compare/PWM Register2 (CCPR2) is comprised of two
8-bit registers: CCPR2L (low byte) and CCPR2H (high byte)
CCP2CON register controls the operation of CCP2
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 6 / 16
Introduction CCP Module - Control Register Format
bit 7 bit 0
Unimplemented (read as ’0’) LSBs of PWM duty cycle Mode select (11xx for PWM mode)
1
CCP2CON used for PIC16F914/917 only Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 7 / 16
Pulse Width Modulation (PWM) Mode
Outline
1 Introduction
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 8 / 16
Pulse Width Modulation (PWM) Mode PWM Basics
PWM Mode
PWM Basics
A PWM output is a signal that has a time-base (period) and a time
that the output stays high (duty cycle)
The period is the duration after which the PWM rising edge
repeats itself
The resolution of the PWM output is the granularity with which the
duty cycle can be varied
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 9 / 16
Pulse Width Modulation (PWM) Mode PWM in PIC16F917
PWM in PIC16F917
PWM period
Duty cycle
TIMR2 = PR2
TIMR2 = PR2 TIMR2 = CCPRxH
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 10 / 16
Pulse Width Modulation (PWM) Mode PWM in PIC16F917
PWM in PIC16F917
where PR2 is the 8-bit period register and Tosc is the oscillator
time period
When TMR2 is equal to PR2, the following three events occur on
the next increment cycle:
TMR2 is cleared
The RC5/T1CKI/CCPx/SEG10 pin is set (exception: if PWM duty
cycle = 0%, the RC5/T1CKI/CCP1/SEG10 pin will not be set)
The PWM duty cycle is latched from CCPR1L into CCPR1H
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 11 / 16
Pulse Width Modulation (PWM) Mode PWM in PIC16F917
PWM in PIC16F917
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 12 / 16
Pulse Width Modulation (PWM) Mode PWM in PIC16F917
PWM in PIC16F917
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 13 / 16
Pulse Width Modulation (PWM) Mode PWM in PIC16F917
PWM in PIC16F917
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 13 / 16
Pulse Width Modulation (PWM) Mode PWM in PIC16F917
PWM in PIC16F917
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 13 / 16
Pulse Width Modulation (PWM) Mode PWM in PIC16F917
PWM in PIC16F917
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 13 / 16
Pulse Width Modulation (PWM) Mode PWM in PIC16F917
PWM in PIC16F917
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 13 / 16
Pulse Width Modulation (PWM) Mode PWM in PIC16F917
PWM in PIC16F917
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 13 / 16
Example Program - PWM
Outline
1 Introduction
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 14 / 16
Example Program - PWM
Hardware connections
#define N2 PORTD,2 ; PWM with CCP2 module
#define P1 PORTD,7 ; Variable to turn on the motor
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 15 / 16
Example Program - PWM
Initialize bank
clrf STATUS ; bank 0
bsf STATUS,RP0 ; we’ll set up the bank 1 Special Function Registers
first
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 15 / 16
Example Program - PWM
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 15 / 16
Example Program - PWM
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 15 / 16
Example Program - PWM
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 15 / 16
Example Program - PWM
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 15 / 16
Example Program - PWM
Main program
;;;;;;;;;;;;;; Set duty cycle for 316 RPM ;;;;;;;;;;;;;
movlw 0x3F ; Turn on PWM, bit # 5,4 = 1,1
iorwf CCP2CON,f
movlw 0x13 ; 8 bit of CCPR2L
movwf CCPR2L
bsf P1 ; Turn on Motor
end ; directive ’end of program’
Winter 2009
M.S. Miah (University of Ottawa) ELG4154: Integrated Control System March 16, 2009 16 / 16