2 out of 2 members found this post helpful.
Did you find this post helpful?

|
Re: Infrared HPWM setup
prescaler is 4 , 16 is also a possibility
(64Mhz / (4*TMR2 prescale value * 38Khz))-1 = PR2
(64Mhz / (4*4*38Khz)) - 1 = PR2
(64Mhz / (152000*4)) - 1 = PR2 <=>
Code:
64,000,000
<=> PR2 = ------------ -1 <=>
152,000*4
<=> PR2 = 104
(PR2 + 1) * TMR2 prescale * 50% Duty Cycle = value for CCPRL1, or
(104+ 1) * 4 * 0.50 = 421 * 0.50 = 210
T2CON = %00000101
PR2 = 104 ' Set PWM Period for approximately 38KHz
CCPR1L = 210>>2 ' Set PWM Duty-Cycle to 50%
note
PR2 is a 8bit reg it cannot ever be 420 or anything larger than 255
CCPR1L are the upper 8 bits of the duty cycle word value
CCP1CON bit 4 and 5 are the lower two bits
Warning I'm not a teacher
Bookmarks