Hi everybody! I spent a lot of time trying to get the B-G431B-ESC1 board to work with its software, but I had many problems. Finally, I stumbled upon the simpleFoc library and I got better results. I followed the steps shown in the SimpleFOC tuning guide on the youtube channel using a brushless motor and an encoder(EMAX CF2822 1200KV Brushless Motor and Omron incremental encoder 200 ppr). I used what I had just to do some testing and everything went well, at least I think so! Now for my project, I have to use brushless motors with hall sensor, which are placed 120 ° apart, and already from the first steps I have some problems. I share the characteristics of the motor with the hall sensor:
The sensor test is fine, I read the values with the function getAngle() correctly;
When I try to run the open loop velocity control I have problems reading the speed. The read values oscillate between the right speed value and zero. I noticed that the problem occurs in the function getVelocity() because the variable pulse_diff is often set to zero.
In the next step (voltage control) another problem occurs in sensor alignment. It usually the following problem occurs: “MOT: Failed to notice movement”. In some cases when the alignment works, I get as offset 0 or 6.28. However in this case the motor seems to increase the torque in proportion to the increase of the voltage but it does not move.
Do you know why I have these problems with the hall sensors? Do you have any suggestions? Thanks in advance for your help.
UPDATE: After reading other topics, I checked the interrupt number by printing the value of the variable inside the loop method. With unpowered motor, the number of interrupts for one revolution is correct and is equal to 66 (3 HALL sensors * 11 pp * 2 edges). When motor is powered, the number of interrupts per revolution is greater than 50k per second. Checking the sensor signals with an oscilloscope, I noticed that on pin PB6 (attached at HALL1) there was a PWM signal at 25 kHz with a variable duty cycle. I think the increase in the number of interrupts is due to this signal. I applied the solution proposed by @Owen_Williams in https://community.simplefoc.com/t/b-g431b-esc1-hoverboard-motor-not-working-with-closed-loop-modes/898, so I put a 2K ohm pull up resistor between hall1 and VDD. Now the number of interrupts per revolution is correct but I have not solved the problem, because the PWM signal is still present but with a lower amplitude. In reference to the schematic of the board, I do not understand how it is possible that a PWM signal is present on this pin. I checked if there were any errors in the pin definition but I did not find any. Moreover, in the voltage control (TorqueControlType::voltage and MotionControlType::torque), the alignment phase seems to work but once this phase is completed the motor does not start. It does not respond to any reference. Do you have any suggestions to investigate the problem? Thanks in advance.
Looking at the schematic and the routing of the board there does not seem to be any connection between pin HALL1 and pwm output signals. I didn’t check with the multimeter, could you tell me what to check?
Hay, did you consider if it’s the magnetic field of the coils triggering that one hall sensor, creating a PWM signal… from what I read 3.3k resistor on the hall’s is often used. 2k could be to low. Don’t know.
I don’t think the problem is the motor or the sensor. I tried to load the code on another board B-G431B-ESC1 without connecting the motor and the sensor and with the oscilloscope I read the same PWM signal. I will try to do more tests to find some hardware bridge, but maybe it’s more probable that is a software problem. However I am trying to find a possible solution in the library but I still haven’t found anything.
Hey, to help us understand the problem, would it be possible for you to provide a picture of the oscilloscope plot? I’d like to see if one can tell if it is noise or signal of the PWM we see on the hall signal line…
And if you could provide high-res photos of the top and bottom of the board, people might spot problems, if there are any visible ones.
On the software side, it could help if you could provide some of the code you’re running? If that is possible…
It would be interesting to get to the bottom of this!
Thanks everyone for your help! I show you the tests I have done. I am using the arduino ide and to install B-G431B-ESC1 board I used the instructions of @Wittecactus in beginner-guide-i2c-guide.
First of all, I ran the code related to open loop velocity control:
Attaching the oscilloscope probe to the HALL 1 pin I detected a PWM signal with a frequency of 25 kHz, with a variable duty cycle and with a signal amplitude of 2.2 Vpp:
I noticed that the PWM signal on pin HALL 1 is synchronized with the output signal related to phase 2 of the motor (green signal). Maybe this could be useful to find a possible bridge (hardware or software).
I also noticed that changing the value of the variable motor.voltage_limit changes the range of variation of the duty cycle. For example by setting the variable voltage_limit = 1 the duty cycle range is 42-57%.
I replaced the existing 10K pull up resistor with a 2.2K resistor and I obtained a decrease in the amplitude of the pwm signal on pin HALL1. This made it possible to avoid the increase of the number of false interrupts but did not actually solve the problem.
In this case the alignment phase seems to work but when the alignment is completed the motor does not move whatever the reference voltage value is.
Also I tried to skip the alignment step by entering the obtained parameters in the initFOC function:
The motor still does not move but I have read on pin HALL1 a pwm signal with fixed duty cycle.
I add a complete image of all the connections, where orange is HALL1, yellow is HALL2 and white is HALL3 (I also checked the welds with a microscope):
Wow, that is weird… either there is an electrical connection between phase B and Hall 1, or its a mysterious software bug where the PWM of phase B gets output to hall 1, PB6.
To check the electrical connection, measure the resistance (or even better, use beep mode) using a multimeter between pins PA9 (phase B high) and Hall 1 and also PA12 (phase B low) and Hall 1. Either of these signals could be the culprit, since PA12 is the same PWM as PA9, just inverted, so from the looks of your oscilloscope, it is probably PA12.
You can check the pins directly on the MCU with a fine probe, or on the driver’s input pin, but I guess you already did this to get the green plot.
To check the software, lets see what’s going on:
PA12 is TIM1 channel 2N (inverted channel 2). PA9 is TIM1 channel 2 - neither of these channels is on PB6, and in fact TIM1 is not on PB6. So PB6 can’t really be outputting the PWM signal.
You code looks ok to me - I can’t see where PHASE_UL, PHASE_UH, etc are defined, but I assume they are correct? Could you check their definition to be sure?
As a comment regarding the initialisation, don’t use the ASCII float value 1.05 - it is rounded. While it could be exactly 1.05, maybe it is also 1.04555 - if possible, use the exact float value returned, or print it to 3 or 4 decimal places.
I am not sure if it helps, but the installation procedure described by Owen is not required anymore since his work is now part of the standard Arduino environment. Just select " ST B-G431B-ESC1 Discovery" as board type and everything should be set. However, note that you will have to rename the defines in your code to e.g. (note the A_!):
Since there is no electrical connection I guess it has to be a software problem. Either that or a broken STM32 chip.
While the definition files you link to look correct, perhaps there is a subtle incompatibility between these files and the official framework ones. Also because the framework has been through several upgrades since Owen created those original files.
So I agree with @Grizzly , first thing to do is to change the project to use the official board setup from the STM32 framework. If the problem still exists then, we look further into it.
I installed the library again following the procedure on the SimpleFOC website. I ran the code related to open loop velocity control and I noticed that the PWM signal seems to have disappeared. However I have not solved the problems related to closed loop voltage control because after the alignment the motor does not move.
There is something wrong but I don’t know what! After installing the library again, I printed the pins of A_PHASE_UL, A_PHASE_UH, etc and I noticed that A_PHASE_WL is 207 instead of 23. I tried to change this value but nothing changed. Moreover, during the alignment phase I always read the following messages on the monitor:
So I wrote in the function the value of the offset and the direction
and I printed the target and angle on the monitor. I always read as angle 0.0945 and the motor does not move for any voltage reference. By increasing the reference voltage value, the absorbed current increases but the motor does not move. I’m starting to think that the problem is in the alignment phase or the problem could be the motor or the sensor.