generating 3phase SPWM with MCU/DSP

Discussion in 'Embedded Systems and Microcontrollers' started by optionfa, Nov 2, 2009.

  1. optionfa

    Thread Starter New Member

    Nov 2, 2009
    15
    0
    Hey everyone,

    I am working on a 3phase inverter project and need to develop a three phase sine PWM signal to control my gate drive IC.

    I know the most common way to get three SPWM signals 120 degrees apart is through MCU or DSP programming. Unfortunately I am not very familiar with MCU/DSP programming so I was hoping to get some input from anyone who has some experience on this topic.

    I would much appreciate any input, like what would be the best MCU or DSP for this particular application as well as any open sources codes regarding SPWM.

    Thanks.
     
  2. GetDeviceInfo

    Senior Member

    Jun 7, 2009
    1,571
    230
    I would search for some info on dedicated devices such as the 68332 from Motorola. There are a number of devices, but such info typically explores theoretical viewpoints.
     
  3. optionfa

    Thread Starter New Member

    Nov 2, 2009
    15
    0
    That just seems like overkill for something that should be a fairly simple concept..

    I found the following code which is written for a pic16f84a (8 bit MCU)

    ;Author: Jonathan Weaver, Copyright 2005.
    ;Purpose: Generate three simultaneous PWM 60 Hz sine waves 120 degrees apart
    ; to simulate a Y-connected three phase power system. Assumes a pic16f84a
    ; running at 4 MHz.
    ;Revision History:
    ; v1.0 - 2/14/2005 - Created file

    ;==============================================================================
    ; P r o c e s s o r
    ;==============================================================================
    list p=16f84a
    include p16f84a.inc

    ;==============================================================================
    ; C o n s t a n t s
    ;==============================================================================
    phaseA equ 2 ;RB2
    phaseB equ 1 ;RB1
    phaseC equ 0 ;RB0
    outPort equ PORTB

    ;==============================================================================
    ; D a t a M e m o r y
    ;==============================================================================
    cblock 0x0C
    outPortBuffer
    valueA
    valueB
    valueC
    timeA
    timeB
    timeC
    stateVar
    endc

    ;==============================================================================
    ; M A C R O S
    ;==============================================================================

    BANK0 macro
    bcf STATUS, RP0
    endm

    BANK1 macro
    bsf STATUS, RP0
    endm

    ;==============================================================================
    ; R e s e t V e c t o r
    ;==============================================================================
    org 0x0000
    call Initialize
    goto Main

    ;==============================================================================
    ; I n t e r r u p t V e c t o r
    ;==============================================================================
    org 0x0004 ;Do not have to save context because of implementation

    ;Interrupt code

    clrf outPortBuffer

    incf timeA, f ;Advance time
    movf timeA ,w
    addlw D'21'
    movwf timeB
    addlw D'22'
    movwf timeC

    call PWM ;Update

    btfsc stateVar, 0 ;Phase rotation is rounded depending upon state
    goto StateB
    btfsc stateVar, 1
    goto StateC
    StateA
    bsf stateVar, 0
    goto EndState
    StateB
    incf timeB, f
    bsf stateVar, 1
    goto EndState
    StateC
    incf timeB, f
    incf timeC, f
    clrf stateVar
    EndState

    call PWM ;Update

    movlw D'65' ;Ensure between 0 and 64
    subwf timeA, f
    btfss STATUS, C
    addwf timeA, f
    subwf timeB, f
    btfss STATUS, C
    addwf timeB, f
    subwf timeC, f
    btfss STATUS, C
    addwf timeC, f

    call PWM ;Update

    movf timeA, w ;Get sinewave value, phase A
    call SineWave
    movwf valueA
    movf timeB, w ;Get sinewave value, phase B
    call SineWave
    movwf valueB
    movf timeC, w ;Get sinewave value, phase C
    call SineWave
    movwf valueC
    bcf INTCON, T0IF ;Reset interrupt flag

    retfie

    ;==============================================================================
    ; M A I N
    ;==============================================================================
    Main
    bcf INTCON, GIE ;Disable interrupts
    call PWM
    bsf INTCON, GIE ;Enable interrupts
    goto Main

    ;------------------------------------------------------------------------------
    Initialize
    ;Set up output port
    BANK1
    movlw ~(1 << phaseA | 1 << phaseB | 1 << phaseC)
    movwf outPort

    ;Set up TIMER0
    movlw B'10001000'
    movwf OPTION_REG
    BANK0

    ;Set up for interrupt routine
    clrf stateVar
    clrf timeA

    ;Set up values
    movlw D'127'
    movwf valueA
    movlw D'241'
    movwf valueB
    movlw D'19'
    movwf valueC

    ;Set up timer interrupt
    movlw B'10100000'
    movwf INTCON

    return

    ;------------------------------------------------------------------------------
    PWM
    movf TMR0, w ;Get time
    subwf valueA, f ;Calculate for Phase A
    btfss STATUS, C
    bsf outPortBuffer, phaseA
    addwf valueA, f ;Restore ValueA

    subwf valueB, f ;Calculate for Phase B
    btfss STATUS, C
    bsf outPortBuffer, phaseB
    addwf valueB, f ;Restore ValueB

    subwf valueC, w ;Calculate for Phase C
    btfss STATUS, C
    bsf outPortBuffer, phaseC
    movf outPortBuffer, w
    movwf outPort
    return

    ;------------------------------------------------------------------------------
    SineWave
    if (high TableStart)
    movlw high TableStart
    movwf PCLATH
    endif
    if (high TableStart) == (high TableEnd)
    addwf PCL, f
    else
    messg "Table crosses page boundary"
    addwf PCL, w
    btfss STATUS, C
    incf PCLATH, f
    movwf PCL
    endif
    TableStart
    retlw D'127'
    retlw D'139'
    retlw D'151'
    retlw D'163'
    retlw D'175'
    retlw D'186'
    retlw D'197'
    retlw D'207'
    retlw D'216'
    retlw D'224'
    retlw D'232'
    retlw D'238'
    retlw D'243'
    retlw D'248'
    retlw D'251'
    retlw D'253'
    retlw D'254'
    retlw D'254'
    retlw D'252'
    retlw D'250'
    retlw D'246'
    retlw D'241'
    retlw D'235'
    retlw D'228'
    retlw D'220'
    retlw D'211'
    retlw D'202'
    retlw D'191'
    retlw D'181'
    retlw D'169'
    retlw D'157'
    retlw D'145'
    retlw D'133'
    retlw D'121'
    retlw D'109'
    retlw D'97'
    retlw D'85'
    retlw D'73'
    retlw D'63'
    retlw D'52'
    retlw D'43'
    retlw D'34'
    retlw D'26'
    retlw D'19'
    retlw D'13'
    retlw D'8'
    retlw D'4'
    retlw D'2'
    retlw D'0'
    retlw D'0'
    retlw D'1'
    retlw D'3'
    retlw D'6'
    retlw D'11'
    retlw D'16'
    retlw D'22'
    retlw D'30'
    retlw D'38'
    retlw D'47'
    retlw D'57'
    retlw D'68'
    retlw D'79'
    retlw D'91'
    retlw D'103'
    TableEnd
    retlw D'115'

    ;==============================================================================
    ; I N C L U D E S
    ;==============================================================================

    end

    If I understand the concept, It should get the fundamental sine frequency from a lookup table and then generates some sort of carrier frequency for the PWM.. I believe the pic 16f84a is an outdated processor so hopefully I can find a development board for cheap?
     
  4. GetDeviceInfo

    Senior Member

    Jun 7, 2009
    1,571
    230
    the device and it's implementation may be complex, but the application notes cover basic concepts.

    Semikron, who manufacture gate drivers, also has some excellent technical notes on thier website.
     
Loading...