Skip to content

Commit c4e8470

Browse files
Merge pull request #493 from uLipe/enhance/replace_mod
ESP32: replaced the mod base circular increment
2 parents 46f543f + 9c616ba commit c4e8470

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/current_sense/hardware_specific/esp32/esp32_mcpwm_mcu.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,15 @@ static bool IRAM_ATTR _mcpwmTriggerADCCallback(mcpwm_timer_handle_t tim, const m
105105

106106
// sample the phase currents one at a time
107107
// ESP's adc read takes around 10us which is very long
108-
// increment buffer index
109-
p->buffer_index = (p->buffer_index + 1) % p->no_adc_channels;
110108
// so we are sampling one phase per call
111109
p->adc_buffer[p->buffer_index] = adcRead(p->pins[p->buffer_index]);
112110

111+
// increment buffer index
112+
p->buffer_index++;
113+
if(p->buffer_index >= p->no_adc_channels){
114+
p->buffer_index = 0;
115+
}
116+
113117
#ifdef SIMPLEFOC_ESP32_INTERRUPT_DEBUG // debugging toggle pin to measure the time of the interrupt with oscilloscope
114118
gpio_set_level(GPIO_NUM,0); //cca 250ns for on+off
115119
#endif

0 commit comments

Comments
 (0)