cancel
Showing results for
Did you mean:

# To measure Sine wave Voltage and Frequency directly with help of MCU STM32F030CC.

Associate II

I want to measure AC signal voltage and frequency .Presently i am using function generator to generate sine wave having 3Vpp(peak to peak Voltage) and feed directly to MCU pin which support ADC channel(Channel 7).

So any one can guide on this.

I have implemented this as below.

For every 1ms i am taking 40 reading from ADC and then calculate Vrms value.

But it is true as taking 40 reading for signal having 50Hz frequency.

But as i think this is not true method to measure voltage.

So is there any way other than this.

Please find attached below code of my.

@Tesla DeLorean

4 REPLIES 4
Guru

To calculate VRMS, you need to capture the signal over several periods. A 1ms period of a 50Hz signal is only 5% of a single period, so basically useless. You could also estimate it by capturing the min/max values over a duration of at least a few periods and assuming a sine profile.

You'll also need to ensure your entire signal falls within the 0V to VREF voltage range allowable by the ADC, otherwise you can't get an accurate reading (and may also damage the chip). If you are not interested in the DC component of the signal, this can be done with AC coupling using a bias voltage of VREF/2.

Associate II

Yes u r right that i have to sample over some period.

As u might have seen in my code that every millisecond i read one sample and i took 40 samples over 40 ms.After that i calculate rms value.

Here i have know that frequency is 50 Hz that's why i take 40 ms span to cover 2 cycles of sine wave.But if i don't know frequency then i can not predict period.

To measure the frequency of a signal assumed to be sinoid, zero crossing detection is the easierst method.

Just check where the signal transits from "positive" to "negative" signal ranges, and measure the time (i.e. number of sample periods).

You would need to take more than one expected signal period for this evaluation, e.g. 50 to 100ms.

Of course you need to evaluate which asymetric (0V ... +3.3V) ADC values represent positive and negative signal values.

This works considerably well for single-frequency signals with light to medium distortions (e.g. caused by reactive loads).

Use a period that is long enough to captures the frequencies of interest. Surely there is some lower cutoff.