Skip to content

Commit 8946d2e

Browse files
committed
Fix slow oscilloscope
1 parent 3f009e9 commit 8946d2e

File tree

1 file changed

+16
-3
lines changed
  • src/registers/converters

1 file changed

+16
-3
lines changed

src/registers/converters/adc1.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ void SetBUFFER_IDX(uint8_t idx, volatile uint16_t *V) {
7272
* This interrupt handler is called every time the ADC finishes a conversion, if
7373
* the ADC interrupt is enabled. It checks if the trigger condition is
7474
* fulfilled, and if so copies ADC values into the buffer.
75+
*
76+
* @warning
77+
* If this compilation unit is built with -O0 the ADC1_Interrupt
78+
* functions won't be inlined. This causes call overhead which
79+
* significantly reduces the oscilloscope sample rate.
7580
*/
7681
void __attribute__((interrupt, no_auto_psv)) _AD1Interrupt(void) {
7782
ADC1_InterruptFlagClear();
@@ -85,9 +90,17 @@ void __attribute__((interrupt, no_auto_psv)) _AD1Interrupt(void) {
8590
LED_Toggle();
8691

8792
if (TRIGGERED) {
88-
int i;
89-
for (i = 0; i <= CHANNELS; i++) {
90-
*(BUFFER_IDX[i]++) = *ADCVALS[i];
93+
/* Aweful-looking nested if clause ahead. This turns out to be faster
94+
* than a for loop or a switch case, so we're stuck with it. */
95+
*(BUFFER_IDX[0]++) = *ADCVALS[0];
96+
if (CHANNELS >= 1) {
97+
*(BUFFER_IDX[1]++) = *ADCVALS[1];
98+
if (CHANNELS >= 2) {
99+
*(BUFFER_IDX[2]++) = *ADCVALS[2];
100+
if (CHANNELS >= 3) {
101+
*(BUFFER_IDX[3]++) = *ADCVALS[3];
102+
}
103+
}
91104
}
92105

93106
if (++SAMPLES_CAPTURED == SAMPLES_REQUESTED) {

0 commit comments

Comments
 (0)