Infrared HPWM setup


Results 1 to 20 of 20

Threaded View

  1. #1
    Join Date
    Oct 2010
    Posts
    411

    Default Infrared HPWM setup

    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.

    Name:  HPWM.jpg
Views: 747
Size:  47.6 KB

    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.
    Last edited by astanapane; - 31st May 2023 at 22:16.

Similar Threads

  1. Replies: 3
    Last Post: - 23rd October 2011, 12:53
  2. InfraRed Data Com
    By rayzrocket in forum Off Topic
    Replies: 5
    Last Post: - 29th March 2010, 15:42
  3. Infrared x PIC
    By ewandeur in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 29th December 2009, 18:30
  4. infrared help
    By griffin in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th December 2008, 05:34
  5. infrared
    By bmohnsen in forum General
    Replies: 1
    Last Post: - 2nd May 2007, 16:35

Members who have read this thread : 15

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts