/******************************************************************
* NOTES:
* Code uses the Peripheral library support available with MCC18 Compiler
* Code Tested on:
* PicDem2+ demo board with PIC18F4685 controller
* PWM output is obtained on CCP1 pin. duty cycle is gievn by
*
*Formula for Period and Duty cycle calculatio
*
* PWM period = [(period ) + 1] x 4 x Tosc x TMR2 prescaler
*
* PWM x Duty cycle = (DCx<9:0>) x Tosc
*
* Resolution (bits) = log(Fosc/Fpwm) / log(2)
**********************************************************************/
#define USE_OR_MASKS
#include <p18cxxx.h>
#include "pwm.h"
void main(void)
{
char period=0x00;
unsigned char outputconfig=0,outputmode=0,config=0;
unsigned int duty_cycle=0;
//----Configure pwm ----
period = 0xFF;
OpenPWM1( period); //Configure PWM module and initialize PWM period
//-----set duty cycle----
duty_cycle = 0x0F00;
SetDCPWM1(duty_cycle); //set the duty cycle
//----set pwm output----
outputconfig = FULL_OUT_FWD ;
outputmode = PWM_MODE_1;
SetOutputPWM1( outputconfig, outputmode); //output PWM in respective modes
while(1); //observe output on CCP1 pin
//-----close pwm----
ClosePWM1();
}