You are on page 1of 102

i

MICRO-CONTROLLER BASED
SPACE VECTOR MODULATION (SVM) SIGNAL GENERATOR

KELVIN LYE KWONG LOONG

SUPERVISOR
ASSOC. PROF. DR. NIK RUMZI BIN NIK IDRIS

This Thesis is submitted to fulfil


Part of the requirements for the
Degree of Bachelor of
Electrical Engineering

FACULTY OF ELECTRICAL ENGINEERING


UNIVERSITI TEKNOLOGI MALAYSIA
MAY 2008
iii

To my beloved family and friends


iv

ACKNOWLEDGEMENTS

Throughout the entire process of development and implementation of the


project, I was very fortunate to have a number of wonderful and experience people
who have been giving me assistance and direction towards completing this project.

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

The rapid development of high switching frequency power electronics


devices has been significant in the past decade which leads towards wider application
of voltage source inverters (VSI) in AC power generation. The use of VSI involves
modulation techniques that control the switches of VSI such as Sinusoidal Pulse
Width Modulation (SPWM), Third Harmonic Sinusoidal PWM and Space Vector
Modulation (SVM). The main aims of modulation techniques are to achieve lesser
harmonics and to provide a wider linear modulation range for the inverter generated
output voltage. Digital implementation using micro-controllers and microprocessors
have also been evident of late as both are being widely used in various sectors
including in power electronics devices. In this project, Space Vector Modulation
(SVM) will be utilized as another alternative modulation technique which was
known to be better than SPWM techniques in certain areas. PIC micro-controller
would be used to realize the application of SVM on 3-phase VSI, whereby two main
inputs from the combination of all three phases of voltages were taken into
consideration which were the reference voltage vector, VREF and its phase, θ. The
output of this project would represent the switching pattern of the switches on 3-
phase VSI.
vi

ABSTRAK

Pembangunan dan kemajuan yang pantas dalam peranti elektronik kuasa


berfrekuensi pensuisan tinggi menjadi semakin ketara dalam dekad lepas dan telah
membawa kepada aplikasi penyongsang sumber voltan (VSI) yang lebih meluas
dalam penjanaan kuasa arus ulang-alik. Penggunaan VSI melibatkan teknik
pemodulatan yang mengawal suis-suis VSI seperti Pemodulatan Lebar Denyut
Sinusoidal (SPWM), Pemodulatan Lebar Sinusoidal Harmonik Ketiga dan
Pemodulatan Vektor Ruang (SVM). Tujuan utama untuk teknik pemodulatan
adalah untuk mencapai kurang harmonik dan untuk menyediakan julat
pemodulatan linear yang lebih besar untuk voltan keluaran janaan bagi
penyongsang. Implementasi digital dengan menggunakan mikro-pengawal dan
mikro-pemproses juga adalah ketara buat masa kini disebabkan kedua-duanya
digunakan secara meluas dalam sektor-sektor berlainan termasuk dalam peranti-
peranti elektronik kuasa. Dalam projek ini, Pemodulatan Vektor Ruang (SVM)
akan digunakan sebagai satu alternatif kepada teknik pemodulatan yang dikatakan
lebih baik daripada teknik-teknik PWM dalam bidang-bidang tertentu. Mikro-
pengawal PIC akan digunakan untuk merealisasikan aplikasi SVM pada VSI 3
fasa, di mana dua masukan utama daripada gabungan voltan fasa bagi ketiga-tiga
fasa akan diambil kira, yakni vektor voltage rujukan, VREF dan fasanya, θ.
Keluaran daripada projek ini akan menunjukkan corak pensuisan untuk suis-suis
pada VSI 3-fasa.
vii

TABLE OF CONTENTS

CHAPTER TTTLE PAGE

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

4 RESULTS AND DISCUSSION


4.1 Implementation of Project 51
4.2 Results of Project 53
4.2.1 Results for High Frequency 53
4.2.2 Results for Low Frequency 53
4.3 Discussion and Explanation 59

5 CONCLUSION AND SUGGESTIONS FOR


FURTHER RESEARCH
5.1 Summary 61
5.2 Conclusion and Suggestions 62

REFERENCES 63 – 64

Appendix A 65 – 69

Appendix B 70 – 73

Appendix C 74 – 86
x

LIST OF TABLES

TABLE NO. TTTLE PAGE


1.1 Simple comparison between Sinusoidal PWM and 3
SVM
1.2 Some specifications of SVM signal generator 4
2.1 Comparison between SPWM and SVM 9
2.2 3 phase VSI switching states (upper switches) and 13
respective line to neutral voltages
3.1 Some features of PIC16F876A 22
3.2 List of variables used in the program of project 32
3.3 List of array and binary code for each sector 33
3.4 Description of modf() function 37
3.5 Description of sin() function 37
3.6 Description of output_b() function 38
3.7 Description of delay_us() function 38
3.8 Time variables involved for each switching state for 48
every sector
4.1 Initial Parameters for Calculation and Implementation 52
Purposes (High Frequency)
4.2 Initial Parameters for Calculation and Implementation 52
Purposes (Low Frequency)
xi

LIST OF FIGURES

FIGURE NO. TTTLE PAGE


2.1 Comparison of locus in terms of DC voltage 9
utilization between SVM and SPWM
2.2 3 Phase voltage source inverter (VSI) 10
2.3 8 switching topologies of a 3 phase VSI 11
2.4 Representation of 8 switching topologies in 12
hexagon form (or space vector hexagon) and
interpretation of reference voltage into d-q plane
2.5 Graphs of 3 modulating voltages where reference 12
voltage is shifted from one sector to another
2.6 Algorithms of output signals based on sector 1 14
2.7 Output signal based on symmetrical sequence 15
algorithm in sector 1
2.8 Output patterns each sector based on symmetrical 16
sequence
2.9 Synthesizing reference voltage sector in sector 1 17
3.1 PIC16F876A 21
3.2 Schematic diagram drawn and captured using 23
Multisim 8
3.3 Schematic diagram of project circuit using Multisim 24
3.4 Hardware implementation of SVM signal generator 25
using PIC micro-controller on breadboard
3.5 Microchip MPLAB IDE and PIC micro-controller 26
programmer developed by Cytron Technologies
3.6 CCS C Compiler for PIC micro-controllers 27
xii

FIGURE NO. TTTLE PAGE


3.7 CCS C (PCM) Compiler compiles the project file 28
original.c
3.8 Project file original.c has been successfully compiled 28
and built
3.9 CCS C Compiler Help File Menu 29
3.10 Flow chart of program for SVM signal generator 30
3.11 Output pattern for sector 1 33
3.12 Header files included in the C language program of 37
project
3.13 Command for I/O port initialization of the PIC micro- 38
controller
3.14 Input Counter Output 39
3.15 Flow chart of the sector identification section of the 41
program
3.16 Command for sector identification function, idsec() 42
3.17 Command of the time calculation function, tcal() 43
3.18 Sequence of time variables inserted into timema array 44
3.19 Flow chart of rounding up function 45
3.20 Command for roundup() function 45
3.21 Command for rdjob() function 46
3.22 Time columns for output pattern 47
3.23 Flow chart for the output display function 49
3.24 Command for the process of output display 50
4.1 Results obtained at high frequency of 10 kHz 54
4.2 Results taken at low frequency of 50 Hz 55
4.3 Line-to-line signal obtained on the oscilloscope 56
4.4 Subtracting pulse of one phase with another 57
4.5 Waveforms and frequency response for one phase 58
4.6 Frequency Response of one phase 58
xiii

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

APPENDIX TTTLE PAGE

A Source code of program of this project 63


B Calculation of time variables using Microsoft 68
Excel
C Part of Data Sheet of PIC16F87 72
1

CHAPTER 1

INTRODUCTION

This chapter will discuss the background of the project, project statement,
objectives and scope of project, and outline of thesis.

1.1 Project Background

In general, inverters are known to be a type of electronic circuit which


converts DC power to AC power. Inverters are normally used in applications
regarding AC power generation, such as DC power source utilization, uninterruptible
power supplies (UPS), variable-frequency drives and so fourth. In the same context,
three phase inverters are also used for variable-frequency drive applications and for
high power applications such as HVDC power transmissions.

At particularly high frequency application, modulation techniques are utilized


on inverters to control switches on these inverters. Some of the modulation
techniques that are widely used are Pulse Width Modulation (PWM), Sinusoidal
PWM, 3rd Harmonic PWM, to name a few. These modulation techniques vary from
each other in terms of specifications and performance but all modulation techniques
2

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.

With rapid development in the power electronics field, a new modulation


technique has been developed and it is known as Space Vector Modulation (SVM).
This technique has been widely discussed in journals and other literature sources and
SVM has been touted as a better modulation technique than other methods
particularly PWM in terms of linear modulation range, commutation and switching
losses and efficiency. It is also interesting to note that SVM is a digital based
modulation technique would fit into the rapid development of digital electronic
components and thus SVM would prove be easier to be implemented and would be
cheaper to be utilized.

1.2 Problem Statement

As mentioned earlier, there are many PWM techniques such as Sinusoidal


PWM, Hysterisis PWM, 3rd Harmonic PWM etc. that are widely used at the moment.
Table 1.1 shows the comparison between Sinusoidal PWM and SVM.

Sinusoidal PWM technique treats each modulating voltages as separate


identity and each modulating voltages are compared to the carrier signal. However,
using the SVM technique, all modulating voltages are combined (using vector
summation) into one reference voltage or a single unit which make things easier in
terms of interpretation and implementation, especially in digital systems. Moreover,
SVM would enable lesser commutation and switching losses, wider linear
modulation range and higher frequency.
3

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.

Table 1.1: Simple comparison between Sinusoidal PWM and SVM in


Sinusoidal PWM SVM
• Considers each modulating voltages • All 3 modulating signals are
as separate identity simultaneously taken into account
within 2D reference frame (Vd – Vq
axes)
• Compares high frequency triangular • Complex reference vector is
carrier with 3 sinusoidal reference processed as a single unit
signals (modulating signals)

1.3 Objectives of Project

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

Implementation of SVM using PIC micro-controller would involve


interpretation of inputs which includes magnitude and phase of the reference voltage,
VREF (vector summation of all three modulating voltages), the process of calculation
of relevant parameters based on theoretical formulas and lastly the generation and
display of respective output waveform pattern or output signal based on the inputs.

1.4 Scope of Project

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.

Table 1.2: Some Specifications of SVM Signal Generator


Properties Characteristics
Type of waveform Symmetrical Sequence
Sampling Frequency 10 to 20kHz
Modulation index Set as 1 throughout the whole project
Input Set in the program internally
5

1.5 Methodology

The methodology of this project is divided into 4 main sections, namely


literature review on SVM and PIC micro-controller, development of project
including hardware and software development, troubleshooting and verification
process and lastly the implementation results using the SVM signal generator
produced which employs PIC micro-controller.

1.5.1 Literature Review on SVM and PIC Micro-controller

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.

Besides, since micro-controller would be used, it would also be important to


acquire knowledge and information on the potential micro-controller (PIC) to be
used, such as the characteristics and instruction code of the micro-controller, the
troubleshooting equipments and related process, and so forth. All these are done by
understanding the data sheet of the micro-controller, attending workshops and
additional classes to gain hands-on experience on PIC micro-controllers as well as to
understand the advanced uses of the micro-controller that can be utilized for this
project.
6

1.5.2 Hardware and Software Development

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.

1.5.3 Troubleshooting and Verification Process

Usually it is anticipated that most of the problem and difficulties of the


project would occur in the software development part and thus, troubleshooting and
verification process has to be conducted throughout the whole project so as to ensure
a smooth journey for this project development. The troubleshooting part can be done
using debugger developed by PIC itself or using other techniques such as inspection
and testing of the PIC program employing self-written programs.
7

1.6 Thesis Outline

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.

2.1 Introduction to Space Vector Modulation

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.

Table 2.1: Comparison between SPWM and SVM

Sinusoidal Pulse Width Modulation Space Vector Modulation

Comparing high frequency triangular Taking all 3 modulating signals into


carrier signal with 3 sinusoidal account simultaneously within a 2D
reference signals (treated as separate reference frame (in d-q axis or complex
identity) form)
Unable to fully utilize available DC Increase utilization of DC supply
supply voltage voltage, 15% more than SPWM

More Total Harmonic Distortion Less Total Harmonic Distortion

Does not facilitate more advanced Enable more advanced vector control
vector control implementation implementation

Figure 2.1: Comparison of locus in terms of DC voltage utilization


between SVM and SPWM
10

2.2 Principles of SVM

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

Figure 2.2: 3 Phase Voltage Source Inverter (VSI)

Space Vector Modulation (SVM) refers to a special switching sequence


which is based on the upper switches of a 3 phase voltage source inverter (VSI).
Theoretically, SVM treats a sinusoidal voltage as a phasor or amplitude vector which
rotates at a constant angular frequency, ω. This amplitude vector is represented in d-q
plane where it denotes the real and imaginary axes. As SVM treats all 3 modulating
signals or voltages as one single unit, the vector summation of 3 modulating signals
or voltages are known as the reference voltage, VREF which is related to the
magnitude of output voltage of the eight switching topologies of a 3 phase VSI. Bear
in mind that the aim of SVM is to approximate the reference voltage vector, VREF
using the eight switching topologies which are shown in Figure 2.3.

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

anti-clockwise direction from one sector to another at a constant angular speed, ωt


for steady state operating condition. Another important note is that the time taken by
reference voltage vector to complete one revolution is equal to the fundamental
period of the output voltage.

Figure 2.3: 8 switching topologies of a 3 phase VSI

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


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

Figure 2.4: Representation of 8 switching topologies in hexagon form (or Space


Vector Hexagon) and interpretation of reference voltage into d-q plane

VREF

Figure 2.5: Graphs of 3 modulating voltages where reference voltage is shifted


from one sector to another
13

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

2.3 Algorithms of SVM

Symmetrical Alternating
Sequence Sequence

Left Aligned Bus Clamped


Sequence Sequence

Figure 2.6: Algorithms of output signals based on sector 1

Since the development of SVM technique, there have been various


suggestions on the algorithms of the output signal or the waveform for the switches
of 3 phase VSI. There are several aspects that need to be considered especially ease
of implementation and performance of the signal (i.e. THD and switching losses).
Therefore, different types of algorithms contribute different level of performance and
each algorithm or scheme is suitable for different operating condition.
15

According to Rakesh Parekh’s note on Space Vector Modulation for


Microchip Technology, there are several switching rules that have to be followed and
they are: (a) trajectory of reference voltage vector, VREF should be circular in shape,
(b) only one switching per state transition, (c) not more than three switchings in a
sampling period, Ts, and (d) the final state within a sampling period must be the
initial state within the next sampling period. These rules aid in limiting the number of
switching actions that would lead towards reduction in switching losses. Besides,
symmetry property could be maintained in waveforms at 3 phase VSI to achieve
lower THD.

In this section, we discuss briefly about the “Symmetrical Sequence”


algorithm which would be used in this project. Coincidentally, this algorithm has the
lowest THD among the four types of algorithms shown in Figure 2.6. As you can see
in Figure 2.7 below, there are 6 commutations in one sampling period, Ts. If
compared to the right aligned algorithm, both algorithms have 3 switch turn-ons and
3 switch turn-offs and thus both algorithms are expected to possess approximately
the same amount of switching losses.

000 100 110 111 111 110 100 000 000 100 110 111 111 110 100 000

S3

S2

S1

Ts Ts

Figure 2.7: Output signal based on Symmetrical Sequence algorithm in sector 1


16

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

Figure 2.8: Output patterns each sector based on symmetrical sequence


17

2.4 Operation of SVM

As shown in Figure 2.2, there are basically 2 zero voltage vectors


(represented by switching states 000 and 111) and 6 non-zero voltage vectors
(switching states other than 000 and 111). All these zero and non-zero voltage
vectors represent the hexagon representation as shown in Figure 2.3 (hexagon
representation). Synthesizing the reference voltage vector within the hexagon
representation or hexagon limit involves resolving the reference voltage vector into 2
components parallel to the adjacent non-zero voltage vectors. For example, based on
Figure 2.8, in sector 1, the reference voltage vector can be resolved into a component
parallel to V1 and another parallel to V2. Therefore, the angle, θ and magnitude of
the reference voltage vector can be obtained.

Figure 2.9: Synthesizing reference voltage vector in sector 1

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

generation of average output of VSI in a sampling period, Ts which is to be the same


as the average output of the reference voltage vector in the same period. As shown in
the previous paragraph, the approximation of reference voltage vector, VREF would
be based on the location of the reference voltage vector lies in or in other words
based on which sector the reference voltage vector lies in. It is also noteworthy that
the adjacent non-zero voltage vectors provide the required phase displacement while
the zero voltage vectors control the magnitude of the reference voltage, VREF.

2.5 Generation of SVM

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,

2 cos 0° 2 1


Va = VDC   = V DC  
3  sin 0°  3 0
(2.6)
2 cos 60°
Vb = V DC  
3  sin 60° 

Therefore, by substituting equations in (2.6),

cos α  2 1   T  2 cos 60°  Tb 


VREF ×   = VDC   ×  a  + VDC   ×  T  (2.7)
 sin α  3 0   Ts  3  sin 60 °   s 
where 0 ≤ α ≤ 60°

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.

3.1 Hardware Development and Implementation

3.1.1 Introduction to PIC micro-controllers

PIC is a family of Harvard architecture microcontrollers made by Microchip


Technology, derived from the PIC1650 originally developed by General Instrument's
Microelectronics Division. The name PIC was originally an acronym for
"Programmable Interface Controller".

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.

Microchip Technology has produced a range of micro-controllers with


different bits such as 8-bit micro-controller (i.e. PIC16, PIC17, PIC18), 16-bit micro-
controllers (i.e. PIC24) and 16-bit digital signal controllers (i.e. dsPIC30 and
dsPIC33F). Some of the PIC micro-controllers use flash memory and some can be
electronically erased. Different characteristics of micro-controllers cater to different
purposes as well.

3.1.2 Introduction to PIC16F876A

Figure 3.1: PIC16F876A

PIC16F876A is one of the 8-bit micro-controller produced by Microchip


Technology. This micro-controller is considered to be unique as it uses flash memory
as its program memory and thus it can be programmed again and again without using
ultra-violet to erase its program memory. It is also interesting to note that
PIC16F876A consumes low power supply and voltage which is approximately 5
volt. It is also fully static or non-volatile whereby program memory in PIC16F876A
would not be lost when the supply is taken off the micro-controller. Compared to
other 8-bit PIC micro-controllers (i.e. PIC16, PIC17), PIC16F876A has a relatively
22

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.

Table 3.1: Some features of PIC16F876A


Features Characteristics/Value
Architecture 8 bit
Program Memory Type Enhanced Flash
Kbytes 14
Data EEPROM 256
I/O 22
Max Speed (MHz) 20
Pin Count 28

3.1.3 Schematic of Hardware Design

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.

The schematic diagram was then drawn using an electrical engineering


software known as Multisim 8, which is commonly used to simulate electrical and
electronics circuits and capture these circuits to be shown on documents and others.
Figure 3.2 shows the process of drawing the schematic diagram of the interfacing
23

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.

Figure 3.2: Schematic diagram drawn and captured using Multisim 8

3.1.4 Description of Hardware Design

The implementation of SVM is based mainly on the PIC micro-controller


used, which is PIC16F876A. In the project, PIC16F876A would function as the
“brain” or central processing unit of the circuit and thus interfacing circuit is required
to ensure PIC16F876A function at its maximum capability. Interfacing circuit is built
with the addition of various supplementary components such as resistors, capacitors,
power supply and oscillator.

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

A switch is connected to MCLR (master clear) pin of the micro-controller to


enable micro-controller to be “reset” by switching the switch on. External oscillator
circuitry is also required in this project to generate device clock for instruction
execution with high speed capability which is important for this project. Therefore,
High Speed Crystal (HS) is chosen to establish oscillation at high frequency where
the crystal would be connected in between OSC1 and OSC2 pins of the micro-
controller.

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

Figure 3.3: Schematic diagram of project circuit using Multisim

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.

Figure 3.4: Hardware implementation of SVM signal generator using PIC


micro-controller on breadboard

3.2 Software Development and Implementation

In this section, PIC equivalent programming languages and compilers, and


the software design of the project would be discussed.

3.2.1 PIC Equivalent Programming Languages

In PIC micro-controllers, the main computer language used is assembly


language. Each PIC type has certain amount of instructions and has different types of
26

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.

3.2.2 PIC Equivalent Compilers and Related Tools

Figure 3.5: Microchip MPLAB IDE and PIC micro-controller programmer


developed by Cytron Technologies
27

The compiler that would be used in this project is known as MPLAB


Integrated Development Environment (IDE). MPLAB IDE is a software program
that runs on PC to provide a development environment for embedded microcontroller
design. Therefore, for processes involving programming such as writing, compiling,
troubleshooting, debugging etc., MPLAB IDE is the important software to use. There
are several equipments which are used together with the software for programming
purposes such as programmers and debuggers.

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.

3.2.3 MPLAB IDE and C Language

Figure 3.6: CCS C Compiler for PIC micro-controllers

In this project, MPLAB IDE would be the main programming software to


write, edit and insert or burn the written computer program into the PIC micro-
28

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

CCS C Compiler contains standard C operators and a huge variety of built-in


libraries that are specific to PIC registers. Therefore, it actually makes C language
accessible to the hardware side of the PIC micro-controller. However, note that
different C compilers have distinct C operators and built-in libraries. Some of its
features include wide range of integer types (1, 8, 16, 32 bit) and 32 bit floating
point, enabling bit arrays, fixed point decimal, possessing capability to create user
defined address spaces in memory device and so on.

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.

Figure 3.9: CCS C Compiler Help File Menu

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.

3.2.4 Software Design

Figure 3.10: Flow chart of program for SVM signal generator

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

Calculation of parameters would involve the use of floating point in the


program code and thus more memory space of the PIC16F876A would be used.
However, the input and output are all in digital form or binary form, which is either 1
or 0. Figure 3.10 would briefly explain the flow of the program in a simple manner.

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.

After that, interrupt would be activated to enable the calculation of


parameters. This would be followed by obtaining the output waveform or binary
code from a look-up table (assembly language) or an array (C language). With all
those ready, interrupt would be de-activated and output waveform would be
displayed based on the binary code and the values of parameters. The process would
be repeated when a new input is inserted into the program.

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

3.2.4.1 Variables and Arrays

The C language program writing process requires different variables and


functions. In this project, most of the variables are either taken from the main
mathematical equations as shown in Chapter 2 or others such as loop counters, input
and output variables and so on. Table 3.2 shows the list of variables declared and
used in the program of this project. All these variables would be described in their
respective C language functions in the next subtopics.

Table 3.2: List of variables used in the program of project


Purpose Name of variables Variables Type of variables
Time variables ts, ta, tb, t0, tmag Float numbers
Calculation of time

phase, phaset1,
variables

Phase variables phaset2, thetha, Float numbers


thetha1, thetha2
Modulation index modin Float numbers
Voltages variables vref, vdc Float numbers
Initial variables XX Float numbers
Rounding
up Job

result, integral,
Resulting variables Float numbers
integral1, integral2
End variables YY Integers
Sector identification i Integers
counters
Loop

Output display j Integers


Input counter h Integers

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

Figure 3.11: Output pattern for sector 1

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}

2 outta2[8] = {0b00000000, 0b00000010, 0b00000110,


0b00000111, 0b00000111, 0b00000110, 0b00000010, 0b00000000}

3 outta3[8] = {0b00000000, 0b00000010, 0b00000011,


0b00000111, 0b00000111, 0b00000011, 0b00000010, 0b00000000}

4 outta4[8] = {0b00000000, 0b00000001, 0b00000011,


0b00000111, 0b00000111, 0b00000011, 0b00000001, 0b00000000}

5 outta5[8] = {0b00000000, 0b00000001, 0b00000101,


0b00000111, 0b00000111, 0b00000101, 0b00000101, 0b00000000}
6 outta6[8] = {0b00000000, 0b00000100, 0b00000101,
0b00000111, 0b00000111, 0b00000101, 0b00000100, 0b00000000}
34

To describe further on arrays of the output pattern display, let us look at


Figure 3.11. Since port B (pin 0, 1 and 2) of micro-controller PIC16F876A are used,
only the first 3 bits (starting from LSB) of the 8 bit code would vary according to the
output pattern for each time column. This eventually means that switching states or
phases S2, S1 and S0 refer to pin 2, 1 and 0 for port B respectively. For example, for
time column ta of sector 1, the binary code for output of port B would be
“0b00000100”. Same could be said for time column tb, where the binary code would
be “0b00000110”. The binary code would then be synthesized repeatedly for other
time columns. Therefore, each sector has an array consisting of 8 binary codes for 8
time columns. Table 3.3 shows all the arrays for every sector of output pattern.

3.2.4.2 Library Functions

One of the main advantages of using C language for programming purposes


is the availability of various library functions. C language provides various library
functions especially in terms of mathematical equations and functions. However,
before these library functions are available for use, the C language program has to
add header files to access different library functions. For example, PIC16F876A
header or 16F876A.h is used to get access to main C language functions from the
CCS C Compiler, math header or math.h is used to have access to mathematical
functions and float header or float.h is used to enable the use of float numbers.

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]

Table 3.4: Description of modf() function


Syntax: result= modf (value, & integral)

Parameters: value and integral are floats


Returns: result is a float
Function: The modf function breaks the argument value into integral and
fractional parts, each of which has the same sign as the argument. It
stores the integral part as a float in the object integral.
Requires: math.h must be included
Examples: float result, integral;

result=modf(123.987,&integral);

// result is .987 and integral is 123.0000

Table 3.5: Description of sin() function


Syntax: val = sin (rad)

Parameters: rad is a float representing an angle in radians -2pi to 2pi. val is a


float with the range -1.0 to 1.0. Value is a float.
Returns: rad is a float representing an angle in radians -pi/2 to pi/2
val is a float with the range -1.0 to 1.0.
rad1 is a float representing an angle in radians 0 to pi
rad2 is a float representing an angle in radians -pi to pi
Result is a float
Functions: Returns the sine value of the parameter (measured in radians)
Requires: math.h must be included
Examples: float phase;
// Output one sine wave
for(phase=0; phase<2*3.141596; phase+=0.01)
set_analog_voltage( sin(phase)+1 );
36

Table 3.6: Description of output_b() function


Syntax: output_b (value)

Parameters: value is a 8 bit int


Returns: undefined
Functions: Output an entire byte to a port. The direction register is changed in
accordance with the last specified #USE *_IO directive.
Requires: Nothing
Examples: OUTPUT_B(0xf0);

Table 3.7: Description of delay_us() function


Syntax: delay_us (time)

Parameters: time - a variable 0-65535(int16) or a constant 0-65535


Returns: undefined
Functions: Creates code to perform a delay of the specified length. Time is
specified in microseconds. Shorter delays will be INLINE code and
longer delays and variable delays are calls to a function. This
function works by executing a precise number of instructions to
cause the requested delay. It does not use any timers. If interrupts
are enabled the time spent in an interrupt routine is not counted
toward the time.
The delay time may be longer than requested if an interrupt is
serviced during the delay. The time spent in the ISR does not count
toward the delay time.
Requires: #use delay

Examples: #use delay(clock=20000000)

do {
output_high(PIN_B0);
delay_us(duty);
output_low(PIN_B0);
delay_us(period-duty);
} while(TRUE);
37

3.2.4.3 Initialization

The initialization process is a process required to interface the computer


language program with the micro-controller. The main purpose is to activate the
required functions and important pins on the micro-controller as well as the I/O ports
to function either as an input or as an output. This process is vital so as to ensure the
output and input of the whole project on the PIC micro-controller. Based on the
scope of this project, the PIC micro-controller would only be initialized to have
outputs since the input will be internally (in the computer program itself) generated.

The process of initialization requires basic knowledge of the micro-controller


especially in C language since C is used in this project. As mentioned earlier, header
files such as 16F876A.h, math.h and float.h must be included in order to enable
important library functions, C commands and operations can be applied in the C
language program. Besides, important knowledge on the configuration bits of the
micro-controller must be applied so as to activate necessary configuration bits in the
project. Figure 3.12 shows part of the header files used in the project.

#include <16F876A.h>
#include <float.h>
#include <math.h>
#use delay(clock=20000000)
#fuses HS,NOWDT,NOPROTECT,PUT,NOWRT,BROWNOUT,NOLVP

Figure 3.12: Header files included in the C language program of project


38

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.

#define TRISA 0b00000000


#define TRISB 0b00000000
#define TRISC 0b00000000
#define Port_Ai 0b00000000 //Initial valua for Port A
#define Port_Bi 0b00000000 //Initial valua for Port B
#define Port_Ci 0b00000000 //Initial valua for Port C

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

3.2.4.4 Input Counter

Input counter is generally a counter involving the increment of phase from 0


to 360 degrees. This counter would repeat once it reaches 360 degrees. Note that the
phase represents the angle of the rotating VREF. In this project, the unit degrees would
39

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

Figure 3.14: Input Counter Output

The input counter graph as shown in Figure 3.14 is a graphical description of


a loop with counter of 0 to 360 degrees used to represent the input counter, since the
input to the program is not included in this project. Note that the period of each pulse
(of the output signal for each state S1, S2 and S3) can be estimated from the
fundamental period, Tf using the following relationship:

Tf
Pulse period, T p =
360
40

3.2.4.5 Sector Identification

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

For θ = 145 degrees (2.53 radians), let n be 1.


1
phaset1 = π − 2.53 = −1.48
3
1 −1
phaset2 = 2.53 −  π = 2.53
 3 
Then let n be 3.
3
phaset1 = π − 2.53 = 0.611
3
 3 −1
phaset2 = 2.53 −  π = 0.436
 3 

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;

if((phaset1 >=0) && (phaset2 >=0))


{
n = i;
}
}
}

Figure 3.16: Command for sector identification function, idsec()

3.2.4.6 Calculation of Time Variables

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;
}

Figure 3.17: Command of the time calculation function, tcal()

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

Figure 3.18: Sequence of time variables inserted into timema array

3.2.4.7 Rounding Up Job

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.

Figure 3.19: Flow chart of rounding up function

//Function to round up ta, tb and t0


void roundup()
{

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;
}
}
}

Figure 3.20: Command for roundup() function


46

//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;
}

Figure 3.21: Command for rdjob() function

3.2.4.8 Output Function

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

Figure 3.23: Flow chart for the output display function


50

//Function to transfer output from array to output port


void showout(){

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]);
}
}
}

Figure 3.24: Command for the process of output


51

CHAPTER 4

RESULTS AND DISCUSSION

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.

4.1 Implementation of Project

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.

Table 4.1: Initial Parameters for Calculation and Implementation Purposes


(High Frequency)
Parameters Value
Internal clock cycle 20 MHz
Fundamental Period 100 ms
Sampling time, frequency Ts = 100 µs, fs = 10000 Hz

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

Table 4.2: Initial Parameters for Calculation and Implementation Purposes


(Low Frequency)
Parameters Value
Internal clock cycle 20 MHz
Sampling time, frequency Ts = 200 ms, fs = 5 Hz

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

4.2 Results of Project

4.2.1 Results For High Frequency

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.

4.2.2 Results For Low 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.

Figure 4.1: Results obtained at high frequency of 10 kHz


55

Sector 1 Sector 2

Sector 3 Sector 4

Sector 5 Sector 6

Figure 4.2: Results taken at low frequency of 50 Hz


56

Line-to-Line Signal (S3 – S1) Line-to-Line Signal (S3 – S2)

Line-to-Line Signal (S2 – S1)

Figure 4.3: Line-to-line signal obtained on the oscilloscope at low frequency

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.

Since the algorithm of the output pattern is in symmetrical form as shown in


Figure 4.3, the line-to-line signal would show bipolar form (positive and negative
magnitudes) as output pattern for each phase based on each sector differs from each
other. This can be explained and verified using Figure 4.4, where both positive pulse
and negative pulse can be obtained while taking the line-to-line signal. The line-to-
line signal graph would enable us to obtain the fundamental period. Referring to
Figure 4.3, it can be seen that the period of the line-to-line signal is roughly 25 to 26
seconds. This period signifies the fundamental period, whereby it matches 100
samples with a sampling period of roughly 250 ms (100 × 250 ms = 25 s).

S3 S3

S1 S1

S3 – S1 S3 – S1

t0 ta tb t0 t0 tb ta t0 t0 ta tb t0 t0 tb ta t0

Positive Pulse Negative Pulse


Figure 4.4: Subtracting pulse of one phase with another

It is noteworthy that the concept of SVM is generally a combination of


SPWM and third harmonic injected to it. Even though such combination is done in
Third-Harmonic PWM, this concept still applies for SVM, whereby each phase
58

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.5 Waveforms and frequency response for one phase

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.

4.3 Discussion and Explanation

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.

This interrupt function is known to be a crucial part of the project because it


can halt the internal clock of the micro-controller and proceed with the calculation of
time variables while the internal clock is halted. Once this is done, the large time gap
between pulses can be eliminated. However, that was not the case as it failed to
function even after much discussion regarding this problem with some other experts
in application of this PIC micro-controller.

Since PIC micro-controllers are complicated devices, it usually takes a person


to fully understand its functions and applications a lot of time to do that. As my
knowledge on PIC micro-controllers is not deep enough, I can still handle a lot of
basic aspects of PIC micro-controllers. Familiarity with complex parts of a PIC
micro-controller might be the key towards successfully achieving the overall
objectives of this project. Because of its complexity as well, problems in PIC micro-
controllers sometimes are hard to detect, especially when it involves both hardware
and software problems.
61

CHAPTER 5

CONCLUSION AND SUGGESTIONS FOR FURTHER RESEARCH

5.1 Summary

The rapid development of high switching frequency power electronics


devices in the past decade leads towards wider application of voltage source inverters
(VSI) in AC power generation. Therefore, this prompts the need for a modulation
technique with less THD, less switching and commutation losses, and wider linear
modulation range. SVM provides a better technique compared to the more
commonly used Pulse Width Modulation (PWM), Sinusoidal PWM and so fourth.

With the increasing usage of micro-controllers in electrical engineering, this


project presents another solution to implement SVM, by using PIC micro-controller
to generate SVM signal. Space Vector Modulation (SVM) refers to a special
switching sequence which is based on the upper switches of a 3 phase voltage source
inverter (VSI). The aim of SVM is to approximate the reference voltage vector, VREF
using the eight switching topologies of a VSI.

Since PIC micro-controller is used, hardware and software development are


involved and the crucial section of the project focuses on the software development.
In the circuit, PIC micro-controller acts as the “brain” of the system by obtaining
input, processing them and then displaying the correct output pattern according to the
62

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.

5.2 Conclusion and Suggestions

In conclusion, the development and implementation of micro-controller-based


SVM signal generator has been partially successful as the output pattern at high
frequency had a much larger time gap/period due to certain problems that occurred. The
reason is that there were only a few minor problems to be solved, particularly in the
software part of the project, in order to achieve all objectives of the project.

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.

Besides, there is a possibility that other micro-controllers can be used to


implement SVM to generate SVM signal in other various sequence (other than
symmetrical sequence). However, this has to be done only if one fully understands the
features and characteristics of the micro-controller in order to avoid unnecessary
problems such as what have been encountered in this project. Larger memory and higher
frequency range are some of the features that can be taken into consideration for
choosing the suitable micro-controller to be used in such SVM projects.
63

REFERENCES

1. CCS, CCS C Compiler v.4 Help File. Custom Computer Services Incorporated,
2007.

2. J.F. Moynihan, M.G.Egan, J.M.D Murphy, Theoretical Spectra of Space-Vector


Modulated Waveforms, IEE Proc.-Electr. Power Appl., Vol. 145, No. 1, January
1998.

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

4. L. Zhang, C. Wathanasarn, F. Hardan, An Efficient Microprocessor-Based Pulse-


Width Modulator using Space Vector Modulation Strategy, IEEE, pp.91-96, 1994

5. Microchip, PIC16F87XA Data Sheet: 28/40/44 - Pin Enhanced Flash


Microcontrollers. Microchip Technology Inc. 2003.

6. Muhammad H. Rashid, Power Electronics: Circuits, Devices and Applications Third


Edition. Prentice Hall

7. NEC, 78K0 Application Note: An Introduction to Space Vector Modulation using


NEC’s 8-bit Motor Control Microcontrollers. NEC Corporation, 2004.
64

8. Ned Mohan, Tore M Undeland, William P Robbins, Power electronics : converters,


applications, and design 2nd Edition.New York : John Wiley & Sons, 1995

9. Parekh, Rakesh. AN955 Application Note: VF Control of 3-Phase Induction Motor


Using Space Vector Modulation. Microchip Technology, 2005.

10. STMicroelectronics, AN2154 Application Note: Space Vector Modulation Using 8-


Bit ST7FMC Microcontroller AND AK-ST7FMC Starter Kit. STMicroelectronics
Worldwide. 2005.

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

#define TRISA 0b00000000


#define TRISB 0b00000000
#define TRISC 0b00000000
#define Port_Ai 0b00000000 //Initial valua for Port A
#define Port_Bi 0b00000000 //Initial valua for Port B
#define Port_Ci 0b00000000 //Initial valua for Port C

typedef struct {
int1 bit0;
int1 bit1;
int1 bit2;
int1 bit3;
int1 bit4;
int1 bit5;
int1 bit6;
int1 bit7;
} flags;

//Important time variables


float ts, ta, tb, t0, tmag; //time related variable

//Important phase variables


float phase, phaset1; //to identify sector number
float phaset2, thetha, thetha1, thetha2; //to calculate related time variables
float modin; //modulation index
float ZZ; //to convert angles larger than 360 degrees into the scale of 0 to 360 degrees

//Important voltage related variables


float vref, vdc; //to calculate modulation index

//Other variables
int8 i, j, h; //counter
float nsamp, result1; //condition for one complete cycle
int8 n; //sector number

//Variables for Rounding up Process


float result, integral, integral1, XX; // variables for rounding up process
int8 YY, integral2;
float testa1;

//Interrupt Bit
flags sys01;
#define flg_10ms sys01.bit0

//Arrays of Outputs of Each Sector (1 to 6)


int8
outta1[8]={0b00000000,0b00000100,0b00000110,0b00000111,0b00000111,0b00000110,0b00000100,
0b00000000}; //test mar
int8
outta2[8]={0b00000000,0b00000010,0b00000110,0b00000111,0b00000111,0b00000110,0b00000010,
0b00000000}; //test mar
67

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);
}

//Function to transfer output from array to output port


void showout(){

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]);
}
}

//Function to round up ta, tb and t0


void roundup()
{

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 identifying sector number


void idsec()
{
for(i=1;i<=6;i++)
{
phaset1 = i*3.142/3;
phaset1 = phaset1 - phase;
phaset2 = phase - (i - 1)*3.142/3;

if((phaset1 >=0) && (phaset2 >=0))


{
n = i;
}
}
}

//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;
}

//Function to obtain input details


void in_put()
{
vdc = 10;
vref = 10;
//fundamental frequency of 10 Hz (100 samples)
phase = 2*3.142*h*0.01;

// Calculation of time ta, tb, ts and t0


69

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++;

} while (h < integral2);

goto Mainloop;

Appendix A: Source code of program of this project


70

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

49 3.079 3 1.36E-06 1.8E-05 1.53E-05


50 3.142 4 1.88E-05 9.61E-21 1.56E-05
51 3.204 4 1.8E-05 1.36E-06 1.53E-05
52 3.267 4 1.72E-05 2.71E-06 1.5E-05
53 3.33 4 1.64E-05 4.06E-06 1.48E-05
54 3.393 4 1.55E-05 5.38E-06 1.46E-05
55 3.456 4 1.45E-05 6.69E-06 1.44E-05
56 3.519 4 1.34E-05 7.97E-06 1.43E-05
57 3.581 4 1.24E-05 9.22E-06 1.42E-05
58 3.644 4 1.12E-05 1.04E-05 1.42E-05
59 3.707 4 1E-05 1.16E-05 1.42E-05
60 3.77 4 8.81E-06 1.27E-05 1.42E-05
61 3.833 4 7.55E-06 1.38E-05 1.43E-05
62 3.896 4 6.26E-06 1.48E-05 1.45E-05
63 3.958 4 4.94E-06 1.58E-05 1.46E-05
64 4.021 4 3.61E-06 1.67E-05 1.49E-05
65 4.084 4 2.26E-06 1.75E-05 1.51E-05
66 4.147 4 9.07E-07 1.83E-05 1.54E-05
67 4.21 5 1.85E-05 4.53E-07 1.55E-05
68 4.273 5 1.78E-05 1.81E-06 1.52E-05
69 4.335 5 1.7E-05 3.16E-06 1.49E-05
70 4.398 5 1.61E-05 4.5E-06 1.47E-05
71 4.461 5 1.51E-05 5.82E-06 1.45E-05
72 4.524 5 1.41E-05 7.12E-06 1.44E-05
73 4.587 5 1.31E-05 8.39E-06 1.43E-05
74 4.65 5 1.2E-05 9.63E-06 1.42E-05
75 4.712 5 1.08E-05 1.08E-05 1.42E-05
76 4.775 5 9.63E-06 1.2E-05 1.42E-05
77 4.838 5 8.39E-06 1.31E-05 1.43E-05
78 4.901 5 7.12E-06 1.41E-05 1.44E-05
79 4.964 5 5.82E-06 1.51E-05 1.45E-05
80 5.027 5 4.5E-06 1.61E-05 1.47E-05
81 5.089 5 3.16E-06 1.7E-05 1.49E-05
82 5.152 5 1.81E-06 1.78E-05 1.52E-05
83 5.215 5 4.53E-07 1.85E-05 1.55E-05
84 5.278 6 1.83E-05 9.07E-07 1.54E-05
85 5.341 6 1.75E-05 2.26E-06 1.51E-05
86 5.404 6 1.67E-05 3.61E-06 1.49E-05
87 5.466 6 1.58E-05 4.94E-06 1.46E-05
88 5.529 6 1.48E-05 6.26E-06 1.45E-05
89 5.592 6 1.38E-05 7.55E-06 1.43E-05
90 5.655 6 1.27E-05 8.81E-06 1.42E-05
91 5.718 6 1.16E-05 1E-05 1.42E-05
92 5.781 6 1.04E-05 1.12E-05 1.42E-05
93 5.843 6 9.22E-06 1.24E-05 1.42E-05
94 5.906 6 7.97E-06 1.34E-05 1.43E-05
95 5.969 6 6.69E-06 1.45E-05 1.44E-05
96 6.032 6 5.38E-06 1.55E-05 1.46E-05
97 6.095 6 4.06E-06 1.64E-05 1.48E-05
98 6.158 6 2.71E-06 1.72E-05 1.5E-05
73

99 6.22 6 1.36E-06 1.8E-05 1.53E-05


100 6.283 1 1.88E-05 1.39E-20 1.56E-05

Appendix B: Calculation of time variables using Microsoft Excel


74

APPENDIX C
75
76
77
78
79
80
81
82
83
84
85
86

Appendix C: Part of Data Sheet of PIC16F87

You might also like