Interfacing an opamp output with the STM32 ADC - Page 1
Forum section: electronics / general

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: January 12, 2019, 10:15:23 pm
content: I have an opamp which has designed as an amplifier.it amplifies signals which could have around 10.8V amplitude at the output pin. This voltage is not good to be injected directly to the STM32 ADC. The first thought would be a resistor divider. I selected 2.7K and 1.2K, which convert 10.8V to around 3.3V.But by reading the STM32 datasheet, high ADC speeds need a very low impedance at the ADC input (they give a formula for it). for the 1Msps speed, I think it should be less than 400Ohm. I have already set up this circuit and I see some ADC sampling noises on the signal when I examine the pin by an oscilloscope, something like saw teeth on the signal.I intend to use either STM32F103 or STM32F405, which suits better.the questions are1) is this a good method to do this? I mean using a resistor divider? I don't have access to the 3.3V rail to rail opamps (at least 15MHz GBW and 10V/us Slew rate)2) is this normal to see that ADC noise on the signal?

author: nsrmagazin
author_rank: Regular Contributor
timestamp: January 13, 2019, 07:09:31 pm
content: Lets start with the following.The frequency does matter.A resistor divider is the most common used option. But the resistors are "9.1k" and "1k" You reduce it 10 times. The noise can be reduced both by hardware and software filters, a combination of both will be needed for your application.if the resistance should be less than 400 ohms(can you show me this in the datasheet please), you need a circuit after the opamp and resistor divider to reduce the output impedance.Can you post your circuit please, like this its not as good.

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: January 13, 2019, 07:18:40 pm
content: QuoteThe signal itself does not have noise, but I mean when the ADC is ON, I see the sampling effect on the signal. something like needles. for example, if the ADC is 1Msps, then every 1uS I see a noise like a needle on the signal. I don't know if it is normal or not. if it is normal, I'll let it as it is.The datasheet:

author: MasterT
author_rank: Frequent Contributor
timestamp: January 13, 2019, 07:37:16 pm
content: Don't worry, chipping on the input of adc is natural/ normal effect. S/H capacitor needs to be charged. The only things to watch, if charging is completed during S/H timing, on stm32F4 you can adjust this timing.What is the OPA? NE5532 could drive 600 Ohm loads, so you can decrease resistors values in the divider.

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: January 13, 2019, 08:07:57 pm
content: Quote from: MasterT on January 13, 2019, 07:37:16 pmif it is normal then it is Okay. I was worry that it affects the ADC readings. I was thinking that this is the effect of impedance mismatch for the ADC.I use CA3130. it looks like to be a good opamp. I used it as an inverting amplifier. I used low resistors because of this actually.(OP Out) ----> 2.7K ---(ADC)---- 1.2K ----(GND)The ADC sees 1.2K impedance then?

author: Yansi
author_rank: Super Contributor
timestamp: January 13, 2019, 08:37:34 pm
content: Yes it definitely WILL affect the reading!High impedance voltage source and high sampling frequencies equal distorted wrong ADC readouts. The current, flowing due to the sampling capacitor being periodically charged will draw current from the divider, producing error in the readout.Note that using a decoupling capacitor on the output of the divider will ONLY help with a single-shot measurement, it won't fix the current drawn from the source (due to I = Csample * Usample * fsample).And also, the sampling capacitor is non-linear, or the drawn current respectively: The ADC may both inject current or draw a current from the source, depending on the instantaneous voltage present (the internal workings of the ADC are not so trivial as they teach in the school).It is always a good practice to buffer ADC inputs with a "zero impedance" buffers, with additional decoupling at the ADC input pin to compensate for the pulsed current from the sampling action.For 1MSps, there is no way a 9k1 - 1k0 divider would be sufficient. You need a low impedance source. Say 100ohm impedance.

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: January 13, 2019, 09:52:02 pm
content: Quote from: Yansi on January 13, 2019, 08:37:34 pmSo if the impedance is correct, then I should not see that sampling noise??Actually, after the voltage divider, I used another opamp as a voltage follower. it distorted the signal somehow, but I used it just for the impedance test. The ADC sampling noise was still there.I use 2.7K and 1.2K at the moment. Should I try to find a 3.3V rail to rail opamp or use another opamp as a buffer?

author: MasterT
author_rank: Frequent Contributor
timestamp: January 13, 2019, 10:42:54 pm
content: Quote from: VanitarNordic on January 13, 2019, 08:07:57 pmNo, ADC sees (1.2 || 2.7) = 0.83 k.

author: Yansi
author_rank: Super Contributor
timestamp: January 13, 2019, 11:41:13 pm
content: Quote from: VanitarNordic on January 13, 2019, 09:52:02 pmGuessing STM32F4... read this:https://www.st.com/content/ccc/resource/technical/document/application_note/a0/71/3e/e4/8f/b6/40/e6/DM00050879.pdf/files/DM00050879.pdf/jcr:content/translations/en.DM00050879.pdfIn nutshell: STM32F2 and F4 (those older ones: 405 to 439, probably not the newer 446-479) have insanely craptacular ADCs.On STM32F1 it should behave good, on STM32F3 the ADCs are very tame.

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: January 13, 2019, 11:57:47 pm
content: Quote from: Yansi on January 13, 2019, 11:41:13 pmnot actually, it is for STM32F1. I wanted to try F4 for its speed. if you think these are not good chips in terms of ADC, I'll select a different MCU or use an external ADC

author: MasterT
author_rank: Frequent Contributor
timestamp: January 14, 2019, 12:44:09 am
content: For speed better to get F303, it has 4-x ADC 5.1 msps, and "build-in" rail-to-rail OPA's.

author: Yansi
author_rank: Super Contributor
timestamp: January 14, 2019, 12:46:43 am
content: STM32F3 are superior for analog signal processing, no doubt.

author: r0d3z1
author_rank: Regular Contributor
timestamp: January 14, 2019, 07:32:41 am
content: Quote from: Yansi on January 14, 2019, 12:46:43 amI am interested on this point, could you explain more in detail what are the differances between STM32F3 and F4 ADCs ?Thanks

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: January 14, 2019, 08:00:26 am
content: I can do the job with 1Msps, but the noise level should be low. Do you still suggest F3 series or I can get better from F1?I have stm32f730r8t6 from F7 series also

author: MasterT
author_rank: Frequent Contributor
timestamp: January 14, 2019, 10:27:33 am
content: Quote from: VanitarNordic on January 14, 2019, 08:00:26 amIf it's me, I'd run sampling as fast as possible, than average/ decimate down to necessary sampling rate. It'd simplify anti-aliasing filtering and gain 6-12 dB in SNR.IMHO, all series F1-F7 has the same poorly designed adc architecture, it's could happened when someonestilldidn't pay to inventor, and downgrade was done intentionally.

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: January 14, 2019, 10:47:29 am
content: QuoteSo you mean I should select F3 at last, OR use another MCU or an external ADC?Do you have any suggestion regarding the part number?

author: Yansi
author_rank: Super Contributor
timestamp: January 14, 2019, 01:01:20 pm
content: Quote from: MasterT on January 14, 2019, 10:27:33 amPlease be that kind and stop talking rubbish you have absolutely no clue about.The ADCs across the STM32 family have quite some different designs, which, at minimum, are dictated by the different silicon technologies the chips are manufactured on.

author: Yansi
author_rank: Super Contributor
timestamp: January 14, 2019, 01:02:27 pm
content: Quote from: VanitarNordic on January 14, 2019, 10:47:29 amSTM32F3 have absolutely fine ADC.If you need more resolution, speed or SNR, use external one. We can't tell, as we don't know your intentions, what you will use the ADC for.

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: January 14, 2019, 01:42:09 pm
content: QuoteI have one F3 model in the local market which is STM32F373. I don't know if it is F3, why its ADC has 1Msps speed instead of 5MspsMy application needs low ADC noise, but not a high-end one. Therefore MCU ADC looks Okay but it should not be inherently noisier than what it is normal between MCUs.in my local market, F1, F4, and F7 series are easier to find.So far I made a test just using F103C8 and I had an intention to try F405.in the meantime, I verified that I can reduce the amplifier supply voltage to 5V. therefore I could use lower values for the resistor divider and make it more close to the required impedance

author: Yansi
author_rank: Super Contributor
timestamp: January 14, 2019, 01:50:24 pm
content: Why don't you spend a bit of time reading the datasheets?STM32F373, obviously aF3series part, has a single SAR 12bit ADC and three 16bit sigma-delta ADCs.

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: January 14, 2019, 01:51:34 pm
content: The AN4195 says that F1 and F3 are typically identical, except f3 introduce more features

author: Yansi
author_rank: Super Contributor
timestamp: January 14, 2019, 02:17:45 pm
content: So what?F3 series was made as a direct replacement for F1 devices, which is the oldest product line of Cortex M from ST. Hence why they are almost feature compatible. Most of F3 devices are even pin and binary compatible with F1 devices.

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: January 14, 2019, 03:05:26 pm
content: Quote from: Yansi on January 14, 2019, 02:17:45 pmMaybe I can stick to the F1 because I hardly can find F3 in the local market (I could find STM32F303CCT6 and STM32F373). the majority are F1, F4 or F7.in your applications, did you noticed that sampling noise on the signal? (if you checked it by an oscilloscope on the ADC pin)

author: Yansi
author_rank: Super Contributor
timestamp: January 14, 2019, 03:17:28 pm
content: When using a low impedance buffer and a suitable decoupling capacitor on the ADC input, sampling noise should not be very visible.I have no clue what electronic component markets are in Iran, however I think there are some pretty well established distributors in there. And STM32F3 devices are no unobtaininum, should not be any problem getting them from like Mouser, Farnell, Arrow, whatever is in Iran.

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: January 14, 2019, 03:30:10 pm
content: Quote from: Yansi on January 14, 2019, 03:17:28 pmWhat I have in the circuit is a CA3130 amplifier. the output goes through a resistor divider and then goes to the MCU pin (F103C8). I have not used a decoupling cap for the ADC input, but for sure for VDDA and other pins as datasheet says. as I mentioned now I tested that I can reduce the supply voltage of the opamp to 5V. therefore I can reduce the resistor values.if you think this match will not work, I'll order an STM32F303 (or an external ADC) and a 3.3V opamp. otherwise, if you have a suggestion for the existing circuit, I really appreciate it.

author: Yansi
author_rank: Super Contributor
timestamp: January 14, 2019, 03:55:33 pm
content: I have already posted, how an an ADC buffer might look like. The schematic just does not include the ADC input decoupling cap, which may be something around the few nF (1 to 3nF).The cap there is there to decrease the output impedance of the buffer at high frequency (the sampling current pulses), and the circuit is wired so that the DC output impedance is zero, yet it is fully stable with that capacitive load.

author: mvs
author_rank: Frequent Contributor
timestamp: January 14, 2019, 04:42:38 pm
content: Quote from: VanitarNordic on January 14, 2019, 03:30:10 pmYou can try to reduce resistor values and add some small decoupling capacitor, like 100-220pF, but there is a limit, what your opamp can drive. You may go for some more suitable opamp, like THS4031.

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: January 14, 2019, 05:11:10 pm
content: QuoteI can not use dual supply opamps because it is a battery powered application. Therefore I selected a rail to rail opamp. it should have low bias current, therefore a Fet or CMOS opamps can work. the opamp input should be sensitive enough. The input frequency is below 1KHz, and the gain is around 1000. I was thinking to use TSV991 if this opamp could not work properly.

author: Yansi
author_rank: Super Contributor
timestamp: January 14, 2019, 06:45:20 pm
content: Why the hell do you need then a 1MSps or more for a 1kHz signal?With such insane gain, your first enemy is noise. Depending on the source impedance, a FET input or BJT input opamp might suit. Most of the RRIO single 5V opamps are CMOS/FET input, with rather high noise. But I may be a bit offtopic with that.Driving the ADCs to insane speeds and pushing the limits also produces more noise (less ENOB) and creates more tough requirements for the buffering circuitry.

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: January 15, 2019, 08:01:55 am
content: Finally, I decided to go with STM32F303CC.as few of you mentioned correctly, it seems the focus on F3 parts are for ADC and analog signals processing, which introduces internal opamps which can be configured as buffers or even amplifiers to fix the impedance issue. I think the best result could be achieved by the F3.