Continue to Site

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.

Want to change the Phase of the Sine Wave Generated by PIC16F877A

Status
Not open for further replies.

xpress_embedo

Advanced Member level 4
Joined
Jul 5, 2011
Messages
1,154
Helped
161
Reputation
396
Reaction score
189
Trophy points
1,353
Location
India
Activity points
10,591
I have generated Sinusoidal Wave using PIC16F877A and DAC0808

Here is my look table that i used to generate the sine wave

Code:
const unsigned char wave[180] = {128,132,137,141,146,150,155,159,163,168,172,176,180,184,188,192,196,200,203,207,210,214,217,220,223,226,229,232,234,237,239,241,243,245,247,248,250,251,252,253,254,254,255,255,255,255,255,255,255,255,254,253,252,251,250,248,247,245,243,241,239,237,234,232,229,226,223,220,217,214,210,207,203,200,196,192,188,184,180,176,172,168,163,159,155,150,146,141,137,132,128,124,119,115,110,106,101,97,93,88,84,80,76,72,68,64,60,56,53,49,46,42,39,36,33,30,27,24,22,19,17,15,13,11,9,8,6,5,4,3,2,1,1,0,0,0,0,0,1,1,2,3,4,5,6,8,9,11,13,15,17,19,22,24,27,30,33,36,39,42,46,49,53,56,60,64,68,72,76,80,84,88,93,97,101,106,110,115,119,124};

But now i have to generate a new sine wave which must have same frequency as that of the above..

But the second sine wave must have some additional functionality of phase shifting..

I have change the Phase of Second Sine Wave with respect to the first....

Any iDeas relating to that are welcomed..

Thanks
 

Phase change just means that the two sine waves will reach their peaks/zero-crossings at some time offset relative to each other. If you have a loop that is reading the value out of the "wave" array (we'll assume you are using the variable "i" for that loop), then you can add a second line to output the value at i+offset, where offset is equal to the number of points you are reading ahead (or behind) to shift the second sine wave's phase.

Since you have 180 points to cover the 360 degrees of sine, that means each point represents 360 deg. / 180 pts = 2 degrees/pt. So, if you want to outphase the two signals by X degrees, you need offset to be... X deg / (2 deg/pt). Add or subtract offset will depends on if you want to lead or lag the second wave. Be sure to round your offset to whole integers, since you will be using that as the index value for reading a value out of the wave array.

Also, when you calculate the outphased signal index pointer, don't forget to wrap it back around to the beginning of the array, if the number is larger than your 180 point array length.

Hope that gives you some ideas on where to start.
 

When creating circular buffers, I prefer to make them a power of 2, so my roll-over logic is simplified, because I can use AND mask instead of IF statement.

For example, for next entry in 8 entry buffer:

ix = (ix + 1) & 0x7;
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top