6 HPWM signal generation with PIC18F4431


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: 6 HPWM signal generation with PIC18F4431

    Quote Originally Posted by senertek View Post
    hi ,
    I have already developped many ac inverters range 0.75 kw to 915 kw..with . I seen this thread ..it s very good..to see picbasic projects in this field....
    Designing one 3 phase ac inverter is not easy project...you must know many kind of points about high voltage igbt , drivers , dcbus topologys ,emc ,emi , multi tasking etc...(it take many years)
    If you want , I can help for your project..
    I can try your codes with my high voltage kits , igbt driver modules ...and inform you ..codes works or not...

    savas
    Thanks.

    Well, I'm doing studies in electrical engineering, so I've a litte knowledge about this.
    I'm using an intelligent IGBT module from STMicroelectronics, the STGIPS20K60 (datasheet : http://www.st.com/internet/com/TECHN...CD00244265.pdf).

    No drivers needed (they're integrated), just optocouplers.

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: 6 HPWM signal generation with PIC18F4431

    Ok, a little update.

    I've tested the program on the real PIC with an oscilloscope. All of the output signals are correct, but the sine cycle is very slow (about 4 seconds to make a complete sine period, so f=1/4=0,25Hz).
    The PWM frequency seems correct (3,245kHz).
    I've defined correctly the configuration fuses (or bits), with "HS oscillator" setting, because I'm using a 40MHz quartz oscillator connected to OSC1/OSC2 pins with 22pF ceramic capacitors.

    The code (note I'm not using the FOR... NEXT loop in this case, like the upper programs, it's a lot faster if I use the FOR... NEXT loop, but I don't know why) :

    Code:
    'PIC initialization
    DEFINE OSC 40      
    DEFINE LCD_EREG PORTD
    DEFINE LCD_DREG PORTD
    DEFINE LCD_EBIT 0
    DEFINE LCD_RSBIT 1
    
    
    'DT interrupt system include
    INCLUDE "DT_INTS-18.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"  ' Include if using PBP interrupts
    
    
    'Port registers configuration
    PORTB=%0          ' Clear ports
    TRISB=%11000000   ' PWM 0,1,2,3,4,5 outputs
    
                                
    'PCPWM registers configuration
    DTCON=%110        ' Deadtime (600ns)
    PTCON0=%100       ' 1:1 postscale, Fosc/4 1:1 prescale, free running mode
    PTCON1=%10000000  ' PWM time base is ON, counts up, 19.45kHz/4
    PTPERL=%0         ' PWM low-side
    PTPERH=%1         ' PWM high-side
    
    	
    'PWM registers configuration
    PWMCON0=%1000000  'PWM 0,1,2,3,4,5 set in pair mode
    PWMCON1=%1        'PWM timer sync configuration
    
    
    'Interrupt processor
    ASM
    INT_LIST  macro    ; IntSource, Label, Type, ResetFlag
            INT_Handler   TMR1_INT,  _pwmint,   PBP,  yes
        endm
        INT_CREATE     ; Creates the interrupt processor
    ENDASM
    
    
    'Timer configuration
    T1CON=%10000001            ; Prescaler = 1:8, TMR1ON, 16-bit counter
    @ INT_ENABLE  TMR1_INT     ; Enable Timer 1 interrupts
    
    
    'PWM calculation variables
    uduty VAR WORD     'U phase duty
    vduty VAR WORD     'V phase duty
    wduty VAR WORD     'W phase duty
    dutydiv var WORD   'Frequency diviser
    dutymul VAR WORD   'Duty multiplier
    t VAR byte         'Incremental value
    
    
    'Variables definition
    dutydiv=0       'Range : 0-65535
    dutymul=65535   'Range : 0-65535 (for exemple, 32767=0.5)
    t=%0            'T initial value
    
    
    'Main program loop
    mainlp:
    
    HIGH PORTA.0
    pause 100
    LOW PORTA.0
    pause 100
    
    goto mainlp
    
    
    'PWM calculation and update interrupt
    pwmint:
    
        'Frequency diviser
        pauseus dutydiv
    
        'PWM U, V, W phases calculation
        uduty=(((sin(t)+%01111111)*%100)**dutymul)+%100
        vduty=(((sin(t+%01010101)+%01111111)*%100)**dutymul)+%100
        wduty=(((sin(t+%10101010)+%01111111)*%100)**dutymul)+%100
    
        'PWM U phase update
        PDC0L=uduty.LOWbyte
        PDC0H=uduty.HIGHByte
    
        'PWM V phase update
        PDC1L=vduty.LOWbyte
        PDC1H=vduty.HIGHByte
    
        'PWM W phase update
        PDC2L=wduty.LOWbyte
        PDC2H=wduty.HIGHByte
        
        'T variable verification and incrementation
        if t<%11111111 then 
        t=t+%1
        else 
        t=%0 
        endif
    
    @ INT_RETURN
    I think it's a TIMER problem (TMR1 is at 32kHz, isn't it?)

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


    Did you find this post helpful? Yes | No

    Default Re: 6 HPWM signal generation with PIC18F4431

    Hi,
    Yes, it's probably a timer problem. You have TMR1 set up to derive its clock from the main oscillator (Fosc/4) so 10Mhz in your case. (Your code comments says you have a prescaler of 8 but you don't - it's 1:1.

    TMR1 is a 16bit timer and generates an interrupt when it overflows from $FFFF to $0000. In your case this means that the interrupt frequency is 10MHz/65536 = 152.6Hz. In other words, the pwmint interrupt service routine is executed 156 times per second.

    If a complete sinus cycle consists of 256 "steps" you should get a frequency of 152.6/256=0.6Hz but you claim 0.25Hz so I'm not sure what's going on exactly.

    If you want to speed up the frequency you must increase the interrupt frequency. You do this by preloading TMR1 in the interrupt service routine so that it doesn't have to count all the way from 0. If you, for example, preset it to 32768 you'll get twice as many interrupts per second as when letting it free run.

    /Henrik.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: 6 HPWM signal generation with PIC18F4431

    Thanks Henrik, now I use TMR1L and TMR1H registers, I got a 40 Hz sine (it's better).

    I've heavly modified the code, I didn't use the SIN function anymore, but a lookup table with 72 values (5 degrees/value).

    Now, for debugging, I want to vary the timer value. For that, I use two buttons, one for increase (PORTC.4), one for decrease (PORTC.5), and then display the value to my LCD.

    The LCD works fine, but not the inputs. If I push the buttons, nothing happens. No increase or decrease. Same thing in the simulator.

    My code :
    Code:
    ' PIC initialization
    DEFINE OSC 40      
    DEFINE LCD_DREG PORTC
    DEFINE LCD_EREG PORTD
    DEFINE LCD_RSREG PORTD
    DEFINE LCD_EBIT 0
    DEFINE LCD_RSBIT 1
    DEFINE LCD_COMMANDUS 10000
    DEFINE LCD_DATAUS 1000 
    
    
    ' BAS includes
    INCLUDE "DT_INTS-18.bas"
    INCLUDE "Sine_table.bas"
    
    
    ' Port registers configuration
    TRISB=%11000000   ' PWM 0,1,2,3,4,5 outputs
    TRISC=%00110000   ' +/- buttons
    
    ' PCPWM registers configuration
    DTCON=%110        ' Deadtime (600ns)
    PTCON0=%0         ' 1:1 postscale, Fosc/4 1:1 prescale, free running mode
    PTCON1=%10000000  ' PWM time base is ON, counts up, 19.45kHz/4
    PWMCON0=%1000000  ' PWM 0,1,2,3,4,5 set in pair mode
    PWMCON1=%1        ' PWM timer sync configuration
    
    
    ' PWM calculation variables
    ustep var byte
    vstep var byte
    wstep var byte
    uduty var word
    vduty var word
    wduty var word
    timer var word
    amplitude var word
    carrier VAR word
    
    
    ' Variables definition
    ustep=72          ' 360 degrees phase angle
    vstep=48          ' 240 degrees phase angle
    wstep=24          ' 120 degrees phase angle
    timer=60950       ' Frequency adjust (60950=80Hz) 
    amplitude=65535   ' Sinewave amplitude adjust (65535=max amplitude)
    carrier=1023      ' Carrier frequency adjust (1023=13kHz)
      
    
    ' PWM carrier frequency register configuration
    PTPERL=carrier.lowbyte  
    PTPERH=carrier.highbyte
    
    
    ' Inverter startup
    pause 2000
    Lcdout $FE,1 
    LCDOUT $FE,2,"Varidrive 1.0"
    LCDOUT $FE,$C0,"DR Electronique"
    pause 2000
      
      
    ' Interrupt processor 
    ASM
    INT_LIST  macro
            INT_Handler   TMR1_INT,   _pwmint,   ASM,  yes
        endm
        INT_CREATE
    ENDASM
     
            
    ' Timer configuration
    T1CON=%1           
    @ INT_ENABLE  TMR1_INT   
    
    
    test var word
    test=1
    
    
    ' Main program loop
    mainlp:
    
    ' Debug display
    LCDOUT $FE,1
    LCDOUT $FE,2,"Timer var :"
    LCDOUT $FE,$C0,#test
    
    if PORTC.4=1 then test=test-1
    if PORTC.5=1 then test=test+1
    pause 100
    
    goto mainlp
    
    
    ' PWM calculation and update interrupt 
    pwmint:
    
    ' Sinewaves frequency
    TMR1L=timer.lowbyte
    TMR1H=timer.highbyte
    
    ' PWM U phase calculation
    uduty=sine[ustep]
    uduty=uduty<<4**amplitude
    
    ' PWM V phase calculation
    vduty=sine[vstep]
    vduty=vduty<<4**amplitude
    
    ' PWM W phase calculation
    wduty=sine[wstep]
    wduty=wduty<<4**amplitude
    
    ' PWM U, V and W update
    PDC0L=uduty.lowbyte
    PDC0H=uduty.highbyte
    PDC1L=vduty.lowbyte
    PDC1H=vduty.highbyte
    PDC2L=wduty.lowbyte
    PDC2H=wduty.highbyte
    
    ' Phase angle calculation
    ustep=ustep-1
    vstep=vstep-1
    wstep=wstep-1
        
    ' Phase angle reinitialization
    if ustep=0 then ustep=72
    if vstep=0 then vstep=72
    if wstep=0 then wstep=72
     
    @ INT_RETURN
    The faulty code is in bold.
    Last edited by pxidr84; - 27th February 2011 at 10:55.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: 6 HPWM signal generation with PIC18F4431

    Problem resolved, I will open a new thread.

  6. #6
    Join Date
    Dec 2012
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: 6 HPWM signal generation with PIC18F4431

    hello, i am new to this forum, I am final year electrical engg. student, my project is 'Speed control of Induction motor using PCPWM in PIC18f4431'. Plz guide me how to go about it, i want to write a code for sinusoidal PWM generation using PCPWM in edge aligned mode.

Members who have read this thread : 1

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