Você está na página 1de 10

ME 4340 Mechatronic Systems Engineering

Programming PIC18F452 with


C18 using MPLAB IDE

Pulse Width Modulation


Characteristics

 PWM controls use pulse width modulation to


regulate the current sent to a motor or any other
modules.
 PWM controls produce smoother current at higher
switching frequencies, typically between 1 and
20 kHz.
 At 20 kHz, the switching frequency is inaudible to
humans, thereby eliminating the hum which
switching at lower frequency produces.
Pulse width Modulation (PWM)
Very efficient way of providing intermediate amounts
of electrical power between fully on and fully off
DC Brushed Motor Controlling

 A PWM controller typically contains a large reservoir


capacitor and an H-bridge arrangement of switching
elements (thyristors, mosfets or transistors).

 Eg :- L298 (typical solid state H-Bridge).


Basics Construction of a H-Bridge

 A solid state H-bridge is typically constructed using


BJTs or MOSFETs
Interfacing a microcontroller/H-bridge
and motor
Parameters of the CCP module
Registers/Modules associate with PWM
 TMR2 module and associated registers.
 CCPXCON - capture/compare/pwm x control
 CCPRXL - capture/compare/pwm x register low
 CCPRXH (Read only) - capture/compare/pwm x register high
 Etc..
 All these associated registers’ functionality and configurations
settings can be found in the PIC18F452 data sheet.

X – can be either 1 or 2 for the 2 modules in a 18f452


Setting up the PWM modules

 Set the CCPX pins and directional control I/O pins as


out puts.
 Set the PWM period by writing to the PR2 register.
 Set the PWM duty cycle by writing to the CCPXRL
and CCPXCON<5:4> registers.
 SET the Timer2 prescaler and enable Timer2.
 Configure the CCPX module for PWM operation
Example Using C18 library

Você também pode gostar