Multiple PWM pins


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009
    Posts
    583

    Default Multiple PWM pins

    Hi

    My current project uses an 18F4520 with two hardware PWM pins (C1 and C2) to drive two LED drivers so that the chains of LEDs can be ramped up and down. My code also uses an internal timer overflow to generate the clock so using software with pause statements is out of the question.

    I've been doing some research to try and find a PIC that can provide more hardware PWM outputs and stumbled across the 18F4331 which seems to have dedicated 4 independent PWM outputs, which is primary used for motor control. I've looked at the datasheet but can not comprehend the information so wondered if one of you guys who understand these sheets can offer some advice. The data sheet can be found here http://ww1.microchip.com/downloads/e...Doc/39616d.pdf

    Basically I need four independent PWM outputs where the duty cycle changes for each output (the frequency can be the same for each channel.

    Currently I use the
    Code:
        hpwm 1,W_PWM,200        
        hpwm 2,B_PWM,200
    Where W_PWM is the duty cycle to fade up the white LEDs and B_PWM the blues. This currently used the two CCP1 and CCP2 registers. Ideally I would like to have something like HPWM 3, and 4 in the code.

    Would this work, or can the 18F4520 CCP registers be configured to give two more additional PWM outputs as the data sheet states the 18F4520 has "One, two or four PWM outputs". Again I'm assuming that four outputs are used for motor control where the duty cycle is identical for each output rather than being independent.

    My settings for CCP registers are
    Code:
    CCP1CON = %00001100                     'Set CCP1 to PWM 
    CCP2CON = %00001100                     'Set CCP2 to PWM
    I'd rather not post up my full code in the forum, but will send it via PM if required.

    Any help would be most appreciated

    Malcolm

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Multiple PWM pins

    Hi,
    The 4520 has 2 CCP modules so you can get two PWM-outputs, ie two PWM-signals with the same frequency but different dutycycle. The reference to "one, two or four outputs" probably refers to using the ECCP module in half or full bridge mode. Then the PWM signal "comes out" on multiple pins but it's still "the same" signal - basically.

    The 2331 also has 2 CCP modules plus the PCPWM-module with 3 PWM generators (the 4331 has 4) so all in all, using the 2331, you can get 5 PWM outputs. Note that the HPWM command does not work for PCPWM module in the 2331, you'll have to configure it "manually".

    If you don't need the extended features of the PCPWM module (which, by the sound of it you don't) then perhaps something like the 25K22 might work, it's a lot cheaper then the 2331. There are loads and loads of 18F series parts with 3 or more (E)CCP modules. I'm not entirely sure if the HPWM command supports more than 2 channels though but it's easy enough to configure the registers manually.

    /Henrik.

  3. #3
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Multiple PWM pins

    Quote Originally Posted by HenrikOlsson View Post
    There are loads and loads of 18F series parts with 3 or more (E)CCP modules. I'm not entirely sure if the HPWM command supports more than 2 channels though but it's easy enough to configure the registers manually.

    /Henrik.
    After doing hours of googling, I stumbled across this post on a forum http://www.sonsivri.to/forum/index.php?topic=24131.0

    Looking through his sample code it has

    Code:
    'PIC16F767 Device Controlling Red/White/Blue LED's
    'Written July 2, 2009
    'Copyright (c) PilotPTK
    'U1 Main LED Driver
    
    
    DEFINE OSC 20
    ADCON1 = %10001101	'Port A0,A1 Analog, VREF+ = VDD, Right Justified Result
    CCP1CON = %00001100	'CCP Setup (PWM Mode)
    CCP2CON = %00001100	'CCP Setup (PWM Mode)
    CCP3CON = %00001100	'CCP Setup (PWM Mode)
    And then later down

    Code:
    HPWM 1,0,5000
    HPWM 2,0,5000
    HPWM 3,0,5000
    So on that basis I would assume PBP's HPWM command support more than two channels.... so now to look for a chip that's 5v (as 3.3v is not supported on my development board) and has four ECCP modules, and then see if I can port the working code on the 18f4520 to it

Similar Threads

  1. Replies: 11
    Last Post: - 29th December 2010, 11:24
  2. Multiple Variables - Pins
    By GatorGuy in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st February 2010, 01:08
  3. Aliasing multiple pins
    By eshatara in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 25th April 2009, 14:53
  4. Drive multiple LED with one PWM
    By microuser in forum General
    Replies: 3
    Last Post: - 27th September 2007, 13:26
  5. using all pins of pwm in pic 18f2431
    By jorgequesada in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 4th May 2007, 21:43

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