Many thanks for all the replies The solution is not as simple as I had hoped. Still I know now what I have to look for. I might reduce the freq. range to 250hz to 3khz which will make things a lot easier. I will try the active filter route and may be the passive with switched in caps. Cheers Tim -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Michael Rigby-Jones Sent: Thursday, February 13, 2003 10:17 AM To: PICLIST@MITVMA.MIT.EDU Subject: Re: [EE]: Rounding the square wave > -----Original Message----- > From: Olin Lathrop [SMTP:olin_piclist@EMBEDINC.COM] > Sent: Wednesday, February 12, 2003 6:16 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [EE]: Rounding the square wave > > > I need to be able to round off the square wave coming from the HWPM on > my > > PIC. The HPWM output is being used to generate sound. I am currently > using > > the standard 2 Rs + 2 caps which works in a fashion but is still rather > > harsh. The freq range is potentionaly from 247 hz up to 12.5 kHz so an > > active filter is needed (I think). Can any body point me in the right > > direction? > > You shouldn't need an active filter, at least with a 20MHz PIC. In fact, > you probably don't need much filtering at all. A 20MHz PIC can do 8 bit > resolution PWM at 78KHz. That's over 6 times the highest frequency of > interest, and certainly higher than anyone can hear. A passive two pole > filter with both poles at 17.7KHz (half octave above 12.5KHz) will > attenuate the PWM frequency by about 25dB. > > Note that all the PWM frequencies are well above the audible range, so the > only reason for filtering is so that downstream active electronics doesn't > do strange things due to the high out of band frequency content. Most > decent amplifiers will have a low pass filter right on the input anyway, > but I agree that filtering and buffering it yourself is a good idea. > > The "quality" of the sound is much more a function of the PWM resolution > and the quality of the function to create the output samples. Doing a > sine, for example, on the fly is too much for a simple PIC. This is best > done with a lookup table. > Olin, I jumped to the same conclusion as you initialy which is why I asked the OP for some more information. He is not using PWM to produce e.g. a sine, but is simply setting the pulse width to 50% and using the CCP as a simple square wave tone generator. The filter he requires is not there to simply remove the PWM carrier, which would be trivial. Unfortunately the desired range spans several octaves which requires a tracking filter as described by other people. A possibility is to use a voltage controlled filter (VCF) and use another (low pass filtered) PWM output as the control voltage. This would also let you have some nice swept filter effects if you wanted to. Unfortunately VCF's are not trivial to design, although I would expect there are some dedictaed IC's. I'm sure any synth enthusiasts could give you more information. The idea of a switched capacitor filter is nice, apart from the fact that the clock you must supply is a fairly high multiple of the filters corner frequency, i.e. 50 or 100 times, so driving such a filter directly from the CCP module is not possible, you'd need some way of upping the frequency e.g. phase locked loop, and it all starts getting a bit complicated for a simple project. Regards Mike -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details. -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.