Convert amplitude from sine into 0-3V3, help ? - Page 1
Forum section: electronics / projects

author: Ribster
author_rank: Frequent Contributor
timestamp: October 16, 2015, 08:57:30 pm
content: I have a sine wave behind my capacitor from 1KHz - 50MHz.This gets sampled by the ADC of my MCU.The sine wave is +- 1.5V, but can be adjusted if necessary.How can i make:0V amplitude sine wave -> 0V to ADC1.5V amplitude sine wave -> 3V3 to ADCSo linearize the amplitude of the sine wave into a DC voltage..I just need some direction, i just don't have a clue how to do this..PS: this is the same project as this threadhttps://www.eevblog.com/forum/projects/calculating-dc-offset/

author: Phoenix
author_rank: Frequent Contributor
timestamp: October 17, 2015, 12:39:30 am
content: A peak detector circuit might do what you want.In fact, there is a fundamentals friday on this:(Though I just noticed your MHz frequency - maybe it won't work so well...)

author: IanB
author_rank: Super Contributor
timestamp: October 17, 2015, 12:43:45 am
content: I think in principle, if you were to rectify the sine wave and use it to charge a capacitor then the capacitor would charge up to the peak voltage of the sine wave. However, I imagine there might be some tricky details to get right in practice. Have you tried anything like this so far?

author: MrAureliusR
author_rank: Unknown
timestamp: October 17, 2015, 12:55:54 am
content: Peak detector followed by a x2 gain opamp.

author: langwadt
author_rank: Super Contributor
timestamp: October 17, 2015, 01:30:04 am
content: Quote from: MrAureliusR on October 17, 2015, 12:55:54 ammaking a peak detector linear from 1kHz to 50MHz is going to be .. interesting ..

author: Ribster
author_rank: Frequent Contributor
timestamp: October 17, 2015, 06:52:04 am
content: i've already got a few opamps of 200MHz GBP in my design, so the gain is no issue i think.I'll try some SPICE simulations this evening and let you guys/girls know!Let's hope it will work!I just don't like to see my ADC resolution wasted..

author: Ian.M
author_rank: Super Contributor
timestamp: October 17, 2015, 07:25:32 am
content: You'd probably do better with two separate peak detector circuits, a conventional one for low frequencies up to lets say 150KHz, and the other a RF peak detector (e.g.LTC5507, each with suitable buffering and scaling to suit your ADC inputs, feeding two separate ADC inputs. You will still need to add software calibration and linearisation.

author: akis
author_rank: Frequent Contributor
timestamp: October 17, 2015, 03:29:49 pm
content: You may also want to consider applying the signal on the negative terminal, ground the positive. It is very common and also shown on Rod Elliot's web site. However this is a low input impedance application and also requires low source impedance. I am not sure of the advanatages but I hope to test it on the sim and on breadboard.

author: Ribster
author_rank: Frequent Contributor
timestamp: October 17, 2015, 03:42:59 pm
content: Quote from: akis on October 17, 2015, 03:29:49 pmI'm afraid i do not understand fully what you are trying to say...

author: Kalvin
author_rank: Super Contributor
timestamp: October 17, 2015, 05:05:27 pm
content: You probably want to see your problem from a different angle altogether. Your voltage divider circuit with the ac-blocking capacitor drives the ADC input to the mid-point of the 3V3 and 0V, approx. 1.65V when there is no signal.Now, when you apply the signal and you sample fast enough, your ADC will be reading the values centered at this 1.65V value. For example, if your sine signal amplitude is 3Vp-p the ADC will read values between range 1.65V-1.5V ... 1.65V+1.5V.You know that 1.65V is your zero reading, so you will just subtract this value from the values that ADC is giving, and you will end up with the values between -1.5V ... +1.5V which will correspond to the signal 3Vp-p value. After that you have nice stream of sampled signal centered around zero, which is suitable for further digital signal processing.

author: Ribster
author_rank: Frequent Contributor
timestamp: October 17, 2015, 09:10:53 pm
content: Kalvin,That is exactly what i have right now.But, i am wasting resolution of my ADC..I'm only having about 45% of 2^10. so instead of 0-4095 discrete levels i have only 0-1841 discrete levels.I've ordered some LTC5507 chips. Really thanks for the input Ian.M, invaluable!Because i am making a filter tester, and want to get the filter respons over frequency.I'm going to measure the power before the filter and after the filter.With an analog switch i can change between 0-150KHz and the LTC5507. Making this 2 times, 1 before and 1 after the filter.I'm going to use a low bandwidth opamp for the low frequencies, based on dave jones' video.I'll mock something up next week, i'll keep you guys posted!

author: IanB
author_rank: Super Contributor
timestamp: October 17, 2015, 11:13:59 pm
content: Quote from: Ribster on October 17, 2015, 09:10:53 pmThat's barely more than 1 bit of resolution. Do you have tight enough tolerances in the rest of your system that 1 bit is actually measurable? And if you try to do something clever to amplify the signal, can you be sure that you will not introduce more than 1 bit of additional error with that extra signal manipulation?I would think if you are measuring a periodic waveform and sampling over many cycles, you can make up with sample averaging what you lose with one shot resolution.

author: akis
author_rank: Frequent Contributor
timestamp: October 18, 2015, 07:55:41 am
content: 2^10 = 1024. The possible values from the ADC are 0..1023.Most MCUs have an analogue reference pin where you can adjust it to suit your demands. Simply apply 1.65V to that pin and then your 1023 reading will mean 1.65V. In addition MCUs have internal references of 1V, 3.3V and 5V if I remember correctly.

author: Ribster
author_rank: Frequent Contributor
timestamp: October 18, 2015, 12:50:04 pm
content: Quote from: akis on October 18, 2015, 07:55:41 amExcuse me, you are right!My STM32 has 12bit.I do have a seperate VREF pin, but i have it coupled to 3V3.I could make the reference 1V5 and only use the top half of the waveform.But that adds extra cost of a voltage reference (2€), which to me is kinda silly...

author: Ribster
author_rank: Frequent Contributor
timestamp: October 18, 2015, 12:54:50 pm
content: Quote from: IanB on October 17, 2015, 11:13:59 pmThe goal is to sweep the frequency.So i need the amplitude in and amplitude out.Constantly sampling a sine wave is kinda crazy if i can just single sample the amplitude of the waveform.Yes this adds hardware components, but it's much simpler in software.If i was using an FPGA, i would agree with you, but with an MCU it's simpler this way.

author: Ian.M
author_rank: Super Contributor
timestamp: October 18, 2015, 01:03:44 pm
content: Read the datasheet before you reduce Vref too much. In many cases, the ADC will loose accuracy faster than you gain it by improving the input range usage.However there are significant benefits in NOT using the MCU Vdd supply for Vref as it is really difficult to keep a supply used for fast digital circuits clean, and if any of the digital noise correlates to the ADC's sampling clock, it can cause gross errors.What are you doing for phase measurement?

author: Ribster
author_rank: Frequent Contributor
timestamp: October 18, 2015, 01:27:16 pm
content: Quote from: Ian.M on October 18, 2015, 01:03:44 pmI've set up a ferrite bead plus decoupling cap on the analog reference.I can add supplementary capacitors for a more wideband filtering.I'm not going to read the phase measurement in this version.It would be nice if it could, but it will only add complexity.Better to get this up and running and add phase measurement later.Any tips on doing that though ?

author: Kalvin
author_rank: Super Contributor
timestamp: October 18, 2015, 01:55:22 pm
content: Quote from: Ribster on October 18, 2015, 12:54:50 pmI haven't been quite following your project and I didn't realize that you just wanted to measure the waveform amplitude. In that case a peak detector might be a good choice. The simplest form of amplitude detector might be a diode-detector with a proper RC-time constant. It needs some calibration and it will be somewhat temperature sensitive. Also, it may not work at the lowest signal levels unless the diode is biased properly. For the better accuracy an op amp-based solution is good choice. There are also dedicated wide-bandwidth RMS-converters which can output the signal level either in decibels or in linear scale.Even using your existing ADC and sampling the signal using random (non-uniform) sample intervals, and given that the you sample often enough (so called sub-sampling, let's say at an average of 10kHz sample rate, but varying the sample interval randomly so that the measured signal and the sampling rate wouldn't be synchronized accidentally), and if you sweep slowly enough that the signal's envelope amplitude will not change rapidly compared to the average 10kHz non-uniform sample rate you might get good results. I haven't been using that myself, but it might work, so this is just an idea but it might be worth looking if you have some extra time.For the combined amplitude and phase measurement, there are ICs that can perform the both at the same time in a single package.

author: Kalvin
author_rank: Super Contributor
timestamp: October 18, 2015, 05:29:39 pm
content: Analog Devices has ICs that operate from 100Hz/1kHz up to GHz range, although the devices are meant to be used at the RF-frequencies. Here is an application note which shows how those devices perform at low frequencies:http://www.analog.com/media/en/technical-documentation/application-notes/AN-691.pdf