0% found this document useful (0 votes)
63 views4 pages

MBS Lab 11

This document appears to be a lab manual for a microprocessor-based systems course. It includes instructions for a lab assignment on pulse width modulation (PWM) using a PIC microcontroller. The document provides background information on PWM period, duty cycle, and how to configure the CCP module registers for PWM output. It then lists an objective to generate a 2.5 kHz PWM signal with 75% duty cycle as an example. The lab assignment instructs students to create programs to generate 1.5 kHz waves with 25% and 50% duty cycles, and 50% duty cycle waves at 1 kHz and 2.5 kHz, submitting code, simulations, and testing on a trainer kit.

Uploaded by

MuhammadHadi
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)
63 views4 pages

MBS Lab 11

This document appears to be a lab manual for a microprocessor-based systems course. It includes instructions for a lab assignment on pulse width modulation (PWM) using a PIC microcontroller. The document provides background information on PWM period, duty cycle, and how to configure the CCP module registers for PWM output. It then lists an objective to generate a 2.5 kHz PWM signal with 75% duty cycle as an example. The lab assignment instructs students to create programs to generate 1.5 kHz waves with 25% and 50% duty cycles, and 50% duty cycle waves at 1 kHz and 2.5 kHz, submitting code, simulations, and testing on a trainer kit.

Uploaded by

MuhammadHadi
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/ 4

Page 1 of 4

Department of Electrical Engineering

LAB WORK - 11
Microprocessor Based System
Spring/Fall/Summer 20__
Student Name SID Marks

Marks Distribution:
CLO_2
Tasks Total Marks
Marks Obtained
PWM Assembly Code. 3
Task Proteus simulation. 2
Home Assignment. 2
Hardware Working. 3
Total Marks 10

CLASS ID: __________________

DATE: ______________________

Signature of Faculty/Lab Engineer: ___________________________________________

Remarks: ________________________________________________________________
Microprocessor Based System Instructor:
College of Engineering Ashar Ali Qureshi
PAF-Karachi Institute of Economics & Technology asharali.qureshi@pafkiet.edu.pk
Page 2 of 4

BASIC THEORY CLO_2


Another feature of CCP is pulse width modulation (PWM). The PWM feature allows us to create
pulse with variable widths. Although we can program timers to create PWM, the CCP module makes
the programming of PWM much easier and less tedious. PWM is widely used in industrials controls
such as DC motor controls.
PERIOD AND DUTY CYCLE

TIME PERIOD OF PWM


The CCP module uses timer2 and its associated register, PR2, for the PWM time-base, which means that
the frequency of the PWM is a fraction of the Fosc, the crystal frequency. It uses the PR2 register to set
the PWM period as follows:

𝑇𝑃𝑊𝑀 = [(𝑃𝑅2) + 1] 4 × 𝑁 × 𝑇𝑂𝑆𝐶


Where 𝑇𝑂𝑆𝐶 is the inverse of 1⁄𝐹 the crystal frequency, 𝑇𝑃𝑊𝑀 is the desired PWM period, and N is the
𝑂𝑆𝐶
prescaler of 1, 4, or 16 set by the Timer2 control register (T2CON). Therefore, we can get the value for
the PR2 register as follows:

PR2 = [𝐹𝑂𝑆𝐶 / (𝐹𝑃𝑊𝑀 × 4 × N)] – 1


We can conclude that the maximum value for 𝑇𝑃𝑊𝑀 can be achieved when N = 16 and PR2 = 255.
Therefore, we have:

𝑇𝑃𝑊𝑀 = [(255) + 1] × 4 × 16 × 𝑇𝑂𝑆𝐶 = 16382 𝑇𝑂𝑆𝐶


Which means that the minimum allowed PWM frequency is:

𝐹𝑃𝑊𝑀 = 𝐹𝑂𝑆𝐶 /16,382

Microprocessor Based System Instructor:


College of Engineering Ashar Ali Qureshi
PAF-Karachi Institute of Economics & Technology asharali.qureshi@pafkiet.edu.pk
Page 3 of 4

CCP1CON REGISTER/CCP2CON REGISTER

Microprocessor Based System Instructor:


College of Engineering Ashar Ali Qureshi
PAF-Karachi Institute of Economics & Technology asharali.qureshi@pafkiet.edu.pk
Page 4 of 4

OBJECTIVE #1
Make a program that will create a 2.5 KHz PWM frequency with a 75% duty cycle on the
CCP1 pin.
Example Code:
LIST P=PIC18F452, F=INHX32, N=0, ST=OFF, R=HEX ; INCLUDE CONTROLLER TYPE
#include P18F452.INC ; INCLUDE CONTROLLER FILE
; FUSE BIT SETTINGS
CONFIG OSC = HS, OSCS = OFF ; HS=HIGH OSCILATOR
CONFIG WDT = OFF ; WATCH DOG TIMER OFF
CONFIG PWRT = ON, BOR = OFF ; POWER UP TIMER ON
; BROWN OUT RESET VOLTAGE OFF
CONFIG DEBUG = OFF, LVP = OFF, STVR = OFF ; DEBUG OFF
; LOW VOLTAGEPROGRAMMING OFF
ORG 0X00 ; STARTING ADDRESS
CLRF CCP1CON ; CLEAR CCP1CON REG
MOVLW D'249'
MOVWF PR2 ; FREQUENCY
MOVLW D'186' ; 75% DUTY CYDLE
MOVWF CCPR1L
BCF TRISC, CCP1 ; MAKE PWM PIN AN OUTPUT
MOVLW 0x01 ; TIMER2, 4 PRESCALE, NO
; POSTSCALER
MOVWF T2CON
MOVLW 0x3C ; PWM MODE, 11 FOR DC1B1: B0
MOVWF CCP1CON
CLRF TMR2 ; CLEAR TIMER2
BSF T2CON, TMR2ON ; TURN ON TIMER2
AGAIN BCF PIR1, TMR2IF ; CLEAR TIMER2 FLAG
OVER BTFSS PIR1, TMR2IF ; WAIT FOR END OF PERIOD
BRA OVER
GOTO AGAIN ; CONTINUE
#INCLUDE<DELAY_20MHZ.ASM> ; DELAY FILE
END ; END PROGRAM
Lab Assignment: CLO_2
• Make a program that will generate waves of 1.5 KHz frequency with different duty cycle (DC) as follows:
1) 25% 2) 50%
• Make a program that will generate waves of 50% duty cycle with different frequencies as follows:
1) 1KHz 2) 2.5KHz
Submission Details:
• Lab manual
• Print of code of all tasks in assembly language.
• Proteus simulation, screen shot of wave forms.
• Code simulate on trainer kit.

Microprocessor Based System Instructor:


College of Engineering Ashar Ali Qureshi
PAF-Karachi Institute of Economics & Technology asharali.qureshi@pafkiet.edu.pk

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy