Briefing
The generation of Space Vector Modulation (SVM) used for Pure Sine Wave Inverters requires software development unlike conventional Pulse Width Modulation. This code was developed in line with the SVM Inverter implementation already discussed on this blog!Facts about the code
This piece of code was developed using Assembly (ASM) programming language for PIC16F84A. This code will fit into other PIC microcontrollers with some modifications on the address registers used.Assembly language programming requires a great deal of knowledge about the MCU address registers used. As a result, the MCU datasheet must be at hand when debugging any ASM code. C Language could be better, but as events may have it, the program ended up being written in ASM language. To make the code a little bit comprehensible, detailed comments were added to important lines of the code in order to explain what happens at each point in the code.
To generate the hex file required for the SVM schematic featured in SVM Inverter implementation, simply compile the code using MPLAB IDE. Different SVM algorithms can be implemented by some modifications in the code. The bunch of the code are listed below.
For those with little or no background on assembly language programming, you may need to refer to a resource on PIC assembly language basics!
SVM Inverter ASM Code
; Note: MCU frequency = 4MHz - crystal oscillators usedStart ORG 0x00 ;code begins
BSF 03,5 ; migrate to bank1 to setup ports
MOVLW 00h
MOVWF 05h
MOVWF 06h
BCF 03,5 ; go back to bank0
; This routine loads SVM data into an allocated registers (SVM registers)
movlw 00h
movwf 10h ;file 10h is the table pointer
movlw 13h
movwf 04h ; SVM registers starts from 13h to 1ah
getnext incf 10h,1 ;increment table pointer
movf 10h,0 ;move the content of 10h to the working reg
continue movf 10h,0
call tableSVM
movwf 00h ;store the SVM vectors returned from the table in files
incf 04h
xorlw 0aah ;check when last line of data table is returned
btfsc 03,2 ;if last line is returned, generate SVM signals
goto gen_svm
goto getnext
;routine that returns SVM data to be saved in registers
tableSVM ADDWF 02h,1 ;Add W to Program Counter
RETLW 00h ; this line is skipped!
retlw 1ch ;SW vector0 =13h
retlw 8ch ;SW vector1 =14h
retlw 0c4h ;SW vector2 =15h
retlw 54h ;SW vector3 =16h
retlw 70h ;SW vector4 =17h
retlw 38h ;SW vector5 =18h
retlw 0a8h ;SW vector6 =19h
retlw 0e0h ;SW vector7 =1ah
retlw 0aah ;when this line is returned, return ends!
; subroutine for switching times(T0,T1, and T2) - use Delay Code Generator
DelT0_2 movlw 0ah ;Delay for 33us
movwf 0fh
del0_2 DECFSZ 0fh,1
GOTO del0_2
RETURN
DelT0 movlw 15h ;Delay for 66us
movwf 0fh
del0 DECFSZ 0fh,1
GOTO del0
RETURN
DelT1 movlw 0bh ;Delay for 36us
movwf 0fh
del1 DECFSZ 0fh,1
GOTO del1
RETURN
DelT2 movlw 20h ;Delay for 98us
movwf 0fh
del2 DECFSZ 0fh,1
GOTO del2
RETURN
;this subroutine generates SVM (Symmetric algorithm) switching signals
gen_svm
movf 13h,0 ;sector1 switching signals
movwf 06h
CALL DelT0_2
movf 14h,0
movwf 06h
CALL DelT1
movf 15h,0
movwf 06h
CALL DelT2
movf 1ah,0
movwf 06h
CALL DelT0
movf 15h,0
movwf 06h
CALL DelT2
movf 14h,0
movwf 06h
CALL DelT1
movf 13h,0
movwf 06h
CALL DelT0_2
movf 13h,0 ;sector2 switching signals
movwf 06h
CALL DelT0_2
movf 16h,0
movwf 06h
CALL DelT1
movf 15h,0
movwf 06h
CALL DelT2
movf 1ah,0
movwf 06h
CALL DelT0
movf 15h,0
movwf 06h
CALL DelT2
movf 16h,0
movwf 06h
CALL DelT1
movf 13h,0
movwf 06h
CALL DelT0_2
movf 13h,0 ;sector3 switching signals
movwf 06h
CALL DelT0_2
movf 16h,0
movwf 06h
CALL DelT1
movf 17h,0
movwf 06h
CALL DelT2
movf 1ah,0
movwf 06h
CALL DelT0
movf 17h,0
movwf 06h
CALL DelT2
movf 16h,0
movwf 06h
CALL DelT1
movf 13h,0
movwf 06h
CALL DelT0_2
movf 13h,0 ;sector4 switching signals
movwf 06h
CALL DelT0_2
movf 18h,0
movwf 06h
CALL DelT1
movf 17h,0
movwf 06h
CALL DelT2
movf 1ah,0
movwf 06h
CALL DelT0
movf 17h,0
movwf 06h
CALL DelT2
movf 18h,0
movwf 06h
CALL DelT1
movf 13h,0
movwf 06h
CALL DelT0_2 ;
movf 13h,0 ;sector5 switching signals
movwf 06h
CALL DelT0_2
movf 18h,0
movwf 06h
CALL DelT1
movf 19h,0
movwf 06h
CALL DelT2
movf 1ah,0
movwf 06h
CALL DelT0
movf 19h,0
movwf 06h
CALL DelT2
movf 18h,0
movwf 06h
CALL DelT1
movf 13h,0
movwf 06h
CALL DelT0_2
movf 13h,0 ;sector6 switching signals
movwf 06h
CALL DelT0_2
movf 14h,0
movwf 06h
CALL DelT1
movf 19h,0
movwf 06h
CALL DelT2
movf 1ah,0
movwf 06h
CALL DelT0
movf 19h,0
movwf 06h
CALL DelT2
movf 14h,0
movwf 06h
CALL DelT1
movf 13h,0
movwf 06h
CALL DelT0_2
GOTO gen_svm
end
This comment has been removed by the author.
ReplyDeletevery well written article and I understood SVPWM after reading your article. Great work for power electronics begineers
ReplyDeletecode for atmage380
ReplyDeleteHI ,YOU HAVE CODE FOR PIC16F877A?
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteDo you for basic microcontroller 8051
ReplyDeleteDo you have code for basic microcontroller 8051
ReplyDeleteDo you have code for basic microcontroller 8051
ReplyDeleteHELLO, great work do YOU HAVE CODE FOR PIC16F877A?
ReplyDeleteplease !
what are modifications needed for 20Mhz frequency?
ReplyDeleteyou have code for arduino mega?
ReplyDeleteNo code is 4 pic micros
Deletedo you have the code in c ? great work bro !
ReplyDelete