Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PWM generation using PIC12F675


To generate PWM(Pulse Width Modulation) both analog and digital circuits can be used. But using a micro-controller is much easier than other methods. To generate PWM, the micro-controller has a built-in PWM module. But if there is no such PWM module then how can you generate PWM? Yes, in this article we are going to learn how we can generate a PWM signal if there is no such module built-in. Let’s start!

Usually, there is a built-in module in micro-controllers. But not all the micro-controllers have this feature. When there is such a module, you can not generate PWM using the built-in modules. But you can use some programming skills to generate a PWM signal.

Using timer interrupt, we can generate a PWM signal from any micro-controller. The method is very simple. First, use a timer interrupt to call interrupt say 100 times per second. Then, count each interrupt and set it zero at 100, besides creating a condition that until a duty (say 40 for 40%) the output is high, then the output is 0 until the counter is 0 again. So what will happen? Until 40 the pulse will be on and the rest 60 pulses will be off. So, we can get a 40% duty cycle at a frequency 1Hz. Now to increase this frequency simply increase timer interrupt speed i.e. reduce time.

Program for, PWM generation using PIC12F675
Program Written by_ Engr. Mithun K. Das; mithun060@gmail.com
MCU:pIC12F675; X-Tal: 4MHz(internal). Compiler: mikroC pro for PIC v7.6.0
Date: 30-03-2021; © labprojectsbd.com
#define pwm_pin GP0_bit
unsigned int scale=0,duty=0;

void InitTimer0()
OPTION_REG = 0x80;
TMR0 = 200;
INTCON = 0xA0;

void Timer_interrupt() iv 0x0004 ics ICS_AUTO
if (TMR0IF_bit)
TMR0IF_bit = 0;
TMR0 = 200; // change this value [0-255] to change the total frequency.
pwm_pin = 1;
pwm_pin = 0;

void main()
TRISIO = 0b00000000;//set I/O
GPIO = 0x00;
CMCON = 0x07;//comparator off
ANSEL = 0b00000000;

duty = 90;

}//end of while(1)
}//end of void main


Circuit diagram:​


Read Full Article


There are no comments to display.

Part and Inventory Search

Blog entry information

Last update

More entries from Mithun_K_Das