# PWM inverter circuit issues PIC

Status
Not open for further replies.

#### James A

##### Newbie level 3
Hello to everyone,
Guys I designed a pic based PWM inverter using the CCP1 and CCP2 and then use the low pass filters to obtain the PWM outputs in sine. I used the micro c to program the pic16f887 and obtained my required sine wave in simulation, however I am new to designing and I think I made a mistake in using the CCP pins as I checked the internet for similar design for confirmation and found none I hope someone here could provide some perspective.

Code C - [expand]1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
unsigned short duty_cycle=255;
unsigned short duty_cycle1=0;
void initial()
{
ANSEL=0;
ANSELH=0;

PORTA=0;
PORTB=0;
PORTC=0;
TRISA=255;
TRISC=0;
PWM1_INIT(5000);
PWM2_INIT(5000);
}

void main() {

pwm1_set_duty(duty_cycle);
pwm2_set_duty(duty_cycle1);
pwm2_start();
pwm1_start();

while(1)
{
while (duty_cycle>0)
{
duty_cycle-=15;
pwm1_set_duty(duty_cycle);
}
while (duty_cycle1<255)
{
duty_cycle1+=15;
pwm2_set_duty(duty_cycle1);
}

while (duty_cycle1>0)
{
duty_cycle1-=15;
pwm2_set_duty(duty_cycle1);
}
while (duty_cycle<255)
{
duty_cycle+=15;
pwm1_set_duty(duty_cycle);
}
}
}

and the simulation results along with the circuit diagram are given below

In the graph the one below is required and the above one is being produced from dc by the circuit.
Btw, my adviser thinks this wont work.

Last edited by a moderator:

#### betwixt

##### Super Moderator
Staff member
I think you are completely off course!

The idea of using PWM is that you use the digital signal to drive the power stages so they are fully on or fully off (= max efficiency) then filter it to a sine wave afterwards.
Just using PWM to produce low level sine waves isn't wrong if you want a signal genarator but it isn't good for an inverter application.

Brian.

#### Tahmid

You are constantly changing the duty cycle by a fixed amount. You need to implement SPWM and the duty cycle needs to be changed, not by a fixed amount, but variably so that the generated sequence of pulses represent a digital implementation of a sine wave. Thus, the values must vary sinusoidally. Also, in the main code, you haven't called the initial() subroutine.

You can find a tutorial here that describes how to generate a sine table and implement SPWM: https://tahmidmc.blogspot.com/2011/01/generation-and-implementation-of-sine.html
You may also find these helpful:
https://www.edaboard.com/blog/1800/
https://www.edaboard.com/blog/1803/
https://www.edaboard.com/blog/1798/

Hope this helps.
Tahmid.

#### James A

##### Newbie level 3
Thanks a lot for the reply,
If I were to use high power transistors instead of 2n2222 like IGBTs would that help. Plus are there any nice capacitors and resistors which can handle in excess of 500W.
P.S. The op amp is just being used to take difference I was having problems while taking difference and observing it in oscilloscope so i just used a differential circuit. Practically it should not be there.

Regards
James A

#### Tahmid

Practically, you should be feeding drivers from the output signals from the microcontroller. The drivers should drive a full-bridge converter stage (using IGBTs or MOSFETs). The output of the full-bridge converter stage should be filtered using LC filter, not RC filter.

Hope this helps.
Tahmid.

#### James A

##### Newbie level 3
Thanks a lot for the reply,

But I don't have an issue with the signal generated. Power rating and capacitor capability and availability of the required components in the circuit is the problem. Could you hep with that.

Regards
James A

- - - Updated - - -

Further more could you elaborate the usage of LC filter, rather than RC not really good at that stuff.

Regards
James A

#### Tahmid

Power rating of the capacitor?
Choose a capacitor that has a sufficient voltage rating and ripple current rating.

Availability of which components?

Status
Not open for further replies.