Author Topic: Interfacing an opamp output with the STM32 ADC  (Read 8528 times)

0 Members and 1 Guest are viewing this topic.

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Interfacing an opamp output with the STM32 ADC
« on: January 12, 2019, 10:15:23 pm »
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 are

1) 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?
 

Offline nsrmagazin

  • Regular Contributor
  • *
  • !
  • Posts: 156
  • Country: ru
Re: Interfacing an opamp output with the STM32 ADC
« Reply #1 on: January 13, 2019, 07:09:31 pm »
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.
Hi all!
If you like the post, please press "thanks".
 
The following users thanked this post: VanitarNordic

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: Interfacing an opamp output with the STM32 ADC
« Reply #2 on: January 13, 2019, 07:18:40 pm »
Quote
The noise can be reduced both by hardware and software filters, a combination of both will be needed for your application.

The 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:
 

Online MasterT

  • Frequent Contributor
  • **
  • Posts: 783
  • Country: ca
Re: Interfacing an opamp output with the STM32 ADC
« Reply #3 on: January 13, 2019, 07:37:16 pm »
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. 
 
The following users thanked this post: VanitarNordic

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: Interfacing an opamp output with the STM32 ADC
« Reply #4 on: January 13, 2019, 08:07:57 pm »
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.

if 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?
« Last Edit: January 13, 2019, 08:12:58 pm by VanitarNordic »
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Interfacing an opamp output with the STM32 ADC
« Reply #5 on: January 13, 2019, 08:37:34 pm »
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.

« Last Edit: January 13, 2019, 08:39:33 pm by Yansi »
 
The following users thanked this post: VanitarNordic

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: Interfacing an opamp output with the STM32 ADC
« Reply #6 on: January 13, 2019, 09:52:02 pm »
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.

So 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?

 

Online MasterT

  • Frequent Contributor
  • **
  • Posts: 783
  • Country: ca
Re: Interfacing an opamp output with the STM32 ADC
« Reply #7 on: January 13, 2019, 10:42:54 pm »

(OP Out) ----> 2.7K ---(ADC)----  1.2K ----(GND)

The ADC sees 1.2K impedance then?
No, ADC sees (1.2 || 2.7) = 0.83 k.
 
The following users thanked this post: VanitarNordic

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Interfacing an opamp output with the STM32 ADC
« Reply #8 on: January 13, 2019, 11:41:13 pm »
The ADC sampling noise was still there.

Guessing 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.pdf

In 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.
 

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: Interfacing an opamp output with the STM32 ADC
« Reply #9 on: January 13, 2019, 11:57:47 pm »
The ADC sampling noise was still there.

Guessing 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.pdf

In 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.

not 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
 

Online MasterT

  • Frequent Contributor
  • **
  • Posts: 783
  • Country: ca
Re: Interfacing an opamp output with the STM32 ADC
« Reply #10 on: January 14, 2019, 12:44:09 am »
For speed better to get F303, it has 4-x ADC 5.1 msps, and "build-in" rail-to-rail  OPA's.
 
The following users thanked this post: VanitarNordic

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Interfacing an opamp output with the STM32 ADC
« Reply #11 on: January 14, 2019, 12:46:43 am »
STM32F3 are superior for analog signal processing, no doubt.

 
The following users thanked this post: VanitarNordic

Offline r0d3z1

  • Regular Contributor
  • *
  • Posts: 116
  • Country: it
Re: Interfacing an opamp output with the STM32 ADC
« Reply #12 on: January 14, 2019, 07:32:41 am »
STM32F3 are superior for analog signal processing, no doubt.

I am interested on this point, could you explain more in detail what are the differances between STM32F3 and F4 ADCs ?

Thanks
 
The following users thanked this post: VanitarNordic

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: Interfacing an opamp output with the STM32 ADC
« Reply #13 on: January 14, 2019, 08:00:26 am »
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
« Last Edit: January 14, 2019, 08:02:29 am by VanitarNordic »
 

Online MasterT

  • Frequent Contributor
  • **
  • Posts: 783
  • Country: ca
Re: Interfacing an opamp output with the STM32 ADC
« Reply #14 on: January 14, 2019, 10:27:33 am »
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
If 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 someone still didn't pay to inventor, and downgrade was done intentionally.
 
The following users thanked this post: VanitarNordic

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: Interfacing an opamp output with the STM32 ADC
« Reply #15 on: January 14, 2019, 10:47:29 am »
Quote
If 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 happen when someone still didn't pay to inventor, and downgrade was done intentionally.

So 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?
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Interfacing an opamp output with the STM32 ADC
« Reply #16 on: January 14, 2019, 01:01:20 pm »
IMHO, all series F1-F7 has the same poorly designed adc architecture, it's could happened when someone still didn't pay to inventor, and downgrade was done intentionally.

Please 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.
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Interfacing an opamp output with the STM32 ADC
« Reply #17 on: January 14, 2019, 01:02:27 pm »
Quote
If 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 happen when someone still didn't pay to inventor, and downgrade was done intentionally.

So 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?

STM32F3 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.
 

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: Interfacing an opamp output with the STM32 ADC
« Reply #18 on: January 14, 2019, 01:42:09 pm »
Quote
STM32F3 have absolutely fine ADC

I 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 5Msps

My 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
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Interfacing an opamp output with the STM32 ADC
« Reply #19 on: January 14, 2019, 01:50:24 pm »
Why don't you spend a bit of time reading the datasheets?

STM32F373, obviously a F3 series part, has a single SAR 12bit ADC and three 16bit sigma-delta ADCs.


 

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: Interfacing an opamp output with the STM32 ADC
« Reply #20 on: January 14, 2019, 01:51:34 pm »
The AN4195 says that F1 and F3 are typically identical, except f3 introduce more features

 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Interfacing an opamp output with the STM32 ADC
« Reply #21 on: January 14, 2019, 02:17:45 pm »
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.

 

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: Interfacing an opamp output with the STM32 ADC
« Reply #22 on: January 14, 2019, 03:05:26 pm »
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.

Maybe 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)
« Last Edit: January 14, 2019, 03:07:57 pm by VanitarNordic »
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Interfacing an opamp output with the STM32 ADC
« Reply #23 on: January 14, 2019, 03:17:28 pm »
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.
 

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: Interfacing an opamp output with the STM32 ADC
« Reply #24 on: January 14, 2019, 03:30:10 pm »
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 unobtainium, should not be any problem getting them from like Mouser, Farnell, Arrow, whatever is in Iran.

What 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.
« Last Edit: January 14, 2019, 03:35:37 pm by VanitarNordic »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf