Motor makes loud noise

Hi all!

A little while ago I came across SimpleFOC. So far I am pretty impressed by the library and its active community. I am curious what cool things will be achieved here in the near future!

My SimpleFoc shield recently came in and I made my first setup with it using an arduino Mega, an Emax GB4114 motor, and an AS5047P magnetic encoder. After hooking it all up, I tried some of the example code, which seems to work.

However, the motor makes a very loud noise. To test the setup for different control modes, I have tried the angle_contol, open_loop_velocity_example, and find_pole_pairs_number examples. They all resulted in the motor making a very loud noise. I also tried to adjust the driver.voltage_power_supply voltage and tried various power supplies, but that does not seem to solve the issue.

I have configured it as follows:

  • BLDCMotor motor = BLDCMotor( 11 );
  • BLDCDriver3PWM driver = BLDCDriver3PWM(9, 10, 11, 8);
  • Encoder encoder = Encoder(3, 2, 1000);
  • driver.voltage_power_supply = 12;

The following movie shows the setup while running the find_pole_pairs_number example.

What do you guys think could be the problem?

Hey @Jornel,

The reason is because the library does not support high frequency pwm setting for the Arduino MEGA :smiley:

The reason is mostly because I do not have a mega on my hands :smiley:

I’d you are willing to do some experimenting I would like to use you as our test subject :smiley:
The code is not too different from Arduino uno’s but some timer pins are different.
Would you be in for some testing?

Hi @Antun_Skuric,

Ah, that makes sense! I used the Mega, because I had laying it around. I am planning to use a Nucleo-64 F401RE in the near future.

For now I am definitely willing to do some testing with the Mega. If you tell me what to test, I will try to execute it.

I already tried some stuff myself my setting the pwm frequency of pin 9 10 and 11 to 31372.55 Hz using:
TCCR1B = TCCR1B & B11111000 | B00000001; // for PWM frequency of 31372.55 Hz on D11
TCCR2B = TCCR2B & B11111000 | B00000001; // for PWM frequency of 31372.55 Hz on D9 D10

This results in smooth operation. Which I don’t really get, as according to the documentation I found, this should also result in a pwm frequency of 31372.55 Hz on pin 9 10 11 on an Uno board (but then TCCR1B controls the D9 and D10 pwm freq. and TCCR2B controls the D11 pwm freq.). So how is the PWM frequency exactly set in the SimpleFOC library? And to which frequency? (haven’t had the time to look in the library itself)

Nevertheless, during the initialization the noises are still quite horrifying. So the pwm frequency might be too high now?

That’s basically the same thing what simplefoc does. Just the problem is that the arduino uno have different timers for different pwm pins so we need to adapt it.

I’ve added a proper support for the mega2560 from what I was able to find on the internet and from what I knew from arduino UNO. So it should more or less work well.

This might be because you added the pwm frequency initialisation lines after the motor init .
In any case this should not happen with the new code.

This is true, but I’ve included the compiler switches to avoid configuring stuff for different mcu. In your case it would actually work well, but this is just a lucky coincidence :smiley:
We use max frequency 32kHz on all 3 timers of arudino uno and all 5 timers of Mega2560.

Thanx @Antun_Skuric! I tried your changes and they gave the same result as writing to the registers in the setup() code.

Did fix a typo in generic_mcu.cpp though:
#elif #if defined(AVR_ATmega2560) // if mcu is not atmega2560
changed to
#elif defined(AVR_ATmega2560) // if mcu is not atmega2560

Nevertheless, still noisy at initialisation. I will make a new video this evening for you to hava a look at.

Thanks @Jornel!

Too fast typing :smiley:
I’ve added this to the dev branch.

This is very curios. Could you show us the code?
Make sure to do driver.init() before motor.init() and motor.initFOC().

I am not sure what else could it be.
Maybe there is something wrong with the shield :confused:

As promised, the movie:


However, after seeing this post The motor driver is very hot, I realised that my power supply might be the problem (can not provide enough current during initialization?) After changing to another power supply, the squeaky noise at initialization is almost gone. Seems like it’s time to invest in a proper lab supply :wink:.

For now, thanks a lot for the great help! I am planning on making a 3 DOF interactive robotic arm using SimpleFOC and gimbal motors. I will try to keep you guys updated and I will probably run into more issues :wink:.

Wow,

That does not sound good :smiley:
I am really not sure where does it come from, it could be the power supply. But I am not 100%.

You can try lowering the motor.voltage_sensor_align variable to somewhere under 3 volts for example. This will remove maybe the noise during the intialisation. (5 steps left + 5 steps right)
But this still does not make sense somehow, because you have a loud nose before the init. Before the init the driver should be disabled and no current should be drawn.

DId you maybe try to change the driver enable pin pin 7 or 8. It seems to me a bit like the driver enable is not pulled to 0 before the driver is initialized.

Basically the problem comes from the fact that the driver is separate circuit from the motor and each time the driver has power on it can start working. Arduino needs some time to initialise the pins. And during the time before arduino says that it will use pin 8 for example as enable pin and that it should be LOW on the begging to disable the driver (before initialization) the pin 8 is actually floating. It goes high and low randomly. And during that time the driver just randomly switches on and off (it thinks that the arduino sends him these commands).
To avoid this the shield has a pull-down resistor R2 which makes sure that when arduino pin is floating that the driver input is 0.
So maybe this resistor is badly soldered and it does not pull-down the motor?

Hmm interesting, I see your point. I will check if it is still the case that the motor draws current before it is initialised and will also check if pin 8 is pulled down properly. Can I just measure the resistance between pin 8 and gnd?

Below you can see the initialization as it is currently with the new power supply. There is still some squeaky noise, but it seems quite exceptable to me.

So I checked this and the soldering seems fine. However, one end of the resistor does not seem to be connected to ground. After diving in a bit further, I realised that there might be a problem with the pcb. @Antun_Skuric could it be that the plane as indicated below is not connected to ground (which it should I think)? This would indicate there is a mistake in the pcb layout. This would also result in the fact that C1 and C3 are also not connected to gnd.

1 Like

Yes, you are absolutely right!
There is a problem of my design, I have not seen this one. Thanks a lot for putting the time to investigate this.

I’m in the process of making a new board and anyone that will have problems due to this I’ll be happy to send the new board.

I am not sure why I did not see this during the testing!

The good news is that the boards actually work even with this error, the bad news is that the behaviour caused by my mistake could look completely random.
I’ll take steps to correct this error right away and I’ll need to order the new boards. Once when I have it, I’ll make sure to send you the replacements.

But in the mean time, the board should work more or less ok :smiley:

1 Like

Thanx for checking @Antun_Skuric!
I really appreciate it you sending me new boards when the are in. You should be able to find my address in the shipping details of my last order.

For the two I have now I will quickly fix them by soldering the indicated plane to gnd using a wire.

Ok, great!
I’ll send you the new ones as soon as I have them :smiley:

For anyone that has stumbled to the same problem, please do not hesitate to contact me directly.

Otherwise I’ve updated the Arduino-SimpleFOCShield repository to avoid this error!

The problem is caused by my error being that this area on the top of the pcb is not connected to the ground plane:
Untitled_missing
If you have a board and if you just want to make it to work, just scratch a bit the solder mask on this ground plane and the ground plane on a side and solder a wire in between them.
Untitled

This error is a bit stochastic and in many cases it will not cause big problems. But in some other cases it could produce errors that can seem completely random :smiley:

Just to give a short update: after soldering the wire, the little squeaky noise that was left at intialization is gone!:slight_smile:

Great thanks, I’m happy to hear that!
I’ve created a new thread for this issue.

1 Like