6 HPWM signal generation with PIC18F4431


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1

    Lightbulb 6 HPWM signal generation with PIC18F4431

    Hi there,

    I'm currently making a 3-phase variable frequency drive.
    I'm using the PIC18F4431 (5V - 40 pins - 40MHz), who's perfect for motor control (8 hardware PWM outputs).

    Datasheet : http://ww1.microchip.com/downloads/e...Doc/39616d.pdf

    I like to generate 3 high-side hardware PWM (HU, HV, HW) and 3 low-side hardware PWM (LU, LV, LW - same as HU, HV, HW but inverted with a low deadtime) for fed my high and low-side IGBTs.
    I would like a PWM carrier frequency between 2 and 20kHz (approx.)

    Picbasic Pro seems to use CCP1 and CCP2 modules with "HPWM" command, but I get only 2 HPWM outputs.
    I have no idea how to use these hardware PWM modules on my PIC.

    Thanks for your help.
    Last edited by pxidr84; - 10th February 2011 at 20:27.

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


    Did you find this post helpful? Yes | No

    Default Re: 6 HPWM signal generation with PIC18F4431

    Hi,
    PBP (the HPWM command) only suports PWM thru the standard CCP modules, you'll have to set up the PWM registers manually. A quick search for 18F4431 on the forum brings up a couple of threads, this one for example, contains some sample code from Bruce which may serve as a starting point.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: 6 HPWM signal generation with PIC18F4431

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    PBP (the HPWM command) only suports PWM thru the standard CCP modules, you'll have to set up the PWM registers manually. A quick search for 18F4431 on the forum brings up a couple of threads, this one for example, contains some sample code from Bruce which may serve as a starting point.
    Thanks, I will take a look.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: 6 HPWM signal generation with PIC18F4431

    Okay, I've a little bit modified the Bruce's program.
    It runs well in ISIS Proteus with my defined duty cycles, and all of the 6 PWM outputs works.

    But there is a little problem :


    As you can see, U and W phases are working properly, but not the V phase (the low-side PWM is not inverted like the others).

    Here's my modified code :
    Code:
    DEFINE LOADER_USED 1
    DEFINE OSC 20
        
        ' At 20MHz, to figure a PWM frequency of 19.455kHz
        ' TPWM = time period of PWM frequency
        ' PTPER = 12-bit period register PTPERL and PTPERH
        ' PTMRPS = PWM time base prescaler
        ' 
        '        (PTPER+1)*PTMRPS  257
        ' TPWM = ----------------  =  ------------ = 0.0000514 
        '             Fosc/4            5000000
        '
        ' Frequency = 1/TPWM = 1/0.0000514 = 19.455kHz
        '
        ' PWM resolution (bits resolution for duty cycle)
        '
        '              log(20MHz/19.455kHz)    3.01
        ' Resolution = ------------------ = ----------- = 10 bits
        '                    .301              .301
          
        ' so we'll need a word sized var for Duty
    uduty VAR WORD
    vduty VAR WORD
    wduty VAR WORD
       
        PORTB = 0               ' clear port latch
        TRISB = %11000000       ' PWM0,1,2,3,4,5 outputs
        
        TRISC = 2         ' RC1 = FLTA input (ground RC1 to halt PWM)
                                ' RC1 should be pulled high for normal PWM operation
                                ' when fault A is enabled.
        ' PCPWM init
        DTCON = %00000101       ' ~500nS dead-time (for complementary outputs only)
        PTCON0 = %00000100      ' 1:1 postscale, Fosc/4 1:1 prescale, free running mode
                                ' PTCON0 = %00000100 would give 19.45kHz/4
        PTPERL = 0              ' 
        PTPERH = 1              ' PTPER = $0100 or 256d for ~19.45kHz
    	
        ' PWM4,5 independent, PWM0,1,2,3 complementary
        PWMCON0 = %01010100     ' PWM[5:0] outputs enabled
        PWMCON1 = 1             ' updates enabled, overrides sync w/timebase
        PTCON1 = %10000000      ' PWM time base is ON, counts up
        FLTCONFIG = %00000011   ' enable fault A, cycle-by-cycle mode
    
    
    'Phases duty test
    uduty = 800              ' ~50%
    vduty = 500
    wduty = 300
            
    pwmlp: ' PWM update loop
    
    'PWM U phase 
    PDC0L = uduty.LowByte
    PDC0H = uduty.HighByte
    
    'PWM V phase
    PDC1L = vduty.LowByte
    PDC1H = vduty.HighByte
    
    'PWM W phase  
    PDC2L = wduty.LowByte
    PDC2H = wduty.HighByte
    
    goto pwmlp
    Thanks in advance for any advice.
    Last edited by pxidr84; - 11th February 2011 at 23:38.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: 6 HPWM signal generation with PIC18F4431

    Hi,
    Are you sure it's not the W-phase output that isn't complementary?

    Look at the PWMCON0 register, you have it set to %01010100 which means that PWM0 and PWM1 is in complentary mode while PWM2 (the W-phase according to your code) is in independant mode.

    /Henrik.

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: 6 HPWM signal generation with PIC18F4431

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    Are you sure it's not the W-phase output that isn't complementary?

    Look at the PWMCON0 register, you have it set to %01010100 which means that PWM0 and PWM1 is in complentary mode while PWM2 (the W-phase according to your code) is in independant mode.

    /Henrik.
    Thanks a lot, you guided me on the right way.
    I've read the datasheet, and especially the "PWMCON0" register description. I've modified the value to PWMCON0 = %01000000, and now the 3 phases are working very well (the low-side V phase is now inverted properly).

    Now, I've to modify the duty according to a sinus function. I think about it.

  7. #7
    Join Date
    Dec 2012
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: 6 HPWM signal generation with PIC18F4431

    Which Simulator you people are using for viewing waveforms???? Thanks

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