Best Practice for ADC Reading & Op-Amp Toggling in Motor Control (STM32G431CBU6)
- October 30, 2025
- 1 reply
- 349 views
Hello everyone,
I'd first like to mention that this project is being developed with support from ST Brasil, which has provided important components to aid in this development.
I'm working on firmware for motor control and, being new to this area, I'm looking for guidance on the best way to implement a specific part of the logic.
1. Summary and Context
Here is a summary of the hardware and MCU configuration:
Hardware: 3 low-side shunts. The signal from the Phase U shunt resistor is shared, acting as a common input for two of the MCU's integrated op-amps.
MCU Config:
1.1. Timer 1: Configured for Center-Aligned Mode 1. * CH1/CH1N, CH2/CH2N, CH3/CH3N are complementary PWM outputs. * CH4 is used to generate a capture-compare interrupt.
1.2. ARR Value: The ARR (Auto-Reload Register) value is 1000.
1.3. Interrupt Trigger: Timer 1 CH4 is set to generate a capture-compare interrupt when the CNT (counter) reaches 900.
1.4. Modulation Index: For modulation index purposes, the maximum value for CCR1, CCR2, and CCR3 should be 800.
1.5. Op-Amps: Configured for high-speed mode. The non-inverting input pin needs to be switched programmatically (in software).
1.6. ADCs: * Using DMA. * Regular conversions are triggered by software. * Scan Mode is On. * The "End of Sequence of conversions" (EOS) option is enabled.
2. My Main Question
(Thank you for reading this far.)
Given this configuration—specifically the need to read currents and switch the op-amp inputs—I'm trying to figure out the most robust and efficient way to handle the logic.
What is the best practice or recommended method for:
Reading the ADC values?
Saving the conversion data?
Programmatically toggling the non-inverting inputs for the op-amps in sync with the PWM cycle?
- After the currents and voltages are read and saved, I will implement a state observer. Where in the execution flow (e.g., in which interrupt context, or in the main loop) should I perform these observer calculations to avoid race conditions with the data that is being updated by the DMA/ADC?
I'm looking for advice on the general approach .
Thank you for your time.
Best Regards,
Raul Undergraduate Student & Scientific Initiation
Universidade Federal de Santa Maria (UFSM)
