Showing results for 
Search instead for 
Did you mean: 

STM32F303 Comparator & ADC for AC RMS measurements

Associate II

I come from the PJRC Teensy 4.x after many years playing around with it and building a product or two based on it. (NXP IMXRT chip)

But for a new project I need to be able to rapidly calculate the RMS value of an AC sine wave from an audio signal, with a wide range of 10Hz to 20Khz.

I was looking and googling and found that the F303 has a 5MSPS ADC and can also use the comparator at the same time on the same pin.

My need/goal is to be able to detect zero crossing point with the comparator, trigger an interrupt that will kickoff ADC readings/calculations and then once another interrupt arrives at the next zero crossing, stop the current ADC readings, switch buffers and start again for the next half cycle of the sine wave.

Is this something the 303 could handel?
I would also need to offset the ADC input to be able to handle the ac value, and also provide the comparator with the extact same offset voltage for the zero crossing point.

So what I looking for is confirmation of the ability to do what I need, and also if someone has a schematic of how I would hook up the hardware - that would be great!


Sure the F303 can do that, just not using only one pin. 

For the circuit you could look for help:


If you feel a post has answered your question, please click "Accept as Solution".

So one pin for the comparator, one for the ADC.

Would I just connect them together, of should I split the signal using a buffer for each input?
Same for the vref/2 offset voltage?

ADC and comp can be connected together.

But about the offset...draw a circuit and show it. It's more easy to talk about.

If you feel a post has answered your question, please click "Accept as Solution".
Associate II

I'll try to better explain it before drawing it out:

On the ADC input, I need to DC offset the AC signal, so that it always floats above ground, so I will need to provide 1.65v dc to the ADC input, so that it can accept an ac signal.

The Comparator needs two signals, the input signal, and a reference voltage for the "zero point"
Input signal would be the same signal going into the ADC (which is already DC offset)

But the reference voltage for zero crossing detection would be half of Vcc(3.3v), in this case also 1.65v

The question is, can I use a voltage divider for example, and feed both inputs (ADC and comparator reference) with the same voltage path, or should I isolate them using op-amps or transistors etc (some active form of signal isolation)
Per the logic, I would say they need to be isolated.

I do it - just for fun - on a F303 to build a mini - DSO.

Virtual ground for ADC and comp input is 1/2 VDD, comp negative input comes from DAC output. So I can adjust trigger level.  

And you can not use same input pin for different functions at same time, so one is ADC input and comp positive input on another, connected together.

If you feel a post has answered your question, please click "Accept as Solution".
Associate II


Okay so here is my example.
I have a voltage divider to generate 1.65v which is to be used for both the ADC DC bias as well as the CMP reference voltage for zero point.

But in the circuit below, we are actually connecting all signals together, which might lead to unexpected behavior on the comparator.
That's why I figured that using a buffer between ADC/CMP_N  and CMP_P would solve the potential issue