Professional Documents
Culture Documents
MICRO-CONTROLLER BASED
SPACE VECTOR MODULATION (SVM) SIGNAL GENERATOR
SUPERVISOR
ASSOC. PROF. DR. NIK RUMZI BIN NIK IDRIS
ACKNOWLEDGEMENTS
First and foremost, I would like to express my utmost and deepest gratitude to
my project supervisor, PM Dr. Nik Rumzi bin Nik Idris for his advice, aid and
guidance when needed throughout the whole academic year in order to realize the
development and implementation of this project. PM Dr. Nik Rumzi has been kind
enough to let me explore and design my project without hindering creativity and
freedom from me.
At the same time, there are also two important people whom I want to express
my utmost gratitude, namely Mr. Lee Kong Pheng and Mr. Foo Kon Sian. Mr. Lee,
who is my former boss during my industrial attachment period at his company, has
provided me all the necessary equipments, facilities and programming tools to
proceed with my project. Mr. Foo, who is my coursemate as well, has also offered
me a helping hand on the software development side of the project to make the
project workable.
Last but not least, I am also thankful to my family and friends who have been
giving their full support to me all these while. Their encouragement, support, care
and comfort have been equally vital to me towards the completion of this project.
v
ABSTRACT
ABSTRAK
TABLE OF CONTENTS
TITLE PAGE i
DECLARATION ii
DEDICATION iii
ACKNOWLEDGEMENTS iv
ABSTRACT v
ABSTRAK vi
TABLE OF CONTENTS vii
LIST OF TABLES x
LIST OF FIGURES xi
LIST OF ABBREVIATIONS xiii
LIST OF APPENDIX xiv
1 INTRODUCTION
1.1 Project Background 1
1.2 Problem Statement 2
1.3 Objectives of Project 3
1.4 Scope of Project 4
1.5 Methodology 5
1.5.1 Literature Review on SVM and PIC 5
Micro-controller
1.5.2 Hardware and Software Development 6
1.5.3 Troubleshooting and Verification 6
Process
1.6 Thesis Outline 7
viii
2 LITERATURE REVIEW
2.1 Introduction to Space Vector Modulation 8
(SVM)
2.2 Principles of SVM 10
2.3 Algorithms of SVM 14
2.4 Operation of SVM 17
2.5 Generation of SVM 18
3 METHODOLOGY
3.1 Hardware Development and Implementation 20
3.1.1 Introduction to PIC micro-controllers 20
3.1.2 Introduction to PIC16F876A 21
3.1.3 Schematic of Hardware Design 22
3.1.4 Description of Hardware Design 23
3.2 Software Development and Implementation 25
3.2.1 PIC Equivalent Programming Languages 25
3.2.2 PIC Equivalent Compilers and Related 26
Tools
3.2.3 MPLAB IDE and C Language 27
3.2.4 Software Design 30
3.2.4.1 Variables and Arrays 32
3.2.4.2 Library functions 34
3.2.4.3 Initialization 37
3.2.4.4 Input Counter 38
3.2.4.5 Sector Identification 40
3.2.4.6 Calculation of time variables 42
3.2.4.7 Rounding up job 44
3.2.4.8 Output function 46
ix
REFERENCES 63 – 64
Appendix A 65 – 69
Appendix B 70 – 73
Appendix C 74 – 86
x
LIST OF TABLES
LIST OF FIGURES
LIST OF ABBREVIATIONS
3Ф - Three Phase
VREF - Reference Voltage Vectors
PIC - Programmable Interface Controller
VSI - Voltage Source Inverter
Hz - Hertz
V - Voltage
AC - Actuating Current
DC - Direct Current
OSC - Oscillator
PWM - Pulse Width Modulation
SPWM - Sinusoidal Pulse Width Modulation
I/O - Inputs/Outputs
THD - Total Harmonic Distortion
IGBT - Insulated-gate bipolar transistor
MOSFET - Metal Oxide Semiconductor Field Effect Transistor
FPGA - Field Programmable Gate Array
2D - 2 Dimensional
HS - High Speed
BASIC - Beginner's All-purpose Symbolic Instruction Code
CCS - Custom Computer Services
xiv
LIST OF APPENDIX
CHAPTER 1
INTRODUCTION
This chapter will discuss the background of the project, project statement,
objectives and scope of project, and outline of thesis.
are developed to achieve several common aims including less Total Harmonic
Distortion (THD), less switching losses and thus less commutation losses, wider
linear modulation range and also achieving the possibility of controlling frequency
and magnitude of the output voltage.
The most notable advantage of SVM is that this technique can be digitally
implemented into the ever-growing microprocessor and/or micro-controller. In power
electronics, there have been problems regarding the design of complex circuitry for
base/gate drive circuits for switching components (e.g. IGBT, MOSFET) which
might lead to the increase of production cost due to complicated circuits and constant
modification of circuits. With the use of microprocessor or micro-controller such as
PIC and FPGA, such problems can be reduced as well as ease the process of
designing relevant modulation method using SVM.
There are two main objectives in this project and they are:
(a) to understand the concept of Space Vector Modulation (SVM) and the
application of PIC micro-controller
(b) to implement Space Vector Modulation (SVM) based on three phase voltage
source inverter (VSI) using PIC micro-controller
4
This project would involve the main theory of Space Vector Modulation
(SVM) solely, that is to generate the respective output signal based on the inputs and
the intervals which the inputs occupy. Other related aspects in the scope of SVM
such as overmodulation and harmonics would be excluded from the scope of this
project. This is mainly due to time constraint as more time would be needed to
consider overmodulation and to suppress or reduce harmonics that are produced
using the SVM technique. Besides, this project would involve high switching
frequency application and thus a sampling frequency of approximately 10 to 20 kHz
would be used for approximation. Note that the waveforms of the SVM would be in
symmetrical form. Table 1.2 shows the specifications of the SVM generator
produced in this thesis.
1.5 Methodology
To begin with the project, information and knowledge on SVM are crucial
and needed so as to understand thoroughly the myth of the fundamentals of the SVM
concept. Such information were searched and looked through from different sources
such as important reference books, internet websites and journals (which are listed in
the Appendix of this thesis). The purpose is to ensure that no confusion of the main
concept occurs during the implementation of the project so as to reduce any
additional problems due to lack of understanding of the concept.
The project development involves 2 parts: the hardware part and the software
part. As for the hardware part, PIC micro-controller would be used as the “brain” of
the main circuit. The type of PIC micro-controller is PIC16F786A, which is from
the family of PIC16 and has 8 bit I/O. Further information on the hardware
development can be obtained in Chapter 3. Once the hardware part is set up, the
software part then can proceed. In this project, the software development involves
the application of C language using PIC micro-controller related software known as
MPLAB.
This thesis comprises of 5 chapters. Brief description of each chapter is listed below:
(a) Chapter 1 discusses about the introduction of the project, including the
project background, problem statement, objectives and scope of the project
and a short description of the project methodology.
(b) Chapter 2 would provide an in-depth look into the concept of Space Vector
Modulation, its related waveforms and mathematical equations and formulas.
(c) Chapter 3 would then describe the methodology of the project, including the
tools and equipments (PIC micro-controller, related programmer and software
etc.), and procedure and processes (the main circuit, the flow of project,
program related descriptions and functions etc.) involved for the hardware
and software development of the entire project.
(d) Chapter 4 would discuss about the results obtained from the micro-controlled
based SVM signal generator produced for this project.
(e) Lastly, chapter 5 would summarize the thesis with conclusions and
recommendations to be used for further research on such subject in the future.
8
CHAPTER 2
LITERATURE REVIEW
This chapter will present the literature review on Space Vector Modulation
(SVM) and PIC micro-controller that would be used in this project.
In the past few decades, Sinusoidal PWM (SPWM) has been widely used as a
popular means for AC motor control. SPWM uses the method of comparing high
frequency triangular carrier signal with 3 sinusoidal reference signals, whereby
SPWM considers each modulating signals as separate identity. However, there are
obvious drawbacks or weaknesses of SPWM technique which directly affect the
efficiency of the overall system. In order to overcome these drawbacks, a newer and
more advanced technique is introduced known as Space Vector Modulation (SVM)
which is also aimed to increase the system efficiency.
Basically, SVM uses the method of taking all 3 modulating signals into
account simultaneously within a 2D reference frame (in d-q axis or complex
9
form).[8] In other words, SVM is more sophisticated and it offers more voltage output
(approximately 15% more, referring to Figure 2.0) if compared to SPWM, and thus
DC voltage utilization is increased by using SVM.[9] In terms of THD and losses
such as switching and commutation losses, SVM has an advantage over SPWM as
SVM minimizes both aspects which tend to haunt the SPWM technique. Advantages
and strength of SVM over SPWM are paving the way towards wider usage of SVM
in AC motor control and AC power generation. Table 2.1 compares both SVM and
SPWM techniques in a simple manner.
Does not facilitate more advanced Enable more advanced vector control
vector control implementation implementation
Upper switches
a b
Vdc N
c
Note:
1) S1, S2, S3 are upper switches
2) Upper and bottom switches are
Bottom switches S1 S2 S3 complementary
In figure 2.3, the 8 switching topologies can also be represented in the form
of space vector hexagon, where it is divided into 6 sectors and each sector is
separated with a phase shift of 60°. Reference voltage vector, VREF derived from the
vector summation of all 3 modulating voltages (refer to equation 2.2), is rotated in
11
Note that reference voltage vector, VREF is the vector summation of all 3 modulating
voltages and can be represented in the following equation:
V REF =
2
3
[
Va + aVb + a 2Vc ] (2.1)
VREF =
2
3
[
S a + aS b + a 2 S c ] (2.2)
12
2π
j
where a = e 3
Va = Vm sin(ωt )
Vb = Vm sin(ωt − 120°)
Vc = Vm sin(ωt + 120°)
S a , S b , S c are switching states representing each phase
VREF
Table 2.2: 3 phase VSI switching states (upper switches) and Respective Line to
Neutral Voltages [9]
Switching State Sector
VaN VbN VcN
(S1S2S3) number
0 0 0 0 0 (Origin)
2 1 1
1 V DC − V DC − V DC 1
3 3 3
1 1 2
2 VDC VDC − VDC 2
3 3 3
1 2 1
3 − V DC V DC − V DC 3
3 3 3
2 1 1
4 − V DC V DC V DC 4
3 3 3
1 1 2
5 − VDC − VDC VDC 5
3 3 3
1 2 1
6 V DC − V DC V DC 6
3 3 3
7 0 0 0 7 (origin)
14
Symmetrical Alternating
Sequence Sequence
000 100 110 111 111 110 100 000 000 100 110 111 111 110 100 000
S3
S2
S1
Ts Ts
t0 ta tb t0 t0 tb ta t0 t0 ta tb t0 t0 tb ta t0
Sector 1 Sector 2
t0 ta tb t0 t0 tb ta t0 t0 ta tb t0 t0 tb ta t0
Sector 3 Sector 4
t0 ta tb t0 t0 tb ta t0 t0 ta tb t0 t0 tb ta t0
Sector 5 Sector 6
Bear in mind that the main aim of SVM is to approximate the reference
voltage vector using the 8 switching patterns based on upper switches of a 3 phase
VSI. Therefore, the approximation method used in SVM is basically based on the
18
To determine the time duration for each switching states in a sector, the following
equation which is derived from the volt-seconds integral of the switching states, is
used:
Ts T0 Ta Tb T7
∫ VREF dt = ∫ V0 dt + ∫ Va dt + ∫ Vb dt + ∫ V7 dt
0 0 0 0 0
(2.3)
Where
1. Ts is the switching period or sampling period
2. Ta and Tb are the dwelling time for non-zero voltage vectors
3. T0 and T7 are the dwelling time for zero voltage vectors. Both values are the
same.
4. Va and Vb are the adjacent non-zero voltage vectors in each sector
5. V0 and V7 are the zero voltage vectors
Using equation (2.3), as non-zero voltage vectors are null or zero, equation (2.3) can
be transformed into the following equation:
T T
V REF = Va a + Vb b (2.4)
Ts Ts
19
To obtain the dwelling time of non-zero voltage vectors, we take the magnitude of all
voltage vectors using equation (2.4),
cos α T T
V REF × = V a × a + Vb × b (2.5)
sin α Ts Ts
However,
Equations from (2.5) to (2.7) are based on sector 1. Through derivation and
mathematical equations, the equations for all sectors can be obtained using the
following formulas:
3 × Ts × VREF n
Ta = sin π − θ
2VDC 3
3 × Ts × VREF n −1
Tb = sin θ − π (2.8)
2V DC 3
T − Ta − Tb
T0 = T7 = s , where 1 ≤ n ≤ 6 , n ∈ integer
2
20
CHAPTER 3
METHODOLOGY
This chapter will discuss the methodology of the project, including the tools,
equipments, procedures and processes involved in the hardware and software
development and implementation of the project.
PICs are popular with developers and hobbyists alike due to their low cost,
wide availability, large user base, extensive collection of application notes,
21
availability of low cost or free development tools, and serial programming (and re-
programming with flash memory) capability.
sufficient memory for storage purposes and industrial applications, and can also
support high frequency, which is approximately up to a maximum of 20 MHz. For
more information on the PIC16F876A, refer to parts of the data sheet of the micro-
controller in the Appendix section.
The circuit of the hardware part of the project is firstly obtained by referring
to the common schematic diagram for interfacing circuit of PIC micro-controllers,
where power supply, inputs and outputs are connected likewise depending on one’s
needs and requirements. Based on the standard interfacing circuit, the circuit is then
modified based on the requirements of the project, which would be described in the
next subtopic.
circuit using Multisim 8. Note that the schematic diagram is then captured from
Multisim 8 to be shown in this thesis in Figure 3.2.
This circuit could be divided into 2 parts; (a) power supply of 5 volt, and (b)
interfacing circuit of PIC16F876A. Based on the data sheet of PIC16F876A, in order
to ensure the micro-controller function, a supply of 5 volt has to be provided to VDD
pin of the micro-controller. Since a 9 volt battery would be used as a source of
supply, a linear regulator LM7805 is used to provide stable 5 volt supply.
24
U2
LM7805CT
1
LINE VREG
VOLTAGE
COMMON
R3
330Ω
V_1 C1 C2 4
9V 100nF 100nF
LED1
U1 R2
5 VSS VDD 14
6 RB0/INT RA0 17
XSC1
5 7 RB1 RA1 18 10kΩ
8 RB2 RA2 1
9 RB3 RA3 2
G 10 3
RB4 RA4/TOCK1
11 RB5 ~MCLR 4
T 12 16 12
RB6 OSC1/CLKIN
6 13 RB7 OSC2/CLKOUT 15 2
A B C D 7 X1 R1
PIC16F876A
11
100Ω
8 3 C3
C6 HC-49/US_11MHz 10uF-POL
100uF-POL
C4 C5 J1
22pF 22pF
Key = A
0
At the initial stage of the design, the input has not been completely designed
but it would be designed from one stage to another. So, the input at the beginning of
project implementation would utilize the changing of sector number using the
computer program.
On the other hand, the output of the circuit would utilize one of the I/O ports
whereby only 3 pins of one of the ports would be used. Note that port B of pin 0, 1
and 2 are used in this project. These output pins would be connected to an
oscilloscope to investigate and evaluate the output waveform pattern based on sector
25
number. Figure 3.4 shows the actual circuit assembled on a breadboard. Note that the
output waveform pattern for different sector numbers would be shown in Chapter 4.
functions in assembly language. The assembly language used in PIC also differs
quite a bit from other microprocessors and micro-controllers such as 68000 and
others. For instance, for PICs, bi-operand arithmetic operations always involve W
(commonly known as the W register) writing the result back to either W or the other
operand register. In other words, a register is needed to move and write results from
one parameter or address register to the other parameter or address register, which is
quite troublesome. This situation does not apply on 68000 microprocessor.
However, there are also other computer languages that are linked to PIC such
as BASIC, C language, FORTRAN which makes PIC a widely used micro-
controller. In this project, C language would be used due to several reasons. Firstly,
C language is easier to understand. C language is a language designed by humans for
the benefit and convenience of humans. In C Language, the use of address and file
registers are not important even though the process is basically the same as assembly
language in terms of data transfer. Besides, many operations such as logic and
arithmetic operations could be implemented easily if compared to assembly
language. This makes C language more accessible and convenient without having to
consider too much on conditional branches.
Programmers are vital as it is used to get program code into the target PIC
micro-controller. There are numerous PIC micro-controller programmers, ranging
from simple designs which depend on In-Circuit Serial Programming (ICSP) which
allow direct download of code from host computer, to intelligent programmers that
can verify the device at several supply voltages. The programmer used throughout
this project is Cytron Programmer, applicable for wide range of PIC micro-controller
using USB, which is developed by Cytron Technologies Sdn. Bhd.
controller. The main language for writing programs for PIC micro-controller using
MPLAB IDE on Windows OS is the assembly language and thus in order to write C
language programs to be inserted into the PIC micro-controller, compilers or
assemblers related to C language has to be utilized. Therefore, CCS C Compiler was
chosen as the main C language compiler for this project as I have some experience of
using this C compiler during my industrial attachment session.
Figure 3.7: CCS C (PCM) Compiler compiles the project file original.c
Figure 3.8: Project file original.c has been successfully compiled and built
29
Another plus point of CCS C Compiler is that it is applicable for a wide range
of PIC micro-controllers, including PIC10, PIC12, PIC14, PIC16, and PIC18
provided the type of CCS Compiler for each type of PIC is identified. For PIC16, the
type of CCS C Compiler used is PCM Compiler while PCH Compiler is for PIC18.
Note that the license of PCM and PCH compiler of CCS C Compilers have to be
bought before it can be used. Figure 3.7 and 3.8 shows examples on how CCS C
Compiler is used on MPLAB IDE to compile C language written computer
programs.
CCS C Compiler also provides a help menu which serves as an extensive help
library for users to browse and obtain relevant C language related source code and
30
library functions. This help menu eases the process of understanding the C language
used by CCS C Compiler and thus makes C language program writing faster, more
accurate and more efficient. Figure 3.9 shows the menu of the CCS C Compiler Help
File menu.
The software design of this project would be based on the concept of SVM.
To be more exact, the program code that would be written during the project would
be based a lot on the equations that have been presented in Chapter 2, which involves
the calculation of important parameters such as Ts, Ta, Tb, T0 and to approximate the
reference voltage vector into certain sector number in the hexagon representation.
31
The program would start with the acceptance of input parameters including
magnitude and phase. Then generation of counter which involves degrees from 0° to
360° would be conducted. This counter would ensure that only a complete cycle is
taken into consideration.
Once the input phase has been identified, sector number would be chosen
based on the phase angle of the input. As shown in Chapter 2, there are 6 sectors
where each sector is separated by 60°. Sector number would be important to select
the output waveform and equations to calculate the parameters.
The flow of the program is not difficult to understand but the program code
would involve excessive use of loops and functions which might be confusing at
times. Therefore, it is important to make planning for the program writing part before
executing the process of program writing.
In the next few subtopics, each part of the process of C language program
writing would be explained, starting from input counter to output display, as well as
the description of important variables, arrays and C language library functions
provided by CCS C Compiler.
32
phase, phaset1,
variables
result, integral,
Resulting variables Float numbers
integral1, integral2
End variables YY Integers
Sector identification i Integers
counters
Loop
Arrays, on the other hand, are vital as it contains a string of binary codes
located in consecutive addresses in the memory of the micro-controller and they
would be used whenever called upon. In this project, there are two situations which
require the use of arrays. One is for displaying the output pattern of the SVM signal
generator while the other purpose is to provide spaces in the memory storage for the
33
calculated time variables to be used during the process of output display which is
named as “timema[8]”.
S
2
S
1
S
0
t0 ta tb t0 t0 tb ta t0
Table 3.3: List of array and binary code for each sector
Sector Name of array and the binary code involved
1 outta1[8] = {0b00000000, 0b00000100, 0b00000110,
0b00000111, 0b00000111, 0b00000110, 0b00000100, 0b00000000}
In this project, the use of trigonometry function (sine) and other related
mathematical function are vital for processing the input (phase, voltage and time
variables) so as to obtain and display the output pattern required. Besides, library
functions that are related to interface the C language program with the PIC micro-
controller. Note also that some library functions must be used together with
predefined functions such as “#use delay” to enable the application of library
function “delay_us()” and “delay_ms()”.
35
The mathematical functions used are listed in Table 3.4 and Table 3.5 which
[1]
are obtained from the CCS C Compiler help menu . The main functions are listed
in Table 3.6 and 3.7 which are also obtained from the same source.[1]
result=modf(123.987,&integral);
do {
output_high(PIN_B0);
delay_us(duty);
output_low(PIN_B0);
delay_us(period-duty);
} while(TRUE);
37
3.2.4.3 Initialization
#include <16F876A.h>
#include <float.h>
#include <math.h>
#use delay(clock=20000000)
#fuses HS,NOWDT,NOPROTECT,PUT,NOWRT,BROWNOUT,NOLVP
Since this project only involves 3 output ports, the initialization of I/O ports
involve only port B. Using the PIC version of the initialization of I/O port
commands, input and output can be activated on a particular chip by using an
example command (based on C Language) shown in Figure 3.13.
Figure 3.13: Command for I/O port initialization of the PIC micro-controller
For PIC16, setting a bit in TRISA register defines the corresponding port pin
(port A for TRISA) as input, and clearing a bit in TRISA register defines the
corresponding port pin as output. The initial value for each port can also be set to the
desired bit for each pin depending on the project itself. Therefore, since 3 output
ports are needed, all TRISA, TRISB and TRISC are set to 00000000 to indicate all
ports are output ports
be used to indicate the phase counter instead of the unit radians for ease of
verification purposes. So in each period of the input counter, a particular number of
samples will be taken within 0 to 360 degrees to be used for calculation of time
variables and display of output signal. Note that the angle in degrees would then be
converted into unit radians in the program itself for calculation purposes.
Input Counter
(Degrees)
360
0
Time
fundamental
period, Tf
Tf
Pulse period, T p =
360
40
As mentioned in Chapter 2, each degree would fall into different sectors and
the output pattern for all phases or states (S1, S2 and S3) based on different sectors
would differ from one and another. Thus, sector identification is vital to ensure that
the output pattern is correct for a particular sector and also the ensure the accuracy of
calculation of time variables.
To identify and determine which degree falls into which sector, a simple rule
has been designed to make sure that the condition applies to all degrees fro 0 to 360
degrees. Referring to equations (2.8) from Chapter 8, the equation in the argument of
sine of Ta and Tb were used.
Let them be phaset1 and phaset2. Then, refer to the flow chart in Figure 3.15.
n
phaset1 = π −θ
3
(3.1)
n −1
phaset2 = θ − π
3
The reason of using phaset1 and phaset2 in the sector identification process is
that if the certain angle (for instance 145 degrees) is not in the correct sector (145
degrees is in sector 3), both values for phaset1 and phaset2 would have opposite
signs (one would be positive and the other would be negative). If the angle is in the
correct sector, both phaset1 and phaset2 would be positive in sign. The following
calculation would clear things up.
41
Figure 3.16 shows the sector identification function in the program, known as
idsec(). As mentioned in 3.2.4.4, the angle (in degrees) would all be converted to
radians for calculation purposes and thus there is a need to add the conversion
formula in idsec() function.
Figure 3.15: Flow chart of the sector identification section of the program
42
void idsec()
{
for(i=1;i<=6;i++)
{
phaset1 = i*3.142/3;
phaset1 = phaset1 - phase;
phaset2 = phase - (i - 1)*3.142/3;
In this project, the calculation of time variables would be the core element of
the project. As explained in Chapter 2, the time variables Ta, Tb and T0 can be
calculated using the equations (2.8). All the calculation would be done in a function
known as tcal().
3 × Ts × VREF n
Ta = sin π − θ
2VDC 3
3 × Ts × VREF n −1
Tb = sin θ − π (2.8)
2V DC 3
T − Ta − Tb
T0 = T7 = s , where 1 ≤ n ≤ 6 , n ∈ integer
2
43
void tcal()
{
ts = 1000/100;
thetha = phase;
thetha1 = (n*3.142/3) - thetha;
thetha2 = thetha - (n - 1)*3.142/3;
tmag = (sqrt(3))*(modin)*ts/4; //moin=vref1/vdc1
ta = (tmag)*(sin(thetha1)); //test time
tb = (tmag)*(sin(thetha2)); //test time
t0 = ts - ta - tb;
t0 = t0/2;
rdjob();
//Putting times into timema array
timema[0]=t0;
timema[3]=t0;
timema[4]=t0;
timema[7]=t0;
timema[1]=ta;
timema[6]=ta;
timema[2]=tb;
timema[5]=tb;
}
In this function, the value of the sampling period is set to the desired value
(the value of sampling period would be discussed in Chapter 4). At first, calculation
of the argument of sine function for both equations involving Ta and Tb (or ta and tb
in the C language program) are calculated. Next, as the coefficient in front of the sine
function is then calculated which involves variables modin and ts.
Bear in mind that the arguments of sine function have to be in unit radians.
After calculating ta and tb, t0 is then calculated just as shown in Figure 3.18. After
all time variables are obtained, a set of array (which is declared at the beginning of
the program) is then used to store the time variables ta, tb and t0 into a specific
sequence. This sequence is actually derived from the symmetrical sequence pattern
as shown in Figure 2.8 in Chapter 2. All the time variables have also been calculated
using Microsoft Excel (refer to Appendix) so as to enable checking and verification
of the C language program.
44
The rounding up job function is a self written function to cater to the needs of
the C Language library function, which is the delay function (delay(), delay_us()
and delay_ms()). As shown in Table 3.7, the variable used in delay functions must
be integers but the time variables calculated are all in float numbers. Fortunately
enough, the delay functions include delay in milliseconds and microseconds, which
totally fits the project well as most of the time variables are in microseconds.
However, since the time variables are in float numbers, there is no choice but
to round up the numbers to the nearest integer. To round up the numbers, library
function modf() is used to ease the rounding up process. As described in Table 3.4,
modf() function separates a float number into its integer and its decimal numbers.
For instance, 1.97 can be separated into 1 and 0.97 using the function. Thus the logic
shown in Figure 3.20 is used to obtain rounded numbers. Note that XX and YY are
intermediate variables used for rounding up purposes.
From Figure 3.18, after the calculation of time variables, a function known as
rdjob() would be reached. This function actually leads to rounding up of time
45
variables ta, tb and t0 before inserting these values into the timema array. This
rdjob() is shown in Figure 3.23.
result=modf(XX,&integral);
YY = integral;
if ((result >=0) && (result <0.5))
{
YY = YY + 0;
}
else{
if ((result >= 0.5) && (result < 1))
{
YY = YY + 1;
}
}
}
XX = tb;
roundup();
tb = YY;
XX = t0;
roundup();
t0 = YY;
}
Output display is the final part of the C language program for this project.
Before reaching this part, time calculation has been conducted through the tcal()
function. In this part, the time variables would be obtained from the array timema
and be used for output display.
The method of obtaining the time variable for displaying the output pattern is
based on each time column. For example, referring to Figure 3.22, each time column
has a time variable represented by different colours. The output pattern starts with
blue column with time variable t0. For this column, the time variables would be
obtained from the array timema, whereby timema[0], timema[3], timema[4] and
timema[7] are equal to the value of time variable t0 (refer to subtopic 3.2.4.7).
The blue coloured time column is then followed by the yellow coloured time
column where it features time variable ta. The same procedure is repeated for this
47
column whereby timema[1] and timema[6] both are equal to the value of ta. For
the next column till the end of the pattern, the same steps are taken.
S
2
S
1
S
0
t0 ta tb t0 t0 tb ta t0
Figure 3.22: Time columns for output pattern
It is important to note that each sector has different pattern and also different
values of ta, tb and t0 as the value of phase or angle differs from time to time.
However, for a single sector, the pattern would alter in terms of pulse size when the
phase increases from the initial angle of the sector till the final angle of the sector.
For instance, for sector 1, the pulse size for all three switching states (or phases)
would alter starting from the 1st degree till the 60th degree, but the output pattern
would be the same in the range of phase of 1 degree to 60 degrees. To simplify the
output pattern (featuring each switching states) for every sector, Table 3.8 is
formulated. The output pattern has been shown graphically in Figure 2.8 of Chapter
2.
The entire process in the function showout() is described in the flow chart
in Figure 3.23. After the tcal() function, the program would enter showout()
function and start identifying the correct sector number in order to obtain the correct
output pattern from the arrays declared earlier (outta1, outta2, outta3, outta4,
outta5, outta6). The arrays have been explained in subtopic 3.2.4.1 in detail.
48
Table 3.8: Time variables involved for each switching state for every sector
Sector Time Variables
number, n State S1 State S2 State S3
1 T0 + Ta + Tb T0 + Tb T0
2 T0 + Tb T0 + Ta + Tb T0
3 T0 T0 + Ta + Tb T0 + Tb
4 T0 T0 + Tb T0 + Ta + Tb
5 T0 + Tb T0 T0 + Ta + Tb
6 T0 + Ta + Tb T0 T0 + Tb
Now that the correct output array and sector number had been identified.
Thus, the program would proceed by entering a loop with counter 8 as each output
pattern has 8 time columns (note that each array contains 8 binary codes in it). For
each looping, one binary code is taken from the output array and then sent to Port B
through library function output_b() to be displayed. Next, one binary code is taken
from the timema array to be inserted into the library function delay_ms()(or
delay_us()) to enable the output pattern to be delayed for a certain amount of time
(based on the time variable of the time column).
For instance, based on sector 1, for the 1st looping, a binary code from outta1
(the binary code is outta1[0] = 0b00000000) is obtained and then sent to Port B
through the library function output_b() to be displayed. Then, a binary code is then
taken from timema array (the code is timema[0] = t0) to be inserted into library
function delay_us(). The pattern (based on outta1[0]) is then delayed for t0 time.
The procedure is then repeated until the counter ends. The command for the function
showout() would give a clearer insight into the flow of the output display process.
49
if(n == 1)
{
for(j=0;j<8;j++)
{
output_b(outta1[j]);
delay_us(timema[j]);
}
}
if(n == 2)
{
for(j=0;j<8;j++)
{
output_b(outta2[j]);
delay_us(timema[j]);
}
}
if(n == 3)
{
for(j=0;j<8;j++)
{
output_b(outta3[j]);
delay_us(timema[j]);
}
}
if(n == 4)
{
for(j=0;j<8;j++)
{
output_b(outta4[j]);
delay_us(timema[j]);
}
}
if(n == 5)
{
for(j=0;j<8;j++)
{
output_b(outta5[j]);
delay_us(timema[j]);
}
}
if(n == 6)
{
for(j=0;j<8;j++)
{
output_b(outta6[j]);
delay_us(timema[j]);
}
}
}
CHAPTER 4
This chapter will discuss the results obtained from the implementation
process of the project. Problems and situations that arose during the implementation
process will also be explained and discussed.
To implement this project, the first step was to determine the values for all
parameters used to obtain the time variables. These parameters, shown in Table 4.1,
would influence the values of time variables and also the pulse width of the output
pattern. Besides, the fundamental frequency and period were set to the desired value
in order to see the output pattern for a particular amount of samples taken.
The implementation process of the project was initially conducted for high
frequency. Therefore, the original initial parameters shown in Table 4.1 were used.
However, during the implementation period, it was found that the there were some
problems on the output pattern at high frequency. The reason would be discussed in
the following subtopic. Because of these problems, another set of initial parameters
52
were used whereby its sampling frequency has been changed to low frequency. This
would also be discussed in the following subtopic.
3 × Ts × V REF n
Ta = sin π − θ
2VDC 3
3 × Ts × VREF n −1
Time variables (ta, tb, t0) Tb = sin θ − π
2VDC 3
T − Ta − Tb
T0 = T7 = s , where 1 ≤ n ≤ 6 , n ∈ integer
2
Modulation index (modin) 1
3 × Ts × V REF n
Ta = sin π − θ
2VDC 3
3 × Ts × VREF n −1
Tb = sin θ − π
Time variables (ta, tb, t0) 2VDC 3
T − Ta − Tb
T0 = T7 = s , where 1 ≤ n ≤ 6 , n ∈ integer
2
n = sector number
Modulation index (modin) 1
53
The results shown in Figure 4.1 were obtained at 10 kHz sampling frequency.
Bear in mind that within 100 µs of fundamental period, one cycle (0 to 360 degrees)
is taken and thus the 5 samples would change its output pattern based on each sector,
starting from sector 1 to sector 6.
Based on the pulses on this figure, it can be seen that the time gap between
pulses was large, approximately about 16 ms. Note that the sampling frequency of
these pulses was supposed to be 100 µs. Due to this problem, only a total number of
5 samples were taken for a fundamental period of 100 µs.
Even so, the output pattern changed from sector 1 until sector 6 according to
what had been described and shown in Figure 2.8 in Chapter 2.Yet, the only problem
with the output pattern now is that the time gap between pulses taken from the
project does not match with what we want at high frequency.
Due to the problem occurred for high frequency, a much lower frequency for
was taken for the sampling frequency in order to overcome the time gap between
pulses (16 ms for high frequency). For low frequency though, the fundamental period
of the input counter was not set. A number of 100 samples were taken for one cycle
(0 to 360 degrees). The output pattern obtained is shown in Figure 4.2
54
Note that the time period obtained from the output at low frequency were
roughly 250 ms, which still differ from the sampling period of 200 ms. However,
since the difference of 50 ms is smaller compared to the sampling period, the gap
between the pulses did not seem to be large and thus a clearer series of pulses can be
seen. The variation of output pattern from one sector to another sector can also be
seen clearly, with the pulses widening and narrowing according to the time
calculated. To understand how the pulse size changes, refer to the calculation of time
variables in Appendix B and subtopic 3.2.4.8 for further information.
Sector 1 Sector 2
Sector 3 Sector 4
Sector 5 Sector 6
Apart from that, there were other analyses that could be obtained based on the
output pattern obtained at low frequency. Since the pulses have a less significant
time gap between each other, the line to line signal also could be seen. Line-to-line
signal was obtained by subtracting output signal of one phase or switching state with
the other. The reason for observation of the line-to-line signal was to determine
57
whether the algorithm of the sequence is correct, and to verify calculation of time
variables.
S3 S3
S1 S1
S3 – S1 S3 – S1
t0 ta tb t0 t0 tb ta t0 t0 ta tb t0 t0 tb ta t0
would have a third harmonic component in it. Therefore, the frequency response of
the output pattern for each phase is as shown in Figure 4.5.
Fundamental waveform
Distorted waveform
3rd Harmonic
frequency
Third Harmonic
Fundamental Sampling
frequency frequency
Figure 4.6: Frequency Response of the output pattern for one phase
Figure 4.5 shows the frequency response of the output pattern of one of the
phases, S3. We know that the fundamental period estimated was roughly 25 seconds,
which gives us a fundamental frequency of 0.04 Hz. As the fundamental frequency is
59
small, the third harmonic could not be seen clearly from the frequency response
taken from the oscilloscope. The sampling frequency though, valued at roughly 4 to
5 Hz, can be observed. The overall frequency response pattern was deemed to be
correct.
Both set of results have been taken for high and low frequency (10 kHz and
50 Hz). As mentioned earlier, the results at high frequency was not satisfactory due
to the large time gap between pulses (roughly 16 ms) and thus results were retaken
for low frequency in order to make the difference of time between actual sampling
period and time period obtained from output less significant.
Several reasons have been touted to have caused the problem. The main cause
of such situation is the use of float number or floating points in the C language
program. Note that calculation of time variables involved the use of float numbers in
order to obtain accurate time variables. However, it is noticed that C language is not
the main language for PIC micro-controller.
Note that regardless of whatever computer language used for PIC micro-
controller programming, all these languages would be translated back into assembly
language for compiling purposes. In C language, the use of float numbers may seem
easy but that is not the case with assembly language. A simple command of float
number might take a few assembly language commands to execute. Therefore, it is
suspected that because of this reason, more time is taken to process the float numbers
to obtain the time variables.
This reason has been considered into the design of program and thus interrupt
has been suggested even in the earlier stages of the program writing process.
Unfortunately, when the program was written, all the functions written worked
60
properly, except for the interrupt function. The interrupt function was not discussed
in Chapter 3 due to this reason.
CHAPTER 5
5.1 Summary
sector number. PIC micro-controller would function as a center for time variable
calculation and output display. By using an input counter, the variation of pulse from
one sector to another sector (1 to 6) can be obtained.
As mentioned in Chapter 4, solving the large time gap between pulses would be
vital to enable this micro-controller-based SVM signal generator to function to its fullest
potential and the possible method of solution would be to focus on improvising the
implementation of interrupt function in the program. This can be done by fully
understanding the interrupt function of the PIC micro-controller used in future projects.
REFERENCES
1. CCS, CCS C Compiler v.4 Help File. Custom Computer Services Incorporated,
2007.
3. Keliang Zhou and Daniel Wang, Member, IEEE. Relationship Between Space
Vector Modulation and Three Phase Carrier-Based PWM: A Comprehensive
Analysis. IEEE Transactions on Industrial Electronics, Vol. 49, No. 1, February
2002
11. Wei Chong Low, Implementation of SVM Signal Generator for a 3 Phase Inverter
Employing Altera FPGA. Thesis of Bachelor Degree. Universiti Teknologi Malaysia;
2006.
65
APPENDIX A
66
//***************************************************************************************
//***************************************************************************************
//********** Micro-controller Based SVM Signal Generator **********
//********** **********
//********** Written by Kelvin Lye **********
//********** **********
//***************************************************************************************
//***************************************************************************************
#include <16F876A.h>
#include <float.h>
#include <math.h>
//#device *=16 ADC=8 //16bit pointer, 8-bit ADC
#use delay(clock=20000000)
#fuses HS,NOWDT,NOPROTECT,PUT,NOWRT,BROWNOUT,NOLVP
typedef struct {
int1 bit0;
int1 bit1;
int1 bit2;
int1 bit3;
int1 bit4;
int1 bit5;
int1 bit6;
int1 bit7;
} flags;
//Other variables
int8 i, j, h; //counter
float nsamp, result1; //condition for one complete cycle
int8 n; //sector number
//Interrupt Bit
flags sys01;
#define flg_10ms sys01.bit0
int8
outta3[8]={0b00000000,0b00000010,0b00000011,0b00000111,0b00000111,0b00000011,0b00000010,
0b00000000}; //test mar
int8
outta4[8]={0b00000000,0b00000001,0b00000011,0b00000111,0b00000111,0b00000011,0b00000001,
0b00000000}; //test mar
int8
outta5[8]={0b00000000,0b00000001,0b00000101,0b00000111,0b00000111,0b00000101,0b00000101,
0b00000000}; //test mar
int8
outta6[8]={0b00000000,0b00000100,0b00000101,0b00000111,0b00000111,0b00000101,0b00000100,
0b00000000}; //test mar
int8 timema[8];
//Initialization
void init(){
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
// enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1);
}
if(n == 1)
{
for(j=0;j<8;j++)
{
output_b(outta1[j]);
delay_ms(timema[j]);
}
}
if(n == 2)
{
for(j=0;j<8;j++)
{
output_b(outta2[j]);
delay_ms(timema[j]);
}
}
if(n == 3)
{
for(j=0;j<8;j++)
{
output_b(outta3[j]);
delay_ms(timema[j]);
}
}
if(n == 4)
{
for(j=0;j<8;j++)
{
output_b(outta4[j]);
delay_ms(timema[j]);
}
}
if(n == 5)
{
for(j=0;j<8;j++)
{
output_b(outta5[j]);
delay_ms(timema[j]);
}
}
if(n == 6)
{
for(j=0;j<8;j++)
{
68
output_b(outta6[j]);
delay_ms(timema[j]);
}
}
result=modf(XX,&integral);
YY = integral;
if ((result >=0) && (result <0.5))
{
YY = YY + 0;
}
else{
if ((result >= 0.5) && (result < 1))
{
YY = YY + 1;
}
}
}
//Function to collect and re-insert rounded up numbers for important time variables
void rdjob()
{
XX = ta;
roundup();
ta = YY;
XX = tb;
roundup();
tb = YY;
XX = t0;
roundup();
t0 = YY;
}
void tcal()
{
ts = 1000/100;
thetha = phase;
thetha1 = (n*3.142/3) - thetha;
thetha2 = thetha - (n - 1)*3.142/3;
tmag = (sqrt(3))*(modin)*ts/4; //moin=vref1/vdc1
ta = (tmag)*(sin(thetha1)); //test time
tb = (tmag)*(sin(thetha2)); //test time
t0 = ts - ta - tb;
t0 = t0/2;
rdjob();
//Putting times into timema array
timema[0]=t0;
timema[3]=t0;
timema[4]=t0;
timema[7]=t0;
timema[1]=ta;
timema[6]=ta;
timema[2]=tb;
timema[5]=tb;
}
//Main function
void main()
{
Mainloop:
nsamp = 100;
result1=modf(nsamp,&integral1);
integral2=integral1+1;
h=1;
do
{
in_put();
idsec();
tcal();
h++;
goto Mainloop;
APPENDIX B
71
Degree thetha n ta tb t7
1 0.063 1 1.8E-05 1.36E-06 1.53E-05
2 0.126 1 1.72E-05 2.71E-06 1.5E-05
3 0.188 1 1.64E-05 4.06E-06 1.48E-05
4 0.251 1 1.55E-05 5.38E-06 1.46E-05
5 0.314 1 1.45E-05 6.69E-06 1.44E-05
6 0.377 1 1.34E-05 7.97E-06 1.43E-05
7 0.44 1 1.24E-05 9.22E-06 1.42E-05
8 0.503 1 1.12E-05 1.04E-05 1.42E-05
9 0.565 1 1E-05 1.16E-05 1.42E-05
10 0.628 1 8.81E-06 1.27E-05 1.42E-05
11 0.691 1 7.55E-06 1.38E-05 1.43E-05
12 0.754 1 6.26E-06 1.48E-05 1.45E-05
13 0.817 1 4.94E-06 1.58E-05 1.46E-05
14 0.88 1 3.61E-06 1.67E-05 1.49E-05
15 0.942 1 2.26E-06 1.75E-05 1.51E-05
16 1.005 1 9.07E-07 1.83E-05 1.54E-05
17 1.068 2 1.85E-05 4.53E-07 1.55E-05
18 1.131 2 1.78E-05 1.81E-06 1.52E-05
19 1.194 2 1.7E-05 3.16E-06 1.49E-05
20 1.257 2 1.61E-05 4.5E-06 1.47E-05
21 1.319 2 1.51E-05 5.82E-06 1.45E-05
22 1.382 2 1.41E-05 7.12E-06 1.44E-05
23 1.445 2 1.31E-05 8.39E-06 1.43E-05
24 1.508 2 1.2E-05 9.63E-06 1.42E-05
25 1.571 2 1.08E-05 1.08E-05 1.42E-05
26 1.634 2 9.63E-06 1.2E-05 1.42E-05
27 1.696 2 8.39E-06 1.31E-05 1.43E-05
28 1.759 2 7.12E-06 1.41E-05 1.44E-05
29 1.822 2 5.82E-06 1.51E-05 1.45E-05
30 1.885 2 4.5E-06 1.61E-05 1.47E-05
31 1.948 2 3.16E-06 1.7E-05 1.49E-05
32 2.011 2 1.81E-06 1.78E-05 1.52E-05
33 2.073 2 4.53E-07 1.85E-05 1.55E-05
34 2.136 3 1.83E-05 9.07E-07 1.54E-05
35 2.199 3 1.75E-05 2.26E-06 1.51E-05
36 2.262 3 1.67E-05 3.61E-06 1.49E-05
37 2.325 3 1.58E-05 4.94E-06 1.46E-05
38 2.388 3 1.48E-05 6.26E-06 1.45E-05
39 2.45 3 1.38E-05 7.55E-06 1.43E-05
40 2.513 3 1.27E-05 8.81E-06 1.42E-05
41 2.576 3 1.16E-05 1E-05 1.42E-05
42 2.639 3 1.04E-05 1.12E-05 1.42E-05
43 2.702 3 9.22E-06 1.24E-05 1.42E-05
44 2.765 3 7.97E-06 1.34E-05 1.43E-05
45 2.827 3 6.69E-06 1.45E-05 1.44E-05
46 2.89 3 5.38E-06 1.55E-05 1.46E-05
47 2.953 3 4.06E-06 1.64E-05 1.48E-05
48 3.016 3 2.71E-06 1.72E-05 1.5E-05
72
APPENDIX C
75
76
77
78
79
80
81
82
83
84
85
86