diff --git a/radio/src/debug.cpp b/radio/src/debug.cpp index 101359994..3b1c32a64 100644 --- a/radio/src/debug.cpp +++ b/radio/src/debug.cpp @@ -221,8 +221,6 @@ const char * debugTimerNames[DEBUG_TIMERS_COUNT] = { ,"Mix eval " // debugTimerEvalMixes, ,"Mix 10ms " // debugTimerMixes10ms, ,"ADC read " // debugTimerAdcRead, - ,"ADC loop " // debugTimerAdcLoop, - ,"ADC wait " // debugTimerAdcWait, ,"mix-pulses " // debugTimerMixerCalcToUsage ,"mix-int. " // debugTimerMixerIterval }; diff --git a/radio/src/debug.h b/radio/src/debug.h index 6edabc6f0..299edfcfa 100644 --- a/radio/src/debug.h +++ b/radio/src/debug.h @@ -321,8 +321,6 @@ enum DebugTimers { debugTimerMixes10ms, debugTimerAdcRead, - debugTimerAdcLoop, - debugTimerAdcWait, debugTimerMixerCalcToUsage, debugTimerMixerIterval, diff --git a/radio/src/targets/horus/adc_driver.cpp b/radio/src/targets/horus/adc_driver.cpp index 7353bce5c..def0d6f4c 100644 --- a/radio/src/targets/horus/adc_driver.cpp +++ b/radio/src/targets/horus/adc_driver.cpp @@ -157,27 +157,24 @@ uint32_t adcReadNextSPIChannel(uint8_t index) { 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 // after the MUX changes from one channel to the other. // It was determined experimentally. Biggest problem seems to be // the cross-talk between A4:S1 and A5:MULTIPOS. Changing S1 for one extreme // to the other resulted in A5 change of: // - // delay value A5 change - // 0 76 - // 100 26 - // 300 13 - // 500 undetectable - delay_01us(500); + // delay value A5 change Time needed for adcRead() + // 1 16 0.154ms - 0.156ms + // 300 5 0.197ms - 0.199ms + // 500 0 0.225ms - 0.243ms + delay_01us(300); for (uint8_t i = 0; i < 4; i++) { ADC_CS_LOW(); 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 (JITTER_MEASURE_ACTIVE()) { rawJitter[index].measure(val); @@ -191,7 +188,7 @@ uint32_t adcReadNextSPIChannel(uint8_t index) return result >> 2; } -void adcStartNextOnChipRead() +void adcOnChipReadStart() { DMA2_Stream1->CR &= ~DMA_SxCR_EN; // Disable DMA 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; } -void adcEndNextOnChipRead() +bool adcOnChipReadFinished() { - for (uint32_t i=0; i<20000; i++) { - if (DMA2->LISR & DMA_LISR_TCIF1) { - break; - } - } + return (DMA2->LISR & DMA_LISR_TCIF1); } void adcRead() { uint16_t temp[NUMBER_ANALOG-MOUSE1] = { 0 }; + uint8_t noInternalReads = 0; + adcOnChipReadStart(); + adcReadSPIDummy(); adcReadSPIDummy(); for (uint32_t index=0; index> 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) { if (ana_direction[index] < 0) - return 4096 - adcValues[index]; + return 4095 - adcValues[index]; else return adcValues[index]; } diff --git a/radio/src/targets/taranis/adc_driver.cpp b/radio/src/targets/taranis/adc_driver.cpp index 810ea883b..1d010deb5 100644 --- a/radio/src/targets/taranis/adc_driver.cpp +++ b/radio/src/targets/taranis/adc_driver.cpp @@ -185,7 +185,7 @@ uint16_t getAnalogValue(uint8_t index) index = ana_mapping[index]; #endif if (ana_direction[index] < 0) - return 4096 - adcValues[index]; + return 4095 - adcValues[index]; else return adcValues[index]; }