Repository navigation
Conversation
) With SIMPLEFOC_STM32_ADC_INTERRUPT the F1 phase currents stayed frozen at the first conversion. Since the regular group is software triggered and not continuous (68120bf), the F1 HAL_ADC_IRQHandler disables JEOC after every injected conversion, then calls the callback: enable it again there. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On STM32F1 with
SIMPLEFOC_STM32_ADC_INTERRUPT, the low-side phase currents stay frozen at the value of the firstinjected conversion (taken during the offset calibration, so they read ~0 A forever). There is no error message:
the current controllers believe the current is 0 and apply wrong voltages (wheel braking in zero torque), and any
overcurrent check based on the measured currents is blind.
Cause
Since 68120bf ("inital support for reading regular channels"), the F1 ADC regular group is
software triggered and not continuous (
ContinuousConvMode = DISABLE, it wasENABLEbefore). The F1HAL_ADC_IRQHandlerthen disables the JEOC interrupt after each injected conversion(stm32f1xx_hal_adc.c: it disables JEOC if the injected group is software triggered or if the regular group is
software triggered and not continuous), then calls
HAL_ADCEx_InjectedConvCpltCallback. The interrupt runs once andthe
adc_valbuffer is never updated again. The ADC itself keeps converting (JDR1/JDR2 change).Other families are not affected (reading the HAL of the STM32 Arduino core 2.12, not tested on hardware): F4/F7
disable JEOC only if the injected group is also software triggered, G4/L4/H7 only if the injected group is software
triggered, and SimpleFOC triggers the injected conversions from the timer TRGO in every family.
Without the flag nothing changes: when the timer has a repetition counter (TIM1/TIM8), the injected registers are
read directly and no interrupt is used.
Change
One line in the F1
HAL_ADCEx_InjectedConvCpltCallback:__HAL_ADC_ENABLE_IT(AdcHandle, ADC_IT_JEOC);after thebuffer update (the HAL calls the callback right after disabling JEOC). Only
stm32f1_mcu.cppchanges.Tests (hoverboard boards, 6PWM on TIM1, low-side current sense on the R_ds_on, 2 phases on ADC1, 26 V, motor with
hall sensors and SmoothingSensor; Arduino STM32 core 2.12, 64 MHz)
modes run, no fault.
_readRegularADCVoltage()(the feature of 68120bf) on the bus voltage pin (PC2) every 20 ms while the motor runs:works with the fix (2837 reads, 0 errors) and without the flag (6682 reads, 0 errors), same torque.
🤖 Generated with Claude Code