using the pwm's in pic18f2431-2331-4331-4431


Closed Thread
Results 1 to 28 of 28

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    WOW, that's a tough read.

    But after a few hrs in the datasheet. Yeah, these are cool.

    Got the (IC) Input Capture block: Very cool.
    The (QEI) Quadrature Encoder Interface: OK sorta cool.
    And up to 4 14-bit PWM's. (4 additional complimentary outputs) Not usable with CCP's at the same time.
    Not as cool as I expected.

    Still worth further investigation.
    Samples on order. Thanks Bruce.
    <br>
    DT

  2. #2
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    How about a 28-pin PIC24FJxxGA002. 5 independent input capture AND 5 independent PWM's/OC (up to 16-bit resolution and 500kHZ). About $2 each (depending on flash from 16-64kB, 4kB or 8kB RAM). Plus lots of other stuff like 2 UART's, built-in RTCC, 2 SPI, 2 I2C, etc. Plus you can select which pins you want to use for most of the peripherals.

  3. #3
    Join Date
    Aug 2007
    Posts
    15


    Did you find this post helpful? Yes | No

    Default mystified

    Thanks did not know that ccp and pwm0-5 are not the same pins that helped now how about setuo for timer 2.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    If you're using HPWM you don't need to mess with Timer2. It's automatically handled
    for you.

    If you plan to setup hardware PWM manually, these calcs should help.
    Code:
    PR2=(Fosc/(4*PS*Freq))-1
    TMR2 Prescaler = 1 PR2 = (8MHz/(4*1*12,000)) = (8MHz/48,000)-1 PR2 = 165.666
    TMR2 Prescaler = 4 PR2 = (8MHz/(4*4*12,000)) = (8MHz/192,000)-1 PR2 = 40.666
    TMR2 Prescaler = 16 PR2 = (8MHz/(4*16*12,000))-1 = (8MHz/768,000))-1 PR2 = 9.416
    
    CCPR1L:CCP1CON<5:4>=(PR2+1)*4*Duty%
    (165+1)*4*0.5 = 332
    (40+1)*4*0.5 = 82
    (9+1)*4*0.5 = 20
    
    To load the duty cycle registers just place the value calculated in a word, and
    do something like this;
    
    Duty = 332              ' Roughly 50% duty cycle
    CCP1CON.4 = Duty.0	' Setup 10-bit duty cycle as
    CCP1CON.5 = Duty.1	' a 10-bit word
    CCPR1L = Duty >> 2
    Search here for HPWM and you'll find a boat-load more examples.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Jan 2010
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Hi Bruce,

    you mentioned above that the equation used to calculate the PWM resolution is

    log(20MHz/19.455kHz) 3.01
    Resolution = ------------------ = ----------- = 10 bits
    .301 .301

    In the 18F2431 datasheet it says that Fosc must be divided by four, i.e.

    log(5MHz/19.455kHz) 2.41
    Resolution = ------------------ = ----------- = 8 bits
    .301 .301

    and in other microchip document (link below) it provides the same equation you used.
    http://ww1.microchip.com/downloads/e...doc/31014a.pdf

    I am confused here! Can you please tell me what you think of that?

    Kind regards,

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Look at equation 17-4 PWM RESOLUTION. Then look at Table 17-2 just below it.

    Try plugging in some numbers on your calculator using both methods, and see what you get according to the resolutions shown in Table 17-2 for different values of Fosc, at various frequencies.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    Join Date
    Jan 2010
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    You are right. So for 10 bits, thats 2 LSBs of PDCxH and 8 bits of PDCxL. Thanks.

  8. #8
    Join Date
    Mar 2014
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: using the pwm's in pic18f2431-2331-4331-4431

    hello bruce
    i have a doubt abt carrier generation in 18f4431.sine wave ne how il generate through luk up table bt m nt bin able to generate carrier frequency of 20khz to compare it with ma sine wave.i'm attaching image for ur reference.can u plz help me in dis .Name:  carrier vs reference plot.JPG
Views: 4993
Size:  111.6 KB
    Last edited by park21; - 15th April 2014 at 10:59.

  9. #9
    Join Date
    Jan 2013
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: using the pwm's in pic18f2431-2331-4331-4431

    Hi,
    Finding this old thread may have answered some questions, I wanted to know, so thanks for it, especially Bruce.
    Cheers, Camerart.

Members who have read this thread : 2

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