KansaiRobot
Member
in the documentation of the compiler C18 we can find
Now... I am unexperienced on PWM, so I have a hard time understanding this.
For example, lets see the duty cycle
Isn't it supposed that the duty cycle is 10 bits??
but 0x0F00= 1111 0000 0000 right? so 12 bits....
in this example, how much percentage (%) are we putting...?
(as an aside note, I tried to compile it for my PIC18F2550 and it didnt work. It didnt recognize the macros FULL_OUT_FWD and PWM_MODE_1)
Can anybody help me on this???
Code:
/******************************************************************
* 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();
}
Now... I am unexperienced on PWM, so I have a hard time understanding this.
For example, lets see the duty cycle
Code:
duty_cycle = 0x0F00;
SetDCPWM1(duty_cycle);
Isn't it supposed that the duty cycle is 10 bits??
but 0x0F00= 1111 0000 0000 right? so 12 bits....
in this example, how much percentage (%) are we putting...?
(as an aside note, I tried to compile it for my PIC18F2550 and it didnt work. It didnt recognize the macros FULL_OUT_FWD and PWM_MODE_1)
Can anybody help me on this???