Skip to main content
EFeru
Associate
July 2, 2019
Solved

Custom FOC control: Current measurement / DMA Timer interrupt needs review

  • July 2, 2019
  • 2 replies
  • 9090 views

Hello,

We are working on implementing a custom FOC control for hoveboards on the stock boards that feature an STM32F103RCT6 with 2 phase current measurement.

However, we encounter issues when measuring the Phase currents. They appear to be noisy with high peaks (see attached picture).

https://user-images.githubusercontent.com/24780745/60458354-b0d27a00-9c3e-11e9-99ca-e87e29aa17ed.png

The problem could be that we do not trigger the current measurement at the right moment, when the lower MOSFET is conducting.

Thus, I am asking if you can review the settings for the DMA interrupt by the timer?

More exactly, to review the following files:

master/Src/setup.c

master/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc_ex.h

All the files can be found on github (along with the full project) here:

https://github.com/EmanuelFeru/hoverboard-firmware-hack

EDIT: For more details, there is an open issue on this topic on github:

https://github.com/bipropellant/bipropellant-hoverboard-firmware/issues/41

We would greatly appreciate it.

Thank you in advance!

This topic has been closed for replies.
Best answer by cedric h1

Hello Guys,

I prepared on my free time a small documentation. Be aware that it is not an ST documentation, just a collection of hints that are used in the MCSDK.

I think it will allow you to understand how things are plumbed together. I really advise you to generate a project single drive 3 shunts for STM32F1 and a dual drive 3 shunts / 3 shunts for STM32F4. We do use cubeMX to generate the project tree and all the initialization of the peripherals. Open the generated IOC file with cubeMX is also a nice way to understand how things are configured.

Hope it helps

Regards

Cedric

2 replies

cedric H
ST Technical Moderator
July 9, 2019

Hello Emmanuel,

Thanks to your post I discovered the amazing project you forked on github : https://github.com/NiklasFauth/hoverboard-firmware-hack.

From the revert engineered schematic linked to your github, the Current sensing is actually done with only one shunt per motor.

If I understood correctly, you do not use at all the MC-SDK provided by ST. Is it right ?

Do you know what is the strategy for doing single shunt current sensing ?

ST in the MCSDK uses an active window insertion mechanism to be able to sample the current and this is the main reason we use a DMA.

If you use another method, you can do without DMA. STM32F1 has ADC injected channel that can store several conversions and can be read afterward,

using this method we do not need DMA to copy the ADC data conversion into the memory.

Best Regards

Cedric

EFeru
EFeruAuthor
Associate
July 10, 2019

Hello Cedric,

Thanks for your quick reply.

To answer your questions:

► Yes, indeed. We do not use the MC-SDK provided by ST. That is because our setup is different. For each motor, we only have two motor phase currents and one DC Link currents available, while as far as I read, the MC-SDK supports 3 currents or 1 current setups. On the other hand, MC-SDK supports the boards provided by ST and not the specific hoverboard stock board. I am not sure, is it possible to customize MC-SDK for other boards?

► Regarding the current sensing mechanism... We also use DMA in our setup, triggered on the TIM8 underflow event, when the lower MOSFETs are closed. The only issue we had with this setup is that when operating at high PWM values, the window to sample the Phase currents is quite short and we get few samples when the lower MOSFETs become opened (see picture below).

https://user-images.githubusercontent.com/1426607/60817729-8a5f9200-a19c-11e9-8e27-ec286d27ff39.PNG

This leads to spikes in the current measurements.

We have already some ideas how can we solve this, thanks to the STM documentation So we do use MC-SDK, but not the SDK itself, just the documentation =)

► We are now triggering the ADC read exactly in the middle of counter underflow, while we saw that in MC-SDK there is a suggestion to start earlier on the OCR4 compare event (see picture below)

https://user-images.githubusercontent.com/24780745/60801923-232fe680-a178-11e9-8671-6331c53b63aa.png

We are now trying this idea. Not yet tested. However, when we have updates we will let you know.

Best regards,

Emanuel

cedric H
ST Technical Moderator
July 10, 2019

► For each motor, we only have two motor phase currents and one DC Link currents available, while as far as I read, the MC-SDK supports 3 currents or 1 current setups.

I do not understand your point here. From the schematic, the current reading is done only with one shunt per motor, L_MTR_SHUNT and R_MTR_SHUNT, after the amplification network amplified signals become L_MTR_CURR and R_MTR_CURR connected to ADC IN11 IN10. Did I miss something ? the three phases are connected to the same shunt.

It is true that in the schematic you have also the sampling of two phase voltage per motor. L_MTR_PHC_SENSE / L_MTR_PHB_SENSE and R_MTR_PHA_SENSE / R_MTR_PHB_SENSE. ( I have real doubt regarding the correctness of the sheet phase_sense.sch - here you try to amplify the Vbat voltage injected into the motor phase with a differential OPAMP circuit... sounds strange)

It is true that with the MC-SDK we do not use phase voltage measurement for FOC, we use it only for 6steps (You can have a look to our schematic to see how we do the voltage sensing ( basically it is nothing more than resistor bridge and filtering capacitor ).

►On the other hand, MC-SDK supports the boards provided by ST and not the specific hoverboard stock board. I am not sure, is it possible to customize MC-SDK for other boards?

The boards proposed when you start a new project is only an entry point to ease the life of our users. You can select a board with the same configuration than you have ( From current sensing point of view) and the same voltage and power range, and customize afterward all the power parameters based on your electronic (Dead time/ T-Rise etc ).

►We have already some ideas how can we solve this, thanks to the STM documentation So we do use MC-SDK, but not the SDK itself, just the documentation =)

Happy to help you even without our software ;), but If you are sure you do FOC, please consider to read the topic around one shunt current strategy, because this is how you hardware is done.

In FOC, we need always to sample at least two phase current. With 3 shunts configuration, we can easily sample 2 phases among the three available. In 1 shunt topology, we have to sample twice in the PWM period in order to extract from this two samples, the 2 phases current.

Do you know how many current sample you do per PWM period ?

►We are now trying this idea. Not yet tested. However, when we have updates we will let you know.

With pleasure !

Regards

Cedric

cedric h1
cedric h1Best answer
Visitor II
July 12, 2019

Hello Guys,

I prepared on my free time a small documentation. Be aware that it is not an ST documentation, just a collection of hints that are used in the MCSDK.

I think it will allow you to understand how things are plumbed together. I really advise you to generate a project single drive 3 shunts for STM32F1 and a dual drive 3 shunts / 3 shunts for STM32F4. We do use cubeMX to generate the project tree and all the initialization of the peripherals. Open the generated IOC file with cubeMX is also a nice way to understand how things are configured.

Hope it helps

Regards

Cedric

If you agree with my answer, please accept it by clicking on 'Accept as solution'.""