Arduino-FOC
Arduino-FOC copied to clipboard
B g431 b current sense fixes
Only tested on B-G431B with inline current sense.
Did you try using LowsideCurretSense instead of InlineCurrentSense?
Because all the additions that you've made are already present in the _driverSyncLowSide function which is not called in for in-line class. I have moved them there in the last release to remove bg431 specific code from the driver code and because bg431 only has the low-side current sensing. So I would prefer not to use the inline code with it.
https://github.com/simplefoc/Arduino-FOC/blob/84a4aba4e83c50b2a3ec5c8eeb2cd763934f43da/src/current_sense/hardware_specific/stm32/b_g431/b_g431_mcu.cpp#L137
That's a good point. I feel I messed up with the original implementation, we called it inline current sense, but it really implements low side current sense. I'm confused why the wiki claims inline current sensing support for this board, it seems that placing the required resistors would require very advanced soldering...
I tried using low side current sense, but it doesn't work. There are multiple problems with initialization and syncing, I will attempt a fix.
Hey @sDessens, I'll order the board and try to fix it as well. If you don't have time dont worry about it. This PR is already a great step in finding the real reasons for why it does not work.
The docs are wrong you are right! I've written in that way because at some point we only had your implementation of the BG431 board which was done using the inline current sese (the only one supported at the time).
So I've gone quickly through the code and can it be that the line:
LL_TIM_SetTriggerOutput(HardwareTimer_Handle[index]->handle.Instance, LL_TIM_TRGO_UPDATE);
has to be called before the timer init?
I did not have any problems with this so far for f1, f4 and g4 low-side current sensing. They all work with the TRGO UPDATE setting https://github.com/simplefoc/Arduino-FOC/blob/1acfda1d22aac484ab231fafd729f480603fd854/src/current_sense/hardware_specific/stm32/b_g431/b_g431_mcu.cpp#L151
and repetition counter downsampling https://github.com/simplefoc/Arduino-FOC/blob/1acfda1d22aac484ab231fafd729f480603fd854/src/current_sense/hardware_specific/stm32/b_g431/b_g431_mcu.cpp#L144
that are done after the timer init. They are called when the timer is stopped and once they are called the timer is resumed.
However, the bg431 code is the only one which for now uses the DMA so this might be the issue.
I managed to fix the problem, it turns out there was a null-pointer and this caused unpredictable behavior.
With this rebase, LowsideCurrentSense works but InlineCurrentSense does not work.
Awesome, thanks!
This was my fault, I've refactored the code but as I did not have the board I did not test it properly! Thanks a lot for taking the time to debug.
I feel the community might be slightly confused that we switched from inline to lowside current sensing on this board. Would it be a good idea to display a warning when the user initializes inlineCurrentSense on this board. For example by displaying a debug message in _configureADCInline?
I'll make sure to update the docs for the next release. All the library examples already use the low-side current sensing so that should make things a bit easier.
I think adding the message in configure inline is a good idea, just to be make the transition a bit smoother for the people used to use inline cs. Once you add the message we can merge it. @runger1101001 you're fine with this?
Merging, thanks again!