This method was used in the power meter design that was done a few years back using PSoC for a 50 to 60Hz input AC.
1. Use ADCINCVR at 8 bits and set the sampling rate to 32 samples in a cycle.
2. Using MAC find the square of the instantaneous signal
3. When multiplication is performed, the result is accumulated in the 32 bit accumulator
4. After 32 samples, read from the accumulator and extract the square root.
For this method to work, there should be exactly 32 readings every cycle. For this, use a Zero crossing detector and count the number of ADCINCVR results between each ZCD event. If the number of samples is greater than 32, increase the CalcTime parameter incrementally till the number of samples becomes 32. If the number of samples is less than 32, decrease the CalcTime parameter incrementally to bring the number of samples to 32.
I wouldn't call this method to be a simple one, but this works very well. The other way that I can think is to use an RMS converter and use PsoC to measure the output of the RMS converter. But this will be an expensive solution.
I am currently working on the method you have mentioned on CY8CKIT-001. However, I am stuck on one problem: to make ADCINCVR sample 32 times on one cycle. Maximum I can do is 5 measurements.
Do have any recommendations on that?
I guess it should be done by clock setting and calctime but I could not figured out the best values.
I know for sure that there are the required formulas in the ADCINCVR datasheet. Have a look at pages 4 and 5.
You need 1024 DataClock cycles for the integrate-time and you may specify a calc-time to expand the total sampletime to your needs.
Here is a couple of threads that might help -
I found a reference to this as being the fastest RMS calculation using shifts and adds.
April 1996 issue......
In 1996, an article in Dr Dobbs journal presented a square root algorithm that uses only shifts and adds--no multiplies and certainly no divides. It can be found here: www.ddj.com/documents/s=962/ddj9604l/ (requires registration).
I've been using this in every job and every project ever since--it's by far the fastest integer square root around, and I'm amazed that it's still so little known.
Try it out--you'll never look back!
- Paul Hills
Then this sub reference -
I haven't analyzed it well yet, but certainly going to do. Thank you for your recommendation. It looks quite interesting.
For high CPU clock frequency and low data clock, I could increased the sampke rate. And now I can calculate RMS values very well. In that implementation I am using a sampling counter to get the mean of squares. However, the implementation graa introduced interests me in which the sample count over a period is constant, but in order to make it contant time interval of each sampling may vary. Now I am considering to make that implementation. However, I am stuck on assigning calctime parameter on code.
When I want to read PWM16_MSB & PWM16_LSB I get the result as zero. The datasheet states it can be read/set by device editor or PWM16 API. But I did not understand how to use PWM16 API on ADCINCVR. I assume I need to use the functions of a PWM16 with base addresses of ADC's PWM registers. But I do not know how to.
I think this is the controlling desciption, in the TRM, of why you can't
read the PWM counter registers - attached.
See the notes at very bottom. Looks like those counters are not muxed
to a buss so they can be read.
PSOC PWM Register Read.jpg 96.1 K
But why "RMS-to-DC..."?
"Sin-to-DC..." would be correct, is not it?
"Sine-to-DC..." , sorry.
Not sure what you are asking, but "true" RMS generally specifies crest
factor to account for non-sinusoidal input signal RMS measurements.
RMS is used to compute power or signal energy.
So no, normally one thinks of RMS to DC conversion, which implies handling
of non-sinusoiudal (or distorted sine) signals as well for power measurements.
To measure non-sinusoidal voltage, RMS of the voltage is required to measure and calculate.
So "RMS measuring and calculating" is required, instead of "RMS-to-DC conversion", isn't it ?
You are measuring the area under the periodic signal curve. Or instantaneous power
for a non-periodic signal.
Both statements are correct, in that you are doing calculations, trying to
get to the RMS value, which has a DC equivalent.
Semantics getting in the way.