How to setup 38kHz PWM with PIC18F1330


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Re: How to setup 38kHz PWM with PIC18F1330

    Thanks Henrik.

    I had to use a 4,7µF capacitor to finally get a nice clean signal

    Thank you for the explanation too. I'll have a go for some tests with the formulas; this is going to be the hardest for me...maths are not really my best friends

    Roger
    Roger

  2. #2
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Re: How to setup 38kHz PWM with PIC18F1330

    So there's where I am now:

    Desired freq = 38kHz (PWMperiod = 26,3157µs), crystal (Fosc) 20MHz, prescaler = 1
    SEARCHING FOR PTPER (max 4095)

    Transform formula:
    PWMperiod[µs] = (PTPER+1 * prescaler) / (Fosc / 4)
    => (PTER+1 * prescaler) = PWMperiod * (Fosc / 4)
    => PTPER+1 = (PWMperiod * (Fosc / 4)) / prescaler
    (26,3157µs * 5'000'000) / 1 = 131

    But how do I calculate the duty-cyle register (PDC0) admitting I'd like to have a 50% value to set?
    Roger

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default Re: How to setup 38kHz PWM with PIC18F1330

    Hi,
    There will be aproximately 4 times as many "steps" (+/-3) to the dutycycle value as you set PTPER to. If PTPER is 131 then you'll have 131*4 = 524 steps so to get a a 50% dutycycle you set the dutycycle register to 264 (PDC0H=1, PDC0L=8).

    /Henrik.

  4. #4
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Re: How to setup 38kHz PWM with PIC18F1330

    Well, I just found this in the DS:
    DS note, page 131:
    To get the correct PWM duty cycle, always
    multiply the calculated PWM duty cycle
    value by four before writing it to the PWM
    Duty Cycle registers....
    I think this means a "100%" (in my mind, this is a signal always high - not useful but for the theory) duty-cycle value would be:
    - PTER * 4 => 130 * 4 => 520

    So, for a 50% duty-cycle, the PDC0 value is going to to be:
    - 520 * 50% => 260

    But, playing with the values, I can see on my scope that the numbers would be more accurate taking in account the PTER+1 (131 instead of 130) value.

    Where is the truth?
    Roger

  5. #5
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Re: How to setup 38kHz PWM with PIC18F1330

    ...you were quicker
    Roger

Similar Threads

  1. 38Khz Modulator
    By Gord11 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th September 2011, 08:14
  2. manual hardware PWM setup on 16F1824
    By comwarrior in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 31st January 2011, 18:34
  3. Use Button For setup
    By tump in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 21st November 2007, 19:43
  4. Generated square wave 19Khz and 38Khz
    By blinkstar88 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th August 2007, 16:40
  5. pic12f683 setup
    By erice1984 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th July 2007, 11:48

Members who have read this thread : 0

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