Dear all,
just a quick question. I didnt want to open a new thread but most of the Infrared threads are closed.
I would like to set up the PIC18F26k22 in order to use HPWM for the 38khz IR.
First of all i would like to ask if i can use 64Mhz as the main PIC frequency.
i tried to use mister e's pic multi-calc and set 64Mhz. The following are the results i got.

but from the calculations i made:
(64Mhz / (4*TMR2 prescale value * 38Khz))-1 = PR2
(64Mhz / (4*1*38Khz)) - 1 = PR2
(64Mhz / (152000)) - 1 = PR2 <=>
Code:
64,000,000
<=> PR2 = ------------ -1 <=>
152,000
<=> PR2 = 420
Also calculating the bits:
Code:
log(FOSC / FPWM)
Resolution = ------------------- bits
Log(2)
log(64,000,000 / 38,000) = 3.226
log(2) = 0.301
so we have:
3.226
------- = 10.17 ~ 10 bits
0.301
and calculating the CCPRL1:
(PR2 + 1) * TMR2 prescale * 50% Duty Cycle = value for CCPRL1, or
(420 + 1) * 1 * 0.50 = 421 * 0.50 = 210
So i set in the code the following:
TRISC.2 = 0 ' CCP1 (PortC.2 = Output)
PR2 = 420 ' Set PWM Period for approximately 38KHz
CCPR1L = 210 ' Set PWM Duty-Cycle to 50%
T2CON = %00000100 ' Timer2 ON + 1:1 prescale --> i know this might not be right as at 64Mhz there is no 1:1 scale based on mister's e multi-calc.
CCP1CON = %00001100 ' Mode select = PWM
could you please help me to clear things up?
I dont mind using 16Mhz as a base frequency, but still the calculations i get are not match with mister's e multi-calc.
Thanks for your help in advance.
Bookmarks