Using an opamp as a variable frequency lowpass filter - Page 1
Forum section: electronics / beginners

author: Skimask
author_rank: Super Contributor
timestamp: March 09, 2013, 10:56:35 am
content: Before I dig into this too far and fail profusely...Using a PIC12F1822 and it's 5 bit DAC to make waves ranging from about 5hz up to around 5Khz. Since it's only 5 bits, there's quite a bit of "step" in the waves at all freq's, so the spectrum is going to get pretty ugly at the higher end...lots of noise.I put a simple R/C filter on the output, and of course, with values Rx and Cx, it only works in a certain range of frequencies, whatever they are. Go outside of that range and the sine wave, while the edges are much cleaner, there's quite a bit of distortion.Consulted the "Good Book", had an AHA! moment when I realized that opamps can be configured as filters of various types.So, what if I whip up an low pass filter using an inverting configuration opamp circuit, with a fixed C value, with variable but equal R1and R2values (use a digital pot for both). Keep the gain at unity, but change the frequency response of the opamp by varying the resistance value of both resistors at the same time. I don't have any way to measure distortion other than overlaying the original unfiltered signal over the filtered signal. Good enough for me.Whaddaya think? Good in theory, sucks in practice? Or good in theory, works in practice?

author: hammil
author_rank: Regular Contributor
timestamp: March 09, 2013, 03:41:57 pm
content: A nice idea, but using an op-amp wouldn't make much difference in this case. The only reason you would need one for a pass-filter is if you wanted lower capacitive loading on the circuit and/or a buffered output, which I don't think you need here. They're far more frequently used in boost circuits, where you need active components.The problem you found is one of the big design choices in this area. If you want a smooth output, you need to either lower your transfer rate ( the audio frequency ) increase the resolution ( number of bits ) or the sample rate of your DAC.As an aside, audio DACs tend to have a resolution of 16 or 24 bits per sample, and a sample rate of 44.1KHz at least.Anyway. Regarding your theory, it is possible to create a circuit that would boost a signal to keep a unity gain - I think it's called a normaliser. But what effect would it have on your signal? You'd need to make a digital controller to keep the output exactly as you intended (if you wanted to output a lower amplitude, for example), which would require more cycles of processing time and reduce the maximum frequency you could produce. And you'd need a bunch of analog ICs too. And what other noise and distortions would you introduce from all this? In the end, it would almost certainly be easier and cheaper to just use a faster IC.

author: TerminalJack505
author_rank: Super Contributor
timestamp: March 09, 2013, 04:44:17 pm
content: I don't know how well your idea would work but if you're just needing a tunable low-pass filter for audio frequencies then you might look at ICs such as the TLC14 or MAX7410. The cutoff frequency is selectable by providing the IC with a clock whose frequency is a multiple of the desired cutoff frequency.

author: Skimask
author_rank: Super Contributor
timestamp: March 09, 2013, 05:04:52 pm
content: @hammil - Well, this time I need a buffered output. The DAC on the PIC is rather high impedance and the output amplitude drops off rather quickly even under light load. Only have 5 bits to work with for now. Adding bits comes later on.@TJ505 - Good call on the MAX chips. I like it. Because my program "manually" goes thru a sine wave table to kick out DAC values to make the sine wave, I can easily clock that MAX7410 at 64x the frequency. A 100x is gonna require a bit more work, but should be doable. At least if the freq multiplier is consistent, the distortion will be consistent and repeatable.

author: SeanB
author_rank: Super Contributor
timestamp: March 09, 2013, 07:54:57 pm
content: Clock it at 128times the sample frequency with a 2X multiplier and you will find that distortion will be slightly higher but still much reduced.

author: blackdog
author_rank: Frequent Contributor
timestamp: March 09, 2013, 08:13:21 pm
content: Hi SeanBTake a look at the site of RomanBlack.http://www.romanblack.com/onesec/SineDDS.htmMaybe you can use a part of his design...Kind regarts,Blackdog

author: grenert
author_rank: Frequent Contributor
timestamp: March 09, 2013, 10:07:19 pm
content: Don Lancaster's book has everything you could ever need to build an easy opamp filter:http://www.ebay.com/itm/Active-Filter-Cookbook-Donald-E-Lancaster-1995-/290215496472?pt=US_Texbook_Education&hash=item4392310b18It's incredibly easy to follow, too ("cookbook" describes it perfectly).

author: lewis
author_rank: Frequent Contributor
timestamp: March 09, 2013, 10:40:18 pm
content: I'd use the CCP module in PWM mode to generate the output, you can get 10 bits of resolution at 30-odd kHz PWM which should be just about enough to generate 5kHz sine at low distortion once filtered. Simple RC will do it, and you don't need to make it variable. You can get increased resolution at lower frequencies by dithering the PWM.

author: Skimask
author_rank: Super Contributor
timestamp: March 10, 2013, 01:04:10 am
content: I've tried the PWM method. I dunno. Can't seem to get the hang of it. Probably did something fundamentally wrong when I tried, but just couldn't seem to get the right output even after the R/C filter.Figured the DAC was the better (e.g. easier) option since it's available on this PIC.

author: lewis
author_rank: Frequent Contributor
timestamp: March 10, 2013, 04:18:27 pm
content: DAC probably is easier to implement at first sight, but you need this variable filter and the resolution is limited. Not sure about its speed either. But the PWM method does use the TMR2 resource, so if you need the 16 bit timer elsewhere in your code, you're buggered.The PWM can be a bit of a bastard to set up, but once you've done it setting the output voltage is as simple as writing to the CCP1RL and CCP1CON<5:4> registers. What problems did you encounter?

author: Skimask
author_rank: Super Contributor
timestamp: March 10, 2013, 05:58:48 pm
content: I don't remember what problems I had exactly. It was at least a half dozen years ago when I tried it. Might've only been an output filtering issue. Back then I didn't know much about anything analog.Maybe I'll revisit the PWM method. I checked out the romanblack site, but can't really glean a lot of info from a .hex file. Not using any of the hardware resources on the PIC (using a 12F1822 @ 32Mhz now) and can just as easily switch over to a faster, better equipped PIC if necessary (e.g. 18F26K22 @ 64Mhz comes to mind). Don't need to generate everything from DC to X-hundred Khz. Shooting for around ~50Hz to around ~40Khz in octave-ish steps, give or take (e.g. 50hz, 100hz, 200hz, and so on).

author: Skimask
author_rank: Super Contributor
timestamp: March 10, 2013, 11:26:24 pm
content: Well whatever problems I had before are gone now. Using a PIC12F1822 @ 32Mhz, generating an interrupt driven varying duty cycle PWM output. No idea where I went wrong the last time I tried a few years ago.Now to whip up a filter to make the output look like a sine wave...