I would like to sense commutation sequence using encoder (1024 resolution) for bldc motor and if current state - previous state >= a then motor can move for other sequence but if encoder value change 0-1023 then I can't find the difference. For example if motor position in 10 encoder value and I controlled the motor to move other sequence and new value 1000 now 1000-10 is problem. What is best solution for it, I tried asin(sin(enc_val)) but still doesn't work well ?
Code: Select all
for(int8_t j=0;j<6;j++)
{
Set_DutyCycle(ccw_table[j],1000);
delay_ms(50);
}
for(int8_t j=5;j>=0;j--)
{
Set_DutyCycle(ccw_table[j],1000);
delay_ms(50);
}
delay_ms(500);
qdec_reset_position(&encConfig);
tut_u = qdec_get_position(&encConfig);
say = say+1;
Set_DutyCycle(ccw_table[say],500);
delay_ms(500);
pwm = 500;
volatile double test=0;
//in while(1)
deltaT = (180/PI)*Keep_Enc_Val_Rad();
if((fabs(deltaT - tut) >= thetaMechanicalRad-5))
{
tut = (180/PI)*Keep_Enc_Val_Rad();
say=say+1;
if(dir) Set_DutyCycle(cw_table[say],pwm);
if(!dir) Set_DutyCycle(ccw_table[say],pwm);
if(say==5) say = -1;
//delay_ms(10);
do
{
test = (180/PI)*Keep_Enc_Val_Rad();
}while( (fabs(test - tut) <= (thetaMechanicalRad-2)) );
}
double Keep_Enc_Val_Rad(void)
{
double deltaTheta=0;
uint16_t enc=0;
enc = Get_Position(&encConfig);
deltaTheta = (double)enc*ANGLE_RES_RAD;
deltaTheta = asin( sin(deltaTheta));
return deltaTheta;
}