I'm setting up this ADC triggered each ms with a timer interrupt, or 1 kHz sampling frequency to read a 50/60 Hz AC signal and calculate its RMS with 1% accuracy. Also I'm using DMA. The AC signal will swing around 1.65V or Vcc/2 to avoid the negative cycle enter the ADC. I have another ADC channel to track another variable. I have the following questions for the AC signal sampling:

  1. I need to find the RMS in a single cycle of the AC signal (20 ms or 16.67 ms). Is 1 kHz enough? This mean that for 50Hz I will take 20 samples per cycle and for 60 Hz 16 samples. So I need to fill the DMA buffer with these few samples.
  2. How do I choose the sampling time? I could choose between 1.5 and 160.5 cycles. I chose 160.5 as the signal is slow but I'm not sure.

A little pseudo code would be:

  1. Fill DMA Buffer with the samples
  2. Subtract DC offset from each sample or pass the filter through a high pass filter
  3. Take the filtered buffer and calculate RMS

enter image description here

enter image description here


2 Answers 2

  1. Yes 1 KHz should be enough to get a result. However, most energy meters use at least 64 samples per cycle. But this depends on the harmonics. 64 gives you up to 3.2 KHz. You will also get more error if you sample outside the cycle, this needs to be corrected.

  2. You choose the maximum sampling time your samplerate allows. With 1 KHz this is 1 ms, assuming you only sample 1 channel. So I suspect you can use the slowest (most accurate).

  • \$\begingroup\$ Sampling time should be selected based on the source impedance to ADC. Longer sampling time allows for largest source impedance. In this case though, with such slow sampling rate, it is OK to use the highest sampling time, but we actually don't know if it is long enough as we don't know the source impedance. \$\endgroup\$
    – Justme
    Commented Aug 31, 2020 at 7:07
  • \$\begingroup\$ @Justme What should be an impedance of 50/60Hz electrical grid? \$\endgroup\$ Commented Aug 31, 2020 at 7:45
  • 1
    \$\begingroup\$ @MarkoBuršič that's not how it works. The impedance of the grid depends on the fuses and wiring, typically very low. But you can't hook the grid up to an analog pin. There is circuitry in between. You need the impedance of this circuitry. \$\endgroup\$
    – Jeroen3
    Commented Aug 31, 2020 at 7:52
  • \$\begingroup\$ The Reference Manual states that the ADC conversion time is tCONV = tSMPL + tSAR = [1.5 |min + 12.5 |12bit] x tADC_CLK. My ADC clock will be 16 MHz, then I need to choose my sampling time so that the conversion time is not greater than the time interrupt, right? \$\endgroup\$
    – user115094
    Commented Aug 31, 2020 at 12:00
  • \$\begingroup\$ @Jeroen3 Usually the input signal is buffered with an opamp, even more probable if you have to bias it at Vcc/2, so the impedance is very low. \$\endgroup\$ Commented Aug 31, 2020 at 18:48

In my opinion you would need higher sampling rate, i.e. 8kHz.

  • sample
  • high pass filter
  • square & add
  • subtract offset
  • square root

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.