Author Topic: How to process/generate a phase shifted frequency varying sine wave?  (Read 4378 times)

0 Members and 1 Guest are viewing this topic.

Offline logictomTopic starter

  • Supporter
  • ****
  • Posts: 336
  • Country: au
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[amplitude])

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.
 

Offline fcb

  • Super Contributor
  • ***
  • Posts: 2117
  • Country: gb
  • Test instrument designer/G1YWC
    • Electron Plus
Re: How to process/generate a phase shifted frequency varying sine wave?
« Reply #1 on: February 25, 2013, 09:20:31 pm »
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 degrees
5. 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.
https://electron.plus Power Analysers, VI Signature Testers, Voltage References, Picoammeters, Curve Tracers.
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1310
  • Country: 00
Re: How to process/generate a phase shifted frequency varying sine wave?
« Reply #2 on: February 26, 2013, 02:38:36 am »
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.
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1310
  • Country: 00
Re: How to process/generate a phase shifted frequency varying sine wave?
« Reply #3 on: February 28, 2013, 09:20:17 am »
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's Basics of Phase Locked Loop Circuits and Frequency Synthesis video on YouTube today and he does exactly this at the end of the video by simply offsetting the voltage at the PLL's VCOIN pin.

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 found this article on 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's another EDN article that 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:

« Last Edit: March 05, 2013, 06:28:00 pm by TerminalJack505 »
 

Offline logictomTopic starter

  • Supporter
  • ****
  • Posts: 336
  • Country: au
Re: How to process/generate a phase shifted frequency varying sine wave?
« Reply #4 on: March 05, 2013, 06:09:00 pm »
Thank you guys for the replies, must have missed the notification email.

Thanks for the video link, makes PLL sound so simple :) from 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 that :) The 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.
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1310
  • Country: 00
Re: How to process/generate a phase shifted frequency varying sine wave?
« Reply #5 on: March 05, 2013, 06:31:13 pm »
That link should work now.

So far as using PLLs with sine waves goes I thought you could do that but you might be right.  Hopefully someone else knows the answer.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf