Hi all,
I have function generator (Joy-it JDS6600 lite) and I want generate sine wave 0,02V RMS = on generator I have to setup 0.06V because 0.06 is peak-peak, then divided 2 to have 0-peak and multiply by 0,707 (RMS). So for 0.02V RMS I have to setup 0.06V peak-peak. I hope this is ok.
Now I read 4096 samples. Every sample every 50micros via ADC. ADC has only positive values = on plotter I can see half sine.
When I try find max value = 0-peak then I can see 0.024.
I need to measure volts in RMS - I want to see on Serial monitor value 0.02V - any idea how to do it? Thanks!
My code:
I have function generator (Joy-it JDS6600 lite) and I want generate sine wave 0,02V RMS = on generator I have to setup 0.06V because 0.06 is peak-peak, then divided 2 to have 0-peak and multiply by 0,707 (RMS). So for 0.02V RMS I have to setup 0.06V peak-peak. I hope this is ok.
Now I read 4096 samples. Every sample every 50micros via ADC. ADC has only positive values = on plotter I can see half sine.
When I try find max value = 0-peak then I can see 0.024.
I need to measure volts in RMS - I want to see on Serial monitor value 0.02V - any idea how to do it? Thanks!
My code:
Code:
#include <ADC.h>
const int readpin = A1;
ADC *adc = new ADC();
#define AVERAGING 8
#define RESOLUTION 12
#define ADCSAMPLES 4096
float adcbuffer[ADCSAMPLES];
float volt = 0;
float mmax = 0;
float adc_val = 0;
int k;
void setup() {
Serial.begin(115200);
adc->adc0->setAveraging(AVERAGING);
adc->adc0->setResolution(RESOLUTION);
adc->adc0->setConversionSpeed(ADC_CONVERSION_SPEED::HIGH_SPEED);
adc->adc0->setSamplingSpeed(ADC_SAMPLING_SPEED::LOW_SPEED);
}
volatile uint32_t adcidx;
void adc0_isr() {
adc_val = adc->adc0->readSingle();
if (adcidx < ADCSAMPLES) {
adcbuffer[adcidx] = adc_val;
adcidx++;
}
}
void GetADCData(void) {
delay(100); // wait for usb serial to finish
adc->adc0->stopTimer();
adc->adc0->startSingleRead(readpin);
delay(1);
adc->adc0->readSingle();
adcidx = 0;
adc->adc0->startTimer(SAMPRATE);
adc->adc0->enableInterrupts(adc0_isr);
do {
} while (adcidx < ADCSAMPLES);
adc->adc0->stopTimer();
}
void loop() {
GetADCData();
for (k = 0 ; k < ADCSAMPLES; k++)
{
volt = adcbuffer[k] * (3.3 / 4095);
if(volt > mmax)
{
mmax = volt;
}
}
Serial.print("0 - Peak: "); //I will print 0-peak value
Serial.println(mmax,4);
mmax = 0;
delay(1000);
}