How to process/generate a phase shifted frequency varying sine wave? - Page 1
Forum section: electronics / general

author: logictom
author_rank: Unknown
timestamp: February 25, 2013, 05:32:24 pm
content: So what I want to do is to phase shift an incoming sine wave with varying frequency but I am unsure how to go about doing so in practical terms.A little more info regarding the requirements: I have an encoder producing a sine/cosine pair with a fixed Peak to Peak but as the speed changes so obviously does the frequency. I want to effectively advance/retard the signal by altering the phase of the incoming signal.I also want to generate the cosine but I 'assume' once I have the sine part working I can simply phase shift this also.Where I am unsure is how to go about doing this, if I use a look up table (LUT) for fast frequencies this would be ok but at slower frequencies I am going to get a very rough (digitised) signal. I was thinking I could calculate the signal 'on the fly' but again that would require having a LUT ie output = sin (input(amplitude) + offset)I am looking at using a microchip PIC for the job but I am unsure which route to go, the possible implementations that come to mind are: PWM with LPF to generate the sine/cosine signals, using a DAC or using an external DDS chip.I think I maybe going about this the wrong way and there is possibly a simple solution to this? I'm sure my maths ability it also holding me back here as to the simple solution.As always any help is greatly appreciated.

author: fcb
author_rank: Super Contributor
timestamp: February 25, 2013, 09:20:31 pm
content: So you have a sine/cosine pair of signals from an encoder, and you want to generate a 2nd pair of sine/cosine signals from those with a known phase-shift. The encoder frequency varies. You don't state if you need the encoder to work in both directions?Assuming you want a digital solution and a predictable lag, and a small amount noise/error was acceptable then:1. ADC both analog sine/cosine signals simulataneously.2. Extract quadrant (if it's 0-90, 90-180, 180-270, 270-0) and direction - you'll need the cosine for this unless you track the previous conversion.3. Throw the sine (adjusted for 0-90) against a big LUT - this will extract convert SINE to DEGREES.4. Add/subtract your OFFSET DEGREES to create new sine and cosine angles in degrees5. Throw both against another big LUT to create your new output SINE and COSINE, adjust for quadrant.6. Wack out the numbers using DACS.I've done very successfully used LUT's with interpolation to get manageable LUT size and very high resolution. It's not rocket-science, but you will need to draw this out carefully, it's lots of little steps. If you don't need speed, then you can probably do the maths in a small micro - but LUT's are cheap and simple.

author: TerminalJack505
author_rank: Super Contributor
timestamp: February 26, 2013, 02:38:36 am
content: I've seen some schematics for digitally controlled phase shifters. These just seem to be phase lead, phase lag or phase lead-lag op amp circuits with digital potentiometers.I can't say how well they work or if they are suitable for your application, however.

author: TerminalJack505
author_rank: Super Contributor
timestamp: February 28, 2013, 09:20:17 am
content: When I first read your post I wondered if there was a way to use a PLL to do the phase shifting. Just by chance I watched w2aew'sBasics of Phase Locked Loop Circuits and Frequency Synthesisvideo on YouTube today and he does exactly this at the end of the video by simply offsetting the voltage at the PLL's VCOINpin.This is something else to consider to get your signal phase shifted. By doing the shifting in the analog domain it will solve the 'digitization' issue you mention. Finding a schematic that shows an example of this under MCU control is tricky, however. Maybe my Googlefu is just too weak. I foundthis articleon EDN but the figures (the schematic, in particular) are dead links. The nice thing about that particular circuit is that it claims to be able to lead or lag from 0 to 180 degrees.Here'sanother EDN articlethat uses a digital pot and an op amp to do phase shifting. The article claims "the 720-kHz input sine wave rotates several times from 0 to 360 degrees" but, as someone in the comments points out, this is just an adjustable lag network so the phase shift is likely just 0 to (at most) -180 degrees.For those that are interested, here's w2aew's video:

author: logictom
author_rank: Unknown
timestamp: March 05, 2013, 06:09:00 pm
content: Thank you guys for the replies, must have missed the notification email.Thanks for the video link, makes PLL sound so simplefrom what I researched it appears you can only get PLL for square waves/pulse trains, please correct me if I am wrong - this would be a nice implementation if possible.The first EDN link you gave doesn't appear to have a link attached?FCB, sounds so simple when you put it like thatThe signal will vary between 0-200Hz max, will have to check what the usualable range should be. The current microcontroller I have provisioned doesn't have a DAC so will have a look at either switching the micro and what external DACs are available.

author: TerminalJack505
author_rank: Super Contributor
timestamp: March 05, 2013, 06:31:13 pm
content: That link should work now.So far as using PLLs with sine waves goes Ithoughtyou could do that but you might be right. Hopefully someone else knows the answer.