Skip to content

Commit 0a23510

Browse files
committed
ESP32: replaced the mod base circular increment
of the ADC buffer with a branch based option to avoid the compiler to use a MOD instruction that consumes several cycles. Signed-off-by: Felipe Neves <[email protected]>
1 parent 46f543f commit 0a23510

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/current_sense/hardware_specific/esp32/esp32_mcpwm_mcu.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ static bool IRAM_ATTR _mcpwmTriggerADCCallback(mcpwm_timer_handle_t tim, const m
106106
// sample the phase currents one at a time
107107
// ESP's adc read takes around 10us which is very long
108108
// increment buffer index
109-
p->buffer_index = (p->buffer_index + 1) % p->no_adc_channels;
109+
p->buffer_index = (p->buffer_index + 1);
110+
if(p->buffer_index == p->no_adc_channels){
111+
p->buffer_index
112+
}
113+
110114
// so we are sampling one phase per call
111115
p->adc_buffer[p->buffer_index] = adcRead(p->pins[p->buffer_index]);
112116

0 commit comments

Comments
 (0)