Regulate AC loads using PWM signal with PIC micro-controller

Published by MKDas on

We know that the PWM signal is very easy to generate using micro-controllers and we can control DC loads using this PWM signal. If we could use the PWM pulse to drive AC loads, the control circuit would become very easy. This is why many people look for PWM based driver circuit for AC loads. Here in this article, we will see how we can drive an AC load using the PWM signal.

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.

Before we start the hardware please read this article first to understand how the PWM signal can be used to control AC loads.

PWM generation using micro-controller:

Using a micro-controller makes many works easy. For those who are already experienced working with micro-controller, it is a very easy one to generate a PWM signal. For those who are new, this is not so complex at all.

Here, I’m generating a PWM signal using the PIC16F76 microcontroller. You can select other MCUs with the PWM module built-in. Or you can use software PWM.

Circuit diagram for PWM generation:

Coding:

This same code will be used to drive the load using PWM signal.

/*******************************************************************************
* Program for PWM generation with PIC16F76                                     *
* Program Written by_ Engr. Mithun K. Das                                      *
* MCU:PIC16F76; X-Tal:8MHz; mikroC pro for PIC v7.6.0                          *
* Date: 20-07-2020                                                             *
*******************************************************************************/
// LCD module connections
sbit LCD_RS at RB7_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_D4 at RB5_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D6 at RB3_bit;
sbit LCD_D7 at RB2_bit;

sbit LCD_RS_Direction at TRISB7_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_bit;
// End LCD module connections

int duty=0;
int adc_rd=0;
int i = 0;
int parcentage=0;
char text[4];

void main() 
{
  TRISA=0xFF;
  TRISC = 0xF0;
  ADCON0=0x01;
  ADCON1=0x00;
  Lcd_Init();
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Lcd_Out(1,1,"AC LOAD CONTROL");
  Lcd_Out(2,1,"USING PWM SIGNAL");
  PWM1_Init(5000);// initialize PWM at 5KHz
  PWM1_Start();//start PWM module
  PWM1_Set_Duty(0);//start zero duty pwm
  Delay_ms(3000);
  Lcd_Cmd(_LCD_CLEAR);
  while(1)
  {
     //control PWM with ADC
     adc_rd=0;
     for(i=0;i<20;i++)
     {
        adc_rd+=ADC_Read(0);
     }
     adc_rd/=20;
     
     //display adc_value
     text[0] = adc_rd/100 + 48;
     text[1] = adc_rd/10%10 + 48;
     text[2] = adc_rd%10 + 48;
     Lcd_Out(1,1,"ADC:");
     Lcd_Out(1,5,text);
     
     
     duty = adc_rd;
     PWM1_Set_Duty(duty);
     
     //display PWM duty
     text[0] = duty/100 + 48;
     text[1] = duty/10%10 + 48;
     text[2] = duty%10 + 48;
     Lcd_Out(2,1,"DUTY:");
     Lcd_Out(2,6,text);
  
     parcentage = duty*100/255;
     
     //display %
     text[0] = parcentage/100 + 48;
     text[1] = parcentage/10%10 + 48;
     text[2] = parcentage%10 + 48;
     Lcd_Out(1,10,"P:");
     Lcd_Out(1,12,text);
     Lcd_Out(1,15,"%");  
  }
}

Simulation result with PIC16F76 PWM generation

AC load drive with PIC16F76:

Now if we use this PWM generating control circuit with our previous AC load driving circuit, then we can get this:

Here, the PIC16F76 microcontroller is generating a PWM signal, and the duty cycle can be changed tuning the variable resistor (POT) RV1. As the micro-controller is generating a 5V output signal we need to amplify that signal to switch the MOSFET. An optocoupler 4N35 is used for this purpose. A 12V source is required too which normally comes from the common power supply of the project.

Here a transformer is used across the load to measure the signal across the load. There is no necessity to use this transformer in real hardware.

Here, the blue signal is the PWM output signal from MCU and the Yellow signal is the signal across the load.

Simulation result:

As we see, this project was easier than the previous one with NE555. Because we can control the frequency very easily from code. That makes our work easy.

I hope this project was helpful to you. If you make one for yourself, it will be a great pleasure for me. Anywhere you need help, let me know. Please share this project and subscribe to my blog. Thank you.


MKDas

Mithun K. Das; B.Sc. in EEE from KUET. Blog: https://labprojectsbd.com

5 Comments

Chandana · July 30, 2020 at 11:38 pm

Many Thanks

Rezaul · August 8, 2020 at 5:45 am

Thank you. আমার আরও আগে খোঁজ পাওয়া উচিত ছিল!
আমি pic mcu & mikroc শেখার চেষ্টা করছি.

flexo · October 20, 2020 at 10:29 am

this method isn’t suitable for inductive loads

Leave a Reply

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