Iq and Id currents are not correct. what I'm doing wrong?

No it’s not same frequency.
You have 20 pole pairs.
So you will have 20 electrical revolutions for one mechanical revolution.

And there is an offset between the mechanical and electrical angle.

Maybe it looks like that because of the plot sample rate

yeah, could be the plot sample rate.

To avoid issues with the plot sample rate I took the electrical angle and the mechanical angle out using the DACs and this is what I get

In yellow and light blue are the dq currents, in red and green the opamp output on the phase A and phase B

Maybe I’ve found something weird on the 3 PWM of the micro

the light blue, red and green signal are the low gates… it’s normal the low side mosfet still active so much time? seems like the pwm is working at burst… but during the starting phase the pwm are continuous and not “burst mode”

It looks wrong.

What did you set as driver power supply voltage, driver voltage limit and motor voltage limit?

What do you mean by starting phase actually?

I set 25V to the driver voltage_power_supply
I set 8V to the driver voltage_limit
I set 8V to the motor voltage_limit

and I set 5A to the motor current limit

The system is set in voltage and torque mode

I mean the first part where the library is trying to find the zero electric angle, the number of pair poles…

Don’t set driver.voltage_limit, it will then be equal to driver.voltage_power_supply.
This will center the modulation

https://community.simplefoc.com/t/hoverboard-main-board-with-simplefoc/2610/47?u=candas1

Ok, now I’ve understood better how it works the driver voltage_limit

Now I’ve only to understand why the phase currents are not a sine with constant amplitude but they are “AM modulated”

There are some others settings that can create this result?

Can it be a problem on your hardware ?
[EDIT] Is the amplitude of phase current changing, or is the middle of the sinewave moving up and down ?
Maybe try sinusoidale modulation instead of SVPWM as a test.

I don’t know if could be an hw problem but I tested the current amplifier and the mcu with a constant current of 0.5A through the shunt and the mcu can read it correctly…

It’s the amplitude of the current that is changing.

The red and cyano signals are the phase current readed from the mcu and written out using two dac

I’ve tried with sinusoidale and I get the same result, seems like it’s something limiting the current or “oscillating”… Can be the angle sensor (AS5048) not perfectly aligned (centered) with the magnet?

I added the calibration and now the motor is spinning smoothly and no more vibrating. I’m trying the foc_current mode but I have some troubles with the PID, if I set in this way it seems working

motor->PID_current_q.P  = 0.5;
motor->PID_current_d.P  = 0.5;

motor->PID_current_q.I 	= 0.0;
motor->PID_current_d.I 	= 0.0;

motor->PID_current_q.D = 0.0;
motor->PID_current_d.D = 0.0;

motor->LPF_current_q.Tf = 0.0065;
motor->LPF_current_d.Tf = 0.0065;

motor->PID_current_q.limit = MOT_VOLT_LIMIT;
motor->PID_current_d.limit = MOT_VOLT_LIMIT;

motor->PID_current_q.output_ramp = 0.0;
motor->PID_current_d.output_ramp = 0.0;

motor->target = 5.0;

If I increase the I term the motor rise it speed uncontrollable. How can I tune this type of PID?

Which calibration? So the phase currents look better now?

The calibration for the encoder sensor and with the smoothing

Yes now the phase currents have the same amplitude, I tune the current PIDs in this way…

  1. I icrease P term until the motor (with target set to 5) start oscillating and then I go back to the last
    stable value
  2. I start raise the I term… and here I have the problems, also with 0.01 of I the motor start going crazy.

Not just offset calibration right? Was there some eccentricity?

Now I use calibration offset and the smoothing of the sensor… Yes there was some eccentricity. I have to keep testing it to be sure that the dq currents are dc…

I made all the parts with fusion 360 and I used the 3D model of the board to place the magnet in the center of the AS5048, but than I had to solder it by hand so here it comes the problem, it’s almost impossible to place the sensor in the right (perfect) position on the pcb by hand, so some eccentricity it will always occur.

Any advice for current PID tuning?