In this article, we are going to learn how to make a Pure sine wave inverter using PIC16F76. 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:

Advertisements

Sine wave inverter mechanism:

In most of the cases in sine wave inverters, an H-bridge driving configuration is used. There are four sets of switches that are connected like an H like in this image:

pure sine wave h-bridge
H-Bridge configuration

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

H-Bridge operation
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 the inverter.

Now if you drive this H-bridge with an SPWM signal, an 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 for sine wave:

Before we start, you should read my previous article to understand how we can use the PIC16F76 microcontroller to generate an SPWM signal.

Now our main job is to generate SPWM using a PIC microcontroller. 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:

Sine wave inverter gate signal
SPWM signal for the inverter
Sine wave inverter gate signal
SPWM signal

Here there are two signals at 50Hz in a push-pull configuration and the other two are SPWM signals (20KHz) which are 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 a 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 the microcontroller to the switch MOSFET. These gate-driving circuits simply convert the MCU’s 5V signal into a 10V+ signal which can be used to switch MOSFETs.

Circuit diagram:

So the circuit diagram for our Pure sine wave inverter using PIC16F76:

Pure sine wave inverter circuit diagram
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 generates 4 sets of signals and these signals trigger the MOSFETs with the help of the gate driver IC. The MOSFETs are driving our main power transformer TR1. Which is a UPS transformer rated 7.5v:250v. At the secondary terminal, a high-voltage capacitor C9 is working as our filter (C), and the transformer itself working as an inductor (L). So an L-C filter is formed in our circuit.

There is another option to add feedback in our inverter which is designed with a transformer. Although it can be made of electronic circuits only 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. To turn the inverter on/off, a switch is used which is connected to the RA4 pin of our MCU.

Before we start the coding, you should read my previous article to understand how we can use the PIC16F76 microcontroller to generate an SPWM signal.

Coding:

Here is our code to drive the H-bridge from where our expectation is to get a 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)
   {
      duty++;
      if(duty>=32)
      {
        duty=0;
        alt=~alt;
        CCPR1L = 0;//inverter shutdown
        CCPR2L = 0;
        RC0_bit=0;
        RC3_bit=0;
        asm nop;
        asm nop;
      }

      if(inv_mask)
      {
          if(alt)
          {
             CCPR1L = sin_table[duty]*fb_constant;
             CCPR2L=0;
             RC0_bit=1;
             RC3_bit=0;
          }
          else
          {
             CCPR2L = sin_table[duty]*fb_constant;
             CCPR1L=0;
             RC0_bit=0;
             RC3_bit=1;
          }
      }
      else
      {
         CCPR1L = 0;//inverter shutdown
         CCPR2L = 0;
         RC0_bit=0;
         RC3_bit=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
   PORTC=0x00;
   RC4_bit = 1;//for LCD backlight
   ADC_Init();
   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;
   UART1_Init(9600);
   while(1)
   {
      RC4_bit = 1;
      //switch operation
      if(!RA4_bit)
      {
        inv_mask=1;
        lcd_clr=1;
      }
      else
      {
        inv_mask=0;
        if(lcd_clr)
        {
            lcd_clr=0;
            Delay_ms(1000);
        }
      }
            
      //read output
      output=0;
      for(k=0;k<20;k++)
      {
         output+=ADC_Get_Sample(3);
         Delay_ms(1);
      }
      output/=20;


     if(output<100)
     {
        if(fb_constant<0.7)fb_constant+=0.1;
     }
     if(output>115)
     {
        if(fb_constant>0.5)fb_constant-=0.1;
     }

   }
}// 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, this timing and signal generation is done. Here as we need to regulate the output as a feedback system a feedback variable is used named ‘fb_constant’. This floating-point variable is used to reduce or increase the SPWM duty inside the timer interrupt. This makes a smooth feedback system for the sine wave inverter.

Check these:

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

Download the hex file from here for free!

PCB:

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

Pure sine wave inverter PCB download
PCB for sine wave inverter

Result:

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

Pure sine wave inverter circuit diagram
Pure sine wave inverter

The waveshape of our sine wave inverter:

Sine wave inverter output signal
Output wave shape

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

For more useful articles, don’t forget to subscribe. Thanks.

For Professional Designs or Help:

Loading

Read more:

Categories: ElectronicsMeasuring instrumentsMeters and DisplaysMicrocontrollerPICPower Electronics

MKDas

Mithun K. Das; B. Sc. in EEE from KUET; Head of R&D @ M's Lab Engineering Solution. "This is my personal blog. I post articles on different subjects related to electronics in the easiest way so that everything becomes easy for all, especially for beginners. If you have any questions, feel free to ask through the contact us page." Thanks.

68 Comments

Asimi · 26/07/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 · 27/07/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 · 20/10/2020 at 12:07 pm

a million thanks for this tutorial I love your tutorials

    Mithun K. Das · 20/10/2020 at 2:12 pm

    Thank you too

      Emman · 11/04/2021 at 10:52 am

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

        MKDas · 11/04/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 · 01/01/2021 at 11:05 pm

excelente, como todos sus trabajos ,desde Colombia gracias

    Godwin · 26/02/2021 at 9:02 pm

    Please,hex file I didn’t have the compiler

      Mithun K. Das · 27/02/2021 at 5:10 am

      Install the compiler. Arrange your code. If it shows demo limit, email the complete project file to mithun060@gmai.com

        Ehi · 11/08/2021 at 1:55 am

        The drop in voltage when more than 100w is appliedhow can it be corrected

          MKDas · 11/08/2021 at 11:39 am

          If it is redesigned with feedback then it will work.

manh · 08/05/2021 at 6:38 am

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

Antonio Franca · 07/07/2021 at 12:58 am

Mithun, thank you very much for your prompt attention. I kindly ask if it is possible for you to change and send me the lines of code referring to the LCD.

Sincerely,
Antonio France

    MKDas · 07/07/2021 at 5:08 am

    I don’t know the pin configuration of the easy pic. Kindly change it yourself, please.

      Antonio França · 07/07/2021 at 11:46 am

      Hello Mithun, good morning. Here in Brazil it is 8:45 am

      I don’t know which country you reside in.

      Returning to the question of your project, I would like if possible to make available to everyone the schematic diagram with the connections with the LCD.

      thanks

      Antonio França

        MKDas · 07/07/2021 at 11:48 am

        the diagram is given in the article. Kindly check.

Franca · 07/07/2021 at 1:22 pm

Which Article?

    MKDas · 07/07/2021 at 2:40 pm

    This article. Kindly check again.

      Antonio França · 07/07/2021 at 10:06 pm

      Dear MKDas,

      Unfortunately I didn’t see in your schematic any connection of the PIC16F73 with any LCD

        MKDas · 08/07/2021 at 1:02 am

        Oh sorry, I did not check that this one was LED-based. There is another one with LCD based. I’ll make the hardware ready soon, then write on that.

MUNIKO · 17/08/2021 at 4:54 pm

hi,i want to build your circuit but help me to have protections, battery low and overvoltage,short circuit and display,

    MKDas · 17/08/2021 at 8:25 pm

    First, make this basic one. Then you can add features easily if you understand this.

    Muniko · 19/10/2021 at 10:04 pm

    Is there a feeback in this circuit?

Saddam · 01/11/2021 at 2:06 am

Dear sir aponi ki pic16f73 ic er ips er jonno peogrrame kore dite parben…….

Chimezie · 09/11/2021 at 3:38 pm

Hi please which compiler did you make use of.. and please when are you adding feedback to the design thanks

Paul · 09/11/2021 at 5:02 pm

hi nice work please i need your assistance to add charging mode to this great project thanks mayoortech@gmail.com

Prasanjith · 25/03/2022 at 4:07 pm

In your schematic Where is the Low pass filter after generating PWM signals?

    MKDas · 26/03/2022 at 12:11 pm

    The transformer itself is a big inductor. And just add a capacitor with the output in parallel. So there is a LC filter….

prestley johnson · 10/04/2022 at 1:17 am

hi MKDas, kindly upload video for the spwm inverter.

    MKDas · 10/04/2022 at 7:20 pm

    I’ll, but not this one. With dsPIC one. 🙂

Achira · 14/04/2022 at 12:30 pm

Dear MKdas,
I would like to make the inverter project. Let me have the PCB pattern as a PDF so that I will be able to make it with the toner transfer method. Also a crystal shown in your assembled photo but its not indicated in the circuit diagram ?
Thank you,
Achira
vdslnet@gmail.com

    MKDas · 14/04/2022 at 4:36 pm

    Crystal is not shown in the proteus circuit diagram but in real, you have to use one.

    Eniola · 21/05/2022 at 5:34 pm

    The greatest blog ever,love 💕💕💕 to be in this blog .may take Lord continue to increase your wisdom.love you sir.sir,I want protection for this circuit or can I sense overload for the some port use as input? which port can I sense with overload and short circuit? looking forward to your quick response.i have subscribed to this blog

      MKDas · 21/05/2022 at 8:57 pm

      You can do anything you want if you understand the working principle and know how to add codes.

Love your blog and May the Lord bless you for helping people like me. Love you sir. Sir, how can I add lcd display to display battery sense, inverter on and off · 07/06/2022 at 10:55 pm

Love your blog and May the Lord bless you for helping people like me. Love you sir. Sir, how can I add lcd display to display battery sense, inverter on and off

    MKDas · 08/06/2022 at 9:51 am

    Thank you. Yes you can add the LCD display. Simply use the LCD functions from the library. But only one thing you need to keep in mind about the microcontroller’s range of capacity.

Caleb · 17/07/2022 at 4:56 pm

I love your blog keep up the good work. I will update the code and add feedback, short circuit, overload battery low and charging and will upload foe everyone

Mr.PP · 22/07/2022 at 8:22 am

I want the system Soft Start Amplitude from 0-220v how to do? Please advise.

    MKDas · 22/07/2022 at 12:34 pm

    gradually increase the PWM

Abul Hassan · 09/08/2022 at 8:54 pm

Can this project work in pic16f72 ic?

Faizan · 06/09/2022 at 11:05 pm

Great

Faizan · 06/09/2022 at 11:06 pm

Can this project work in pic16f873 ic?

    MKDas · 07/09/2022 at 4:09 pm

    yes, but configuration changes are required.

EMERITUS · 17/01/2023 at 1:18 am

I finally finished the project have completed the feedback section and can power any heavy load with no output drop, added temperature sensor for shutdown while inverting and charging, added charging section to it can charge upto 15A current and doesnt select transformer, added battery low shutdown, mainsdetect and charges commence after 10secs, trickle charger, overload protection, and shut circuit protection all in the pic16f73. you can contact me for the full c-file written in mikroc for pic

    MKDas · 17/01/2023 at 10:27 am

    Fantastic

    Olly · 13/05/2023 at 1:26 pm

    Hi, good work and more grace to your elbow. Please can you help with your developed design? Thanks in advance.

      MKDas · 13/05/2023 at 3:02 pm

      This one is for learning purpose and its open for all. But for professional ones, I recommend dsPIC. And sorry, professional ones are not open source.

    Olly · 03/08/2023 at 12:44 pm

    Hi Mr Emeritus, you have done a great job to compliment the author of this post.
    Please assist me with your design circuit and code just as the author of this post has done. My email is powerflocrown75@gmail.com. Thanks for the good job.

      MKDas · 12/08/2023 at 6:15 pm

      plz write what you are asking for.

    paul · 14/10/2023 at 5:35 pm

    EMERITUS plese i need it

    Snehrish · 13/11/2023 at 2:00 am

    EMERITUS, please can you email so we can talk about it
    Chriselect1@gmail.com

      MKDas · 13/11/2023 at 11:45 am

      if you need to discuss anything, WhatsApp me.

        CDTES · 23/06/2024 at 3:09 am

        Can I get your whatsapp number, I need the professional one, what will it cost me

          MKDas · 23/06/2024 at 1:21 pm

          given in the subscription section.

kuldip · 28/03/2023 at 2:28 pm

Sir, PWM signal is not generating from the microcontroller as you have shown here, i have simulated the circuit in proteus but didn’t work, what to do? Please help, sir

    MKDas · 29/03/2023 at 11:56 am

    check project settings

Alfrever · 25/06/2023 at 9:53 pm

Hello, your design looks very interesting and thanks for sharing it. I am a beginner in programming, what parts of the code would I have to modify to change the frequency to 60Hz?

    MKDas · 02/07/2023 at 7:28 pm

    Thanks. Edit timer interrupt settings.

paulo obregon · 28/08/2023 at 8:11 pm

ola gostaria de operar em 60 hz ajude-me

Arif · 13/05/2024 at 4:45 pm

Sir, is dead time pwm possible with this IC. For Puspool Transformer ??

    MKDas · 16/05/2024 at 1:54 pm

    not possible directly. but with code not impossible.

Leave a Reply

Avatar placeholder

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