Fixes #3233: Added ADC jitter measurement (use MEASURE_JITTER=YES to enable), Added ADC jitter filter (use JITTER_FILTER=No to disable) (ported from master)

This commit is contained in:
Damjan Adamic
2016-01-19 17:13:11 +01:00
parent c46c1f887a
commit 4aa6bd12ca
6 changed files with 256 additions and 150 deletions
+51 -3
View File
@@ -1485,6 +1485,13 @@ uint16_t BandGap = 2040 ;
uint16_t BandGap ;
#endif
#if defined(JITTER_MEASURE)
JitterMeter<uint16_t> rawJitter[NUMBER_ANALOG];
JitterMeter<uint16_t> avgJitter[NUMBER_ANALOG];
tmr10ms_t jitterResetTime = 0;
#define JITTER_MEASURE_ACTIVE() (menuHandlers[menuLevel] == menuGeneralDiagAna)
#endif // defined(JITTER_MEASURE)
#if !defined(SIMU)
uint16_t anaIn(uint8_t chan)
{
@@ -1521,10 +1528,28 @@ void getADC()
{
uint16_t temp[NUMBER_ANALOG] = { 0 };
#if defined(JITTER_MEASURE)
if (JITTER_MEASURE_ACTIVE() && jitterResetTime < get_tmr10ms()) {
for (uint32_t x=0; x<NUMBER_ANALOG; x++) {
rawJitter[x].reset();
avgJitter[x].reset();
}
jitterResetTime = get_tmr10ms() + 100; //every second
}
#endif
for (uint32_t i=0; i<4; i++) {
adcRead();
for (uint32_t x=0; x<NUMBER_ANALOG; x++) {
#if defined(JITTER_MEASURE)
uint16_t val = getAnalogValue(x);
if (JITTER_MEASURE_ACTIVE()) {
rawJitter[x].measure(val);
}
temp[x] += val;
#else
temp[x] += getAnalogValue(x);
#endif
}
#if defined(VIRTUALINPUTS)
if (calibrationState) break;
@@ -1533,8 +1558,29 @@ void getADC()
for (uint32_t x=0; x<NUMBER_ANALOG; x++) {
uint16_t v = temp[x] >> 3;
#if defined(VIRTUALINPUTS)
if (calibrationState) v = temp[x] >> 1;
if (calibrationState) {
v = temp[x] >> 1;
}
#if defined(JITTER_FILTER)
else {
// jitter filter
uint16_t diff = (v > s_anaFilt[x]) ? (v - s_anaFilt[x]) : (s_anaFilt[x] - v);
if (diff < 10) {
// apply filter
v = (7 * s_anaFilt[x] + v) >> 3;
}
}
#endif
#if defined(JITTER_MEASURE)
if (JITTER_MEASURE_ACTIVE()) {
avgJitter[x].measure(v);
}
#endif
StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[x];
if (!calibrationState && IS_POT_MULTIPOS(x) && calib->count>0 && calib->count<XPOTS_MULTIPOS_COUNT) {
uint8_t vShifted = (v >> 4);
@@ -1546,9 +1592,11 @@ void getADC()
}
}
}
else
else
#endif
s_anaFilt[x] = v;
{
s_anaFilt[x] = v;
}
}
}
#endif