Over the past few weeks, a circuit diagram for the Micro-moto version 2 has been created from the previous considerations. After some productive reviews and discussions about the schematic and the incorporation of various improvements and changes, a board layout was drawn in KiCad.

The production of the board was sponsored by Aisler and after only about a week of waiting the boards and all components arrived in our lab.

Quickly two boards were assembled and except for one single solder bridge successfully soldered in the reflow oven. Only the (optional) vertical Micro-USB connector had been forgotten when ordering the components, but this was no problem, since programming via SWD is more convenient for testing due to its debugger interface.

Step by step, power supply, STM32 microcontroller, status LEDs and gate drivers including MOSFET power stage were tested successfully. Everything worked on the first try, for once.

The development process of the micro-motor can be followed up in several older blog posts.

The next step is to bring the current and voltage measurement into operation. For this purpose we document in this blog post the requirements and development of the implementation with the analog-to-digital converter of the STM32G4 microcontroller.

Requirements

  • ADC sampling synchronous to PWM of motor (approx. 100kHz)
  • Sampling on every PWM cycle
  • For all phases either current or voltage are measured: current on both “switched” phases, voltage on the “high-impedance” phase
  • Measure current in both phases simultaneously
  • Additional ADC measurements at low priority and with low frequency
    • Motor supply voltage
    • 3.3V supply voltage (Vbat)
    • NTC temperature sensor
    • Internal temperature

ADC channel usage on the micro-motor

Measurement Possible ADC channels Gpio pin
Current U Adc1Ch1, Adc2Ch1 GpioA0
Current V Adc1Ch2, Adc2Ch2 GpioA1
Current W Adc1Ch4 GpioA3
Voltage U Adc1Ch15, Adc3Ch12 GpioB0
Voltage V Adc2Ch4 GpioA7
Voltage W Adc2Ch3 GpioA6
Motor supply voltage Adc2Ch12 GpioB2
3.3V supply voltage Adc1Ch17, Adc3Ch17 N/A
NTC temperature sensor Adc1Ch12, Adc3Ch1 GpioB1
Internal temperature Adc1Ch16, Adc5Ch4 N/A

Implementation

The three critical measurements will be sequenced as “Injected Conversions” and triggered by a event generated from the timer which generates the Motor-PWM.

In an “Injected conversions sequence” (sequence length is limited to 4) each conversion has its own output data register. Thus all conversion results can be easily read one after the other in the time until the next PWM cycle and no interrupts are needed.

For every of the six valid commutation steps that define the state of the three MOSFET half bridges, a mapping to the ADC channels is predefined and applied during the commutation.

Low-Priority measurements are sequenced in the ADCs “normal-mode” sequence and are triggered at a lower frequency (by another timer or manually from code).