#include <otMath.h>
#include <otSerial.h>
#include <otPrintf.h>
#include <otTimer.h>
#include <otMalloc.h>
#include <otADS868x.h>
#include <otStatistics.h>
#ifdef FAST_ACQ
#define SAMPLES 1024
S16 buff[SAMPLES];
#else
#define SAMPLES 100000
S16 * buff;
#endif
otADS868x adc;
otStatistics stat;
void setup()
{
UartEnableSignals(UART0);
UartSetBaud(UART0, 115200);
TimerSetAsCounter(TIMER0);
TimerEnable(TIMER0, true);
setStdout(1024, UART0);
adc.init();
adc.setRange(otADS868x::BIP_12V);
#ifndef FAST_ACQ
buff = (S16 *) _malloc(sizeof(S16) * SAMPLES);
#endif
stat.setData(otStatistics::T_S16, (void *) buff, SAMPLES);
}
*
void loop()
{
U32 st, et;
for(int i = 0; i < 10000; i++)
{
st = TimerGetCounts(TIMER0);
adc.read(buff, SAMPLES);
et = TimerGetCounts(TIMER0);
et = ElapsedTimeUs(st, et) / 1000;
printf("[%4d] Sampling time: %8u mS, bandwidth: %.1lf KSample/s\n", i, et, (double) SAMPLES / (double) et);
st = TimerGetCounts(TIMER0);
stat.evaluate();
et = TimerGetCounts(TIMER0);
et = ElapsedTimeUs(st, et) / 1000;
printf("[%4d] Evaluate time: %8u mS, benchmark: %.1lf KSample/s\n", i, et, (double) SAMPLES / (double) et);
printf("[%4d] STATISTICS : min = %8.3lfV, max = %8.3lfV, average = %8.3lfV, sigma = %8.3lfV\n",
i, adc.toVolt((S16) stat.min), adc.toVolt((S16) stat.max), adc.toVolt((S16) stat.average), (double) adc.toVolt((float) stat.sigma));
}
HIBE;
}