"Sense" circuit for MCU ADC (STM32 / ESP32 / Arduino etc...)

Hi.

I'am trying to make a voltage sense circuit for a microprocessor 🙂

I have the ESP32 developmentboard set up to sense a voltage level on it's ADC.
For a start I build an active rectifier with an LM833 opamp.
With this active rectifier + smooting capacitor I can measure fairly good and stable levels within 0.2v ---> 3v (RMS sine)
Next step is to calibrate the ADC so values from 0 ---> 3.3v can be measured. https://github.com/e-tinkers/esp32-adc-calibrate
So far that is good.

But I would also like to have the possibility to measure the output from differential output.

So I could use the circuit below to feed my ESP32 (Diff. to SE ---> Active rectifier ---> ESP32)
I was wondering if I can feed the diff. to SE circuit with an SE input also (+IN to Vin1 and -IN/Vin2 to GND) this way I can use it for both diff. and SE measurements.

I can ofcause just try it out, but I would like to understand it before I do.

One last thing, I don't need crazy exact / precise values!

Jesper.

Diff_to_SE.PNG
 
Last edited:
I was thinking about this yesterday for a limiter and also checking the ADC speed of ESP32/[Arduino-like micros]. A under-clocked Raspberry Pi Pico sounds cool as well, small and cheap.

Are you trying to measure RMS or peaks?
For peaks one could use a CPU interrupt and a comparator.

(Hopefully this isn't too basic, not electric engineer here but learning stuff).
 
Hi.

I'am measuring RMS.
I have this active rectifier on my bench now for test.

The setup is for now a ESP32 Devkit V1, with 16x2 LCD, measuring RMS directly from my sinegen. (0-3VRMS)
next step is to have some relay's for controlling a voltage divider to have the possibility to measure higher voltages...

Jesper.
 
Hi...

I'am using this full wave rectifier : https://circuitdigest.com/electroni...wave-precision-rectifier-circuit-using-op-amp

It does not matter that much, but when measuring the input and output VRMS with my scope, the VRMS is a bit lower after the smothing cap.

The idea with this, is that I would like to make an autoranger for my soundcard, so to have the autoranger adjusting the voltage automatic for the best range into the soundcard (~1.15VRMS / sine).
I'am making it 1. step at a time.
This first step is the "sense" and circuit into the MCU. -I'am far far far away from there 🙂

-If i success with this I will make a pcb with this "sense" circuit :

  • Relay(s)Controlled voltage dividers
  • Balanced to SE input
  • Full wave active rectifier, smooted into the ESP32.
  • Relaydriver ULN2803A to drive 8pcs. 12vdc relay's.
  • PSU
  • Connectors etc...

This first pcb will only host the voltagedividers for the "sense" circuit, but it will also host connectors to the 2. pcb, where the "real" autoranger will be.

Comments are very welcome!

Jesper.
 
You could try another approach. Use external 16bit adc ,like ads1115 , i2c . Peak voltage detection can be made softwarely. Use voltage divider for range up to highest voltage you may supply as signal input. In example , you have amplifier , which supply up to +-50V to load. Cpu and adc voltage is 3,3v as i know for esp32. So you need to supply +1,65v from resistive voltage divider to one of ads1115 inputs , and add resistor , to make voltage divider , to not exceed supply voltage. Maybe divide signal 20 times. Also add capacitor for dc decoupling input signal. Because of 16bit resolution, you will be able measure lower voltages, in comparison to esp internal adc .As i understand, you just need peak value , to switch relay for proper level , to not overload sound card.
 
  • Like
Reactions: lykkedk
RMS voltage of an AC waveform is the voltage that would give the same amount of power into a load over one cycle as some equivalent DC voltage. That DC voltage is the RMS value of the AC waveform.

If that makes sense, one may recall that the instantaneous power is proportional to the square of the instantaneous voltage. So, to get RMS voltage, one way is to sample an AC waveform and square all the readings. Add them up to get the total power for one cycle, then find the DC voltage that would give the same power into the same load.

Hence, RMS is an acronym for the algorithm: Root, Mean, Square. That's what your digital scope is doing.

OTOH, rectifying gives a series of pulses that can then be smoothed by a filter to give an average. If he RC time constant of a simple RC filter is long enough then you get peak rectification instead. So its possible to measure average voltage or peak voltage that way, but not RMS.

However, it is possible to calibrate a peak or average voltage measurement to display the corresponding RMS voltage assuming the waveform is a sine wave. For all other waveforms the calibration factor would be different.

Anyway, if you really want to measure RMS volts you need a different circuit. Fortunately there are chips to help with that: https://www.analog.com/en/product-category/rms-to-dc-converters.html
 
Last edited:
  • Like
Reactions: lykkedk
Maybe another thing to consider would be if an input voltage changes fast enough then there may not be time for a relay to switch before damage occurs. Therefore its probably good to have a clamp circuit to protect the ADC input from transients.
 
  • Like
Reactions: lykkedk
Thanks all...

@Markw4 What iI meant before, was that I did measure the voltage after the balanced to se converter + the active rectifier, and this voltage is a bit lower than the measured (both DMM and scope) VRMS voltage...

Well I'am very interested about the clamp circuit, because it's somewhat very hard to find information regarding this, when used on ADC input (0v - 3.3v)
If you can guide me into the right direction, I really would appreciate that 🙂

Thanks.

Jesper.


Test_1.jpg
 
  • Like
Reactions: lene
I see one problem using your rectifier circuit , mentioned earlier. If you using LM358 , you can't get full swing 0-3,3v out of it. In ideal , need to use a rail to rail output opamp and schottky diodes to lower drop .Current circuit will function until opamp output is trying to saturate, trying to output +3,3v . Also , looking from one side , you should supply LM358 with higher supply voltage , to get rectified 3,3v max out of it , but then you risk to damage cpu adc input, if ic will get damaged in example and give at output more than 3,3V.
 
@ximikas

I see one problem using your rectifier circuit , mentioned earlier. If you using LM358 , you can't get full swing 0-3,3v out of it. In ideal , need to use a rail to rail output opamp and schottky diodes to lower drop .Current circuit will function until opamp output is trying to saturate, trying to output +3,3v . Also , looking from one side , you should supply LM358 with higher supply voltage , to get rectified 3,3v max out of it , but then you risk to damage cpu adc input, if ic will get damaged in example and give at output more than 3,3V.
I'am actually using an LM833 i had in drawer, this was just to test. I'am feeding it with +12vdc / -12vdc.
I was not thinking about writing that in the first post...

Appreciate your'e input's 👍

Jesper.
 
+-12v is ok for lm833 , but think about if you touch input , or connect balanced input jack ,not all pins at same time, how much volts lm833 will output ? Much more than esp allows as analog input. Series current limiting resistor is needed in that case , something like 10k , and protection diodes , to gnd and to 3,3v , also zener 3,3v or something close to that, to prevent esp input over voltage.
 
@ximikas

There will be voltage divider's before the voltage from DUT enters the Bal. to SE buffer + activerectifier.

Anyway, I'am investigating how the diode clamping protection is working.
Looking at the suggested reading here TI adc protection

Case is that the suggested circuit is dealing with -1.4V to 3.6V, but the ADC on my ESP32 is only accepting 0V - 3.3V - not any negative voltage at all.
I need to make some test with this setup.

Jesper.
 
@ximikas ...

Ahh I think I got it now.
At moment I only have some LM358 which I don't think would work.

Well... So I need to have a 3.3V (MAX) PSU to feed the opamp e.g. TLV9162 with GND and +3.1V. as single supply -Correct ?
Then when using this as a active rectifier, just before it enters the ADC (MAX 0V - 3.3V) the opamp can never destroy the ADC I see 👍

I never had this idea.

Thank's.
 
Yes , at best you need to supply rectifier with same supply voltage as adc. But you will have diode drop at rectifier , so again ,rail to rail output would help partially. Or increase voltage of opamp by diode drop voltage value , but again , then overvoltage resistor is needed.
 
Yes...

I think it might be good with 5-6VDC and GND for the supply then.
That's great if possible, because I allready have some opa1656 which can operate at +4.5 and give rail to rail output.
Then a small voltage divider after the active rectifier to maxout the voltage to say 3.1VDC for a safe margin.
As long as the ADC can measure it proberly (more than +250mV are fine).

But can you tell me, how much input voltage the opa1656 can accept by accident?

Jesper
 
Opamp input voltage is limited by supply voltage range , for some it's even a little extends supply range. Datasheet should specify that . Opamps can have rail-to-rail inputs ,outputs ,or both at best. But opamps ,not specified for single supply operation, can't accept input voltages lower than 1,5-2v in reference to negative supply pin.