Professional Documents
Culture Documents
by
S. M. Mohaiminul Islam
ID: 0520145
by
S. M. Mohaiminul Islam
ID: 0520145
This report represents generation of three phase sinusoidal PWM (Pulse Width
signal with variable frequency. When the pulse width of a signal is changed
according to the amplitude of a sine wave is called Sinusoidal PWM signals. The
frequency will be varied depending on the pick value of PWM time base timer. Here
the pick value of PWM time base timer will be depending on ADC (Analog to Digital
Conversion) value. The ADC output is 10-bit. The PWM module also generates Dead
time. The output will be six PWM signals; three signals are in independent mode and
iii
To my parents
iv
ACKNOWLEDGMENTS
valuable suggestions, guidance and constant support throughout this project. I am also
grateful to Mr. Gazi Mohammad Sharif and Khaled Mahmud Sujan for various
We wish to express our parents and university for providing all kinds of financial
Finally, we would like to thank my class mates, particularly Hasan Mahmood and Mr.
v
TABLE OF CONTENTS
Page
LIST OF TABLES…….……………………….……………………………………..ix
LIST OF FIGURES….………………………………………………………………...x
CHAPTER
1 GENERAL INTRODUCTION………………………………………………..... 1
1.1. Overview…………………………………………………………………. 1
1.2. Background……………………………………………………………… 3
1.3. Objective…………………………………………………………………. 3
MODULE OF PIC18F4431…………………………………………………...... 5
2.1. Introduction……………………………………………………………... 5
2.2. PWM…………………………………………………………………….. 5
vi
2.4. Generation Method of Sinusoidal PWM Waveform…………………… 16
vii
3.1. Introduction……………………………………………………………… 39
4.3. ADC……………………………………………………………………….. 62
5.1. Conclusion………………………………………………………………. 66
REFERENCES…………………………………………………………………....... 67
viii
APPENDIX
BY MATLAB………………………………………………………………….. 95
ix
LIST OF TABLES
Table Page
x
LIST OF FIGURES
Figure Page
Source Inverter………………………………………………… 2
sampling………………………………………………………. 10
Complementary Mode………………………………………… 19
Mode…………………………………………………………… 19
2.14 Dead Time Control Unit Block Diagram for One PWM Output
Pair…………………………………………………………… 36
xi
2.15 Dead Time Insertion for Complementary PWM……………… 37
4.5 Simulation result of PWM signal which have also a dead time. 60
Signals…………………………………………………………. 63
4.13 PWM2-PWM3………………………………………………… 65
xii
CHAPTER 1
GENERAL INTRODUCTION
1.1. Overview
In many Instant Power Supply (IPS) or Uninterrupted Power Supply (UPS) use
which will not impact any other communication device and which is following IEEE
rules. Variable Frequency (VF) control using Sine PWM is implemented using for
requirements [8]. The SPWM (Sine PWM) is algorithm is unable to fully utilize the
available DC bus supply voltage to the Voltage Source Inverter (VSI). The generated
line-to-line voltage is less than 90% of VDC in the linear operating region. And this
algorithm gives more Total Harmonic Distortion due to the use of Sine PWM [7], [8],
[12].
The state of the art in motor control provides an adjustable voltage and frequency
to the terminals of the motor through a pulse width modulated voltage source inverter
drive. As the Power devices change switching states, a dead time exists. Although is
short, it causes deviations from the desired fundamental output voltage. While each
deviation does not appreciably affect the fundamental voltage, the accumulated
and torque pulsations. To compensate for the dead time in PWM signals, the industry
2
has investigated this problem and has tried various methods of correction. And also in
Induction motors are the most widely used motors for appliances, industrial
control, and automation; hence, they are often called the workhorse of the motion
industry. They are robust, reliable, and durable. When power is supplied to an
However, many applications need variable speed operations. For example, mechanical
gear systems were used to obtain variable speed. These electronics not only control
the motor’s speed but can improve the motor’s dynamic and steady state
consumption and noise generation of the motor. Variable Frequency (V/F) control can
costly digital signal processors (DSPs) [10]. In Figure 1. 1. showing that the block
implemented.
Inverter [8].
3
1.2. Background
Before 2009, In Bangladesh for generation PWM signal uses the Microcontroller
difficult because there are only three Capture/Compare/PWM modules. For this
reason one is to goes for comparing the value of TIMER2 and what will be the highest
value of TIMER2, and second, third comparing is going for compare the value of
TIMER2 and the other sinusoidal sampling value. For this reason, In PIC16F877A
microcontroller can generate only 2 phase PWM signals. But in the means time world
is going so fast. In 2004, the Microchip released the PIC18F4431 microcontroller for
controlling 3-phase AC Induction motors which were fulfilling our objectives of the
module can generate 8 PWM signals. And our objective is to generate 3 phase PWM
signal for controlling the AC Induction Motor. For controlling speed of the AC
Induction Motor we can make the electric vehicle. And also if we want to control the
3-phase AC Induction Motor we need 3-phase Inverter Bridge. So, if we want to make
the 3-phase Inverter Bridge we need 6 MOSFETs. For 6 MOSFETS we need 6 PWM
pulses. So, we can easily generate the 6 PWM signals using by single microcontroller
1.3. Objective
The main objective of the project is to generate the 3-phase Sinusoidal PWM
(Pulse Width Modulation) signal with variable frequency by using low cost
microcontroller.
4
1.4. Outline of Project
This project divided in to three main chapters. In the second chapter the
theoretical background of the PWM and PCPWM (Power Controlled PWM) module
for PIC18F4431 microcontroller. And how can we generate the PWM signal and
Dead time.
Conversion) module and the process of conversion Analog to Digital signal. And the
next chapter has results and discussion of our project work. In that chapter we have
showed that how can we generate 120 sampling value of Sinusoidal wave using by
MATLAB software and Simulation result of PWM (Pulse Width Modulation) signal
have showed that the practical result which I have taken from storage oscilloscope.
2.1. Introduction
controlled. The main advantage of using microprocessor is that it reduces the complex
control hardware where the control functions can be changed as many times as it is
the 3-phase PWM pulses and implementation of the controller strategy. The hardware
sufficient to fulfill the requirements of generating three phases PWM signal. The
2.2. PWM
performed on “raw” voltage and current waveforms to shape their spectra in a way
beneficial to the application under consideration. Spectra shaping typically mean the
creation of a “dead band” between wanted and unwanted spectral components. For a
component of the PWM waveform. Higher switching frequency causes greater losses
and stresses on the associated switching devices and therefore reduces the life time of
a considerable research effort has gone into minimize those disadvantages. As a result
several specific PWM techniques have been developed. Three of them related to this
Figure 2. 1.
7
switching instants. The points of intersection of these two waves determine the instant
representation of the pulse width only can be solved using Bessel function series or
numerical techniques.
Equation2. 2:
Carrier frequency f
Modulation ratio = = c
Modulating frequency f m
Where, Vp carrier and V p mod represent the amplitudes, f c and f m represents the
Regular sample PWM inverter control was first proposed in 1975. It is recognized to
Two types of modulation, ‘symmetric’ and ‘asymmetric’ are possible. They are
each pulse are determined using two samples of the modulating wave, and therefore
sample is used to determine the pulse width, and therefore both edges of the pulse
modulated equally. The generation of single pulse, using the symmetric regular-
Symmetrical sampling
Asymmetrical sampling
The symmetrical PWM technique, which has been implemented in this work,
amplitude modulated version of the modulating signal b , which, when compared with
the carrier signal c , defines the point of intersection used to determine the switching
instants T2 and T3 of the width modulated pulse d . As a result of this process, the
modulating wave has constant amplitude while each sample is being taken.
[9]
11
Consequently the widths of the pulses are proportional to the amplitude of the
characteristic of regular sampling that the sampling positions and sampled values can
be defined unambiguously, such that the pulses produced are predictable both in
width and position. It should be noted that this is not the case in the natural-sample
process. Because of this ability to define precisely the pulse configuration, it is now
possible to derive a simple trigonometric function to calculate the pulse widths. This
modulation index and ω m represents the angular frequency, then width of a pulse t wp
Equation2. 3:
t pw =
T
{1 + M sin (ω m T1 )}
2
This improved PWM technique using 3rd harmonic injection is explained with the aid
derivation of switching points, the resulting AC and DC term gains, the frequency
spectra, the harmonic distortion, and finally, the degree of difficulty of hardware
sinusoidal PWM technique. In the third harmonic injection method the modulating
Equation2. 4:
This equation shows that 17 percent third harmonic component is added to the
furthers the frequency spectra of the AC term and DC term waveforms. The analytical
Equation2. 5:
It should be noted that the injection of 3rd and 9th harmonics will not affect the quality
of the output voltage, because the output of the three-phase inverter does not contain
14
triplen harmonics as shown in Appendix A. The hardware implementation of this
The PWM generation and the control strategy is performed by a microcontroller, the
PIC18F4431 from Microchip [6]. The block diagram that describes the main features
of the chip is shown in Figure 2. 1. On chip peripherals such as Timers, High Speed
The main features of PIC18F4431 and on-chip peripherals are given as follows [6]:
• 34 Interrupt sources.
• 4 Timers.
• 2 Capture/Compare/PWM modules.
Interface).
• POR, BOR, RESET Instruction, Stack Full, Stack Underflow (PWRT, OST),
• 75 Instructions set.
PCPWM Module means Power Control PWM module. The Power Control PWM
modulated (PWM) outputs for use in the control of motor controllers and power
17
conversion applications. In particular, the following power and motion control
• Up to eight PWM I/O pins with four duty cycle generators. Pins can be paired
example, BLDC.
• PWM outputs disable feature sets PWM outputs to their inactive state when in
Debug mode.
18
The Power Control PWM module supports four PWM generators and eight channels
2. 6. Figure 2. 7 and Figure 2. 8 show how the module hardware is configured for
each PWM output pair for the complementary and independent output modes.
Mode1
Figure 2. 8: PWM Module Block Diagram, One Output Pair, Independent Mode
This module contains four duty-cycle generators, numbered 0 through 3. The module
has eight PWM output pins, numbered 0 through 7. The eight PWM outputs are
1
In the complementary mode, the even channel cannot be forced active by a fault or override event
when the odd channel is active. The even channel is always the complement of the odd channel and is
inactive, with dead time inserted, before the odd channel is driven to its active state.
20
grouped into output pairs of even and odd numbered outputs. In complementary
modes, the even PWM pins must always be the complement of the corresponding odd
PWM pin. For example, PWM0 will be the complement of PWM1, PWM2 will be the
complement of PWM3, and so on. The dead time generator inserts an “off” period
called “dead time” between the going off of one pin to the going on of the
complementary pin of the paired pins. This is to prevent damage to the power
The time base for the PWM module is provided by its own 12-bit timer, which also
There are also 14 registers that are configured as seven register pairs of 16 bits. These
are used for the configuration values of specific features. They are:
21
• PWM Time Base Registers (PTMRH and PTMRL)
The PWM module supports several modes of operation that are beneficial for specific
subsequent sections.
The PWM module is composed of several functional blocks. The operation of each is
• PWM Period
The PWM time base is provided by a 12-bit timer with prescaler and postscaler
functions. A simplified block diagram of the PWM time base is shown in Figure 2. 9.
The PWM time base is configured through the PTCON0 and PTCON1 registers. The
time base is enabled or disabled by respectively setting or clearing the PTEN bit in the
PTCON1 register.2
The PWM time base can be for four different modes of operation:
• Single-shot mode
These four modes are selected by the PTMOD1:PTMOD0 bits in the PTCON0
register. The Free Running mode produces edge-aligned PWM generation. The
mode allows the PWM module to support pulse control of certain electronically
2
The PTMR register pair (PTMRL:PTMRH) is not cleared when the PTEN bit is cleared in software.
23
bit 7 bit 0
bit 7-4 PTOPS3:PTOPS0: PWM Time Base Output Postscale Select bits
bit 3-2 PTCKPS1: PTCKPS0: PWM Time Base Input Clock Prescale Select bits
Fosc
00 =PWM time base input clock is (1:1 prescale)
4
Fosc
01 =PWM time base input clock is (1:4 prescale)
16
Fosc
10 =PWM time base input clock is (1:16 prescale)
64
Fosc
11 =PWM time base input clock is (1:64 prescale)
256
Legend:
cleared
25
PTCON1: PWM Timer Control Register 1
R/W R U U U U U U
PTEN PTDIR - - - - - -
bit 7 bit 0
Legend:
POR cleared
bit 7 bit 0
111 =All odd PWM I/O pins enabled for PWM output.
100 =PWM0, PWM1, PWM2, PWM3, PWM4 and PWM5 pins enabled for
PWM output.
011 =PWM0, PWM1, PWM2 and PWM3 I/O pins enabled for PWM output.
000 =PWM module disabled. All PWM I/O pins are general purpose I/O.
For PMOD0:
For PMOD1:
For PMOD2:
For PMOD3:
Legend:
3
Reset condition of PWMEN bits depends on PWMPIN device configuration bit.
4
When PWMEN:PWMEN0 = 101 then PWM[7:0] outputs are enabled. When PWMEN:PWMEN0 =
111 then PWM outputs 1, 3, 5 and 7 are enabled.
27
-n = Value at POR ‘1’ = bit is set ‘0’ = bit is cleared x = bit is unknown
bit 7 bit 0
bit 7-4 SEVOPS3: SEVOPS0: PWM Special Event Trigger Output Postscale Select
bits
1 =A special event trigger will occur when the PWM time base is counting
downwards.
0 =A special event trigger will occur when the PWM time base is counting
upwards.
1 = Updates from duty cycle and period buffer registers are disabled.
0 = Updates from duty cycle and period buffer registers are enabled.
Legend:
cleared
In the Free Running mode, the PWM time base (PTMRL and PTMRH) will be
begin counting upwards until the value in the Time Base Period Register, PTPER
(PTPER and PTPERH), is matched. The PTMR registers will be reset on the
following input clock edge and the time base will continue counting upwards as long
Fosc
The input clock to PTMR ( ) has prescaler options of 1:1, 1:4, 1:16 or 1:64.
4
These are selected by control bits PTCKPS<1:0> in the PTCON0 register. The
5
The PTMR register is not cleared when PTCON is written.
29
Table.2. 1 shows the minimum PWM frequencies that can be generated with the
PWM time base and the prescaler. An operating frequency of 40 MHz ( FCYC = 10
MHz) and PTPER = 0 × FFF is assumed in the table. The PWM module must be
capable of generating PWM signals at the line frequency (50 Hz or 60 Hz) for certain
Minimum PWM Frequencies vs. Prescaler Value for FCYC = 10 MIPS, (PTPER =
0FFFh)
aligned aligned
1:16 153 Hz 76 Hz
1:64 38 Hz 19 Hz
The match output of PTMR can optionally be post-scaled through a 4-bit post-
scaled through a 4-bit postscaler (which gives a 1:1 to 1:16 scaling inclusive) to
generate an interrupt. The postscaler counter is cleared when any of the following
occurs:
The PWM timer can generate interrupts based on the modes of operation
When the PWM time base is in the Free Running mode (PTMOD<1:0> =00),
an interrupt event is generated each time a match with the PTPER register occurs. The
Using a postscaler selection other than 1:1 will reduce the frequency of
The PWM period is defined by the PTPER register pair (PTPERL and
PTPERH). The PWM period has 12-bit resolution by combining 4 LSBs of PTPERH
and 8-bits of PTPERL. PTPER is a double-buffered register used to set the counting
The PTPER buffer contents are loaded into the PTPER register at the following times:
• Free Running and Single-shot: when the PTMR register is reset to zero after a
Figure 2. 10 indicate the times when the contents of the PTPER buffer are loaded into
Figure 2. 10: PWM Period Buffer Updates in Free Running Count Mode [6].
TPWM =
(PTPER + 1)
Fosc /( PTMRPS / 4)
(PTPER + 1) × PTMRPS
TPWM =
Fosc / 4
1
PWM frequency =
PWM period
The maximum resolution (in bits) for a given device oscillator and PWM frequency
⎛F /4⎞
log⎜⎜ osc ⎟⎟
Re solution = ⎝ FPWM ⎠
log(2 )
32
2.4.1.10. PWM Duty Cycle
PWM duty cycle is defined by PDCx (PDCxL and PDCxH) registers. There
are a total of 4 PWM Duty Cycle registers for 4 pairs of PWM channels. The Duty
Cycle registers have 14-bit resolution by combining 6 LSbs of PDCxH with the 8 bits
of PDCxL. PDCx is a double-buffered register used to set the counting period for the
There are four 14-bit special function registers used to specify duty cycle values
The value in each Duty Cycle register determines the amount of time that the
PWM output is in the active state. The upper 12 bits of PDCn hold the actual duty
cycle value from PTMRH/L<11:0>, while the lower 2 bits control which internal Q-
clock the duty cycle match occurs. This 2-bit value is decoded form the Q-clocks as
6
When prescaler is not 1:1 (PTCKPS 00), the duty cycle match occurs at Q1 clock of the instruction
cycle when the PTMR and PDC match occurs.
33
Each compare unit has logic that allows override of the PWM signals. This logic also
ensures that the PWM signals will complement each other (with dead time insertion)
The four PWM Duty Cycle registers are double-buffered to allow glitches
updates of the PWM outputs. For each duty cycle block, there is a Duty Cycle Buffer
register that is accessible by the user and a second Duty Cycle register that holds the
In edge-aligned PWM output mode, a new duty cycle value will be updated
whenever a PTMR match with the PTPER register occurs and PTMR is reset as
shown in Figure 2. 12. Also the contents of the duty cycle buffers are automatically
loaded into the Duty Cycle registers when the PWM time base is disabled (PTEN = 0)
[6].
34
power switches in half bridge configuration as shown in Figure 2. 13. This inverter
power switch pair is fed by a complementary PWM signal. Dead time may be
optionally inserted during device switching where both outputs are inactive for a short
period. In Complementary mode, the duty cycle comparison units are assigned to the
PWM0/2/4/6 are the complemented outputs. When using the PWMs to control the
half bridge, the odd number PWMs can be used to control the upper power switch and
The Complementary mode is selected for each PWM I/O pin by clearing the
appropriate PMODx bit in the PWMCON0 register. The PWM I/O pins are set to
2.4.1.14. Dead Time Generators
mode to control the upper and lower switches of a half-bridge, a dead time insertion is
highly recommended. The dead time insertion keeps both outputs in inactive state for
a brief time. This avoids any overlap in the switching during the state change of the
amount of time must be provided between the turn-off event of one PWM output in a
36
complementary pair and the turn-on event of the other transistor. The PWM module
allows dead time to be programmed [6]. For a result it reduces a cost and complex
circuit. In previously for creating dead time it take time and cost but for PIC18F4431
Each complementary output pair for the PWM module has a 6-bit down
counter used to produce the dead time insertion. As shown in Figure 2. 14, each dead
time unit has a rising and falling edge detector connected to the duty cycle
comparison output. The dead time is loaded into the timer on the detected PWM edge
event. Depending on whether the edge is rising or falling, one of the transitions on the
complementary outputs is delayed until the timer counts down to zero. A timing
diagram indicating the dead time insertion for one pair of PWM outputs is in Figure 2.
15.
Figure 2. 14: Dead Time Control Unit Block Diagram for One PWM Output Pair
[6].
37
bit 7 bit 0
Fosc
11 =Clock source for Dead Time Unit is .
16
Fosc
10 = Clock source for Dead Time Unit is .
8
Fosc
01 = Clock source for Dead Time Unit is .
4
Fosc
00 = Clock source for Dead Time Unit is .
2
bit 5-0 DT5: DT0: Unsigned 6-bit dead time value bits for Dead Time Unit.
Legend:
-n = Value at POR ‘1’ = bit is set ‘0’ = bit is cleared x = bit is unknown
The actual dead time is calculated from the DTCON register as follows [6]:
38
Equation2. 9: Actual dead time
3.1. Introduction
During the past two decades, the rapid evolution of digital integrated circuit
technologies has led to ever more sophisticated signal processing systems. These
electronics, and telecommunications (terrestrial and satellite). One of the keys to the
for sampling rates of approximately 100 million samples per second (Ms/s) [6].
HSADC means (High Speed Analog to Digital Conversion). But in PIC18F4431 has
acquisition time [4]. This microcontroller can give us our expected result.
40
3.2. Generation Method of ADC
control, sensor interfacing, data acquisition and process control. In many cases, these
features will reduce the software overhead associated with standard A/D modules.
The A/D channels are grouped into four sets of 2 or 3 channels. AN0, AN4 and
AN8 are in Group A, AN1 and AN5 are in Group B, AN2 and AN6 are in Group C
and AN3 and AN7 are in Group D. The selected channel in each group is selected by
The analog voltage reference is software selectable to either the device’s positive
and negative analog supply voltage (AVDD and AVSS), or the voltage level on the
41
combination of supply and external sources. Register ADCON1 controls the voltage
Each port associated with the A/D converter can individually be configured as
an analog input or digital I/O using the ANSEL0 and ANSEL1 registers. The
ADRESH and ADRESL registers contain the value in the result buffer pointed to by
ADPNT<1:0> (ADCON1<1:0>). The result buffer is a 4-deep circular buffer that has
an empty status bit, BEMT (ADCON1<3>, and an overflow status bit BOVFL
(ADCON1<2>) [6].
42
bit 7 bit 0
If ACSCH = 1:
43
11 = Simultaneous Mode2 (STNM2). Two samples are taken simultaneously:
1= A/D Conversion cycle in progress. Setting this bit starts the A/D conversion
Continuous Loop mode is enabled (ACONV = 1), this bit remains set after the
1 = A/D converter module is enabled (after brief power-up delay, starts continuous
sampling)
Legend:
-n = Value at POR ‘1’ = bit is set ‘0’ = bit is cleared x = bit is unknown
44
ADCON1: A/D Control Register 1
bit 7 bit 0
bit 7-6 VCFG<1:0>: A/D VREF+ and A/D VREF− Source Selection bits
00 = VREF+ = AVDD , VREF− = AVss , (AN2 and AN3 are Analog inputs or
Digital I/O)
Digital I/O)
Digital I/O)
1 = FIFO is enabled
0 = FIFO is disabled
1 = FIFO is empty
0= FIFO is not empty (at least one of four locations has unread A/D result data)
1= A/D result has overwritten a buffer location that has unread data
45
00 = Buffer address 0
01 = Buffer address 1
10 = Buffer address 2
11 = Buffer address 3
Legend:
-n = Value at POR ‘1’ = bit is set ‘0’ = bit is cleared x = bit is unknown
bit 7 bit 0
1 = Right justified
0 = Left justified
0001 = 2 TAD
0010 = 4 TAD
0011 = 6 TAD
0100 = 8 TAD
0101 = 10 TAD
0110 = 12 TAD
0111 = 16 TAD
1000 = 20 TAD
1001 = 24 TAD
46
1010 = 28 TAD
1011 = 32 TAD
1100 = 36 TAD
1101 = 40 TAD
1110 = 48 TAD
1111 = 64 TAD
000 = FOSC/2
001 = FOSC/8
010 = FOSC/32
011 = FRC/4
100 = FOSC/4
101 = FOSC/16
110 = FOSC/64
Legend:
-n = Value at POR ‘1’ = bit is set ‘0’ = bit is cleared x = bit is unknown
bit 7 bit 0
bit 7-6 ADRS<1:0>: A/D Result Buffer Depth Interrupt Select Control bits for
1
IF the A/D clock source is selected as RC, a time of TCY is added before sampling/ conversions starts.
2
Due to an increase frequency of the internal A/D RC oscillator, FRC/4 provides clock frequencies
compatible with previous A/D modules.
3
In sequential mode TACQ should be 12 TAD or greater.
47
Continuous Loop mode. The ADRS bits are ignored in Single-shot mode.
01 = Interrupt is generated when the 2nd & 4th words are written to the buffer
11 = Unimplemented
1xxxx = Power Control PWM module rising edge starts A/D sequence4
Legend:
-n = Value at POR ‘1’ = bit is set ‘0’ = bit is cleared x = bit is unknown
bit 7 bit 0
00 = AN3
4
SSRCx<4:0> bits can be set such that any of the triggers will be start conversion (e.g. SSRCx<4:0> =
00101, will trigger the A/D conversion sequence when RC3/INT0 or Input Capture 1 event occurs).
48
01 = AN7
1x = Reserved
00 = AN1
01 = AN5
1x = Reserved
00 = AN2
01 = AN6
1x = Reserved
00 = AN0
01 = AN4
10 = AN8
11 = Reserved
Legend:
-n = Value at POR ‘1’ = bit is set ‘0’ = bit is cleared x = bit is unknown
49
ANSEL0: Analog Select Register 0
bit 7 bit 0
1 = Analog Input
0 = Digital I/O5
Legend:
-n = Value at POR ‘1’ = bit is set ‘0’ = bit is cleared x = bit is unknown
U U U U U U U R/W
- - - - - - - ANS8
bit 7 bit 0
1 = Analog Input
0 = Digital I/O6
5
Setting a pin to an analog input disables the digital input buffer. The corresponding TRIS bit should
be set for an input and cleared for an output (analog or digital). The ANSx bits directly correspond to
the ANx pins (e.g., ANS0 = AN0, ANS1 = AN1, etc.) Unused ANSx bits are to be read as ‘0’.
6
Setting a pin to an analog input disables the digital input buffer. The corresponding TRIS bit should
be set for an input and cleared for an output (analog or digital). The ANSx bits directly correspond to
the ANx pins (e.g., ANS8 = AN8, ANS9 = AN9, etc.) Unused ANSx bits are to be read as ‘0’.
50
Legend:
-n = Value at POR ‘1’ = bit is set ‘0’ = bit is cleared x = bit is unknown
The A/D converter has two types of conversion, two modes of operation and
eight different sequencing modes. These features are controlled by the ACONV bit
(ADCON0<3:2>). In addition, the A/D channels are divided into four groups as
converted
sequentially
converted
sequentially
(STNM1) sampled
simultaneously and
51
converted
sequentially
(STNM2) sampled
simultaneously and
converted
sequentially. Then,
sampled
simultaneously,
sequentially.
sampled and
converted
and converted
and converted
sampled and
converted
52
3.2.3. A/D Result Register
The ADRESH:ADRESL register pair is the location where the 10-bit A/D
result is loaded at the completion of the A/D conversion. The register pair is 16-bits
wide. The A/D module gives the flexibility to left- or right-justify the 10-bit result in
the 16-bit result register. The A/D Format Select bit (ADFM) controls this
justification [6].
ADRESH ADRESL
ADFM = 0
ADFM = 1
53
3.3. Overview Flowchart of the Program in Generating 3 phase Sinusoidal
54
3.4. Flowchart of the Main Function’s Program for generating 3 phase
CHAPTER 4
Here we have defined the value of the sine wave sampling value. It is difficult
to calculate the 120 sine wave sampling value. So, measured that sine wave sampling
value by
y = A + A sin x
Columns 1 through 9
140.9950
Columns 10 through 18
178.1831
Columns 19 through 27
198.0462
Columns 28 through 36
196.1826
Columns 37 through 45
173.0052
Columns 46 through 54
133.6501
Columns 55 through 63
57
128.6335 123.5370 118.3750 113.1617 107.9117 102.6397 97.3603 92.0883
86.8383
Columns 64 through 72
42.9431
Columns 73 through 81
11.6915
Columns 82 through 90
Columns 91 through 99
40.7951
84.2262
58
89.4596 94.7225 100.0000
200
data1
180
160
140
120
100
80
60
40
20
0
0 1 2 3 4 5 6 7
200
180
160
140
120
100
80
60
40
20
0
0 20 40 60 80 100 120
59
200
180
160
140
120
100
80
60
40
20
0
0 1 2 3 4 5 6 7
In Figure 4. 5 showing the generation of saw tooth. When sine wave and saw
tooth wave compare the width of PWM signal is changing. And the pick value of saw
tooth wave depending on the ADC value. For this reason variable frequency of the
Here this output is the simulation of 3 phase PWM signal. And there is also
60
Figure 4. 5: Simulation result of PWM signal which have also a dead time.
In this figure we got that simulation result from MPLAB IDE v8.20. In before
we used MPLAB IDE v.6.20 but there were not any option for visualize the
61
In Figure 4. 6 is the pin diagram of the microcontroller 33 to 38 number of pins will
give the output of PWM and AN0 or 2 number pin is the Analog input which is
62
4.3. ADC
In Figure 4. 2, we are showing that in our project board we are testing the
ADC signal by varying the variable resistance. And depending on the value of
63
4.4. Variable Frequency of Three phase PCPWM Signals output
Signals
waveform we used new digital oscilloscope. This oscilloscope model name and
observe only two signals. That means there were only channel. And we observe that
LED’s output and also correspondingly changing the PWM width, Period and
64
65
In Figure 4.10 showing that Independent mode and complementary mode of
the PWM signals and also there have some dead time. In Channel 2 have 1 delay.
CHAPTER 5
5.1. Conclusion
In this work, a three phase PWM signal with variable frequency has been
follows:
1. HSADC (High speed ADC) module determine the pick value of the saw tooth.
3. Both PWM signal and Dead time control circuits can be implemented in a
single board microcontroller, which makes the system reliable, compact and
low cost.
The laboratory test results confirm that the 3 phase sinusoidal PWM signal
Our low cost Micro Controller based three phases PWM signals could be used
in electrical vehicle application. Therefore further works could be done on control the
speed of motor.
REFERENCES
[1] (n.d.). Retrieved from http://www.tech-faq.com/pulse-width-modulation.shtml
http://ieeexplore.ieee.org/Xplore/defdeny.jsp?url=http%3A%2F%2Fieeexplore.
ieee.org%2Fstamp%2Fstamp.jsp%3Ftp%3D%26isnumber%3D573%26arnumb
er%3D15183&denyReason=-131&arnumber=15183&productsMatched=null
PWM Algorithm.
[5] Kerkman, D. L. Pulse Based Dead Time Compensator for PWM Voltage
Inverters.
Techonology Inc.
Systems using Assembly and C for PIC18. Dorling Kindersley (India) Pvt. Ltd.
[8] Parekh, R. (2005). VF Control of 3-Phase Induction Motor Using Space Vector
[9] Salim, K. M. (June, 1999). Development of Power Conditioner Unit (PCU) For
P.539.
[11] Yedamale, P. (2002). Speed Control of 3-Phase Induction Motor Using PIC18
APPENDIX A
PROGRAM FOR PIC18F4431 MICROCONTROLLER
;***********************************************************************
;ID# 0520145
;************************************************************************
include <p18f4431.inc>
include <3im_vf.inc>
;********************Label Defination**********************
c4 equ 0x24;
c5 equ 0x25;
;For PCPWM
counter1 equ 0x008; for 1st phase: Counting the sine wave
sampling value
counter2 equ 0x009; for 2nd phase: Counting the sine wave
sampling value
counter3 equ 0x00A; for 3rd phase: Counting the sine wave
sampling value
;********************Program Start**************************
goto Start;
;**************************************************************************
*****
;**************************************************************************
*****
; INITIALIZATION
71
;**************************************************************************
*****
;**************************************************************************
*****
Start
call clearall;
call INIT_PORTC; Use for ADC will show 2 bits Digital output
call INIT_PORTD; Use for ADC will show 8 bits Digital output
call INIT_IC1;
call INIT_HSADC;
call INIT_PCPWM;
call INIT_INTERRUPTS;
call MAIN;
;**************************************************************************
*****
;**************************************************************************
*****
;**************************************************************************
*****
;**************************************************************************
*****
SINE_WAVE
addwf PCL,1;
72
retlw D'100'; for Sampling number 1
73
retlw D'193'; for Sampling number 24
74
retlw D'165'; for Sampling number 47
75
retlw D'51'; for Sampling number 70
76
retlw D'1'; for Sampling number 93
77
retlw D'79'; for Sampling number 116
;**************************************************************************
*****
;**************************************************************************
*****
;Clearing the user defined memory cell and initialize the value of user defined memory cell
;**************************************************************************
*****
;**************************************************************************
*****
clearall
;for PCPWM
clrf INTCON;
movlw .40;
movlw .80;
78
movwf counter3; Initialize the 240 degree phase sine wave
value
;for ADC
clrf ADRESH;
clrf ADRESL;
clrf ADCON0;
clrf STATUS;
return;
;**************************************************************************
*****
;Initialize PORTD
;**************************************************************************
*****
INIT_PORTD
clrf PORTD
clrf LATD;
return;
;**************************************************************************
*****
;Initialize PORTC
79
;**************************************************************************
*****
INIT_PORTC
clrf PORTC;
clrf LATC;
clrf PORTC;
return;
;**************************************************************************
*****
;Initialize PORTB
;**************************************************************************
*****
INIT_PORTB
clrf PORTB
clrf LATB;
return;
;**************************************************************************
*****
;Initialize IC1
80
;**************************************************************************
*****
INIT_IC1
; e) Timer5 is enabled
return
81
;**************************************************************************
*****
;**************************************************************************
*****
INIT_HSADC
82
movlw b'00000100' ; ADCHS is configured such that:
movwf TRISA
; b) Single-channel mode is
enabled
; c) Group A signal is
sampled (speed ref on development board)
return
;**************************************************************************
*****
;Initialize PCPWM
;**************************************************************************
*****
INIT_PCPWM
movlw 0xFF
83
movwf PTPERL ;PWM Time Base RegisterL decimal
value will 255
movlw 0x00
84
; a) Clock source for dead-
time is Fosc/2.
movwf OVDCOND
movwf OVDCONS
movwf SEVTCMPL
movlw 0x00
movwf SEVTCMPH
call PWM_DEAUTY_CYCLE1;
call PWM_DEAUTY_CYCLE2;
call PWM_DEAUTY_CYCLE3;
85
return;
;**************************************************************************
*****
;Initialize interrupts
;**************************************************************************
*****
INIT_INTERRUPTS
86
; for ADC
;Enbales the
A/D interrupt
;Low
priority bit.
;Enables
CCP2 Interrupt
;for PCPWM
87
bsf PIE3, PTIE ;PWM Time Base
Interrupt Enable bit
bcf INTCON2,0;
;for IC1
return
88
;**************************************************************************
*****
;**************************************************************************
*****
ISR_HIGH
call PWM_DEAUTY_CYCLE1;
call PWM_DEAUTY_CYCLE2;
call PWM_DEAUTY_CYCLE3;
;PWM Time
Base has not matched the value in PTPER register.
bcf INTCON2,0;
RETFIE FAST
89
;**************************************************************************
*****
;**************************************************************************
*****
ISR_LOW
goto MAIN;
call RESULT_ADC
RETFIE FAST
MAIN
call ISR_HIGH;
nop;
call ENABLE_ADC;
goto MAIN;
ENABLE_ADC
90
call ISR_LOW;
return;
RESULT_ADC
movf ADRESH,0;
movwf c4;
movf ADRESL,0;
movwf c5;
movf c4,0;
movwf PORTC;
movwf PTPERH;
movf c5,0;
movwf PORTD;
movwf PTPERL;
;The A/D
conversion is not complete.
bsf ADCON0, 0;
91
; bsf ADCON0, 1;
return;
PWM_DEAUTY_CYCLE1
call SINE_WAVE;
movwf PDC0L;
incf counter1,1;
movf counter1,0;
xorlw .120;
btfss STATUS,Z;
return;
clrf counter1;
92
return;
PWM_DEAUTY_CYCLE2
call SINE_WAVE;
movwf PDC1L;
incf counter2,1;
movf counter2,0;
xorlw .120;
btfss STATUS,Z;
return;
clrf counter2;
93
return;
PWM_DEAUTY_CYCLE3
call SINE_WAVE;
movwf PDC2L;
incf counter3,1;
movf counter3,0;
xorlw .120;
btfss STATUS,Z;
return;
clrf counter3;
94
return;
END
;*******************************************************************
95
APPENDIX B
PROGRAM FOR GENERATING 120 SAMPLING VALUE OF SINE
WAVE BY MATLAB
x=0:(2*pi/119):(2*pi);
y=100+(100*sin(x))
plot(x,y)
stem(y)
96
APPENDIX C
PROGRAM FOR GENERATING SAW TOOTH BY MATLAB
t = [0:pi/50:2*pi];
x = 101+(101*sawtooth(t));
plot(t,x)