PWM FUNCTIONS
Original by F.Zia, rewritten for the PIC18F4550 by M.F.v.Lieshout, March 2006
Information sources:
The information in this document is obtained from the following Microchip manuals:
- PIC18F4550 Datasheet
- PICmicro® 18C MCU Family Reference Manual
- MPLAB C18 C Compiler Libraries
Function Prototypes:
For a detailed description of these functions, please see:
Section 2.7 Pulse-Width Modulation Functions, in MPLAB C18 C Compiler Libraries manual.
The PIC18F4550 has 2 PWM channels available, so x is 1 or 2 in this case.
void OpenPWMx ( char PR2 ); // Configure PWM channel x.
void SetDCPWMx ( unsigned int dutycycle ); // Write a new duty cycle value to
PWM channel x.
void ClosePWMx ( void ); // Disable PWM channel x.
Notes:
1. PR2 can be any value from 0x00 to 0xff. This value determines the PWM frequency by
using the following formula:
PWM period =[(PR2) + 1] x 4 x TOSC x TMR2 prescaler
2. The value of dutycycle can be any 10-bit number. Only the lower 10-bits of dutycycle are
written into the duty cycle registers. The duty cycle determines the high time of the PWM
waveform.
3. PWM uses TIMER2 for time base. In addition to opening the PWM, TIMER2 must also be
opened with an OpenTimer2(...) statement before the PWM will operate. See the other
manual for the timer functions.
4. TIMER2 postscaler is not used in the determination of the PWM frequency. TIMER2
postscaler could be used to generate TMR2 interrupts at a different frequency than the PWM
output.
5. On the PIC18F4550, also an enhanced PWM can be used. The enhanced PWM can be
used for motor driving: half-bridge and full-bridge (forward and reverse). See the MPLAB C18
C Compiler Libraries manual for the functions.
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉