Skip to content

Commit 9c616ba

Browse files
committed
ESP32: reorder the ADC buffer increment
To happen after the ADC reading to avoid shifting the order of the samples. Signed-off-by: Felipe Neves <[email protected]>
1 parent f5331e0 commit 9c616ba

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/current_sense/hardware_specific/esp32/esp32_mcpwm_mcu.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +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+
// so we are sampling one phase per call
109+
p->adc_buffer[p->buffer_index] = adcRead(p->pins[p->buffer_index]);
110+
108111
// increment buffer index
109-
p->buffer_index = (p->buffer_index + 1);
110-
if(p->buffer_index == p->no_adc_channels){
112+
p->buffer_index++;
113+
if(p->buffer_index >= p->no_adc_channels){
111114
p->buffer_index = 0;
112115
}
113116

114-
// so we are sampling one phase per call
115-
p->adc_buffer[p->buffer_index] = adcRead(p->pins[p->buffer_index]);
116-
117117
#ifdef SIMPLEFOC_ESP32_INTERRUPT_DEBUG // debugging toggle pin to measure the time of the interrupt with oscilloscope
118118
gpio_set_level(GPIO_NUM,0); //cca 250ns for on+off
119119
#endif

0 commit comments

Comments
 (0)