0% found this document useful (0 votes)
27 views2 pages

Course: MMBS Lab No: 08 Title: Pulse-Width Modulation (PWM) Module. CID: - Date

The document is a lab report for a Pulse-Width Modulation (PWM) module experiment. It contains the names and student IDs of two students who participated, as well as an assembly code example for implementing PWM on a PIC microcontroller to control motor speed using two PWM channels. The code initializes timers and I/O ports for PWM output on one of the channels to allow increasing or decreasing the duty cycle via buttons.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views2 pages

Course: MMBS Lab No: 08 Title: Pulse-Width Modulation (PWM) Module. CID: - Date

The document is a lab report for a Pulse-Width Modulation (PWM) module experiment. It contains the names and student IDs of two students who participated, as well as an assembly code example for implementing PWM on a PIC microcontroller to control motor speed using two PWM channels. The code initializes timers and I/O ports for PWM output on one of the channels to allow increasing or decreasing the duty cycle via buttons.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Department of Electronics & Telecommunication Engineering

Course: MMBS
Lab No: 08
Title: Pulse-Width Modulation (PWM) Module.
CID: ________________
Date: _______________
S.No.

Name

SID

SHOAIB AHMED SIDDIQUE

5922

HOOMA AMJAD

6007

Faculty/Lab Engineer

Comments

Initials

Marks

; 16F876 PWM example code


;
; Device 16F876
LIST P=16F877A, W=2, X=ON, R=DEC
; 876
;#INCLUDE P16F876.INC
#INCLUDE P16F877A.INC
__CONFIG 0x393A
portb equ 0x06
status equ 0x03
trisb equ 0x86
CCPR1L equ 0x15
RL
Equ
0x00
FL
Equ
0x03
RR
Equ
0x04
FR
Equ
0x05

ANDLW 0xF8
IORLW 0x02
MOVWF T2CON

;PWM at 2500HZ

MOVF

;set postscaler to

T2CON,W

1
ANDLW 0x07
IORLW 0x00
MOVWF T2CON

;pin for left motor reverse


;pin for left motor forward
;pin for right motor reverse
;pin for right motor forward

;MOVLW D'63'
;movwf
CCPR1L
;set PWM to zero
;CLRF CCPR1L
;set PWM to zero
BCF CCP1CON,4
BCF CCP1CON,5
BSF
T2CON, TMR2ON
;and start the
timer running

;pins 1 and 2 are the 2 PWM channels


ORG

0x0000
NOP
;for bootloader compatibility
NOP
NOP
;GOTO START
;ORG

0x0010

;START
;bsf status,5
;bcf status,5
;CALL Initialise
mainloop
BANKSEL ADCON1
A2D
MOVLW 0x06
MOVWF ADCON1
BANKSEL PORTA
BANKSEL TRISC
MOVLW 0
all outputs
MOVWF TRISC
movlw b'00000011'
movwf trisb
BANKSEL PORTC

;turn off

;set PORTC as

increment
btfss portb,0
btfsc portb,0
goto Continue_1
delay_1
btfss portb,0
goto delay_1
incf CCPR1L
goto increment
Continue_1
decrement
btfss portb,1
btfsc portb,1
goto mainloop
delay_2
btfss portb,1
goto delay_2
decf CCPR1L
goto decrement
GOTO mainloop
;end of Delay routines
END

MOVF

CCP1CON,W

;set

CCP1 as PWM
ANDLW 0xF0
IORLW 0x0C
MOVWF CCP1CON
MOVLW

D'126'

;set highest PWM

BANKSEL PR2
permanently on
MOVWF PR2
BANKSEL TMR2

;over this (127) is

value

MOVF
16

T2CON,W

;set prescaler to

You might also like