Lab 8 - PWM
Lab 8 - PWM
Objective:
To learn about CCP1 and how to generate PWM signal.
Learning Outcomes:
Able to illustrates the use of CCP1 module in PWM mode.
Able to use PWM signal to control speed/direction of a motor.
Equipment/Software/Component:
Equipment/Software/Component
Value
Quantity
MPLAB IDE
ISIS PROTEUS
Procedures:
1. Using ISIS PROTEUS, construct the circuit as shown in Figure 1. Set the crystals
frequency to 4MHz.
2. Using MPLAB IDE, build the program in Figure 2.
3. Load the obtained hex file into the PIC16F887 (Refer to Lab 3 for assistance).
4. Run the circuit and observe.
R1
10k
U1
1
S1
S2
2
3
4
5
6
7
14
13
33
34
35
36
37
38
39
40
RE3/MCLR/VPP
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RA0/AN0/ULPWU/C12IN0RC2/P1A/CCP1
RA1/AN1/C12IN1RC3/SCK/SCL
RA2/AN2/VREF-/CVREF/C2IN+ RC4/SDI/SDA
RA3/AN3/VREF+/C1IN+
RC5/SDO
RA4/T0CKI/C1OUT
RC6/TX/CK
RA5/AN4/SS/C2OUT
RC7/RX/DT
RA6/OSC2/CLKOUT
RA7/OSC1/CLKIN
RD0
RD1
RB0/AN12/INT
RD2
RB1/AN10/C12IN3RD3
RB2/AN8
RD4
RB3/AN9/PGM/C12IN2RD5/P1B
RB4/AN11
RD6/P1C
RB5/AN13/T1G
RD7/P1D
RB6/ICSPCLK
RB7/ICSPDAT
RE0/AN5
RE1/AN6
RE2/AN7
15
16
17
18
23
24
25
26
19
20
21
22
27
28
29
30
8
9
10
D1
R2
330
LED-RED
A
B
C
D
PIC16F887
Figure 1
cblock
0x20
w_temp
pclath_temp
status_temp
endc
#define
#define
DARK PORTB,0
BRIGHT PORTB,1
org
goto
0x0000
main
CCPR1L
DARK
CCPR1L
BRIGHT
CCPR1L
pclath_temp,w
PCLATH
status_temp,w
STATUS
w_temp,f
w_temp,w
banksel
bcf
PIR1
PIR1,TMR1IF
bsf
bsf
bsf
retfie
TMR1H,7
TMR1H,6
INTCON,GIE
OPTION_REG
OPTION_REG,7
WPUB,0
WPUB,1
banksel
clrf
movlw
movwf
TRISC
TRISC
21H
OSCCON
banksel
bcf
bcf
bcf
bsf
banksel
bsf
bsf
bsf
T1CON
T1CON,TMR1CS
T1CON,T1CKPS0
T1CON,T1CKPS1
T1CON,TMR1ON
PIE1
PIE1,TMR1IE
INTCON,PEIE
INTCON,GIE
movlw
banksel
movwf
movlw
banksel
movwf
B'11111101'
T2CON
T2CON
B'11111111'
PR2
PR2
banksel
movlw
movwf
CCP1CON
B'00001100'
CCP1CON
loop
goto
end
loop
Figure 2
3. Replace the LED with a dc motor. Observe the speed of motor by pressing button S1
or S2. Explain the function of S1 and S2 by referring to the given program and circuit.