You need a resistor between Opamp output and inverting input to tame the offset drift getting amplified and saturating over time.
You need a resistor between Opamp output and inverting input to tame the offset drift getting amplified and saturating over time.
Well, since I speak both analog and digital as my dual native languages....
The circuit you propose looks OK on the surface. You are using an op amp in a comparator mode, and as your inputs are greatly larger then any offset voltages it should be stable, so no other parts needed. A brief look at the data sheet make it look like a good choice (my real concern would be are you paying too much for it, you don't need a very refined pricey amp here).
I am assuming you do not have an oscilloscope to check things (or you would have mentioned what you've seen). I would be interested in how sure you are of the sine wave input, if the DC level changes from what you think it is then you would see the symptom you describe.
One thing to try is to make the sine wave make it's own DC reference: on the left side of your schematic you have a brutally locked in DC divider (10uF is huge for that app). But given your 10K R4 and your 10uF C3 then toss out R7/R5 and replace V1/+5V with the sine wave: this is then a low pass filter that gives you the DC level of the sine wave, and will track slow changes too (it has a cut-off of about 16 Hz).
You don't show any power supply bypassing, be liberal with some 0.1uF ceramic caps and try to sprinkle one on every component IC, especially the PIC and the op amp.
One thing to keep in mind with the revision I described is it is incredibly sensitive to noise if the signal goes away. It will chatter at some high frequency, so you either need to code against that or somehow just know when no signal is there so you ignore the input.
Or... you could DC couple the sine signal to the comparator but use the comparator as an amplifier. Feed the amp output direct to a digital input. That should chop the sine wave into digital form while also driving any noise problems away (you either get a square wave or nothing out of it). Input R of 1K, input C of .01uf and a 10K feedback R should get you there with a gain of 10. Increase the feedback if your output signal isn't enough. (Ask me if you need this drawn up.)
A quick check of the 16F628a data sheet shows RA2 is also AN2, so make sure you shut off the comparator function (the default) so it works as a digital input.
I've used schemes such as this in a few products to measure a frequency. What I did there was use the signal to increment one of the counters while another timer would be set up a roll-over interrupt off the internal PIC clock. To start, I would clear both counters and enable the interrupt. When the interrupt occurs read how many counts I got in the first counter and reset it. That way every interrupt time I get a frequency measurement of cycles (counts) per unit time.
Thanks for all the good comments and suggestions!
The oscillator is a wein-bridge oscillator, and DC drift could be the cause of it. I'll be hooking up an oscilloscope to check this weekend. Using the sine wave as it's own DC reference may be the solution.
I'll be trying that this weekend and I'll post the results.
Again, thanks for the suggestions!
Dave
Bookmarks