SPWM V/HZ Inverter
SPWM V/HZ Inverter
SPWM V/HZ Inverter
INTRODUCTION
1.1 Background
After long debates in the past, it is proven that AC transmission and distribution is more
economical and reliable than DC. Hence, AC transmission and distribution is used widely
which has resulted in growing popularity of AC based appliances. AC can also be divided as
single phase or three phases. Three phase AC is more popular in high power application
while single phase is used in home appliances and low power systems.
Even though constant AC sources are readily available, in many cases we need to control the
frequency and magnitude of output voltage of the available AC source. Speed Control of
induction motors, used in various appliances and machines like conveyer belt, air
conditioner, pumps, electric traction, etc is one of the examples where it is necessary to
control the frequency for controlling the speed of the motor to match the variable torque,
power and speed requirement. Due to robust and rugged structure, induction motors are more
popular than DC motors. But speed control of AC motor is not as simple as that of DC
motors due to complex torque-speed Characteristics of AC induction motor. So, it requires
special control system like constant volt/Hz Inverter.
Constant volt/hertz inverter is the inverter which maintains the ratio of magnitude of output
AC voltage to frequency constant. This inverter finds its application for control of AC motor
drive which implements constant V/f speed control method. One of the most popular control
strategies used for variable AC output from inverter is Pulse Width Modulation (PWM)
technique which controls the duty cycle of the controller switches at high switching
frequency to achieve controlled AC output from inverter. In this project, sinusoidal PWM
technique is used to control the magnitude of output AC voltage from the inverter
maintaining constant V/f ratio.
1.2 Objective
To design and fabricate constant volt/hertz inverter
The major objective of this project is to develop a control strategy to change voltage when
frequency is varied externally so as to maintain a constant volt/hertz inverter.
1.4 Methodology
In order to carry out the mentioned objectives, the following methodology will be adopted:
1.
2.
3.
4.
CHAPTER 2
INVERTER SYSTEM
PWM
Where,
D=
And
t ON
tW
f PWM =
1
tw
V dc
2
three arms of the inverter. In complementary mode, if one of the PWM is high, the other is
low and vice-versa as shown in figure below. A certain programmable dead time is inserted
so that upper and lower switches of the H-bridge are not simultaneously ON to prevent
short circuiting of the DC bus. Complementary PWM signals (10 kHz) generated by
microcontroller with 2s dead time between the two signals is shown in figure 2.5
PWMH
PWML
Consider a single phase half bridge as shown with load connected at point a as shown in
figure 2.2. If the complementary outputs have a 50 % duty cycle, then for half of the time,
the upper switch is ON and the voltage across the load is +V DC/2 with respect to point N
and for the next half of the period, the lower switch is ON (with upper switch now in OFF
state) and so the voltage across the load is
to average voltage of zero volts averaged over a PWM period in complementary mode.
The sine values for the 256 different points can be evaluated by the expression;
y [i]=sin
2
i )
( 256
where, i = 0 to 255
The sine values are read from the table at periodic interval, scaled to match the allowable
ranges of duty cycle, and then written to the duty cycle register. If any numerical value is put
in the duty cycle register then the microcontroller produces output PWM waveform of that
particular duty cycle.
At first, the data from table is first multiplied by 50 percent duty cycle value. The resulting
value is then multiplied by the value of modulation index (M.I) to change the average
voltage of through the variation of pulse widths. Finally, 50 percent duty cycle value is then
added to ensure that resulting duty cycle value is positive.
Sine table[i] = y[i] * 50 percent duty cycle * M.I + 50 percent duty cycle
Figure 2.6: Diagram showing the scaling operation to generate the required duty cycle from
the sine table
Figure 2.6 shows the scaling process carried so that duty cycle values are obtained
sinusoidally. Figure 2.7 shows the PWM signals for the upper and lower switch and shows
the variation of duty cycle over a completer electrical cycle for modulation index value of
one. It can be seen that at zero electrical degree of sine wave, the duty cycle of the high side
PWM is 50%, therefore the average voltage is zero for a PWM period as the lower switch is
also ON for remaining 50% of the PWM period. At around 90 electrical degree, the upper
7
switch is ON for all PWM period (i.e 100% duty cycle), so the output is high during this
period and voltage across the load is +VDC/2 with respect to point N. But, at around 270
electrical degrees, the upper switch is OFF for whole PWM period (i.e. 0% duty cycle)
while the lower switch is ON for full PWM period. So, the output voltage is negative and
voltage across the load is VDC/2. Similarly, at other electrical degrees, the duty cycle varies
sinusoidally so as to encode the sinusoidal signal in the PWM waveform.
50%
duty
0% duty
50% duty
100% duty
50% duty
Figure 2.7 Gate signal pattern for upper switch and corresponding complementary gate
signal for lower switch
Figure 2.8 given shows the effect of changing the modulation index on the variation of pulse
width, thereby changing the amplitude of the fundamental voltage component.
Figure 2.8 Changing Vmod through PWM pattern where, M.I (a) > M.I (b) > M.I(c)
16
Delta_phase = 2
76
=498.07=498
10000
After the Phase variable has been adjusted by Delta_Phase, two additional table pointers are
calculated for the 2nd and 3rd motor phases by adding a constant offset to Phase. For a 16-bit
pointer, a value of 0x5555 provides 120
offset.
V dc
V if
2
Where i = A,B,C
Vif represents the 3-phase waveforms shifted at an angle of 120
phase waveform can be represented as shown below:
V Af = m sin
V Bf = m sin (+120)
V Cf = m sin (+240)
V AO =
V dc
m sin
2
V BO =
V dc
m sin (+120)
2
V CO =
V dc
m (+240)
2
V AB = V AO -V BO =
(3)V dc
m sin (+30)
2
V BC = V BO -V CO =
(3)V dc
m sin (+150)
2
V CA = V CO -V AO =
(3)V dc
m sin (+270)
2
From the above equations, it is clear that the maximum line-to line voltage is achieved when
m=1
i. e . Maximum line-to-line voltage =
2V LL ( rms ) = 3
3 V dc
2
V dc
2
V LL ( rms ) 0.612
=
V dc = 0.354V dc
3
3
These equations are valid for modulation index, M.I. = m = 1. For any value of m, the
following equations will be valid.
V LL ( rms ) = 0.612 m
V ph ( rms ) =
Vdc
V LL ( rms ) m 0.612
=
V dc = 0.354 m V dc
3
3
V req
=k
f req
Where k = constant
Dividing both sides of equation (a) by Vph(rms) with m=1, we get
V req
k
=
V ph ( rms ) f V ph ( rms )
or, m=
V req
k
=
f
V ph ( rms ) V ph ( rms )
11
12
CHAPTER 3
SIMULATION STUDIES
Before carrying out activities in hardware, simulations were carried out in softwares such as
MATLAB/Simulink and Proteus. This chapter is mainly concerned with the simulations in
these softwares.
13
Programming
block
14
15
Yes
and f =fmin
No
Is f>fbase?
Yes
Set Modulation Index =
1
No
Calculation of Modulation Index
M.I = K/Vph(max) *f;
16
Figure 3.5: PWM signal generation from microcontroller with PWM frequency of 10 kHz
17
In figure 3.5, PWMH1 and PWML1 are complementary PWM outputs from the
microcontroller for producing gate signals for the first arm of the three-phase H-bridge.
Similarly, PWMH2 and PWML2 are complementary PWM outputs from the microcontroller
for producing gate signals for the second arm of the bridge. Figure 3.6 and 3.7 show the
output waveforms.
18
19
CHAPTER 4
HARDWARE DESIGN AND FABRICATION
4.1 Description of the proposed scheme
This scheme is design of the three phase inverter to drive or supply any load which required
constant V/F such as induction motor. This drive generates the output voltage in proportion
to the output frequency to provide a relatively constant ratio of voltage to frequency (V/Hz).
Sinusoidal pulse width modulation (SPWM) is widely used in power electronics to digitize
the power so that a sequence of voltage pulses can be generated by ON and OFF of the
power switches. The pulse width modulation inverter is simple and provides better control
scheme. SPWM techniques are characterized by constant amplitude pulses with different
duty cycle for each period. The width of this pulses are modulated to obtain inverter output
voltage control and to reduce its harmonic content. To generate this signal, triangular wave is
used as a carrier signal and is compared with sinusoidal wave, whose frequency is the
desired frequency. The proposed alternative approach is to replace the conventional method
with the use of microcontroller. The use of microcontroller brings the flexibility to change
the real-time control algorithms without further changes in hardware. It is also low cost and
has a small size of control circuit for the three phase full bridge inverter. The microcontroller
has the built in dead time control circuit and various other features to control pwm signals.
AC POWER SUPPLY
DC VOLTAGE LINK SUPPLY
RECTIFIER
MICROCONTROLLER
AC VOLTAGE
ISOLATION CIRCUIT
20
a. Rectifier: The first step in this process is to convert the AC supply voltage into DC by the
use of a rectifier. DC power contains voltage ripples which are smoothed using filter
capacitors. This section of the VFD is often referred to as the DC link. In our project,
rectifier is not used. Instead, dc supply is directly taken from the available dc bank.
b. MOSFET Inverter Bridge: This DC voltage is then converted back into AC. This
conversion is typically achieved through the use of power electronic devices such as IGBT
power transistors or MOSFETs using a technique called Pulse width Modulation (PWM).
The output voltage is turned on and off at a high frequency, with the duration of on-time, or
width of the pulse, controlled to approximate a sinusoidal waveform. The MOSFET inverter
bridge has 6 switches that are controlled in order to generate 3-phase AC output from the DC
bus. PWM signals, generated from the microcontroller, control these 6 switches. Switches
H1 through H3 are upper switches. Switches L1 through L3 are lower switches. The
amplitude of phase voltage is determined by the duty cycle of the PWM signals. In this
configuration, three out of six switches will be on at any given time; either one upper and
two lower switches or one lower and two upper switches. The switching produces a
rectangular shaped output waveform that is rich in harmonics. When switches are turned off,
the inductive nature of the load oppose any sudden change in direction of flow of the current
until all of the energy stored in the load is dissipated. To facilitate this, fast recovery diodes
are provided across each switch. These diodes are known as freewheeling diodes.
H1
L1
H2
L2
H3
L3
21
THREE
PHASE
LOAD
4.2.2 Optocoupler
Certain isolation system between high voltage level and low
voltage level is required in Constant V/Hz Inverter system.
The microcontroller which is operating at low voltage level
(3.3V) has to control load which is at much higher voltage level. So, the microcontroller
22
needs to be isolated to protect from overvoltage damage. Optocoupler can provide such
isolation. It is also known as optoisolators.
They are best for transmitting PWM signals with frequent switching. In this project, high
speed 6N137 logic gate optocoupler is selected.
Enhancement mode MOSFET has been used in our project for switching electronic signals.
Enhancement mode MOSFET can be taken as a switch as these transistors require a positive
gate voltage to turn 0N and a zero voltage to turn 0FF making them easily understood as
switches and also easy to interface with logic gates.
The operation of the enhancement mode MOSFET can best be described using its I-V
characteristics curves shown below. When the Input voltage, (Vin) to the gate of the transistor
is zero, the MOSFET conducts virtually no current and the output voltage (V out) is equal to
the supply voltage (VDD). So the MOSFET is fully-OFF and in its cut-off region.
toggles between two values, high and low the MOSFET well behave as a single-pole singlethrow (SPST) solid state switch.
Cut off region
Here the operating conditions of the transistor are zero input gate voltage (V IN), zero drain
current ID and output voltage VDS = VDD .Therefore the MOSFET is switched Fully-OFF.
Saturation region
In the saturation or linear region, the transistor will be biased so that the maximum amount
of gate voltage is applied to the device which results in the channel resistance R DS (on) being
as small as possible with maximum drain current flowing through the MOSFET switch.
Therefore the MOSFET is switched fully 0N.
(Th)
parameter which is defined as the minimum voltage required between the gate and source
terminals to turn the MOSFET on. It will need more than this to turn it fully ON.
One feature of power MOSFETs is that they have a large stray capacitance between the gate
and the other terminal. The effect of this is that when the pulse to the gate terminal arrives, it
must first charge this capacitance up before the gate voltage can reach the 10 V required. The
gate terminal then effectively takes current. Therefore the circuit that drives the gate terminal
should be capable of supplying a reasonable current so the stray capacitance can be charged
up as quickly as possible. The best way to do this is to use a dedicated MOSFET driver chip.
25
After successful implementation of the proposed scheme in softwares, design and fabrication
of hardware was carried out. Some of the pictures of the hardware are shown below:
LM317
VOLTAGE
REGULATOR
DSPIC
MICRONCONTROLLER
FREQUENCY VARYING
KNOB
the microcontroller. LM317 voltage regulator was used so as to convert dc voltage from dc
bank to dc voltage of about 3.3 V as required by the microcontroller.
Figure 4.10 depicts the three phase part of the inverter. Optocoupler 6N137 was used so as to
isolate low voltage level from the high voltage level. The PWM signals are received from the
microcontroller via optocoupler which is applied to MOSFETs. Before applying these gate
signals to MOSFETs, they are firstly fed to MOSFET drivers. There is no problem in turning
ON the lower semiconductor switches but there is problem in turning ON the higher
semiconductor switches. In order to turn ON the higher semiconductor switches, MOSFET
drivers are used which builds up the required gate-to-source voltage by means of bootstrap
capacitor.
Snubber circuit
Three Phase outputs
MOSFET
Optocoupler
MOSFET Driver
27
project. The output waveforms were similar to those observed in softwares such as
MATLAB and Proteus.
Figure 4.11: Complete train of pulses for a complete cycle with complementary outputs
28
0.106 in the code of the microcontroller. The observations of the experiment are tabulated
below in Table 4.1:
DC bus voltage, (Vdc ) = 15 V
For Modulation Index (M.I.) =1
Maximum fundamental line-to-line voltage (V LL )= 0.612 V dc = 9.18 V
Maximum fundamental Phase Voltage (Vph1) =5.3 V
Table 4.1
S.No.
Frequency
Fundamental
Fundamental
(Hz)
RMS line-
RMS Phase
line Voltage
Voltage (Vph)
Modulation Index ( M . I )
=
V ph
V ph1
(VLL)
(volt/Hz)
[
1
2
3
12.38
14.71
31.85
V ph
ratio
f
V ph =
1.9
2.3
5.0
1.09
1.33
2.88
V LL
3
]
0.205
0.251
0.543
0.088
0.090
0.090
From the above observations, it can be noticed that constant volt/hertz ratio is maintained
approximately equal to that previously set.
Simulations in MATLAB was also carried out with the paramaters set the same as in
experiment. And, the results obtained are shown in the pictures below and the results
tabulated below;
30
S.No
.
Frequency
(Hz)
Fundamental
RMS lineline Voltage
(VLL)
Fundamental
RMS Phase
Voltage (Vph)
[
1
2
14.71
31.75
2.724
5.826
V ph =
V LL
3
1.573
3.364
Table 4.2
0.297
0.635
0.111
0.106
CHAPTER 5
CONCLUSION AND RECOMMENDATION
5.1 Conclusion
The major objective of this project is to design and fabricate constant volt/hertz inverter
using sinusoidal pulse width modulation (PWM) technique. In order to achieve this
objective, a series of steps were taken. Firstly, the project was designed and evaluated using
softwares such as Proteus and MATLAB. After achieving satisfactory results, the project was
implemented in hardware. This implementation was found to be successful. It was verified
by observing whether the ratio of voltage to frequency ratio was constant or not when the
frequency was varied externally by means of potentiometer knob. The V/f ratio was noticed
to be nearly constant which implied success of the project.
5.2 Recommendation
31
Constant volt/hertz Inverter system was successfully designed as per the aim of project. But
still we can improve the performance of this system by further study and enhancement. This
system can also be used to drive three phase induction motor with few enhancements and
proper protection system. The following are suggestions for future enhancement for better
performance and reliability of the system:
considering the maximum voltage and current level which the system can handle.
MOSFETs with better static and dynamic characteristics can be used to increase
32
BIBLIOGRAPHY
www.microchip.com
Datasheets of MOSFETs and MOSFET drivers provided in Official International
33
APPENDIX A
SOURCE CODE
The following source code is program for microcontroller.
// Source code compiled in MPLAB using C30 compiler and simulated in
Proteus software
//programming reference can be taken from microchip site and dspic pdf
#define FCY 40000000
#include <p33fj32MC202.h>
#include<libpic30.h>
// derived using PLL, first FRC at first
_FOSCSEL(FNOSC_PRI)
_FOSC(FCKSM_CSECMD & POSCMD_HS & OSCIOFNC_OFF& IOL1WAY_ON)
_FWDT(FWDTEN_OFF)
_FPOR(FPWRT_PWR128 & HPOL_ON & LPOL_ON & PWMPIN_OFF) // LPOL_ON
//
PWM module low side output pins have active-high output
polarity
;;
//
HPOL_ON: PWM module high side output pins have active-high output
polarity
_FICD(ICS_PGD1 & JTAGEN_OFF)
//
Communicate
on
PGC1/EMUC1
and
PGD1/EMUD1
unsigned
volatile
volatile
volatile
void
void
void
void
void
int FREQ_SCALING=1999;
// P1TPER value
unsigned int Modulation_Index=0,Modulation=0;
unsigned int PhaseA=0,PhaseB=0,PhaseC=0,Frequency=0,f=0;
signed int ASinevalue,BSinevalue,CSinevalue;
__attribute__((__interrupt__,no_auto_psv)) _MPWM1Interrupt(void);
__attribute__((interrupt, no_auto_psv)) _ADC1Interrupt(void);
init_PWM(void);
initInterrupts(void);
initAdc1(void);
34
IPC2bits.T3IP
IFS0bits.T3IF
IEC0bits.T3IE
T3CONbits.TON
=
=
=
=
3;
0;
0;
1;
//
//
//
// Start
/
*=========================================================================
====
ADC INITIALIZATION FOR CHANNEL SCAN
==========================================================================
===*/
void initAdc1(void)
{
AD1CON1bits.FORM
= 0b00;
// Data Output Format: integer
AD1CON1bits.SSRC
= 0b010;
// Sample Clock Source: GP Timer
starts conversion
AD1CON1bits.ASAM
= 1;
// ADC Sample Control: Sampling begins
immediately after conversion
AD1CON1bits.AD12B = 0;
// 10-bit ADC operation
AD1CON2bits.VCFG = 0b000; //AVDD,AVSS
AD1CON2bits.CSCNA = 1;
// Scan Input Selections for CH0+
during Sample A bit
AD1CON2bits.CHPS = 0;
// Converts CH0
AD1CON2bits.ALTS = 0;
//always use channel i/p select
for sample A
AD1CON3bits.ADRC = 0; // ADC Clock is derived from Systems Clock
AD1CON3bits.ADCS = 15;
//
ADC
Conversion
Clock
Tad=Tcy*(ADCS+1)= (1/10M)*16 = 1.6us (625Khz)
// ADC Conversion Time for 10-bit Tc=12*Tab = 19.2us
AD1CON2bits.SMPI = (NUM_CHS2SCAN-1);// 1 ADC Channel is scanned..
for input scanning SMPI is one less the
//channels
being scanned
//AD1CSSH/AD1CSSL: A/D Input Scan Selection Register
AD1CSSLbits.CSS0=1;
// Enable AN0 for
channel scan
AD1CSSLbits.CSS1=1;
// Enable AN1 for channel scan
//AD1PCFGH/AD1PCFGL: Port Configuration Register
AD1PCFGL=0xFFFF;
AD1PCFGLbits.PCFG0 = 0;
// AN4 as Analog Input
AD1PCFGLbits.PCFG1 = 0;
// AN5 as Analog Input
IPC3bits.AD1IP=2;
//2nd last priority
IFS0bits.AD1IF = 0;
// Clear the A/D interrupt flag
bit
IEC0bits.AD1IE = 1;
// Enable A/D interrupt
AD1CON1bits.ADON = 1;
// Turn on the A/D converter
}
/
*=========================================================================
====
ADC INTERRUPT SERVICE ROUTINE
==========================================================================
===*/
// this will be called after timer3 register matches the period after
200us (special trigger event)
void __attribute__((interrupt, no_auto_psv)) _ADC1Interrupt(void)
{
float freq;
35
asm("mov _ADC1BUF0,W3"); //Read the ADC results into W3 ::suppose the pot
is set at 100%, then ADC1BUF0 reads //1023d decimal
asm("asr W3,#1,W4");// Right shift by 1 bits to get the frequency(named
in placed of PhaseReq) :: this statement
//divides it by 2..ie1023/2=
511 decimal and this number is the frequency (511*10000)/65536= 77.972 Hz
so the //highesh freq by this method is 77.972 Hz.. So, if we use 10Khz
freq, we can achieve 77.97 Hz maximum freq using this //algorithm
asm("mov W4,_Frequency");
/*
this register w4(adc pin) can be used externally to control the
modulation by slight //modification
asm("mov _ADC1BUF1,W4");//
Read the ADC results into W4
::suppose
the
pot
is
set
at
100%,
then
ADC1BUF1
reads
//1023 decimal
asm("sl
W4,#5,W4");//
Left shift By 5 to get Q15 value in
the
range
::multiply
by
2^5
or
by
32
to
transform
the
//frequency to the range 0 to 32767 (in fractional format to be used
below for MPY instruction)
asm("mov W4,_Modulation");
*/
if(Frequency<66)
Frequency=66;
freq=Frequency;
f=(freq*10000)/65535;
Modulation_Index=f*655;
//if
vdc=15v,vprms=5.3V
and
f=50hz
then and MI=655*freq;
if(Modulation_Index > 32500)
Modulation_Index = 32500;
IFS0bits.AD1IF= 0;
// Clear the ADC1
Interrupt Flag
}
void init_PWM()
{
P1TCONbits.PTMOD = 0b10;// PWM time base input clock period is
TCY (1:1 prescale)
P1TCONbits.PTCKPS = 0b00;
// PWM time base output post
scale is 1:1
P1TCONbits.PTOPS = 0b00;
// Choose PWM time period based on input clock selected
// Refer to Equation 14-1
// PWM switching frequency is 20 kHz
// FCY is 40 MHz
// P1TPER = (FCY/(Fpwm*1*2))-1 =1000=999
P1TPER = 1999;
// PWM I/O pairs 1 to 3 are in complementary mode
// PWM pins are enabled for PWM output
PWM1CON1bits.PMOD1 = 0;
PWM1CON1bits.PMOD2 = 0;
PWM1CON1bits.PMOD3 = 0;
PWM1CON1bits.PEN1H = 1;
PWM1CON1bits.PEN2H = 1;
PWM1CON1bits.PEN3H = 1;
PWM1CON1bits.PEN1L = 1;
PWM1CON1bits.PEN2L = 1;
PWM1CON1bits.PEN3L = 1;
PWM2CON1bits.PEN1H = 0; //PWM module 2 used as general i/o
PWM2CON1bits.PEN1L = 0;
// synchronized update of PWM enabled
PWM1CON2bits.IUE = 0;
//1 means immediate update
36
signals
}
void delay10ms(int n){
int i;
for(i=0;i<n;i++){
__delay_ms(10);
}
}
// MAIN function
int main(void)
{
_TRISB6=0;
_LATB6=1;
/* Configure PLL prescaler, PLL postscaler, PLL divisor */
PLLFBD=30;
/* M = PLLFBD + 2=32 */
CLKDIVbits.PLLPOST=0b00;
/* N2 = 2 */
CLKDIVbits.PLLPRE=0b10;
/* N1 = 4 */
// Fosc=20 * 32 /(2*4)=79.2275 Mhz ; Fcy=39.61375Mhz used in this
case
// coding in assembly language(asm) to switch the clock from 20MHz
to 80MHz using PLL mode and //Fcy=Fosc/2
//Place the New Oscillator Selection (NOSC=0b11) in W0
asm("MOV #0x03,w0");
//OSCCONH (high byte) Unlock Sequence
asm("MOV #OSCCONH, w1");
asm("MOV #0x78, w2");
asm("MOV #0x9A, w3");
asm("MOV.B w2, [w1]"); // Write 0x78");
37
bit
while(OSCCONbits.COSC != 0b011);
// Wait for new Oscillator to
become POSC w/ PLL
while(OSCCONbits.LOCK != 1);
// Wait for Pll to Lock
while (OSCCONbits.OSWEN == 1) { }
// wait till finish: if OSWEN
=0 then oscillator switch is complete;
PMD3bits.PWM2MD=1;
//there is simulation problem in proteus during Pll,ie in lock and oswen
but works in hardware
//which means proteus can't simulate PLL mode using external oscillator ,
but it simulates if clock is set in FRCPLL
init_PWM();
initAdc1();
initInterrupts();
while(1)
{
delay10ms(5);
_LATB6=~_LATB6;
// to check if PIC is in working
}
}
38
asm("mpy W5*W7,A");
//Multiply
by
the
PWM scaling factor
asm("sac A,W8");
//Store the scaled result
asm("add W7,W8,W8");
//Add
the
PWM
scaling
factor to produce 50% offset
asm("mov W8,_P1DC1");
//Write the PWM duty cycle
asm("mov _BSinevalue,W5");
asm("mpy W5*W6,A");
//Multiply
by
the
amplitude scaling
asm("sac A,W5");
//Store the scaled result
asm("mpy W5*W7,A");
//Multiply
by
the
PWM scaling factor
asm("sac A,W8");
//Store the scaled result
asm("add W7,W8,W8");
//Add
the
PWM
scaling
factor to produce 50% offset
asm("mov W8,_P1DC2");
//Write the PWM duty cycle
asm("mov _CSinevalue,W5");
asm("mpy W5*W6,A");
//Multiply
by
the
amplitude scaling
asm("sac A,W5");
//Store the scaled result
asm("mpy W5*W7,A");
//Multiply
by
the
PWM scaling factor
asm("sac A,W8");
//Store the scaled result
asm("add W7,W8,W8");
//Add
the
PWM
scaling
factor to produce 50% offset
asm("mov W8,_P1DC3");
//Write the PWM duty cycle
asm("pop.d W8");
//Save
off
working
registers
;might be used by other interrupts in nested form
asm("pop.d W6");
asm("pop.d W4");
_PWM1IF=0;
}
39
APPENDIX B
DATASHEETS OF SOME OF THE COMPONENTS USED
40
dsPIC33FJ32MC202/204
41
42
43
44
45
46
47
48
49
50