On Thu, Jul 14, 2011 at 4:00 PM, RussellMc wrote: > > I am trying to make a PLL like scheme using PIC 16F887 based on stored > sine > > table values. I have stored 256 step values of sine angles. Its working > well > > with the counter increasing in each TMR0 interrupt at certain intervals= .. > > However the problem now is: how to synchronize with some arbitrary inpu= t > > waveform or arbitrary frequency (changed to square wave using > comparator). > > > Assume: > > i 50 Hz mains. > > ii Input waveform is reduced to two opposite sense zero crossings per cyc= le > > iii User knows how to determine period of input waveform using > available zero crossing information. > > Then: > > Determine period of input waveform. > > 1. You can gross-synchronise by just starting your sine wave on its > rising edge at the negative to positive zero crossing. I think you > already know that. > > 2. If you have a synthesised sinewave already being output and you > want to bring it into synchronisation with an external waveform of the > same frequency then you MUST slip frequency either + or - in order to > change phase. eg if you are say zero crossing 30 degrees too late you > need to progressively advance each of your zero crossings by a > suitably small amount until you catch up. eg you could decide that an > OK rate was 1 degree per cycle. By effectively speeding up to 360/359 > x 50 Hz =3D 19,944 uS/cycle instead of 20,000 uS you will catch up in 30 > cycles +` 0.6 seconds. How fast is acceptable is up to you. > > 3. Synchronising with phase offset is just a matter [tm] of > determining where the desired phase point is wrt the input zero > crossings and steering for that as above. > > 4. To maintain running synchronisation you can monitor input zero > crossings wrt output zero crossings and make decisions about changing > output sampling rate as above. Simplest is just add or subtract an > extra delta count to compensate for observed error. Nicer is to > introduce correction which takes several cycles to correct. You could > end up at something like full PID and also introduce input frequency > filtering in a particularly obnoxious environment but this is unlikely > to be needed. > > > Russell McMahon > Applied technology > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > *If you have a synthesised sinewave already being output and you want to bring it into synchronisation with an external waveform of the same frequency then.....* ** How can I generate an output sinewave of the same frequency as that of the input sinewave? The frequency of the input sinewave although remains steady over certain duration it may vary by +-10%. Regards, Deep. --=20 "*Don't worry about people stealing your ideas. If your ideas are any good= , you'll have to ram them down people's throats*."----- Howard Aiken --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .