thanks, Tim
----- Original Message -----
From: "Tim Forcer" <EraseMEtmfspam_OUT
TakeThisOuTECS.SOTON.AC.UK>
To: <PICLIST
spam_OUTMITVMA.MIT.EDU>
Sent: Friday, March 22, 2002 1:26 AM
Subject: [PIC]: Sine wave oscillator
{Quote hidden}> At 05:17 22/03/2002, Dave Dilatush wrote:
>
> > Date: Thu, 21 Mar 2002 00:46:07 +0000
> > From: Dave Dilatush <
@spam@dilatushKILLspam
COMCAST.NET>
> > Subject: Re: [PIC] Sine wave oscillator
> >
> > Shawn wrote...
> >
> > > ... I would like to replace a 625Hz analog
> > > sine wave oscillator with a low-end PIC
> > > microcontroller -- say 16F84 or 8-pin model.
> > > Is it better to use a look-table approach
> > > to replicate the sine wave or can excellent
> > > results be achieved by generating a square
> > > wave then filtering?
> >
> > It depends. ... modulating the PIC's
> > PWM output ... the resulting signal contains
> > little energy at the lower-numbered harmonics
> > it is much easier to filter into a pure
> > sinewave than a square wave of the same frequency.
>
> You are not restricted to PICs with PWM outputs! You can use a look-up
> table for a one-bit oversampled waveform just as easily as for multi-bit
> sampling.
>
> > On the other hand, if you don't need a
> > particularly pure sine wave out of this
> > device (say, 2% or 3% THD or thereabouts)
>
> That's a LOT of THD.
>
> > then filtering a square wave ... easier
> > with regard to software design.
> >
> > I don't recommend trying to generate a
> > very high-purity sine wave by filtering
> > a square wave ...
>
> Sound advice, but you can generate something MUCH closer to a sine wave
> than a square wave and save on analogue filtering.
>
> For a student exercise in this Department, we use a PIC16F84 with an 8MHz
> resonator to produce four pairs of waveforms. One is a pair of
> pseudo-random binary sequences (PRBS), the other three are 1kHz
sine/cosine
> pairs. A selected pair of outputs are filtered with a quad opamp to
> provide a stereo signal generator. The three sine/cosine pairs are
generated:
{Quote hidden}>
> 1) Conventional 2-bit (four level) binary coding, 16 samples per cycle.
>
> 2) 1-bit oversampled binary coding, 64 samples per cycle.
>
> 3) 2-digit ternary coding, 16 samples per cycle.
>
> Ternary (three-state) coding uses the fact that PIC outputs can take three
> states: HI, LO and OFF, so two outputs can produce up to nine (three
> squared) levels using an appropriate resistor network. Even before any
> analogue filtering, the waveform is remarkably close to sinusoidal.
>
> After filtering, there is no visible difference on the 'scope between the
> signal waveforms produced by these different schemes. What is interesting
> is that a single stage of plain CR filtering of the nine-level signal
> provides a waveform that is remarkably close to sinusoidal, and sounds
> fairly "clean". In contrast, at this stage the four-level and oversampled
> signals have very audible odd harmonic content, very "edgy".
>
> In case you're wondering, the PRBS provides either a digital noise source
> or, after going through the same filter chain, an audio pink noise source.
>
> Two pairs of two-output generators, plus two pairs of one-output
> generators, means there's one pin spare - but that would be a shame. So
> the final output pin provides a SYNC pulse to flag when the 16-bit PRBS
> register goes through the all-1 state as it generates its 32767 bit
sequence.
>
> Total use of PIC '84 resources: 238 words and 54 registers, although I'm
> sure many folk on this list could cut down both of those.
>
> > > ... And finally, would the answer change if I were
> > > generating say a 1MHz wave?
>
> Yup! My code needs an 8MHz oscillator for everything to happen in
> sufficiently close timing for 16k/64k samples per second. If you were
only
{Quote hidden}> trying to produce a single waveform, rather than eight plus sync, then
> simple arithmetic shows you could get up to around 4kHz with a 4MHz
> oscillator - although that simplicity masks the fact that there are more
> instructions required for the ternary coding than the binary coded
> versions, for example. Even with a 20MHz oscillator, the instruction rate
> of 5M instructions/s would be barely enough to produce a square wave, let
> alone a coded sinewave!
>
> HTH,
>
> Tim Forcer
> Department of Electronics & Computer Science
> The University of Southampton, UK
>
> --
>
http://www.piclist.com hint: To leave the PICList
>
KILLspampiclist-unsubscribe-requestKILLspam
mitvma.mit.edu
>
>
>
--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestTakeThisOuT
mitvma.mit.edu