Pulse width modulation (PWM) is a technique for controlling analog circuits with microccontroller digital outputs. PWM is employed in a wide variety of applications, ranging from measurement and communications to power control and conversion. PWM is measured in percent (%) and normally this percentage is also called duty cycle. The PWM strength or duty cycle can be controlled from 0% to 100%.
In microcontroller, PWM is a technique for getting analog results with digital means. Digital control is used to create a square wave, a signal switched between on and off. This on-off pattern can simulate voltages in between full on (5 Volts or 100%) and off (0 Volts or 0%) by changing the portion of the time the signal spends on versus the time that the signal spends off. The duration of "on time" is called the pulse width. To get varying analog values, you may change or modulate that pulse width.
The Interfacing PWM with PIC controller program is very simple and straight forward, which generates a pulse pattern in a particular frequency.
HPwm 1, 64, 1000 '25%, 1kHz PWM signal at PortC.2
PAUSE 100
NEXT i
FOR i = 1 TO 50
HPwm 1, 191, 1000 '75%, 1kHz PWM signal at PortC.2
PAUSE 100
NEXT i
PBP Program
'program to generate a PWM signal
DEFINE OSC 20
@ device hs_osc 'jika guna crytal 20Mhz
i VAR BYTE
loop:
FOR i = 1 TO 50HPwm 1, 64, 1000 '25%, 1kHz PWM signal at PortC.2
PAUSE 100
NEXT i
FOR i = 1 TO 50
HPwm 1, 191, 1000 '75%, 1kHz PWM signal at PortC.2
PAUSE 100
NEXT i
GOTO loop
No comments:
Post a Comment