Hello guys, i'm new to arduino, and i was wondering if you could help me out on this.
i have 3 AC inputs, i can rectify all of the signals via electronics and then move to the arduino. My goal is to compare the values to find the one with highest amplitude and the second best. The waveforms change all the time, so i have to be able to keep track of the the three peaks and keep comparing them at all time.
Should i keep calculating the RMS values of the 3 waveforms, the do the comparison or is there a simpler method of finding the peak?
If RMS: How do i calculate it in arduino?
could you please help me out on this, like a baseline of how to go about this problem.
Should i keep calculating the RMS values of the 3 waveforms, the do the comparison or is there a simpler method of finding the peak?
you give the answer here
The waveforms change all the time, so i have to be able to keep track of the the three peaks and keep comparing them at all time.
what is the peak depends on the time slots, you can update the peak e.g. per second, per 10 seconds, per 60 seconds etc or maybe even a second / minute / hour / day peak.
First step is to get the shortest time slot working.
assuming there is an N second time slot, you get code like this
void loop()
{
// MEASURE ACTUAL
for (uint8_t i=0; i<3; i++)
{
volts[i] = analogRead(pin[i]);
peak[i] = max(peak[i], volts[i]);
}
if (millis() - lastTimeSlot >= period) // e.g. period = 1 second = 1000 millisec
{
lastTimeSlot += period;
// TODO SORT
// peakSorted = peaksort(peak); // e.g. use max()
Serial.print("TOP:\t"); Serial.println(peaksSorted[0]);
Serial.print("MID:\t"); Serial.println(peaksSorted[1]);
Serial.print("LOW:\t"); Serial.println(peaksSorted[2]);
// update hourly peaks
for (uint8_t i=0; i<3; i++)
{
peakHour[i] = max(peakHour[i], peak[i]);
peak[i] = 0;
}
}
if (millis() - lastHour >= hour) // hour = 60 * 60 * 1000 millisec
{
lastHour += hour;
// TODO SORT
Serial.print("\nHOUR STATS\n==========\n");
Serial.print("TOP:\t"); Serial.println(peaksSorted[0]);
Serial.print("MID:\t"); Serial.println(peaksSorted[1]);
Serial.print("LOW:\t"); Serial.println(peaksSorted[2]);
// update DAY peaks
for (uint8_t i=0; i<3; i++)
{
peakDAY[i] = max(peakHour[i], peakDAY[i]);
peakHour[i] = 0;
}
}
}
If you want to find the peak values you are wasting a lot of time calculating the RMS.
What's the frequency of the AC waveform? An analog-to-digital converter has to "sample" the waveform (i.e. CD audio is sampled 44,100 times per second). The Arduino can easily sample 3 power-line frequency signals, but you'd have trouble sampling 3 signals at the highest audio frequencies.
If you can filter the rectified AC, that will make it easier to "capture" the peaks. If this is AC "power" through a step-down transformer, a capacitor following your rectifier will filter and hold the peak. (You also need a resistor to discharge the capacitor over time and to "pull down" the floating ADC input when no input-voltage is present.)
There is a circuit called a [u]peak detector[/u] that will "capture" and hold the peak for a period of time, making it easier to read & compare the peak. (I use peak detectors for my audio-activated lighting projects.) There is also a full-wave version that rectifies to find the highest positive or negative peak.
yes and thank you for replying. i was thinking that since calculating the rms is not really important for me, wouldn't that reduce and limit my processing power unnecessarily.
Option1
if i can change the ac waveform to square waves, by using a comparator cct then it should be much simpler to compare the values, since i will be working with electronics, i wanted to make sure the programming stays light and faster.
Option2
i only need to know which of the 3 similar ac waveforms have the highest magnitude (peak). the frequency is 33Khz. if i sample it at 1/4 its time period, i should be having the peak, and i believe all the 3 waveforms should be in phase, therefore even if im offset, it shouldn't be a problem. Do you think this kind of reasoning would work?