How to measure SIN wave in ADC

Go To Last Post
23 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi folks!

I want to know if is posible to measure a full sin signal(positive and negative) in the ADC of an AVR.

I'm building an Oscilloscope for PC, with an AVR sampling the signal.

Any help would be appreciated!

Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You will have to offset and amplitude adjust the signal so that it falls between 0V and Vref. Op-amps are commonly used for this.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just count the number of sinners. :roll:

If you think education is expensive, try ignorance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Jim!

Yes, offset in the voltage seems to be the best answer, but what kind of information I must look for in the net? Because I looked for "offset control with opamp", but I only found controls/schematics for null offset... Any hint?

Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Look for a 'programmable gain amp' or pga at lineartech, ti, national, and maxim-ic. That should keep you busy for a few hours. The avr can change the gain to keep the external voltage being measured in the correct 0-5v range to be digitized by the a/d.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The circuit is very simple.

Op-amp. Signal in trough 1Meg resistor to inverting input. Switch feedback resistor to control gain.

Add second input resistor to summing junciton. This is for offset. Maybe another 1Meg. Add a pot between a positive voltage and an equal negative voltage. Wiper of pot goes to offset resistor.

You now have an oscilloscope input. One caveat. Bandwidth varies directly with gain since gain-bandwidth product is constant.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Search for single supply biasing.

This is a good one:
http://www.maxim-ic.com/appnotes...

Also search wikipedia.

If you think education is expensive, try ignorance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In this situation, it is probably useful to bias the op-amp at Vref/2 and power it from 0 and Vcc. You WILL have problems near the negative rail but if Vref

Then, your offset pot can be connected between ground and Vref to provide equal offset in both directions. This may argue for a second op-amp buffering Vref. This would give you a better voltage source for op-amp bias and for the offset pot.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Yes, offset in the voltage seems to be the best answer, but what kind of information I must look for in the net? Because I looked for "offset control with opamp", but I only found controls/schematics for null offset... Any hint?

Yes, look up designs for an ac amplifier using an op amp with a single supply. That's what you're trying to do. A "single supply" means a battery, which only has a positive and negative terminal.

One of the best places to find such a schematic/design ideas/instruction is on a website that at least includes how to build guitar effects pedals (aka stomp boxes.) Why? Because stomp boxes are designed to be stomped on to turn them on and off while a guitar player is on stage; the player doesn't want to trip over the power cord so stomp boxes use, usually, one battery. However, most stomp boxes are full of op amps. ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the hints guys! I simulated the circuit that Jim told me to do, and it seems to work well! But the signal is always inverted...If I put a transistor in the output of the OPAMP, can I re-invert it to normal form?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's the circuit for left handed guitars... use a non inverting amp for right handed.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just invert it back to the original sense in software. That is the power of the micro!

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I initially wanted to avoid software tricks.....But I think that making a simple inversion in an unsigned char wouldn't spend too much time, affecting the refresh time of my Oscilloscope...

Another concern, is that a friend of mine told me to not use a LM741, because it's a bad OPAMP....Is this true?

PS: the prototype so far:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Agree. '741 is really poor about getting output voltage close to rails. It is also fairly low bandwidth (gain-bandwidth product, or Ft)

Also avoid TL07x/8x for this application because of poor output swing. Look for something that will come within a half volt of the ground rail, at least. No good recommendations but there are plenty out there.

Inversion of unsigned char is only (0xff - value). You should be able to do that in no more than 6-8 clock cycles per point.

What you have looks pretty nice!

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I agree that looks good.

Are you going to filter the incomming signal ie anti-aliasing filter?
It is probably recommended and of course you have to make sure you are satisfying the Nyquist theorem ie your sampling rate should be 2x the signals maximum frequence so that you can adequitly capture/sample the signal. Been a while since I've been in a DSP class but thats a fundimental theorem and there'll be heaps of info online.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, since it's a project for my graduating class in University, it focus in the PC software, not the HW...Besides, I do not have enough knowledge of electronics to add too much resources in the HW...
The basic idea is to sample a signal as fast as I can, send it to parallel port, and do various stuffs with it (measure frequency, amplitude, FFT, etc).

OF COURSE that after finished, I intend to use it in my bedroom-lab, 'cus I don't have a real oscilloscope, and having a PC with one, would be very usefull to me.

The only thing that I did to the signal is put two resistor-divider (/4) to protect the OPAMP, and offset it to put it in an ATMEGA8 @ 16MHz, sending the sampling to the PC parallel port..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm building an Oscilloscope for PC, with an AVR sampling the signal.

Since the max sampling rate for the AVR is about 40K samples-per-second (full 10 bits) and you are using a PC as the host, it would make much more sense to forget the entire project and instead download a free PC oscilloscope program that uses the Sound Chip that every PC has now.

These programs use the line input of the sound chip as inputs. The line input is stereo, 16-bit, and samples at 44.1K samples per second. Many newer sound chips can sample at 96K sps. The analog inputs must be between 0 and +1.5~2 volts, but larger signals can be scaled to this range using op-amps.

These sound-card oscilloscope programs can use the the entire PC RAM to store the digitized analog signal, which means that you can record signals for hours instead of the few seconds that the $5000 professional Tektronix, LeCroy, and HP scopes allow. Most of these programs also include FFT spectrum analysis and real-time screen display of the input signals.

Since this is an AVR board, whenever an interesting application is suggested that might have an microcontroller solution, everyone jumps in with detailed AVR approaches. But I suggest stepping back and asking 'How did other people solve the same problem?' and 'How can I use their work for my own solution without having to invest a lot of my time and money doing what has been done before?' Since the embedded microcontroller industry is about 35 years old now, nearly everything has been done before by someone.

Sound card PC oscilloscopes might seem like a 'Mickey Mouse' concept. But it's not because the circuitry and programming expense for a stand-alone 16-bit, dual-channel, 44K or 96K sample/second project would be far greater than the cost of a inexpensive sound card that has those specifications and is mass-produced cheaply by the millions. The biggest hurdle is reducing the signal to fit the input voltage requirements of audio. That and dealing with the fact that the input is AC-coupled. But if you have an old PC sound card then you may be able to remove the capacitors between the line input jack and the card's ADC left and right inputs. And replace them with op-amps that are biased to handle the full range of your expected input signal.

Good luck.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Its's an Educational Project I'm building, as I'm Graduating in University, so, going buying things wouldn't make any sense...I have to build something, and explain it to some teachers that will judge my project, and whoever has in my presentation at the stage...

So,again, my project focus now is the PC software...not the hardware..

BUT what I really need in the HW, is a clean signal, as rail-to-rail as possible, cus it will be a full visual presentation, so, the sampled signal in the screen MUST look good! Even if the max frequency is 40kHz or less.

But anyway, thanks for the info, It may be useful in future projects.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you only have the 5 V as supply, use a rail-rail OPamp, like OPA340 or OPA350. If you have a +-12 V or similar supply available you could use an older standard OPamp.
To have at least a little advantage over the soundcard solution you could use an isolated interface to the PC.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Despite some of the limitations to the project eg max sample rate I think your doing a great job. Realistically all you would have to do is upscale everything, ie faster uC etc. But you are certainly proving the concept and your competance - well done

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are lots of audio guys that need a good cheap digital scope with a bandwidth in the audio range.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For a lesson in anti-alias filtering, try a higher frequency input signal, say around 2X sample rate (plus or minus just a little). Do you see a waveform that is at the real frequency (based on the "sweep rate") and full amplitude or does it appear to be at a different, lower, frequency (but full amplitude) or is it lower frequency but reduced amplitude.

All of these are possible depending on your filtering, or lack of filtering, between the input and the ADC.

If you are not inclined to put filtering in, be prepared to answer questions about this phenomenon in your project report. It is a classic for tripping up unsuspecting students.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys!

My project still running! I've finished the HW offset adjust(LM358) and compared a 1k wav with a real oscilloscope, and it looked good(NOT that in the pic below) in my project!(Besides the noise, caused by an chinese power source, hehe)

Thanks for the ideas, 'cus without them, I wouldn' t know waht to do with the offset of the sampling!!

Now the real challenge begins: The high level software(C++)!

The Project so far: