100% found this document useful (1 vote)
167 views6 pages

PWM Speed & Direction Control of DC Motor: Objective

This document discusses using pulse-width modulation (PWM) to control the speed of a DC motor. PWM works by varying the width of voltage pulses to the motor to adjust its average power and thus its speed. The document provides the theory behind PWM motor control and describes the setup and calculation for generating a 10 kHz PWM signal with a 50% duty cycle using a PIC16F877A microcontroller to control a DC motor. Code and flowcharts are included to demonstrate PWM motor speed control.

Uploaded by

vipulkondekar
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
100% found this document useful (1 vote)
167 views6 pages

PWM Speed & Direction Control of DC Motor: Objective

This document discusses using pulse-width modulation (PWM) to control the speed of a DC motor. PWM works by varying the width of voltage pulses to the motor to adjust its average power and thus its speed. The document provides the theory behind PWM motor control and describes the setup and calculation for generating a 10 kHz PWM signal with a 50% duty cycle using a PIC16F877A microcontroller to control a DC motor. Code and flowcharts are included to demonstrate PWM motor speed control.

Uploaded by

vipulkondekar
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/ 6

7.

PWM Speed & Direction Control Of DC Motor

OBJECTIVE :
The objective of this experiment is to design a speed control system of DC Motor by
using PIC16F877A microcontroller.

REQUIREMENT : MPLAB-IDE , PIC SIM Lab .

THEORY :
With the help of PWM it is possible to control the average power delivered to
a load and by thus we can easily regulate the speed of the DC Motor. When the
width of pulse is high, the motor will rotate with full speed. And with low pulse
width, speed of motor gets reduced. In both cases full current reaches the motor and
only the average power changes, thus we get better torque in each case.

PWM Mode -

In Pulse Width Mode, the CCPx pin produces up to 10-bit resolution

PWM output -

Since the. CCP1 pin is multiplexed with the PORTC data latch, the TRISC<2>
bit must be cleared to make the CCP1 pin as output.

Setup for PWM operation -

1. Set the PWM period by writing to the PR2 register.


2. Set the PWM duty cycle by writing to the CCP1L register and CCP1CON
<5:4> bits.
3. Make the CCP1 pin an output by clearing the TRISC<2> bit.
4. Set the TMR2 prescale value and enable Timer2 by writing to T2CON
register.
5. Configure the CCP1 module for PWM operation.
CALCULATION :
Let us generate a square wave having 10kHz frequency with 50% duty cycle and
assume 4MHz clock frequency.

Here : PWM Period = 1/10k

Tosc = 1/4M

PWM duty cycle = 50%

Let us take, TMR2 prescale valve= 1:1

We know , PWM Period = [(PR2)+1] * 4 * Tosc * TMR2 prescale value

1/10k = [(PR2)+1] * 4 * 1/4M * 1:1

(PR2)+1 = 100

PR2 = 99 d

Also ,

PWM Duty cycle = (CCPR1L:CCP1CON<5:4>) *Tosc * TMR2 prescale value

50 = (CCPR1L:CCP1CON<5:4>) * 1/4M * 1:1

50*4 = (CCPR1L:CCP1CON<5:4>)

(CCPR1L:CCP1CON<5:4>) = 200 d

(CCPR1L:CCP1CON<5:4>) = 0011001000 hex

PROGRAM :
; Oscillator : 4 MHz

;Program That Generates PWM

;PR2 = 99 (So The Frequency Would Be 10kHz)

#INCLUDE <P16F877A.INC>
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC
& _WRT_OFF & _LVP_ON & _CPD_OFF

ORG 0X00

GOTO MAIN

MAIN:

BCF STATUS,RP0

CLRF PORTC ;CLEAR CONTENT OF PORT C

BSF STATUS,RP0 ;CHANGE TO BANK 1

CLRF TRISC

MOVLW 0X63 ; period = 0.0001 seconds 99d=63h

MOVWF PR2

BCFSTATUS,RP0

MOVLW B'00110010';50%

;MOVLW B'01010000';80%

MOVWF CCPR1L

BCF CCP1CON,5

BCF CCP1CON,4

BSFSTATUS,RP0

BCF TRISC,2 ; pin 2 of port c is an output

BCFSTATUS,RP0

MOVLW B'00000100'

MOVWF T2CON ; prescale =1 , timer2 is on

BSF CCP1CON,3 ;configuring ccp1 module for pwm operation

BSF CCP1CON,2

END
Figure 1.1 : PICSIM LAB Virtual Board

Figure 1.2 : OUTPUT OF PWM FOR 50% DUTY CYCLE

Figure 1.3 : OUTPUT OF PWM FOR 80% DUTY CYCLE


FLOWCHART :
CONCLUSION :
DC motors have speed control capabilities, which means that speed, torque and
even direction of rotation can be changed at anytime to meet new condition. By
varying the PWM signal from microcontroller to the motor driver, motor speed can
be controlled back to desired value easily.

You might also like