ADC crosstalk fixed, new crosstalk and time measurements (for Horus)

This commit is contained in:
Damjan Adamic
2016-04-10 22:06:53 +02:00
parent 1e3da34ec8
commit 9e0e71ad92
4 changed files with 26 additions and 27 deletions
-2
View File
@@ -221,8 +221,6 @@ const char * debugTimerNames[DEBUG_TIMERS_COUNT] = {
,"Mix eval " // debugTimerEvalMixes, ,"Mix eval " // debugTimerEvalMixes,
,"Mix 10ms " // debugTimerMixes10ms, ,"Mix 10ms " // debugTimerMixes10ms,
,"ADC read " // debugTimerAdcRead, ,"ADC read " // debugTimerAdcRead,
,"ADC loop " // debugTimerAdcLoop,
,"ADC wait " // debugTimerAdcWait,
,"mix-pulses " // debugTimerMixerCalcToUsage ,"mix-pulses " // debugTimerMixerCalcToUsage
,"mix-int. " // debugTimerMixerIterval ,"mix-int. " // debugTimerMixerIterval
}; };
-2
View File
@@ -321,8 +321,6 @@ enum DebugTimers {
debugTimerMixes10ms, debugTimerMixes10ms,
debugTimerAdcRead, debugTimerAdcRead,
debugTimerAdcLoop,
debugTimerAdcWait,
debugTimerMixerCalcToUsage, debugTimerMixerCalcToUsage,
debugTimerMixerIterval, debugTimerMixerIterval,
+25 -22
View File
@@ -157,27 +157,24 @@ uint32_t adcReadNextSPIChannel(uint8_t index)
{ {
uint32_t result = 0; uint32_t result = 0;
ADC_CS_LOW();
delay_01us(1);
SPIx_ReadWriteByte(adcCommands[index]);
ADC_CS_HIGH();
// This delay is to allow charging of ADC input capacitor // This delay is to allow charging of ADC input capacitor
// after the MUX changes from one channel to the other. // after the MUX changes from one channel to the other.
// It was determined experimentally. Biggest problem seems to be // It was determined experimentally. Biggest problem seems to be
// the cross-talk between A4:S1 and A5:MULTIPOS. Changing S1 for one extreme // the cross-talk between A4:S1 and A5:MULTIPOS. Changing S1 for one extreme
// to the other resulted in A5 change of: // to the other resulted in A5 change of:
// //
// delay value A5 change // delay value A5 change Time needed for adcRead()
// 0 76 // 1 16 0.154ms - 0.156ms
// 100 26 // 300 5 0.197ms - 0.199ms
// 300 13 // 500 0 0.225ms - 0.243ms
// 500 undetectable delay_01us(300);
delay_01us(500);
for (uint8_t i = 0; i < 4; i++) { for (uint8_t i = 0; i < 4; i++) {
ADC_CS_LOW(); ADC_CS_LOW();
delay_01us(1); delay_01us(1);
uint16_t val = (0x0fff & SPIx_ReadWriteByte(adcCommands[index])); // command is changed to the next index for the last two readings
// (because the sampled data is lagging behind for two command cycles)
uint16_t val = (0x0fff & SPIx_ReadWriteByte(adcCommands[(i>1) ? index+1 : index]));
#if defined(JITTER_MEASURE) #if defined(JITTER_MEASURE)
if (JITTER_MEASURE_ACTIVE()) { if (JITTER_MEASURE_ACTIVE()) {
rawJitter[index].measure(val); rawJitter[index].measure(val);
@@ -191,7 +188,7 @@ uint32_t adcReadNextSPIChannel(uint8_t index)
return result >> 2; return result >> 2;
} }
void adcStartNextOnChipRead() void adcOnChipReadStart()
{ {
DMA2_Stream1->CR &= ~DMA_SxCR_EN; // Disable DMA DMA2_Stream1->CR &= ~DMA_SxCR_EN; // Disable DMA
ADC3->SR &= ~(uint32_t) ( ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR ); ADC3->SR &= ~(uint32_t) ( ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR );
@@ -202,25 +199,22 @@ void adcStartNextOnChipRead()
ADC3->CR2 |= (uint32_t)ADC_CR2_SWSTART; ADC3->CR2 |= (uint32_t)ADC_CR2_SWSTART;
} }
void adcEndNextOnChipRead() bool adcOnChipReadFinished()
{ {
for (uint32_t i=0; i<20000; i++) { return (DMA2->LISR & DMA_LISR_TCIF1);
if (DMA2->LISR & DMA_LISR_TCIF1) {
break;
}
}
} }
void adcRead() void adcRead()
{ {
uint16_t temp[NUMBER_ANALOG-MOUSE1] = { 0 }; uint16_t temp[NUMBER_ANALOG-MOUSE1] = { 0 };
uint8_t noInternalReads = 0;
adcOnChipReadStart();
adcReadSPIDummy();
adcReadSPIDummy(); adcReadSPIDummy();
for (uint32_t index=0; index<MOUSE1; index++) { for (uint32_t index=0; index<MOUSE1; index++) {
if (index < 8 && !(index & 1)) adcStartNextOnChipRead();
adcValues[index] = adcReadNextSPIChannel(index); adcValues[index] = adcReadNextSPIChannel(index);
if (index < 8 && (index & 1)) { if (noInternalReads < 4 && adcOnChipReadFinished()) {
adcEndNextOnChipRead();
for (uint8_t x=0; x<NUMBER_ANALOG-MOUSE1; x++) { for (uint8_t x=0; x<NUMBER_ANALOG-MOUSE1; x++) {
uint16_t val = adcValues[MOUSE1+x]; uint16_t val = adcValues[MOUSE1+x];
#if defined(JITTER_MEASURE) #if defined(JITTER_MEASURE)
@@ -230,9 +224,18 @@ void adcRead()
#endif #endif
temp[x] += val; temp[x] += val;
} }
if (++noInternalReads < 4) {
adcOnChipReadStart();
}
} }
} }
#if defined(DEBUG)
if (noInternalReads != 4) {
TRACE("Internal ADC problem: reads: %d", noInternalReads);
}
#endif
for (uint8_t x=0; x<NUMBER_ANALOG-MOUSE1; x++) { for (uint8_t x=0; x<NUMBER_ANALOG-MOUSE1; x++) {
adcValues[MOUSE1+x] = temp[x] >> 2; adcValues[MOUSE1+x] = temp[x] >> 2;
} }
@@ -243,7 +246,7 @@ const int8_t ana_direction[NUMBER_ANALOG] = {1,-1,1,-1, -1,1,-1, -1,-1, -1,1,
uint16_t getAnalogValue(uint8_t index) uint16_t getAnalogValue(uint8_t index)
{ {
if (ana_direction[index] < 0) if (ana_direction[index] < 0)
return 4096 - adcValues[index]; return 4095 - adcValues[index];
else else
return adcValues[index]; return adcValues[index];
} }
+1 -1
View File
@@ -185,7 +185,7 @@ uint16_t getAnalogValue(uint8_t index)
index = ana_mapping[index]; index = ana_mapping[index];
#endif #endif
if (ana_direction[index] < 0) if (ana_direction[index] < 0)
return 4096 - adcValues[index]; return 4095 - adcValues[index];
else else
return adcValues[index]; return adcValues[index];
} }