2019-07-02 01:57 AM
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!
Solved! Go to Solution.
2019-07-12 01:30 PM
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
2019-07-09 08:31 AM
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
2019-07-10 04:59 AM
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
2019-07-10 07:09 AM
► 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
2019-07-10 08:03 AM
Hey Cedric
As far as I understand it. the phase_sense circuits are used for current sensing, and they use the Low-Side NMOS as a shunt.
The is where the difficulty comes from, as we need to sample in synchronization with the switching of the MOSFETs. At high duty cycles this can give some issues which we are working to resolve.
Additionally, the shunt measurement that is connected to all phases is not present on all versions of the board, so we have to use the phase currents.
>> 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 avalable. 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
We get 2 samples, one for each measured phase, per PWM period. PWM and thus sample-frequency is 16kHz
2019-07-10 10:43 AM
Hi,
Ok, I missed the trick to use NMOS RDSon as a shunt. I have been confused by the presence of the Shunt resistor connected to all phases. Now it is clear.
So If I understood correctly, you can forget about L_MTR_CURR and R_MTR_CURR, and focus on the two phases : L_MTR_PHC_SENSE / L_MTR_PHB_SENSE for left motor and R_MTR_PHA_SENSE / R_MTR_PHB_SENSE for right motor.
From this document
https://user-images.githubusercontent.com/1426607/60817729-8a5f9200-a19c-11e9-8e27-ec286d27ff39.PNG it looks like you sample the two phases sequentially, MTR_A and after MTR_B. Do you confirm ?
If it is the case, you can save the time of one conversion if you use two ADCs in parallel triggered by the same timer.
for instance, this configuration ADC1_IN0 / ADC2_IN13 can be used in // for sampling MTR_PHA_SENSE/ MTR_PHB_SENSE. It can be triggered by Timer 8 CCR4
ADC1_IN14 / ADC2_IN15 can be used in // to sample L_MTR_PHB_SENSE / L_MTR_PHC_SENSE, using the trigger TRGO or CCR4 from TImer 1.
Of course you have to dynamically reconfigure the ADC trigger based on the timer update interrupt in order to sample Motor R with timer8 and motor L with Timer 1.
In dual motor drive, we start the two PWM timer shifted by half period, meaning one reach ARR-1, when the other is 0. We use center aligned mode. Doing this, let us the time to reconfigure the ADC for the coming conversion while executing the FOC algorithm on the previous motor.
I hope it helps
Regards
Cedric
2019-07-10 12:11 PM
>>In dual motor drive, we start the two PWM timer shifted by half period, meaning one reach ARR-1, when the other is 0. We use center aligned mode. Doing this, let us the time to reconfigure the ADC for the coming conversion while executing the FOC algorithm on the previous motor.
That's great! I didn't think of that, that way you don't have to wait for a conversion to complete before you sample the second motor phases, saving a bunch of time and allowing to sample exactly in center of the ON period. I will look into this, thanks
2019-07-10 01:35 PM
Cederic,
I like very much your proposal for dual motor control using an alternating fashion.
Since my background is Control Systems, is it possible to receive from you such a configuration? It doesn't need to be perfect because we can adjust it to our needs. We just need the core of it:
Do you think you can support us on this?
We would very much appreciate it. Personally, I take this as a great learning opportunity.
2019-07-11 01:08 AM
Hi Emanuel,
I would love to help you more, and spend a lot of time for your amazing project.
Unfortunately, I do not have the time to do so as I have to enhance our own MC-SDK ;) ,
I will prepare a small doc for you to answer your points with some timing diagram for a better understanding.
It will take some time so do not expect an answer in the day.
You are right to say that it is a great learning opportunity. Even if the strategy is different in our MCSDK, I advise you to have a look on our code to see how we configure timers and ADC, almost all of your questions are already answered.
Unfortunately, we do not support dual drive for F1 series in the MC-SDK 5.X but, I advise you to generate two projects, one Dual drive F4 3 shunt and one Single Drive F1, you will find all the hardware configuration trick in the files r3_2_f4xx_pwm_curr_fdbk.c and r3_2_f1xx_pwm_curr_fdbk.c
it is worth to have a look on the stm32[f4xx|f10x]_mc_it.c file too.
Bye
Cedric
2019-07-11 01:26 AM
Hi Cedric,
Thanks a lot for the advises. We will consider them in our project.
I will also check out the configuration for dual motor from MC-SDK and learn from it.
When you have the doc, please let us know.
Good luck with the improvements on MC-SDK. I think you guys are doing an amazing job!
Best regards,
Emanuel