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.
The reason is because the library does not support high frequency pwm setting for the Arduino MEGA
The reason is mostly because I do not have a mega on my hands
I’d you are willing to do some experimenting I would like to use you as our test subject
The code is not too different from Arduino uno’s but some timer pins are different.
Would you be in for some testing?
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
We use max frequency 32kHz on all 3 timers of arudino uno and all 5 timers of Mega2560.
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 .
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 .
That does not sound good
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.
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