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

    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.

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: 6 HPWM signal generation with PIC18F4431

    Problem resolved, I will open a new thread.

  3. #3
    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