I have started to wokr on the stabilization of a single axes gimbal using an Arduino and a BLDC sensorless motor.
I've read many example about this topic, but I have a question about the usage of the sinusoidal PWM applied to the inverter bridge which drives the BLDC motor.
For instance, consider the generation of the sinusoidal PWM as follows
sineSize = 1024;
sineScale = 32767;
int sinTable[1024];
for (int i = 0; i < sineSize ; i++)
{
float x = i * (2*pi)/1024;
sinTable[i] = round(sin(x) * 32767);
}
I am using a simple (and dummy) P controller which gets the shaft orientation (roll angle) of the motor from an IMU as follows
setpoint = 0; // degrees
float error = setpoint + rollAngle;
Pout = Kp * error;
And I am calculating the values which should be applied to the PWM inputs of my inverter bridge (L6234 from ST) in order to stabilize the motor to the setpoint when the axis moves
// 180 : Maximum value which the IMU returns (+/- 180 angles)
// 1024 : Dimension of the sin(.) array
// 255 : Maximum value accepted from Arduino analogWrite(.,.)
int offset= round(Pout / 180 * 1024);
int pwm[3];
// Forcing offset into array range
offset = offset % 1024;
if (offset < 0)
offset = 1024 + offset;
uint16_t pwr= 5 * power;
index = offset % 1024;
// Evaluating PWM value based on the sin(.) look up table values
pwm[0] = (sinTable[index]*pwr + (32767/2))/32767 + (255/2);
index = (offset + (1024/3)) % 1024;
// Evaluating PWM value based on the sin(.) look up table values
pwm[1] = (sinTable[index]*pwr + (32767/2))/32767 + (255/2);
index = (offset + ((2 * 1024) / 3)) % 1024;
// Evaluating PWM value based on the sin(.) look up table values
pwm[2] = (sinTable[index]*pwr + (32767/2))/32767 + (255/2);
The all the PWM are applied to the IN pins of my inverter bridge, in order to spin it.
There is a point I really don't understand, when pwr is high the BLDC motor takes currents like 0.8 A at 12 V. The BLDC motor used can be found here (http ://www.dys.hk/ProductShow.asp?ID=109), but there isn't a detailed datasheet.
(sinTable[index]*pwr + (32767/2))/32767 + (255/2)
- What does sinTable[index] * pwr mean, in terms of power?
- Could you explain the relation between the controller output and the index used in the sin(.) array? (I mean what is the logical relation between the Pout and the index used for choosing the discrete value of the PWM in the sinTable vector).
The code is base on a project which can be found on GitHub, namely EvvGC