Sine Wave inverter using PIC16F76

Published by MKDas on

In this article, we are going to learn how to make a sine wave inverter with PIC16F76 micro-controller. Sine wave inverter is one of the most wanted projects in the power electronics field. Making a pure sine wave inverter is a very pleasurable job too. You can make a pure sine wave inverter for yourself and use it, even you can make a bigger machine with this after learning this project carefully. So stay connected and keep reading…

Disclaimer: Electricity is always dangerous. Skill required to work with electricity. Do work with your own risk. Author will not be responsible for any misuse or harmful act. This website contents is also copyright protected. Anything copied and directly posted in your website and claiming it as yours is prohibited and nonsensical. Author published all the articles as opensource to help you making your project and learning purpose only. Learn and make one for yourself. If need any help feel free to ask the author. Author will be helpful to you. Thanks.

Sine wave inverter mechanism:

Most of the cases in sine wave inverter, a H-bridge driving configuration is used. There are four set of switches which is connected like a H like this image:

H-Bridge configuration

Here there are 4 switches S1 to S4. By switching in sequential way we can generate an alternating current flow through the load. It is like this:

H-Bridge driving way

An alternating current flow generates an alternating voltage across the load. And if this load is a step-up transformer, then we can get an alternating voltage across the secondary of the transformer which will be higher than the supply voltage. This is the basic configuration of inverter.

Now if you drive this H-bridge with SPWM signal, a SPWM can be found on the higher voltage end of the transformer. After filtering that, we can easily get a pure sine wave. This is the concept of a sine wave inverter.

SPWM generation:

Before we start, you should read my previous article to understand how we can use PIC16F76 micro-controller to generate SPWM signal.

Now our main job is to generate SPWM using PIC micro-controller. Then we can use this SPWM signal to drive our H-bridge. But to drive the H-bridge, we need two push-pull types SPWM and two push-pull signals like this:

SPWM signal for inverter
SPWM signal

Here there are two signals at 50Hz in a push-pull configuration and the other two are SPWM signals (20KHz) which is followed by the previous 50Hz signals. These 4 signals are used to drive the H-bridge. The switches can be MOSFET, IGBT, or transistors. We have to choose a suitable one. For inverters, we can use MOSFET as our switching device.

The upper arms of the bridge are switched by 50Hz signal. And the lower arms are switched by 20KHz modulated signals. We can not use these signals directly to switch the MOSFETs. We need gate driving circuits to convert the signal from micro-controller to switch MOSFET. These gate driving circuits simply convert the MCU’s 5V signal into 10V+ signal which can be used to switch MOSFETs.

Circuit diagram:

So the circuit diagram for our inverter will be this:

Sine wave inverter circuit diagram

Here you can see that all the MOSFETs are driven with the help of TLP250 gate driver IC and associated circuitry. The control MCU is PIC16F76 which is generating 4 set of signals and these signals are triggering the MOSFETs with the help of gate driver IC. The MOSFETs are driving our main power transformer TR1. Which is actually a UPS transformer rated 7.5v:250v. At the secondary terminal a high voltage capacitor C9 is working as our filter (C) and transformer itself working as an inductor (L). So a L-C filter is formed in our circuit.

There are another option to add a feedback in our inverter which is designed with a transformer. Although it can be made of electronic circuit only but to keep it simple to understand I kept transformer TR2.

Also to measure the battery voltage, I used a voltage divider circuit with R18 & R19+C14. And to turn the inverter on/off, a switch is used which is connected to the RA4 pin of our MCU.


Here is our code to drive the H-bridge from where our expectation is to get pure sine wave.

* Program for sine wave generation using PIC16F73                              *
* Program Written by_ Engr. Mithun K. Das                                      *
* MCU:PIC16F76; X-Tal:20MHz; mikroC pro for PIC v7.6.0                         *
* Date:18-04-2020                                                              *

unsigned char sin_table[32]={0, 25, 49, 73, 96, 118, 139, 159, 177, 193, 208, 220, 231, 239, 245, 249, 250, 249, 245, 239, 231, 220, 208, 193, 177, 159, 139, 118, 96, 73, 49, 25};
int duty=0;
float fb_constant=0.8;
bit alt;
bit inv_mask;
void Interrupt() iv 0x0004 ics ICS_AUTO
   if (TMR2IF_bit == 1)
        CCPR1L = 0;//inverter shutdown
        CCPR2L = 0;
        asm nop;
        asm nop;

             CCPR1L = sin_table[duty]*fb_constant;
             CCPR2L = sin_table[duty]*fb_constant;
         CCPR1L = 0;//inverter shutdown
         CCPR2L = 0;
      TMR2IF_bit = 0;

int k=0;
unsigned int battery=0,output=0;
bit lcd_clr;
char msg[]="000";

void main()
   TRISA=0xFF;//all input
   TRISC = 0x00;//all output
   RC4_bit = 1;//for LCD backlight
   PR2 = 249;
   CCP1CON = 0x4C;
   CCP2CON = 0x4C;
   TMR2IF_bit = 0;
   T2CON = 0x2C;
   TMR2IF_bit = 0;
   TRISC = 0;
   TMR2IE_bit = 1;
   GIE_bit = 1;
   PEIE_bit = 1;
      RC4_bit = 1;
      //switch operation
      //read output


}// end

Here I used a sine table “unsigned char sin_table[32]={0, 25, 49, 73, 96, 118, 139, 159, 177, 193, 208, 220, 231, 239, 245, 249, 250, 249, 245, 239, 231, 220, 208, 193, 177, 159, 139, 118, 96, 73, 49, 25};” to generate the SPWM and Timer1 to make the 50Hz signal as well as 4 push-pull type signals (2 pairs).

In the timer interrupt section, these timing and signal generation is done. Here as we need to regulate the output as a feedback system so a feedback variable is used named ‘fb_constant’. This floating-point variable is used to reduce or increase the SPWM duty inside timer interrupt. This makes a smooth feedback system for sine wave inverter.

We are using a switch to turn the inverter on/off which is controlled by variable ‘inv_mask’ inside interrupt routine.

Download the hex file from here.


I use Sprint Layout to design PCB for most of the small projects. Here is the PCB design for our inverter.

PCB for sine wave inverter

You can download the PCB files to make your PCB.


After completing the PCB I tested this project. Result was awesome. Project image:

Pure sine wave inverter

Wave shape:

Output wave shape

My oscilloscope’s voltage sensing is not actual. I measured with multi-meter, I got 210V AC output which was good. As a small transformer used here, loading over 100Watts significantly reduces output voltage.



Mithun K. Das; B.Sc. in EEE from KUET. Blog:


Asimi · July 26, 2020 at 2:57 am

Good day Mr Mithun. I have been writing to severally but the message didn’t deliver and I decided to try it again today. Pls I really appreciate all your efforts in all the post created to help individual who want to learn. May God Almighty reward and give you more knowledge. However, I have been facing a lot of challenges in the sine inverter you have posted. (1) how did you get CCP1CON= CCP2CON= 0x4C; = 0b01001100; from the table, in datasheet. I have spent almost completely full day, I couldn’t get it. Pls show me how you got it. (2) how did you get your PR2 = 251, when using “Fosc = 20MHz and Fpwm = 20Kz respectively. When calculated, I got 249 (I e PR2= 249 not 251). (3) pls, explain to me, how did i develop small code to charge the inverter via mains ac sensing. Is it to keep the 2 of ccp1 and ccp2 active and deactivate the low frequency (50Hz) signal or keep low frequency (50Hz) actively and deactivate ccp1 and ccp2. pls, guide me

    Mithun K. Das · July 27, 2020 at 4:37 am

    Yes it was 249 if calculated. I was testing tuning a little bit which gave me good result for my circuit and transformer. You can check on your side.

djalltra · October 20, 2020 at 12:07 pm

a million thanks for this tutorial I love your tutorials

    Mithun K. Das · October 20, 2020 at 2:12 pm

    Thank you too

      Emman · April 11, 2021 at 10:52 am

      Thank you for this article.
      How can we add battery charging code here?

        MKDas · April 11, 2021 at 11:18 am

        This one is a basic one. If it is utilized and reformated in flat coding, all standard options can be added. I’ll try to do something with this later. Stay with us & subscribe. Maybe in future, you’ll get more useful posts.

enrique · January 1, 2021 at 11:05 pm

excelente, como todos sus trabajos ,desde Colombia gracias

    Godwin · February 26, 2021 at 9:02 pm

    Please,hex file I didn’t have the compiler

manh · May 8, 2021 at 6:38 am

Please help,code file I didn’t have the compiler

Leave a Reply

Your email address will not be published. Required fields are marked *