To work out the timer2 value do the instruction speed divided by the period. 1,000,000/1,000 = 1000. Timer2 can't count to 1,000 but it can count to a quarter of that so set timer2 prescaler to 4. Our period is then 250 counts of timer2 so we set PR2= 250-1 = 249. To get 50% duty cycle ccprl must be 50% of PR2 so we set it to 125. Simple really.
Hi thanks for pointing me out Mike & upand_at_them.I understood but that software generating incorrect duty cycle value.
This is the result of that pwm calculator
/*
* PWM registers configuration
* Fosc = 4000000 Hz
* Fpwm = 1000.00 Hz (Requested : 1000 Hz)
* Duty Cycle = 50 %
* Resolution is 10 bits
* Prescaler is 4
* Ensure that your PWM pin is configured as digital output
* see more details on Microcontrollers projects, circuits and source code examples
* this source code is provided 'as is',
* use it at your own risks
*/
PR2 = 0b11111001 ;
T2CON = 0b00000101 ;
CCPR1L = 0b01111100 ;
CCP1CON = 0b00111100 ;
The duty cycle is 499uS not 500uS thats what I mentioning.