# FEEDBACK IN SINE WAVE INVERTER USING PIC16F887.

Status
Not open for further replies.

#### T.A

##### New Member
Hello Guys. I am Timothy

#### T.A

##### New Member
I have been been working on designing a sine wave inverter using PIC16F887 microcontroller using fullbridge configuration.. The part of the design that seems stressful is implementing feedback in the code.

This is an excerpt of the sine wave table.
This is what happens;

The table is a two dimensional array; sinearray[row][column].
The row index ranges from 0 - 6 and the column index ranges from 0-49.

when the value of the row index is between 0-3, the sine wave and the frequency is okay but when the row index start approaching 4 -6,
the sine wave becomes distorted and the frequency is drastically reduced.

#### Attachments

• 1.3 KB Views: 97

#### T.A

##### New Member
please, can i get any help here.

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
Just looking at the table only... The distortion is occurring at 4 onwards... The common factor seems to be signed vs unsigned...

0 and 1 only go as high as 120 3 goes to 140 ( has the sine wave has a distorted top!!!)

4 and 5 will be distorted whilst 6 and 7 may appear as double the frequency..

#### T.A

##### New Member
Just looking at the table only... The distortion is occurring at 4 onwards... The common factor seems to be signed vs unsigned...

0 and 1 only go as high as 120 3 goes to 140 ( has the sine wave has a distorted top!!!)

4 and 5 will be distorted whilst 6 and 7 may appear as double the frequency..
Didnt get the explanation. please kindly elaborate .

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
Okay... In C const char is signed by default.... Therefore its value is 128 ~ -127.... so lets assume you control something with a unsigned character type ( 8 bits ).... Lets call this variable 'A' .. Then get a variable from the table
A = sinearray[2][14];
'A' will now indeed equal 107...
Now we will fetch A = sinearray[7][25];
Hang on a mo... 'A' should be 200 but you have 56!!!!!!!!
Oooh this wont work!!! to fix it you need to declare the table as const unsigned char... or cast the fetch.

A = (unsigned char) sinearray[x][x]l; Now 'A' will indeed hold 200...

#### T.A

##### New Member
Thanks . i just modified that, the problem still persists.

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
I suppose it all depends on the drive... If you are using the inbuilt bridge driver, I would have though the sinearray will be driving the CCPRxL directly, so the const unsigned char is a must... If this isn't your problem then it'll be more than likely a hardware issue..

#### T.A

##### New Member
ok, let me explain better.

i have implemented the design on the veroboard
i used a tranformer 7v-240v
i used a battery of 12vdc, it gave an output of 300v, i scope it, it gave a good sine wave.

without the feedback, the inverter works well, but when the feedback is introduced, the wave becomes distorted

The same problem about the feedback that persists on the software design is the same problem that is appearing on the hard ware.

so i believe if i can get it right on the software design, the hardware design wont give any problem again.

i guess i should post the source code.

#### T.A

##### New Member
This is the source code.

#### T.A

##### New Member
i also notice

if i did something like :
CCPR1L = sinearray[5][dutycycle] ; i get a good wave

if i do something like :
unsigned char index1 = 5;
CCPR1L = sinearray[index1][dutycycle] ; i get a distorted wave

why ????

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
This is still something todo with signed/ unsigned... A constant is an integer in the C environment

If you do this...

volatile int index1=5;
CCPR1L = sinearray[index1][dutycycle] ;
will that work???
Also this line... __delay_ms(0.1); I don't think will work as the macro requires a constant ( whole number ).. I would use its sister __delay_us(100);

Last!! P1M1.... Shouldn't that be CCP1M1?

#### T.A

##### New Member
when i used CCP1M1 instead of P1M1, the waveform got worse.
I also changed index1 also to volatile, the problem still persists.

#### T.A

##### New Member
Any further help, i will indeed appreciate.

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
Here is your sine wave in Proteus circa 1khz.... This is with a simple filter 330Ω and .33μf..

Here is the same 1khz wave form using Roman Blacks "Harmonized" sine table..

C:
const unsigned char sine[50] = {52,57,62,66,70,74,77,80,82,84,85,86,86,
86,85,83,81,78,75,72,69,65,61,56,52,
48,44,39,35,31,28,25,22,19,17,15,14,14,
14,15,16,18,20,23,26,30,34,38,43,48};
The distortion is purely the table...

#### T.A

##### New Member
Thanks, so what is your suggestion ?
how can i generate a better 2D array table ?

Last edited:

#### T.A

##### New Member
how is it generated. what is the basics of generating it ?