V-F Control of Single Phase PWM Inverter using dsPIC30F4011

Tags: Flowchart for Single Phase Inverter program/f control of single phase pwm inverter project using dspic30f, Single Phase Inverter Circuit Connections, DSPIC Connections with PWM Inverter,
Overall rating

The Single Phase PWM Inverter Speed drive control is implemented with hardware setup and software program in C code.

Inverters are used in a wide range of applications, from small switching power supplies in computers, to large electric utility applications that transport bulk power. The main feature used in microcontroller is their peripherals to realize sinusoidal pulse width modulation (SPWM).

The main feature used in dsPIC microcontroller is their peripherals to realize pulse width modulation. One chip and re-programmable ROM replaces the conventional complicated circuit solution. This brings low cost, small size and flexibility to change the control algorithm without changes in hardware.

The digital signal Peripheral Interface Controller (dsPIC) dsPIC30F4011 of Microchip Technology is used for the implementation of the inverter.

A DC to Ac voltage converter consists of four bidirectional switches that is used to convert the voltage. Sinusoidal unipolar Pulse Width Modulation is used for triggering the gates of IGBTs. The control circuit consists of the dsPIC controller and it is used to produce required SPWM for triggering the IGBTs. The driver circuit isolates the control circuit from power circuit. The outputs for variable AC voltages are observed in the CRO.


Power Electronics is the technology associated with efficient conversion, control and conditioning of electric power by static means from its available input form into the desired electrical output form. Power electronic converters can be found wherever there is a need to modify the electrical energy form (i.e., modify its voltage, current or frequency). Therefore, their power ranges from some mill watts (as in a mobile phone) to hundreds of mega watts (e.g.in a HVDC transmission system).

With “classical” electronics, electrical currents and voltage are used to carry information, whereas with power electronics, they carry power. Therefore the main metric of power electronics becomes the efficiency.

An inverter is a circuit which converts a DC power into an AC power at desired output voltage and frequency. The AC output voltage could be fixed or variable voltage and frequency. This conversion is achieved either by controlled turn on and turnoff devices or by forced commutated thyristors, depending on application. The output voltage waveform of an ideal inverter should be sinusoidal.

The dsPIC contains an extensive Digital Signal Processor functionality within a high Performance 16 bit Microcontroller architecture. This is a 16-bit modified Harvard architecture processors with an enhanced instruction set. Instructions are 24-bit wide. The dsPIC microcontrollers are widely used in Motor Control because it contains the enough peripherals for controlling the Motor applications like PWM, Capture, I/O lines etc.

The comparison of the reference sinusoidal signal with the triangular waveform is done in the PWM generator of the DSPIC to generate the control signals for the switching devices along with the inverted signals with the required dead band. A 16-bit counter register is used to measure the frequency of the triangular wave.

The dsPIC30F4011 architecture as shown below,


Single Phase PWM inverter applications of dsPIC are Solar system, Induction heating, hand-held power tools, stand-by power supplies and uninterruptable supplies. The inverter consists of four switching devices connected in the form of a bridge. The control scheme is implemented using dsPIC30F4011 microcontroller. To produce the sinusoidal output voltage waveform of variable frequency and amplitude, a sinusoidal reference signal is compared with the triangular waveform. The frequency & modulation index, which controls the output voltage are changing its value by using input ADC signal.


  • MPLAB Software Setup
  • Microchip C30 Compiler
  • ICD2 / PICKIT2
  • PWM Inverter Hardware Setup
  • dsPIC Controller Evaluation Board

DSPIC Connections with PWM Inverter Hardware setup

The dsPIC Controller connected with LAMP through PWM Inverter Hardware Setup as shown in below,


Fig. 2 dsPIC connected with Induction Motor

For using this microcontroller, it contains six PWM output with dead band and also four Captures. In Three Phase Induction Motor Control we are using six PWMs and a single Capture. First, the six PWM outputs of dsPIC30F4011 controller go to the hardware setup. Then the hardware outputs go to the Single Phase Inverter.

Here, the Lamp load control by using the set frequency & amplitude by using ADC input.

With the controller ready, hardware setup is done by just connecting the wires in-between those parts. A PC is connected to dsPIC board through USB port for uploading the program into dsPIC30F4011. For the microcontroller, the program is written in the FLASH built on the chip.

By hardware implementation and program, the two approaches get the same experimental results. The controller board designed can not only used for this project but also for later other projects.

Single Phase Inverter Circuit Connections as shown below,


Fig. 3 Schematic for the control board using dsPIC30F4011

Pulse Width Modulation (PWM)

PWM is widely used in power electronics to “digitalize” the power so that a sequence of voltage pulses can be generated by the on and off of the power transistors. The fundamental component has variable magnitude and variable frequency.

A pulse width modulation (PWM) signal is generated by using the timer and the comparator. The controller performs the following tasks:

  • The controller is constantly checking for zero crossings through the comparator.
  • If this condition is true the output pin is cleared and the timer is started.
  • The timer counts up to a certain value. If it reaches a predefined value (MODULO), it is stopped.
  • And reset for the next cycle. The output pin is also set.
  • The cycle is repeated by waiting for the next zero crossing.

A PWM period register is used to generate the PWM frequency range. The PWM period register calculation is,

PTPER = FCY / ( FPWM • (PTMR Prescaler) ) - 1

Dead time distortion can be corrected by properly modulating the power stage control signals. The dead time calculation is,

DT = dead time / (prescale valsue * Tcy)

Sinusoidal triangle PWM (SPWM) is the mostly used method. Triangle wave is used as carrier and reference signal is sinusoidal wave, whose frequency is the desired frequency and amplitude is determined by desired voltage amplitude, DC voltage and carrier amplitude.

Two separate single-phase inverters where each inverter produces an output delayed by 180° (of the fundamental frequency) with respect to each other.

The Single Phase Sinusoidal PWM inverter output pulses are shown in below,


Fig. 4 Single Phase Sinusoidal PWM inverter waveform outputs


Fig. 5 Sinusoidal PWM Output Pulses

To drive a PWM inverter, a single phase inverter bridge is driven by a microcontroller outputs. By changing the PWM duty cycles in a regular manner, the PWM outputs are modulated to synthesize the sinusoidal waveform.

The Single Phase PWM inverter Mode is accomplished with the PWM peripheral operated in complementary mode with dead time.

Generating a sinusoidal waveform

The easiest way to generate a sinusoidal waveform is to use a lookup table. You could also calculate the sine value on the fly, but it’s just not worth spending the CPU time to do this.

A lookup table is used that contains all the points of a sine value. The sine values are read from the table at periodic intervals, scaled to match the allowable range of duty cycles, and then written to the duty cycle registers.

The sine table values are stored in program memory. It is transferred data to data memory during initialization for faster access. Three registers are used as offsets to the table through indirect addressing. An array is defined the current location of the lookup table.

A counter variable is added to this array at each interval, the software will move through the table at affixed frequency. The lookup table usually contains from 0 to 256 data.

The offset values are added to the sine table array values at each PWM interrupt with PDC register. The 180 degrees phase shift is loaded into phases. Once lookup table values are obtained from the table, they are multiplied by scaling values to determine the actual amplitude of the modulation output.

Two inverted pulses are generated with dead band by using PWM Generator for a Single Phase PWM Inverter. The PWM interrupt is enabled when internal counter reaches the period register value. When PWM interrupt occurring, a single data is taking from lookup table. The lookup table contains 256 sampling data by using the sine formula,

u = sin ( 1.4 × i × π / 180 )

Here, i - 0 to 256. Π – 3.14.

The main program determines the voltage, amplitude and frequency while PWM ISR realizes the PWM by setting the proper compare registers values, dead band timer control register and timer period register, etc.

The PWM ISR flow chart as shown in below,

ADC Input

The ADC Input is a 10 bit ADC which is used to control the LAMP load output voltage in single phase PWM inverter. The 10-bit A/D is connected to a 16-word result buffer. Each 10-bit result is converted to one of four 16-bit output formats when it is read from the buffer.

The 10 bit ADC value, that is 1024 data read from the required ADC input pin when we can gives +5V DC input supply to the specific ADC input pin. In this project we can use open loop functions only.

The 10-bit high-speed analog-to-digital converter (A/D) allows conversion of an analog input signal to a 10-bit digital number. This module is based on the Successive Approximation Register (SAR) architecture, and provides a maximum sampling rate of 500 Ksps.

ADC modules are useful in applications requiring Voltage Measurement from Sine, Square & DC signals.

The ADC flow chart as shown in below,

Speed control of single phase Sine PWM

The controller gives the PWM outputs to the driver circuit for controlling the Lamp load or Motor load. The PWM pulses are controlled by the set freq & modulation index. The set freq & modulation index values are varying by using input ADC Voltage.

The Four PWM pulses are configured as given below,

  • PWM1 >> Active HIGH
  • PWM2 >> Active LOW (inverted of PWM1)
  • PWM3 >> Active HIGH
  • PWM4 >> Active LOW (inverted of PWM3)

A 4μs dead time is occurring between PWM1 & PWM2 and also between PWM3 & PWM4.

Here we are generating the sine PWM frequency range is from 10Hz to 50Hz. And also the Amplitude range is from 10 to 90%.

Flowchart for Single Phase Inverter program

Procedures of software Installation

  • Install the MPLAB software and Microchip Compiler.
  • Create a project and set the Compiler settings, Project >> Build Options >> Project.
  • Select the dsPIC30F4011 IC, Configure >> Configuration bits.
  • Add the source File into the project.
  • Compile the project, Project >> Build All.
  • If successfully compiled the project, then connect the dsPIC board into PC by using ICD2/PicKit2.
  • Programmer >> Select Programmer >> ICD2/PicKit2.
  • Programmer >> Connect.
  • If successfully connect the device with PC, then Programmer >> Program.
  • The HEX file is successfully dumped into dsPIC30F4011 IC.
  • Now, check it with Hardware and Motor Setup.

To compile the source code you must need to install the Mplab software & Microchip C30 Compiler. The installation procedures are as shown in above.

They must be properly set up and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.

In Mplab, you want to develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without microcontroller Board.

The PICKIT2 software is used to download the hex file into your microcontroller through USB port.

Testing the Inverter with dsPIC30F4011

Give +5V power supply to dsPIC30F4011 Board; the Induction Motor is connected with microcontroller dsPIC30F4011 Board. When the program is downloading into dsPIC30F4011, the LCD screen should show the duty cycle of PWM and the actual speed. Now you are increasing or decreasing the PWM duty cycle by using keys, then the motor is rotated at the corresponding rpm speed.

If you are not getting the actual speed from motor, then checking the feedback connections are correct.

If you are not getting any text from LCD, then you just check the jumper connections & adjust the trim pot level. Otherwise you just check it with debugging mode in Mplab.

If you want to see more details about debugging just see the videos in below link.

  • How to create & Debug a Project in Mplab using dsPIC30F.

General Information

Join the World's Largest Technical Community

we respect your privacy.